blob: ffc67e264d38ae91060fef557e35563b0031af44 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000020import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080021import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Hall Liud892bec2018-11-30 14:51:45 -080022
Shuo Qianccbaf742021-02-22 18:32:21 -080023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
24import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070025import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000027import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070028
Brad Ebinger34c09a52021-02-17 23:23:21 +000029import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080030import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080031import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070032import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000033import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070034import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080035import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070036import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000037import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080038import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000039import android.compat.annotation.ChangeId;
40import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070041import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070042import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.content.Context;
44import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070045import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070046import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070047import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.net.Uri;
49import android.os.AsyncResult;
50import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080051import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.Bundle;
53import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070054import android.os.IBinder;
tom hsu0b59d292022-09-29 23:49:21 +080055import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.Looper;
57import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070058import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080059import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070060import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070061import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080062import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080063import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070064import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070065import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080066import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070068import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070069import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070070import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070071import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080072import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070073import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090074import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080075import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080076import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070077import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080078import android.telephony.AccessNetworkConstants;
79import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070080import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070081import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080082import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070083import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080084import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070085import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080086import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060087import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -070088import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080089import android.telephony.CellIdentityCdma;
90import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070092import android.telephony.CellInfoGsm;
93import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070094import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080095import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070096import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070097import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070098import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080099import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700100import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800101import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700102import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800103import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800104import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700105import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800106import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700107import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800108import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800109import android.telephony.SignalStrengthUpdateRequest;
110import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800111import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800112import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800113import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700114import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700115import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800116import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800117import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800118import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800119import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000120import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000121import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000122import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700123import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700124import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800125import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800126import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700127import android.telephony.gba.GbaAuthRequest;
128import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700129import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800130import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000131import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000132import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700133import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000134import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700135import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800136import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700137import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800138import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700139import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000140import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700141import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800142import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800143import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800145import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700146import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700147import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800148import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800149
Andrew Lee312e8172014-10-23 17:01:36 -0700150import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800151import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800152import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800153import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800154import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700155import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700156import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700157import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800158import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800159import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700160import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700161import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800162import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700163import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800164import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800165import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800166import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700167import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000168import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700169import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800170import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800172import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800173import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800174import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700175import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700176import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700177import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700179import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800180import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700181import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700182import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700183import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700184import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800185import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800186import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700187import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000188import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700189import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700190import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800191import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800192import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800193import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700194import com.android.internal.telephony.data.DataUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800195import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700196import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800197import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700198import com.android.internal.telephony.imsphone.ImsPhone;
199import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000200import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800201import com.android.internal.telephony.metrics.TelephonyMetrics;
Jack Yu285100e2022-12-02 22:48:35 -0800202import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
203import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700204import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700205import com.android.internal.telephony.uicc.IccIoResult;
206import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800207import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700208import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800209import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700210import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000211import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800212import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000213import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800214import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000215import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700216import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700217import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800218import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800219import com.android.phone.callcomposer.CallComposerPictureManager;
220import com.android.phone.callcomposer.CallComposerPictureTransfer;
221import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700222import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700223import com.android.phone.slice.SlicePurchaseController;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700224import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800225import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700226import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700227import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800228import com.android.services.telephony.TelecomAccountRegistry;
229import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800230import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800231
Hall Liu82694d52020-12-11 18:22:04 -0800232import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700233import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800234import java.io.IOException;
235import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700236import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700237import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800238import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000239import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800240import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800241import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800242import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800243import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100244import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800245import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700246import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800247import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800248import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700249import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800250import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800251import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800252import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253
254/**
255 * Implementation of the ITelephony interface.
256 */
Santos Cordon117fee72014-05-16 17:56:12 -0700257public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258 private static final String LOG_TAG = "PhoneInterfaceManager";
259 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
260 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800261 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700262
263 // Message codes used with mMainThreadHandler
264 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700265 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
266 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700267 private static final int CMD_OPEN_CHANNEL = 9;
268 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
269 private static final int CMD_CLOSE_CHANNEL = 11;
270 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800271 private static final int CMD_NV_READ_ITEM = 13;
272 private static final int EVENT_NV_READ_ITEM_DONE = 14;
273 private static final int CMD_NV_WRITE_ITEM = 15;
274 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
275 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
276 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700277 private static final int CMD_RESET_MODEM_CONFIG = 19;
278 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800279 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
280 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800281 private static final int CMD_SEND_ENVELOPE = 25;
282 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000283 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
284 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700285 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
286 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
287 private static final int CMD_EXCHANGE_SIM_IO = 31;
288 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800289 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
290 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700291 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
292 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700293 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
294 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700295 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
296 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
297 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
298 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700299 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
300 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
301 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
302 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700303 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800304 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
305 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000306 private static final int CMD_SWITCH_SLOTS = 50;
307 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700308 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
309 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
310 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
311 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
312 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
313 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
314 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
315 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700316 private static final int CMD_GET_ALL_CELL_INFO = 60;
317 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
318 private static final int CMD_GET_CELL_LOCATION = 62;
319 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700320 private static final int CMD_MODEM_REBOOT = 64;
321 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700322 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
323 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800324 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
325 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700326 private static final int CMD_GET_MODEM_STATUS = 70;
327 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700328 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
329 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700330 private static final int CMD_ERASE_MODEM_CONFIG = 74;
331 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800332 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
333 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
334 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
335 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800336 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
337 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800338 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800339 private static final int CMD_GET_CALL_FORWARDING = 83;
340 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
341 private static final int CMD_SET_CALL_FORWARDING = 85;
342 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
343 private static final int CMD_GET_CALL_WAITING = 87;
344 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
345 private static final int CMD_SET_CALL_WAITING = 89;
346 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700347 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
348 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
349 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
350 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700351 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
352 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800353 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
354 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800355 private static final int CMD_SET_DATA_THROTTLING = 99;
356 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800357 private static final int CMD_SET_SIM_POWER = 101;
358 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800359 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
360 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
361 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
362 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800363 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
364 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000365 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800366 private static final int CMD_GET_SLICING_CONFIG = 110;
367 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800368 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700369 private static final int CMD_ENABLE_VONR = 113;
370 private static final int EVENT_ENABLE_VONR_DONE = 114;
371 private static final int CMD_IS_VONR_ENABLED = 115;
372 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700373 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
374 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700375
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800376 // Parameters of select command.
377 private static final int SELECT_COMMAND = 0xA4;
378 private static final int SELECT_P1 = 0x04;
379 private static final int SELECT_P2 = 0;
380 private static final int SELECT_P3 = 0x10;
381
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000382 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
383 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
384
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385 /** The singleton instance. */
386 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800387 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388
Wink Saville3ab207e2014-11-20 13:07:20 -0800389 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800390 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800391 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700392 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800393 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700394 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800395 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800396 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800397 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700398 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800399 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Gil Cukierman6dac5eb2022-09-19 16:09:04 +0000400 private final Telephony2gUpdater mTelephony2gUpdater;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401
Peter Wangdafb9ac2020-01-15 14:13:38 -0800402 /** User Activity */
403 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800404 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
405
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700406 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
407
Derek Tan97ebb422014-09-05 16:55:38 -0700408 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
409 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800410 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800411 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700412
Michelecea4cf22018-12-21 15:00:11 -0800413 // String to store multi SIM allowed
414 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
415
Derek Tan740e1672017-06-27 14:56:27 -0700416 // The AID of ISD-R.
417 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
418
yinxub1bed742017-04-17 11:45:04 -0700419 private NetworkScanRequestTracker mNetworkScanRequestTracker;
420
David Kelly5e06a7f2018-03-12 14:10:59 +0000421 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
422 private static final int MANUFACTURER_CODE_LENGTH = 8;
423
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800424 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800425 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800426
Sarah Chin2ec39f62022-08-31 17:03:26 -0700427 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
428 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
429
Derek Tan89e89d42014-07-08 17:00:10 -0700430 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700431 * Experiment flag to enable erase modem config on reset network, default value is false
432 */
433 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
434 "reset_network_erase_modem_config_enabled";
435
Rambo Wang0f050d82021-02-12 11:43:36 -0800436 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800437
sandeepjsb6c87872021-09-27 15:34:44 +0000438 /**
439 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
440 * one ICCID active at the same time.
441 * Apps should use below API signatures if targeting SDK is T and beyond.
442 *
443 * @hide
444 */
445 @ChangeId
446 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
447 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800448
Naina Nallurid63128d2019-09-17 14:10:30 -0700449 /**
Chen Xu540470b2021-12-14 17:15:47 -0800450 * Apps targeting on Android T and beyond will get exception whenever icc close channel
451 * operation fails.
452 */
453 @ChangeId
454 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
455 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
456
457 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700458 * A request object to use for transmitting data to an ICC.
459 */
460 private static final class IccAPDUArgument {
461 public int channel, cla, command, p1, p2, p3;
462 public String data;
463
464 public IccAPDUArgument(int channel, int cla, int command,
465 int p1, int p2, int p3, String data) {
466 this.channel = channel;
467 this.cla = cla;
468 this.command = command;
469 this.p1 = p1;
470 this.p2 = p2;
471 this.p3 = p3;
472 this.data = data;
473 }
474 }
475
476 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700477 * A request object to use for transmitting data to an ICC.
478 */
479 private static final class ManualNetworkSelectionArgument {
480 public OperatorInfo operatorInfo;
481 public boolean persistSelection;
482
483 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
484 this.operatorInfo = operatorInfo;
485 this.persistSelection = persistSelection;
486 }
487 }
488
Sarah Chin71b3a852022-09-28 15:54:19 -0700489 private static final class PurchasePremiumCapabilityArgument {
490 public @TelephonyManager.PremiumCapability int capability;
491 public @NonNull String appName;
492 public @NonNull IIntegerConsumer callback;
493
494 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
495 @NonNull String appName, @NonNull IIntegerConsumer callback) {
496 this.capability = capability;
497 this.appName = appName;
498 this.callback = callback;
499 }
500 }
501
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700502 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700503 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
504 * request after sending. The main thread will notify the request when it is complete.
505 */
506 private static final class MainThreadRequest {
507 /** The argument to use for the request */
508 public Object argument;
509 /** The result of the request that is run on the main thread */
510 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800511 // The subscriber id that this request applies to. Defaults to
512 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
513 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700514
Nathan Harold92bed182018-10-12 18:16:49 -0700515 // In cases where subId is unavailable, the caller needs to specify the phone.
516 public Phone phone;
517
vagdeviaf9a5b92018-08-15 16:01:53 -0700518 public WorkSource workSource;
519
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700520 public MainThreadRequest(Object argument) {
521 this.argument = argument;
522 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800523
Nathan Harold92bed182018-10-12 18:16:49 -0700524 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
525 this.argument = argument;
526 if (phone != null) {
527 this.phone = phone;
528 }
529 this.workSource = workSource;
530 }
531
vagdeviaf9a5b92018-08-15 16:01:53 -0700532 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800533 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800534 if (subId != null) {
535 this.subId = subId;
536 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700537 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800538 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700539 }
540
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800541 private static final class IncomingThirdPartyCallArgs {
542 public final ComponentName component;
543 public final String callId;
544 public final String callerDisplayName;
545
546 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
547 String callerDisplayName) {
548 this.component = component;
549 this.callId = callId;
550 this.callerDisplayName = callerDisplayName;
551 }
552 }
553
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700554 /**
555 * A handler that processes messages on the main thread in the phone process. Since many
556 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
557 * inbound binder threads to the main thread in the phone process. The Binder thread
558 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
559 * on, which will be notified when the operation completes and will contain the result of the
560 * request.
561 *
562 * <p>If a MainThreadRequest object is provided in the msg.obj field,
563 * note that request.result must be set to something non-null for the calling thread to
564 * unblock.
565 */
566 private final class MainThreadHandler extends Handler {
567 @Override
568 public void handleMessage(Message msg) {
569 MainThreadRequest request;
570 Message onCompleted;
571 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000572 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800574 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700575
576 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700577 case CMD_HANDLE_USSD_REQUEST: {
578 request = (MainThreadRequest) msg.obj;
579 final Phone phone = getPhoneFromRequest(request);
580 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800581 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700582 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700583
Pengquan Menga1bb6272018-09-06 09:59:22 -0700584 if (!isUssdApiAllowed(request.subId)) {
585 // Carrier does not support use of this API, return failure.
586 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
587 UssdResponse response = new UssdResponse(ussdRequest, null);
588 Bundle returnData = new Bundle();
589 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
590 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700591
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 request.result = true;
593 notifyRequester(request);
594 return;
595 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700596
Pengquan Menga1bb6272018-09-06 09:59:22 -0700597 try {
598 request.result = phone != null
599 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
600 } catch (CallStateException cse) {
601 request.result = false;
602 }
603 // Wake up the requesting thread
604 notifyRequester(request);
605 break;
pkanwar32d516d2016-10-14 19:37:38 -0700606 }
607
Yorke Lee716f67e2015-06-17 15:39:16 -0700608 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700609 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700610 final Phone phone = getPhoneFromRequest(request);
611 request.result = phone != null ?
612 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
613 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700614 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700615 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700616 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700617 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700618
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700619 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000622 uiccPort = getUiccPortFromRequest(request);
623 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700624 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800625 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700626 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700627 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700628 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800629 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000630 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800631 iccArgument.channel, iccArgument.cla, iccArgument.command,
632 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
633 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700634 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 break;
636
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700637 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 ar = (AsyncResult) msg.obj;
639 request = (MainThreadRequest) ar.userObj;
640 if (ar.exception == null && ar.result != null) {
641 request.result = ar.result;
642 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800643 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 if (ar.result == null) {
645 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800646 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800648 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 } else {
650 loge("iccTransmitApduLogicalChannel: Unknown exception");
651 }
652 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700653 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 break;
655
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700656 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
657 request = (MainThreadRequest) msg.obj;
658 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000659 uiccPort = getUiccPortFromRequest(request);
660 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700661 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800662 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700663 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700664 } else {
665 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800666 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000667 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800668 iccArgument.cla, iccArgument.command, iccArgument.p1,
669 iccArgument.p2,
670 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700671 }
672 break;
673
674 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
675 ar = (AsyncResult) msg.obj;
676 request = (MainThreadRequest) ar.userObj;
677 if (ar.exception == null && ar.result != null) {
678 request.result = ar.result;
679 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800680 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700681 if (ar.result == null) {
682 loge("iccTransmitApduBasicChannel: Empty response");
683 } else if (ar.exception instanceof CommandException) {
684 loge("iccTransmitApduBasicChannel: CommandException: " +
685 ar.exception);
686 } else {
687 loge("iccTransmitApduBasicChannel: Unknown exception");
688 }
689 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700690 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700691 break;
692
693 case CMD_EXCHANGE_SIM_IO:
694 request = (MainThreadRequest) msg.obj;
695 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000696 uiccPort = getUiccPortFromRequest(request);
697 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700698 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800699 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700700 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700701 } else {
702 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
703 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000704 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700705 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
706 iccArgument.data, onCompleted);
707 }
708 break;
709
710 case EVENT_EXCHANGE_SIM_IO_DONE:
711 ar = (AsyncResult) msg.obj;
712 request = (MainThreadRequest) ar.userObj;
713 if (ar.exception == null && ar.result != null) {
714 request.result = ar.result;
715 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800716 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700717 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700718 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700719 break;
720
Derek Tan4d5e5c12014-02-04 11:54:58 -0800721 case CMD_SEND_ENVELOPE:
722 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000723 uiccPort = getUiccPortFromRequest(request);
724 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700725 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800726 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700727 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700728 } else {
729 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800730 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700731 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800732 break;
733
734 case EVENT_SEND_ENVELOPE_DONE:
735 ar = (AsyncResult) msg.obj;
736 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700737 if (ar.exception == null && ar.result != null) {
738 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800739 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800740 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700741 if (ar.result == null) {
742 loge("sendEnvelopeWithStatus: Empty response");
743 } else if (ar.exception instanceof CommandException) {
744 loge("sendEnvelopeWithStatus: CommandException: " +
745 ar.exception);
746 } else {
747 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
748 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800749 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700750 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800751 break;
752
Shishir Agrawal566b7612013-10-28 14:41:00 -0700753 case CMD_OPEN_CHANNEL:
754 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000755 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800756 IccLogicalChannelRequest openChannelRequest =
757 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000758 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700759 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800760 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800761 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700762 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700763 } else {
764 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800765 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
766 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700767 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700768 break;
769
770 case EVENT_OPEN_CHANNEL_DONE:
771 ar = (AsyncResult) msg.obj;
772 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700773 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700774 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700775 int[] result = (int[]) ar.result;
776 int channelId = result[0];
777 byte[] selectResponse = null;
778 if (result.length > 1) {
779 selectResponse = new byte[result.length - 1];
780 for (int i = 1; i < result.length; ++i) {
781 selectResponse[i - 1] = (byte) result[i];
782 }
783 }
784 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800785 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800786
787 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700788 if (uiccPort == null) {
789 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
790 } else {
791 IccLogicalChannelRequest channelRequest =
792 (IccLogicalChannelRequest) request.argument;
793 channelRequest.channel = channelId;
794 uiccPort.onLogicalChannelOpened(channelRequest);
795 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700796 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700797 if (ar.result == null) {
798 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700799 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700800 if (ar.exception != null) {
801 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
802 }
803
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700804 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700805 if (ar.exception instanceof CommandException) {
806 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800807 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700808 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700809 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700810 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700811 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700812 }
813 }
814 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800815 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700816 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700817 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700818 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700819 break;
820
821 case CMD_CLOSE_CHANNEL:
822 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000823 uiccPort = getUiccPortFromRequest(request);
824 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700825 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800826 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800827 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800828 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700829 } else {
830 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000831 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700832 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700833 break;
834
835 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800836 ar = (AsyncResult) msg.obj;
837 request = (MainThreadRequest) ar.userObj;
838 if (ar.exception == null) {
839 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800840 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700841 if (uiccPort == null) {
842 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
843 } else {
844 final int channelId = (Integer) request.argument;
845 uiccPort.onLogicalChannelClosed(channelId);
846 }
Chen Xu540470b2021-12-14 17:15:47 -0800847 } else {
848 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800849 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800850 if (ar.exception instanceof CommandException) {
851 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
852 CommandException.Error error =
853 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800854 if (error == CommandException.Error.INVALID_ARGUMENTS) {
855 // should only throw exceptions from the binder threads.
856 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800857 "iccCloseLogicalChannel: invalid argument ");
858 }
859 } else {
860 loge("iccCloseLogicalChannel: Unknown exception");
861 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800862 request.result = (exception != null) ? exception :
863 new IllegalStateException(
864 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800865 }
866 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800867 break;
868
869 case CMD_NV_READ_ITEM:
870 request = (MainThreadRequest) msg.obj;
871 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800872 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
873 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800874 break;
875
876 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700877 ar = (AsyncResult) msg.obj;
878 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800879 if (ar.exception == null && ar.result != null) {
880 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700881 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800882 request.result = "";
883 if (ar.result == null) {
884 loge("nvReadItem: Empty response");
885 } else if (ar.exception instanceof CommandException) {
886 loge("nvReadItem: CommandException: " +
887 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700888 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800889 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700890 }
891 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700892 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700893 break;
894
Jake Hambye994d462014-02-03 13:10:13 -0800895 case CMD_NV_WRITE_ITEM:
896 request = (MainThreadRequest) msg.obj;
897 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
898 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800899 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700900 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800901 break;
902
903 case EVENT_NV_WRITE_ITEM_DONE:
904 handleNullReturnEvent(msg, "nvWriteItem");
905 break;
906
907 case CMD_NV_WRITE_CDMA_PRL:
908 request = (MainThreadRequest) msg.obj;
909 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800910 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800911 break;
912
913 case EVENT_NV_WRITE_CDMA_PRL_DONE:
914 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
915 break;
916
chen xu6dac5ab2018-10-26 17:39:23 -0700917 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800918 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700919 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800920 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800921 break;
922
chen xu6dac5ab2018-10-26 17:39:23 -0700923 case EVENT_RESET_MODEM_CONFIG_DONE:
924 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800925 break;
926
Sooraj Sasindran37444802020-08-11 10:40:43 -0700927 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
928 request = (MainThreadRequest) msg.obj;
929 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
930 request);
931 Phone phone = getPhoneFromRequest(request);
932 if (phone != null) {
933 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
934 } else {
935 loge("isNRDualConnectivityEnabled: No phone object");
936 request.result = false;
937 notifyRequester(request);
938 }
939 break;
940 }
941
942 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
943 ar = (AsyncResult) msg.obj;
944 request = (MainThreadRequest) ar.userObj;
945 if (ar.exception == null && ar.result != null) {
946 request.result = ar.result;
947 } else {
948 // request.result must be set to something non-null
949 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700950 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700951 request.result = ar.result;
952 } else {
953 request.result = false;
954 }
955 if (ar.result == null) {
956 loge("isNRDualConnectivityEnabled: Empty response");
957 } else if (ar.exception instanceof CommandException) {
958 loge("isNRDualConnectivityEnabled: CommandException: "
959 + ar.exception);
960 } else {
961 loge("isNRDualConnectivityEnabled: Unknown exception");
962 }
963 }
964 notifyRequester(request);
965 break;
966
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700967 case CMD_IS_VONR_ENABLED: {
968 request = (MainThreadRequest) msg.obj;
969 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
970 request);
971 Phone phone = getPhoneFromRequest(request);
972 if (phone != null) {
973 phone.isVoNrEnabled(onCompleted, request.workSource);
974 } else {
975 loge("isVoNrEnabled: No phone object");
976 request.result = false;
977 notifyRequester(request);
978 }
979 break;
980 }
981
982 case EVENT_IS_VONR_ENABLED_DONE:
983 ar = (AsyncResult) msg.obj;
984 request = (MainThreadRequest) ar.userObj;
985 if (ar.exception == null && ar.result != null) {
986 request.result = ar.result;
987 } else {
988 // request.result must be set to something non-null
989 // for the calling thread to unblock
990 if (ar.result != null) {
991 request.result = ar.result;
992 } else {
993 request.result = false;
994 }
995 if (ar.result == null) {
996 loge("isVoNrEnabled: Empty response");
997 } else if (ar.exception instanceof CommandException) {
998 loge("isVoNrEnabled: CommandException: "
999 + ar.exception);
1000 } else {
1001 loge("isVoNrEnabled: Unknown exception");
1002 }
1003 }
1004 notifyRequester(request);
1005 break;
1006
Sooraj Sasindran37444802020-08-11 10:40:43 -07001007 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1008 request = (MainThreadRequest) msg.obj;
1009 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1010 Phone phone = getPhoneFromRequest(request);
1011 if (phone != null) {
1012 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1013 request.workSource);
1014 } else {
1015 loge("enableNrDualConnectivity: No phone object");
1016 request.result =
1017 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1018 notifyRequester(request);
1019 }
1020 break;
1021 }
1022
1023 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1024 ar = (AsyncResult) msg.obj;
1025 request = (MainThreadRequest) ar.userObj;
1026 if (ar.exception == null) {
1027 request.result =
1028 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1029 } else {
1030 request.result =
1031 TelephonyManager
1032 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1033 if (ar.exception instanceof CommandException) {
1034 CommandException.Error error =
1035 ((CommandException) (ar.exception)).getCommandError();
1036 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1037 request.result =
1038 TelephonyManager
1039 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001040 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1041 request.result =
1042 TelephonyManager
1043 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001044 }
1045 loge("enableNrDualConnectivity" + ": CommandException: "
1046 + ar.exception);
1047 } else {
1048 loge("enableNrDualConnectivity" + ": Unknown exception");
1049 }
1050 }
1051 notifyRequester(request);
1052 break;
1053 }
1054
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001055 case CMD_ENABLE_VONR: {
1056 request = (MainThreadRequest) msg.obj;
1057 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1058 Phone phone = getPhoneFromRequest(request);
1059 if (phone != null) {
1060 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1061 request.workSource);
1062 } else {
1063 loge("setVoNrEnabled: No phone object");
1064 request.result =
1065 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1066 notifyRequester(request);
1067 }
1068 break;
1069 }
1070
1071 case EVENT_ENABLE_VONR_DONE: {
1072 ar = (AsyncResult) msg.obj;
1073 request = (MainThreadRequest) ar.userObj;
1074 if (ar.exception == null) {
1075 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1076 } else {
1077 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1078 if (ar.exception instanceof CommandException) {
1079 CommandException.Error error =
1080 ((CommandException) (ar.exception)).getCommandError();
1081 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1082 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1083 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1084 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1085 } else {
1086 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1087 }
1088 loge("setVoNrEnabled" + ": CommandException: "
1089 + ar.exception);
1090 } else {
1091 loge("setVoNrEnabled" + ": Unknown exception");
1092 }
1093 }
1094 notifyRequester(request);
1095 break;
1096 }
1097
SongFerngWang3ef3e072020-12-21 16:41:52 +08001098 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001099 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001100 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1101 request);
1102 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001103 break;
1104
SongFerngWang3ef3e072020-12-21 16:41:52 +08001105 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001106 ar = (AsyncResult) msg.obj;
1107 request = (MainThreadRequest) ar.userObj;
1108 if (ar.exception == null && ar.result != null) {
1109 request.result = ar.result; // Integer
1110 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301111 // request.result must be set to something non-null
1112 // for the calling thread to unblock
1113 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001114 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001115 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001116 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001117 loge("getAllowedNetworkTypesBitmask: CommandException: "
1118 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001119 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001120 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001121 }
1122 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001123 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001124 break;
1125
SongFerngWang3ef3e072020-12-21 16:41:52 +08001126 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001127 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001128 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1129 request);
1130 Pair<Integer, Long> reasonWithNetworkTypes =
1131 (Pair<Integer, Long>) request.argument;
1132 getPhoneFromRequest(request).setAllowedNetworkTypes(
1133 reasonWithNetworkTypes.first,
1134 reasonWithNetworkTypes.second,
1135 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001136 break;
1137
SongFerngWang3ef3e072020-12-21 16:41:52 +08001138 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1139 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001140 break;
1141
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001142 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1143 request = (MainThreadRequest)msg.obj;
1144 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001145 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001146 break;
1147
1148 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1149 ar = (AsyncResult)msg.obj;
1150 request = (MainThreadRequest)ar.userObj;
1151 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001152 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001153 break;
1154
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001155 case CMD_SET_VOICEMAIL_NUMBER:
1156 request = (MainThreadRequest) msg.obj;
1157 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1158 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001159 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1160 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001161 break;
1162
1163 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1164 handleNullReturnEvent(msg, "setVoicemailNumber");
1165 break;
1166
Stuart Scott54788802015-03-30 13:18:01 -07001167 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1168 request = (MainThreadRequest) msg.obj;
1169 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1170 request);
1171 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1172 break;
1173
1174 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1175 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1176 break;
1177
Shishir Agrawal302c8692015-06-19 13:49:39 -07001178 case CMD_PERFORM_NETWORK_SCAN:
1179 request = (MainThreadRequest) msg.obj;
1180 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1181 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1182 break;
1183
Hall Liu27d24262020-09-18 19:04:59 -07001184 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001185 request = (MainThreadRequest) msg.obj;
1186 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001187 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1188 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1189 request.argument;
1190 int callForwardingReason = args.first;
1191 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001192 break;
Hall Liu27d24262020-09-18 19:04:59 -07001193 }
1194 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001195 ar = (AsyncResult) msg.obj;
1196 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001197 TelephonyManager.CallForwardingInfoCallback callback =
1198 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1199 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001200 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001201 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001202 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1203 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1204 // Service Class is a bit mask per 3gpp 27.007. Search for
1205 // any service for voice call.
1206 if ((callForwardInfo.serviceClass
1207 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001208 callForwardingInfo = new CallForwardingInfo(
1209 callForwardInfo.status
1210 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001211 callForwardInfo.reason,
1212 callForwardInfo.number,
1213 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001214 break;
1215 }
1216 }
1217 // Didn't find a call forward info for voice call.
1218 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001219 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1220 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001221 }
Hall Liu27d24262020-09-18 19:04:59 -07001222 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001223 } else {
1224 if (ar.result == null) {
1225 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1226 }
1227 if (ar.exception != null) {
1228 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1229 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001230 int errorCode = TelephonyManager
1231 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001232 if (ar.exception instanceof CommandException) {
1233 CommandException.Error error =
1234 ((CommandException) (ar.exception)).getCommandError();
1235 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001236 errorCode = TelephonyManager
1237 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001238 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001239 errorCode = TelephonyManager
1240 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001241 }
1242 }
Hall Liu27d24262020-09-18 19:04:59 -07001243 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001244 }
Shuo Qian4a594052020-01-23 11:59:30 -08001245 break;
Hall Liu27d24262020-09-18 19:04:59 -07001246 }
Shuo Qian4a594052020-01-23 11:59:30 -08001247
Hall Liu27d24262020-09-18 19:04:59 -07001248 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001249 request = (MainThreadRequest) msg.obj;
1250 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001251 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001252 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001253 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1254 request.argument).first;
1255 request.phone.setCallForwardingOption(
1256 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001257 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001258 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001259 callForwardingInfoToSet.getReason(),
1260 callForwardingInfoToSet.getNumber(),
1261 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1262 break;
Hall Liu27d24262020-09-18 19:04:59 -07001263 }
Shuo Qian4a594052020-01-23 11:59:30 -08001264
Hall Liu27d24262020-09-18 19:04:59 -07001265 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001266 ar = (AsyncResult) msg.obj;
1267 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001268 Consumer<Integer> callback =
1269 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1270 request.argument).second;
1271 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001272 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001273 int errorCode = TelephonyManager.CallForwardingInfoCallback
1274 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001275 if (ar.exception instanceof CommandException) {
1276 CommandException.Error error =
1277 ((CommandException) (ar.exception)).getCommandError();
1278 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001279 errorCode = TelephonyManager.CallForwardingInfoCallback
1280 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001281 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001282 errorCode = TelephonyManager.CallForwardingInfoCallback
1283 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001284 }
1285 }
1286 callback.accept(errorCode);
1287 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001288 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001289 }
Shuo Qian4a594052020-01-23 11:59:30 -08001290 break;
Hall Liu27d24262020-09-18 19:04:59 -07001291 }
Shuo Qian4a594052020-01-23 11:59:30 -08001292
Hall Liu27d24262020-09-18 19:04:59 -07001293 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001294 request = (MainThreadRequest) msg.obj;
1295 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1296 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1297 break;
Hall Liu27d24262020-09-18 19:04:59 -07001298 }
Shuo Qian4a594052020-01-23 11:59:30 -08001299
Hall Liu27d24262020-09-18 19:04:59 -07001300 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001301 ar = (AsyncResult) msg.obj;
1302 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001303 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001304 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001305 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001306 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001307 // Service Class is a bit mask per 3gpp 27.007.
1308 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001309 if (callForwardResults.length > 1
1310 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001311 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001312 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001313 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1314 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001315 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001316 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001317 }
1318 } else {
1319 if (ar.result == null) {
1320 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1321 }
1322 if (ar.exception != null) {
1323 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1324 }
1325 if (ar.exception instanceof CommandException) {
1326 CommandException.Error error =
1327 ((CommandException) (ar.exception)).getCommandError();
1328 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001329 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001330 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001331 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1332 callWaitingStatus =
1333 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001334 }
1335 }
1336 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001337 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001338 break;
Hall Liu27d24262020-09-18 19:04:59 -07001339 }
Shuo Qian4a594052020-01-23 11:59:30 -08001340
Hall Liu27d24262020-09-18 19:04:59 -07001341 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001342 request = (MainThreadRequest) msg.obj;
1343 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001344 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1345 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001346 break;
Hall Liu27d24262020-09-18 19:04:59 -07001347 }
Shuo Qian4a594052020-01-23 11:59:30 -08001348
Hall Liu27d24262020-09-18 19:04:59 -07001349 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001350 ar = (AsyncResult) msg.obj;
1351 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001352 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1353 Consumer<Integer> callback =
1354 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1355 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001356 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001357 if (ar.exception instanceof CommandException) {
1358 CommandException.Error error =
1359 ((CommandException) (ar.exception)).getCommandError();
1360 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1361 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001362 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1363 callback.accept(
1364 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001365 } else {
1366 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1367 }
1368 } else {
1369 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1370 }
1371 } else {
1372 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1373 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001374 }
Shuo Qian4a594052020-01-23 11:59:30 -08001375 break;
Hall Liu27d24262020-09-18 19:04:59 -07001376 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001377 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1378 ar = (AsyncResult) msg.obj;
1379 request = (MainThreadRequest) ar.userObj;
1380 CellNetworkScanResult cellScanResult;
1381 if (ar.exception == null && ar.result != null) {
1382 cellScanResult = new CellNetworkScanResult(
1383 CellNetworkScanResult.STATUS_SUCCESS,
1384 (List<OperatorInfo>) ar.result);
1385 } else {
1386 if (ar.result == null) {
1387 loge("getCellNetworkScanResults: Empty response");
1388 }
1389 if (ar.exception != null) {
1390 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1391 }
1392 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1393 if (ar.exception instanceof CommandException) {
1394 CommandException.Error error =
1395 ((CommandException) (ar.exception)).getCommandError();
1396 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1397 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1398 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1399 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1400 }
1401 }
1402 cellScanResult = new CellNetworkScanResult(errorCode, null);
1403 }
1404 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001405 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001406 break;
1407
1408 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1409 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001410 ManualNetworkSelectionArgument selArg =
1411 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001412 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1413 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001414 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1415 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001416 break;
1417
1418 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001419 ar = (AsyncResult) msg.obj;
1420 request = (MainThreadRequest) ar.userObj;
1421 if (ar.exception == null) {
1422 request.result = true;
1423 } else {
1424 request.result = false;
1425 loge("setNetworkSelectionModeManual " + ar.exception);
1426 }
1427 notifyRequester(request);
1428 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001429 break;
1430
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001431 case CMD_GET_MODEM_ACTIVITY_INFO:
1432 request = (MainThreadRequest) msg.obj;
1433 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001434 if (defaultPhone != null) {
1435 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001436 } else {
1437 ResultReceiver result = (ResultReceiver) request.argument;
1438 Bundle bundle = new Bundle();
1439 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001440 new ModemActivityInfo(0, 0, 0,
1441 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001442 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001443 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001444 break;
1445
Hall Liud0f208c2020-10-14 16:54:44 -07001446 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001447 ar = (AsyncResult) msg.obj;
1448 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001449 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001450 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001451 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001452 if (mLastModemActivityInfo == null) {
1453 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1454 mLastModemActivitySpecificInfo[0] =
1455 new ActivityStatsTechSpecificInfo(
1456 0,
1457 0,
1458 new int[ModemActivityInfo.getNumTxPowerLevels()],
1459 0);
1460 mLastModemActivityInfo =
1461 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1462 }
1463
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001464 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001465 // Update the last modem activity info and the result of the request.
1466 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1467 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001468 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001469 }
Kai Shi917fdc62022-11-28 14:01:02 -08001470 // This is needed to decouple ret from mLastModemActivityInfo
1471 // We don't want to return mLastModemActivityInfo which is updated
1472 // inside mergeModemActivityInfo()
1473 ret = new ModemActivityInfo(
1474 mLastModemActivityInfo.getTimestampMillis(),
1475 mLastModemActivityInfo.getSleepTimeMillis(),
1476 mLastModemActivityInfo.getIdleTimeMillis(),
1477 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001478
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001479 } else {
1480 if (ar.result == null) {
1481 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001482 error = TelephonyManager.ModemActivityInfoException
1483 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001484 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001485 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001486 error = TelephonyManager.ModemActivityInfoException
1487 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001488 } else {
1489 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001490 error = TelephonyManager.ModemActivityInfoException
1491 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001492 }
1493 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001494 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001495 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001496 bundle.putParcelable(
1497 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001498 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001499 } else {
1500 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1501 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001502 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001503 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001504 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001505 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001506
Meng Wang1a7c35a2016-05-05 20:56:15 -07001507 case CMD_SET_ALLOWED_CARRIERS:
1508 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001509 CarrierRestrictionRules argument =
1510 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001511 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001512 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001513 break;
1514
1515 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1516 ar = (AsyncResult) msg.obj;
1517 request = (MainThreadRequest) ar.userObj;
1518 if (ar.exception == null && ar.result != null) {
1519 request.result = ar.result;
1520 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001521 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1522 if (ar.exception instanceof CommandException) {
1523 loge("setAllowedCarriers: CommandException: " + ar.exception);
1524 CommandException.Error error =
1525 ((CommandException) (ar.exception)).getCommandError();
1526 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1527 request.result =
1528 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1529 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001530 } else {
1531 loge("setAllowedCarriers: Unknown exception");
1532 }
1533 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001534 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001535 break;
1536
1537 case CMD_GET_ALLOWED_CARRIERS:
1538 request = (MainThreadRequest) msg.obj;
1539 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001540 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001541 break;
1542
1543 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1544 ar = (AsyncResult) msg.obj;
1545 request = (MainThreadRequest) ar.userObj;
1546 if (ar.exception == null && ar.result != null) {
1547 request.result = ar.result;
1548 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001549 request.result = new IllegalStateException(
1550 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001551 if (ar.result == null) {
1552 loge("getAllowedCarriers: Empty response");
1553 } else if (ar.exception instanceof CommandException) {
1554 loge("getAllowedCarriers: CommandException: " +
1555 ar.exception);
1556 } else {
1557 loge("getAllowedCarriers: Unknown exception");
1558 }
1559 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001560 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001561 break;
1562
Nathan Haroldb3014052017-01-25 15:57:32 -08001563 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1564 ar = (AsyncResult) msg.obj;
1565 request = (MainThreadRequest) ar.userObj;
1566 if (ar.exception == null && ar.result != null) {
1567 request.result = ar.result;
1568 } else {
1569 request.result = new IllegalArgumentException(
1570 "Failed to retrieve Forbidden Plmns");
1571 if (ar.result == null) {
1572 loge("getForbiddenPlmns: Empty response");
1573 } else {
1574 loge("getForbiddenPlmns: Unknown exception");
1575 }
1576 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001577 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001578 break;
1579
1580 case CMD_GET_FORBIDDEN_PLMNS:
1581 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001582 uiccPort = getUiccPortFromRequest(request);
1583 if (uiccPort == null) {
1584 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001585 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001586 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001587 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001588 break;
1589 }
1590 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001591 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001592 if (uiccApp == null) {
1593 loge("getForbiddenPlmns() no app with specified type -- "
1594 + appType);
1595 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001596 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001597 break;
1598 } else {
1599 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1600 + " specified type -- " + appType);
1601 }
1602 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1603 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1604 onCompleted);
1605 break;
1606
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001607 case CMD_SWITCH_SLOTS:
1608 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001609 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001610 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001611 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001612 break;
1613
1614 case EVENT_SWITCH_SLOTS_DONE:
1615 ar = (AsyncResult) msg.obj;
1616 request = (MainThreadRequest) ar.userObj;
1617 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001618 notifyRequester(request);
1619 break;
1620 case CMD_GET_NETWORK_SELECTION_MODE:
1621 request = (MainThreadRequest) msg.obj;
1622 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1623 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1624 break;
1625
1626 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1627 ar = (AsyncResult) msg.obj;
1628 request = (MainThreadRequest) ar.userObj;
1629 if (ar.exception != null) {
1630 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1631 } else {
1632 int mode = ((int[]) ar.result)[0];
1633 if (mode == 0) {
1634 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1635 } else {
1636 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1637 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001638 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001639 notifyRequester(request);
1640 break;
1641 case CMD_GET_CDMA_ROAMING_MODE:
1642 request = (MainThreadRequest) msg.obj;
1643 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1644 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1645 break;
1646 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1647 ar = (AsyncResult) msg.obj;
1648 request = (MainThreadRequest) ar.userObj;
1649 if (ar.exception != null) {
1650 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1651 } else {
1652 request.result = ((int[]) ar.result)[0];
1653 }
1654 notifyRequester(request);
1655 break;
1656 case CMD_SET_CDMA_ROAMING_MODE:
1657 request = (MainThreadRequest) msg.obj;
1658 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1659 int mode = (int) request.argument;
1660 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1661 break;
1662 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1663 ar = (AsyncResult) msg.obj;
1664 request = (MainThreadRequest) ar.userObj;
1665 request.result = ar.exception == null;
1666 notifyRequester(request);
1667 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001668 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1669 request = (MainThreadRequest) msg.obj;
1670 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1671 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1672 break;
1673 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1674 ar = (AsyncResult) msg.obj;
1675 request = (MainThreadRequest) ar.userObj;
1676 if (ar.exception != null) {
1677 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1678 } else {
1679 request.result = ((int[]) ar.result)[0];
1680 }
1681 notifyRequester(request);
1682 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001683 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1684 request = (MainThreadRequest) msg.obj;
1685 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1686 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001687 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1688 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001689 break;
1690 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1691 ar = (AsyncResult) msg.obj;
1692 request = (MainThreadRequest) ar.userObj;
1693 request.result = ar.exception == null;
1694 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001695 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001696 case CMD_GET_ALL_CELL_INFO:
1697 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001698 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001699 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001700 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001701 case EVENT_GET_ALL_CELL_INFO_DONE:
1702 ar = (AsyncResult) msg.obj;
1703 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001704 // If a timeout occurs, the response will be null
1705 request.result = (ar.exception == null && ar.result != null)
1706 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001707 synchronized (request) {
1708 request.notifyAll();
1709 }
1710 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001711 case CMD_REQUEST_CELL_INFO_UPDATE:
1712 request = (MainThreadRequest) msg.obj;
1713 request.phone.requestCellInfoUpdate(request.workSource,
1714 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1715 break;
1716 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1717 ar = (AsyncResult) msg.obj;
1718 request = (MainThreadRequest) ar.userObj;
1719 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1720 try {
1721 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001722 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001723 cb.onError(
1724 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1725 ar.exception.getClass().getName(),
1726 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001727 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001728 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001729 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001730 } else {
1731 // use the result as returned
1732 cb.onCellInfo((List<CellInfo>) ar.result);
1733 }
1734 } catch (RemoteException re) {
1735 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1736 }
1737 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001738 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001739 request = (MainThreadRequest) msg.obj;
1740 WorkSource ws = (WorkSource) request.argument;
1741 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001742 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001743 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001744 }
1745 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001746 ar = (AsyncResult) msg.obj;
1747 request = (MainThreadRequest) ar.userObj;
1748 if (ar.exception == null) {
1749 request.result = ar.result;
1750 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001751 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001752 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001753 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001754 }
1755
1756 synchronized (request) {
1757 request.notifyAll();
1758 }
1759 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001760 }
chen xu6dac5ab2018-10-26 17:39:23 -07001761 case CMD_MODEM_REBOOT:
1762 request = (MainThreadRequest) msg.obj;
1763 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001764 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001765 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001766 case EVENT_CMD_MODEM_REBOOT_DONE:
1767 handleNullReturnEvent(msg, "rebootModem");
1768 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001769 case CMD_REQUEST_ENABLE_MODEM:
1770 request = (MainThreadRequest) msg.obj;
1771 boolean enable = (boolean) request.argument;
1772 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001773 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001774 PhoneConfigurationManager.getInstance()
1775 .enablePhone(request.phone, enable, onCompleted);
1776 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001777 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001778 ar = (AsyncResult) msg.obj;
1779 request = (MainThreadRequest) ar.userObj;
1780 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001781 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001782 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001783 if ((boolean) request.result) {
1784 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1785 updateModemStateMetrics();
1786 } else {
1787 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1788 + ar.exception);
1789 }
1790 notifyRequester(request);
1791 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001792 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001793 case CMD_GET_MODEM_STATUS:
1794 request = (MainThreadRequest) msg.obj;
1795 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1796 PhoneConfigurationManager.getInstance()
1797 .getPhoneStatusFromModem(request.phone, onCompleted);
1798 break;
1799 case EVENT_GET_MODEM_STATUS_DONE:
1800 ar = (AsyncResult) msg.obj;
1801 request = (MainThreadRequest) ar.userObj;
1802 int id = request.phone.getPhoneId();
1803 if (ar.exception == null && ar.result != null) {
1804 request.result = ar.result;
1805 //update the cache as modem status has changed
1806 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1807 (boolean) request.result);
1808 } else {
1809 // Return true if modem status cannot be retrieved. For most cases,
1810 // modem status is on. And for older version modems, GET_MODEM_STATUS
1811 // and disable modem are not supported. Modem is always on.
1812 // TODO: this should be fixed in R to support a third
1813 // status UNKNOWN b/131631629
1814 request.result = true;
1815 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1816 + ar.exception);
1817 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001818 notifyRequester(request);
1819 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001820 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1821 request = (MainThreadRequest) msg.obj;
1822 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1823 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1824 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1825 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1826 break;
1827 }
1828 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1829 ar = (AsyncResult) msg.obj;
1830 request = (MainThreadRequest) ar.userObj;
1831 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1832 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1833 args.second.accept(ar.exception == null);
1834 notifyRequester(request);
1835 break;
1836 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001837 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1838 request = (MainThreadRequest) msg.obj;
1839 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1840 Phone phone = getPhoneFromRequest(request);
1841 if (phone != null) {
1842 phone.getSystemSelectionChannels(onCompleted);
1843 } else {
1844 loge("getSystemSelectionChannels: No phone object");
1845 request.result = new ArrayList<RadioAccessSpecifier>();
1846 notifyRequester(request);
1847 }
1848 break;
1849 }
1850 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1851 ar = (AsyncResult) msg.obj;
1852 request = (MainThreadRequest) ar.userObj;
1853 if (ar.exception == null && ar.result != null) {
1854 request.result = ar.result;
1855 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001856 request.result = new IllegalStateException(
1857 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001858 if (ar.result == null) {
1859 loge("getSystemSelectionChannels: Empty response");
1860 } else {
1861 loge("getSystemSelectionChannels: Unknown exception");
1862 }
1863 }
1864 notifyRequester(request);
1865 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001866 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1867 ar = (AsyncResult) msg.obj;
1868 request = (MainThreadRequest) ar.userObj;
1869 if (ar.exception == null && ar.result != null) {
1870 request.result = ar.result;
1871 } else {
1872 request.result = -1;
1873 loge("Failed to set Forbidden Plmns");
1874 if (ar.result == null) {
1875 loge("setForbidenPlmns: Empty response");
1876 } else if (ar.exception != null) {
1877 loge("setForbiddenPlmns: Exception: " + ar.exception);
1878 request.result = -1;
1879 } else {
1880 loge("setForbiddenPlmns: Unknown exception");
1881 }
1882 }
1883 notifyRequester(request);
1884 break;
1885 case CMD_SET_FORBIDDEN_PLMNS:
1886 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001887 uiccPort = getUiccPortFromRequest(request);
1888 if (uiccPort == null) {
1889 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001890 request.result = -1;
1891 notifyRequester(request);
1892 break;
1893 }
1894 Pair<Integer, List<String>> setFplmnsArgs =
1895 (Pair<Integer, List<String>>) request.argument;
1896 appType = setFplmnsArgs.first;
1897 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001898 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001899 if (uiccApp == null) {
1900 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1901 request.result = -1;
1902 loge("Failed to get UICC App");
1903 notifyRequester(request);
1904 } else {
1905 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1906 ((SIMRecords) uiccApp.getIccRecords())
1907 .setForbiddenPlmns(onCompleted, fplmns);
1908 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001909 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001910 case CMD_ERASE_MODEM_CONFIG:
1911 request = (MainThreadRequest) msg.obj;
1912 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1913 defaultPhone.eraseModemConfig(onCompleted);
1914 break;
1915 case EVENT_ERASE_MODEM_CONFIG_DONE:
1916 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001917 break;
zoey chene02881a2019-12-30 16:11:23 +08001918
Kai Shif70f46f2021-03-03 13:59:46 -08001919 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1920 request = (MainThreadRequest) msg.obj;
1921 request.result = defaultPhone.eraseDataInSharedPreferences();
1922 notifyRequester(request);
1923 break;
1924
zoey chene02881a2019-12-30 16:11:23 +08001925 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1926 request = (MainThreadRequest) msg.obj;
1927 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1928 Pair<String, String> changed = (Pair<String, String>) request.argument;
1929 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1930 changed.first, changed.second, onCompleted);
1931 break;
1932 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1933 ar = (AsyncResult) msg.obj;
1934 request = (MainThreadRequest) ar.userObj;
1935 if (ar.exception == null) {
1936 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001937 // If the operation is successful, update the PIN storage
1938 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1939 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001940 UiccController.getInstance().getPinStorage()
1941 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001942 } else {
1943 request.result = msg.arg1;
1944 }
1945 notifyRequester(request);
1946 break;
1947
Michele Berionne5e411512020-11-13 02:36:59 +00001948 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001949 request = (MainThreadRequest) msg.obj;
1950 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1951 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1952 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1953 enabled.first, enabled.second, onCompleted);
1954 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001955 }
zoey chene02881a2019-12-30 16:11:23 +08001956 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1957 ar = (AsyncResult) msg.obj;
1958 request = (MainThreadRequest) ar.userObj;
1959 if (ar.exception == null) {
1960 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001961 // If the operation is successful, update the PIN storage
1962 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1963 int phoneId = getPhoneFromRequest(request).getPhoneId();
1964 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001965 UiccController.getInstance().getPinStorage()
1966 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001967 } else {
1968 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1969 }
zoey chene02881a2019-12-30 16:11:23 +08001970 } else {
1971 request.result = msg.arg1;
1972 }
Michele Berionne5e411512020-11-13 02:36:59 +00001973
1974
zoey chene02881a2019-12-30 16:11:23 +08001975 notifyRequester(request);
1976 break;
1977
Peter Wangdafb9ac2020-01-15 14:13:38 -08001978 case MSG_NOTIFY_USER_ACTIVITY:
1979 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001980 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001981 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1982 getDefaultPhone().getContext().sendBroadcastAsUser(
1983 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1984 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001985
1986 case CMD_SET_DATA_THROTTLING: {
1987 request = (MainThreadRequest) msg.obj;
1988 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1989 DataThrottlingRequest dataThrottlingRequest =
1990 (DataThrottlingRequest) request.argument;
1991 Phone phone = getPhoneFromRequest(request);
1992 if (phone != null) {
1993 phone.setDataThrottling(onCompleted,
1994 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1995 dataThrottlingRequest.getCompletionDurationMillis());
1996 } else {
1997 loge("setDataThrottling: No phone object");
1998 request.result =
1999 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2000 notifyRequester(request);
2001 }
2002
2003 break;
2004 }
2005 case EVENT_SET_DATA_THROTTLING_DONE:
2006 ar = (AsyncResult) msg.obj;
2007 request = (MainThreadRequest) ar.userObj;
2008
2009 if (ar.exception == null) {
2010 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2011 } else if (ar.exception instanceof CommandException) {
2012 loge("setDataThrottling: CommandException: " + ar.exception);
2013 CommandException.Error error =
2014 ((CommandException) (ar.exception)).getCommandError();
2015
2016 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2017 request.result = TelephonyManager
2018 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2019 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2020 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002021 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2022 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002023 } else {
2024 request.result =
2025 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2026 }
2027 } else {
2028 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2029 }
2030 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2031 notifyRequester(request);
2032 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002033
2034 case CMD_SET_SIM_POWER: {
2035 request = (MainThreadRequest) msg.obj;
2036 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2037 request = (MainThreadRequest) msg.obj;
2038 int stateToSet =
2039 ((Pair<Integer, IIntegerConsumer>)
2040 request.argument).first;
2041 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2042 break;
2043 }
2044 case EVENT_SET_SIM_POWER_DONE: {
2045 ar = (AsyncResult) msg.obj;
2046 request = (MainThreadRequest) ar.userObj;
2047 IIntegerConsumer callback =
2048 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2049 if (ar.exception != null) {
2050 loge("setSimPower exception: " + ar.exception);
2051 int errorCode = TelephonyManager.CallForwardingInfoCallback
2052 .RESULT_ERROR_UNKNOWN;
2053 if (ar.exception instanceof CommandException) {
2054 CommandException.Error error =
2055 ((CommandException) (ar.exception)).getCommandError();
2056 if (error == CommandException.Error.SIM_ERR) {
2057 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2058 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2059 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2060 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2061 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2062 } else {
2063 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2064 }
2065 }
2066 try {
2067 callback.accept(errorCode);
2068 } catch (RemoteException e) {
2069 // Ignore if the remote process is no longer available to call back.
2070 Log.w(LOG_TAG, "setSimPower: callback not available.");
2071 }
2072 } else {
2073 try {
2074 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2075 } catch (RemoteException e) {
2076 // Ignore if the remote process is no longer available to call back.
2077 Log.w(LOG_TAG, "setSimPower: callback not available.");
2078 }
2079 }
2080 break;
2081 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002082 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2083 request = (MainThreadRequest) msg.obj;
2084
2085 final Phone phone = getPhoneFromRequest(request);
2086 if (phone == null || phone.getServiceStateTracker() == null) {
2087 request.result = new IllegalStateException("Phone or SST is null");
2088 notifyRequester(request);
2089 break;
2090 }
2091
2092 Pair<Integer, SignalStrengthUpdateRequest> pair =
2093 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2094 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2095 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002096 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002097 request.subId, pair.first /*callingUid*/,
2098 pair.second /*request*/, onCompleted);
2099 break;
2100 }
2101 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2102 ar = (AsyncResult) msg.obj;
2103 request = (MainThreadRequest) ar.userObj;
2104 // request.result will be the exception of ar if present, true otherwise.
2105 // Be cautious not to leave result null which will wait() forever
2106 request.result = ar.exception != null ? ar.exception : true;
2107 notifyRequester(request);
2108 break;
2109 }
2110 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2111 request = (MainThreadRequest) msg.obj;
2112
2113 Phone phone = getPhoneFromRequest(request);
2114 if (phone == null || phone.getServiceStateTracker() == null) {
2115 request.result = new IllegalStateException("Phone or SST is null");
2116 notifyRequester(request);
2117 break;
2118 }
2119
2120 Pair<Integer, SignalStrengthUpdateRequest> pair =
2121 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2122 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2123 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002124 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002125 request.subId, pair.first /*callingUid*/,
2126 pair.second /*request*/, onCompleted);
2127 break;
2128 }
2129 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2130 ar = (AsyncResult) msg.obj;
2131 request = (MainThreadRequest) ar.userObj;
2132 request.result = ar.exception != null ? ar.exception : true;
2133 notifyRequester(request);
2134 break;
2135 }
Jordan Liu109698e2020-11-24 14:50:34 -08002136
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002137 case CMD_GET_SLICING_CONFIG: {
2138 request = (MainThreadRequest) msg.obj;
2139 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2140 request.phone.getSlicingConfig(onCompleted);
2141 break;
2142 }
2143 case EVENT_GET_SLICING_CONFIG_DONE: {
2144 ar = (AsyncResult) msg.obj;
2145 request = (MainThreadRequest) ar.userObj;
2146 ResultReceiver result = (ResultReceiver) request.argument;
2147
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002148 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002149 Bundle bundle = new Bundle();
2150 int resultCode = 0;
2151 if (ar.exception != null) {
2152 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2153 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002154 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002155 } else if (ar.result == null) {
2156 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002157 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002158 } else {
2159 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002160 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2161 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002162 }
2163
2164 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002165 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002166 }
2167 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2168 result.send(resultCode, bundle);
2169 notifyRequester(request);
2170 break;
2171 }
2172
Sarah Chin71b3a852022-09-28 15:54:19 -07002173 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002174 request = (MainThreadRequest) msg.obj;
2175 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002176 PurchasePremiumCapabilityArgument arg =
2177 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002178 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chin71b3a852022-09-28 15:54:19 -07002179 arg.capability, arg.appName, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002180 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002181 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002182
Sarah Chin71b3a852022-09-28 15:54:19 -07002183 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002184 ar = (AsyncResult) msg.obj;
2185 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002186 PurchasePremiumCapabilityArgument arg =
2187 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002188 try {
2189 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002190 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002191 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002192 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002193 + ", result= "
2194 + TelephonyManager.convertPurchaseResultToString(result));
2195 } catch (RemoteException e) {
2196 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002197 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002198 + " failed: " + e;
2199 if (DBG) log(logStr);
2200 AnomalyReporter.reportAnomaly(
2201 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2202 }
2203 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002204 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002205
Michele Berionne5e411512020-11-13 02:36:59 +00002206 case CMD_PREPARE_UNATTENDED_REBOOT:
2207 request = (MainThreadRequest) msg.obj;
2208 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002209 UiccController.getInstance().getPinStorage()
2210 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002211 notifyRequester(request);
2212 break;
2213
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002214 default:
2215 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2216 break;
2217 }
2218 }
Jake Hambye994d462014-02-03 13:10:13 -08002219
Pengquan Menga1bb6272018-09-06 09:59:22 -07002220 private void notifyRequester(MainThreadRequest request) {
2221 synchronized (request) {
2222 request.notifyAll();
2223 }
2224 }
2225
Jake Hambye994d462014-02-03 13:10:13 -08002226 private void handleNullReturnEvent(Message msg, String command) {
2227 AsyncResult ar = (AsyncResult) msg.obj;
2228 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2229 if (ar.exception == null) {
2230 request.result = true;
2231 } else {
2232 request.result = false;
2233 if (ar.exception instanceof CommandException) {
2234 loge(command + ": CommandException: " + ar.exception);
2235 } else {
2236 loge(command + ": Unknown exception");
2237 }
2238 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002239 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002240 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 }
2242
2243 /**
2244 * Posts the specified command to be executed on the main thread,
2245 * waits for the request to complete, and returns the result.
2246 * @see #sendRequestAsync
2247 */
2248 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002249 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2250 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002251 }
2252
2253 /**
2254 * Posts the specified command to be executed on the main thread,
2255 * waits for the request to complete, and returns the result.
2256 * @see #sendRequestAsync
2257 */
2258 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2259 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002260 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002261 }
2262
2263 /**
2264 * Posts the specified command to be executed on the main thread,
2265 * waits for the request to complete, and returns the result.
2266 * @see #sendRequestAsync
2267 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002268 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002269 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2270 }
2271
2272 /**
2273 * Posts the specified command to be executed on the main thread,
2274 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2275 * if not timeout or null otherwise.
2276 * @see #sendRequestAsync
2277 */
2278 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2279 long timeoutInMs) {
2280 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002281 }
2282
2283 /**
2284 * Posts the specified command to be executed on the main thread,
2285 * waits for the request to complete, and returns the result.
2286 * @see #sendRequestAsync
2287 */
Nathan Harold92bed182018-10-12 18:16:49 -07002288 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002289 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002290 }
2291
2292 /**
2293 * Posts the specified command to be executed on the main thread,
2294 * waits for the request to complete, and returns the result.
2295 * @see #sendRequestAsync
2296 */
2297 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002298 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2299 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002300 }
2301
2302 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002303 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2304 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2305 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002306 * @see #sendRequestAsync
2307 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002308 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2309 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002310 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2311 throw new RuntimeException("This method will deadlock if called from the main thread.");
2312 }
2313
Nathan Harold92bed182018-10-12 18:16:49 -07002314 MainThreadRequest request = null;
2315 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2316 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2317 } else if (phone != null) {
2318 request = new MainThreadRequest(argument, phone, workSource);
2319 } else {
2320 request = new MainThreadRequest(argument, subId, workSource);
2321 }
2322
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002323 Message msg = mMainThreadHandler.obtainMessage(command, request);
2324 msg.sendToTarget();
2325
Rambo Wang0f050d82021-02-12 11:43:36 -08002326
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002328 if (timeoutInMs >= 0) {
2329 // Wait for at least timeoutInMs before returning null request result
2330 long now = SystemClock.elapsedRealtime();
2331 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002332 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002333 try {
2334 request.wait(deadline - now);
2335 } catch (InterruptedException e) {
2336 // Do nothing, go back and check if request is completed or timeout
2337 } finally {
2338 now = SystemClock.elapsedRealtime();
2339 }
2340 }
2341 } else {
2342 // Wait for the request to complete
2343 while (request.result == null) {
2344 try {
2345 request.wait();
2346 } catch (InterruptedException e) {
2347 // Do nothing, go back and wait until the request is complete
2348 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002349 }
2350 }
2351 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002352 if (request.result == null) {
2353 Log.wtf(LOG_TAG,
2354 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2355 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002356 return request.result;
2357 }
2358
2359 /**
2360 * Asynchronous ("fire and forget") version of sendRequest():
2361 * Posts the specified command to be executed on the main thread, and
2362 * returns immediately.
2363 * @see #sendRequest
2364 */
2365 private void sendRequestAsync(int command) {
2366 mMainThreadHandler.sendEmptyMessage(command);
2367 }
2368
2369 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002370 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002371 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002372 */
2373 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002374 sendRequestAsync(command, argument, null, null);
2375 }
2376
2377 /**
2378 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2379 * @see {@link #sendRequest(int,Object)}
2380 */
2381 private void sendRequestAsync(
2382 int command, Object argument, Phone phone, WorkSource workSource) {
2383 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002384 Message msg = mMainThreadHandler.obtainMessage(command, request);
2385 msg.sendToTarget();
2386 }
2387
2388 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002389 * Initialize the singleton PhoneInterfaceManager instance.
2390 * This is only done once, at startup, from PhoneApp.onCreate().
2391 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002392 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393 synchronized (PhoneInterfaceManager.class) {
2394 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002395 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 } else {
2397 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2398 }
2399 return sInstance;
2400 }
2401 }
2402
2403 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002404 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002407 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002408 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002409 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002410 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002411 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002412 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002413 mTelephonySharedPreferences =
2414 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002415 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002416 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002417 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002418 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002419 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002420 mTelephony2gUpdater = new Telephony2gUpdater(
2421 Executors.newSingleThreadExecutor(), mApp);
2422 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 publish();
2424 }
2425
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002426 @VisibleForTesting
2427 public SharedPreferences getSharedPreferences() {
2428 return mTelephonySharedPreferences;
2429 }
2430
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002431 private Phone getDefaultPhone() {
2432 Phone thePhone = getPhone(getDefaultSubscription());
2433 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2434 }
2435
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 private void publish() {
2437 if (DBG) log("publish: " + this);
2438
Peter Wangc035ce42020-01-08 21:00:22 -08002439 TelephonyFrameworkInitializer
2440 .getTelephonyServiceManager()
2441 .getTelephonyServiceRegisterer()
2442 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 }
2444
Stuart Scott584921c2015-01-15 17:10:34 -08002445 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002446 if (request.phone != null) {
2447 return request.phone;
2448 } else {
2449 return getPhoneFromSubId(request.subId);
2450 }
2451 }
2452
2453 private Phone getPhoneFromSubId(int subId) {
2454 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2455 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002456 }
2457
Rambo Wange53e07d2022-05-10 13:01:13 -07002458 @Nullable
2459 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002460 Phone phone = getPhoneFromRequest(request);
2461 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002462 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002463 }
2464
Wink Saville36469e72014-06-11 15:17:00 -07002465 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002466 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002467 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002468 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469
Kai Shif70f46f2021-03-03 13:59:46 -08002470 private void sendEraseModemConfig(@NonNull Phone phone) {
2471 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2472 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2473 }
2474
2475 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2476 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2477 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002478 }
2479
Peter Wang44b186e2020-01-13 23:33:09 -08002480 private boolean isImsAvailableOnDevice() {
2481 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2482 if (pm == null) {
2483 // For some reason package manger is not available.. This will fail internally anyway,
2484 // so do not throw error and allow.
2485 return true;
2486 }
2487 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2488 }
2489
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002490 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002491 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002492 }
2493
Wink Savilleb564aae2014-10-23 10:18:09 -07002494 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002495 if (DBG) log("dial: " + number);
2496 // No permission check needed here: This is just a wrapper around the
2497 // ACTION_DIAL intent, which is available to any app since it puts up
2498 // the UI before it does anything.
2499
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002500 final long identity = Binder.clearCallingIdentity();
2501 try {
2502 String url = createTelUrl(number);
2503 if (url == null) {
2504 return;
2505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002506
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507 // PENDING: should we just silently fail if phone is offhook or ringing?
2508 PhoneConstants.State state = mCM.getState(subId);
2509 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2510 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2511 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2512 mApp.startActivity(intent);
2513 }
2514 } finally {
2515 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 }
2517 }
2518
2519 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002520 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002521 }
2522
Wink Savilleb564aae2014-10-23 10:18:09 -07002523 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002524 if (DBG) log("call: " + number);
2525
2526 // This is just a wrapper around the ACTION_CALL intent, but we still
2527 // need to do a permission check since we're calling startActivity()
2528 // from the context of the phone app.
2529 enforceCallPermission();
2530
Jordan Liu1617b712019-07-10 15:06:26 -07002531 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002532 != AppOpsManager.MODE_ALLOWED) {
2533 return;
2534 }
2535
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002536 final long identity = Binder.clearCallingIdentity();
2537 try {
2538 String url = createTelUrl(number);
2539 if (url == null) {
2540 return;
2541 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002542
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002543 boolean isValid = false;
2544 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2545 if (slist != null) {
2546 for (SubscriptionInfo subInfoRecord : slist) {
2547 if (subInfoRecord.getSubscriptionId() == subId) {
2548 isValid = true;
2549 break;
2550 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002551 }
Wink Saville08874612014-08-31 19:19:58 -07002552 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002553 if (!isValid) {
2554 return;
2555 }
Wink Saville08874612014-08-31 19:19:58 -07002556
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002557 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2558 intent.putExtra(SUBSCRIPTION_KEY, subId);
2559 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2560 mApp.startActivity(intent);
2561 } finally {
2562 Binder.restoreCallingIdentity(identity);
2563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 }
2565
Wink Savilleb564aae2014-10-23 10:18:09 -07002566 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002567 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002568 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2569 }
2570
Wink Savilleb564aae2014-10-23 10:18:09 -07002571 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002572 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002573 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2574 }
2575
Wink Savilleb564aae2014-10-23 10:18:09 -07002576 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002577 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002578
2579 final long identity = Binder.clearCallingIdentity();
2580 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002581 Phone phone = getPhone(subId);
2582 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002583 checkSimPin.start();
2584 return checkSimPin.unlockSim(null, pin);
2585 } finally {
2586 Binder.restoreCallingIdentity(identity);
2587 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002588 }
2589
Wink Savilleb564aae2014-10-23 10:18:09 -07002590 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002591 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002592
2593 final long identity = Binder.clearCallingIdentity();
2594 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002595 Phone phone = getPhone(subId);
2596 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002597 checkSimPuk.start();
2598 return checkSimPuk.unlockSim(puk, pin);
2599 } finally {
2600 Binder.restoreCallingIdentity(identity);
2601 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002602 }
2603
2604 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002605 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002606 * a synchronous one.
2607 */
2608 private static class UnlockSim extends Thread {
2609
2610 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002611 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002612
2613 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002614 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2615 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002616
2617 // For replies from SimCard interface
2618 private Handler mHandler;
2619
2620 // For async handler to identify request type
2621 private static final int SUPPLY_PIN_COMPLETE = 100;
2622
Michele Berionne5e411512020-11-13 02:36:59 +00002623 UnlockSim(int phoneId, IccCard simCard) {
2624 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002625 mSimCard = simCard;
2626 }
2627
2628 @Override
2629 public void run() {
2630 Looper.prepare();
2631 synchronized (UnlockSim.this) {
2632 mHandler = new Handler() {
2633 @Override
2634 public void handleMessage(Message msg) {
2635 AsyncResult ar = (AsyncResult) msg.obj;
2636 switch (msg.what) {
2637 case SUPPLY_PIN_COMPLETE:
2638 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2639 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002640 mRetryCount = msg.arg1;
2641 if (ar.exception != null) {
2642 if (ar.exception instanceof CommandException &&
2643 ((CommandException)(ar.exception)).getCommandError()
2644 == CommandException.Error.PASSWORD_INCORRECT) {
2645 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002646 } //When UiccCardApp dispose,handle message and return exception
2647 else if (ar.exception instanceof CommandException &&
2648 ((CommandException) (ar.exception)).getCommandError()
2649 == CommandException.Error.ABORTED) {
2650 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002651 } else {
2652 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2653 }
2654 } else {
2655 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2656 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002657 mDone = true;
2658 UnlockSim.this.notifyAll();
2659 }
2660 break;
2661 }
2662 }
2663 };
2664 UnlockSim.this.notifyAll();
2665 }
2666 Looper.loop();
2667 }
2668
2669 /*
2670 * Use PIN or PUK to unlock SIM card
2671 *
2672 * If PUK is null, unlock SIM card with PIN
2673 *
2674 * If PUK is not null, unlock SIM card with PUK and set PIN code
2675 */
Wink Saville9de0f752013-10-22 19:04:03 -07002676 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002677
2678 while (mHandler == null) {
2679 try {
2680 wait();
2681 } catch (InterruptedException e) {
2682 Thread.currentThread().interrupt();
2683 }
2684 }
2685 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2686
2687 if (puk == null) {
2688 mSimCard.supplyPin(pin, callback);
2689 } else {
2690 mSimCard.supplyPuk(puk, pin, callback);
2691 }
2692
2693 while (!mDone) {
2694 try {
2695 Log.d(LOG_TAG, "wait for done");
2696 wait();
2697 } catch (InterruptedException e) {
2698 // Restore the interrupted status
2699 Thread.currentThread().interrupt();
2700 }
2701 }
2702 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002703 int[] resultArray = new int[2];
2704 resultArray[0] = mResult;
2705 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002706
2707 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002708 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002709 }
2710
Wink Saville9de0f752013-10-22 19:04:03 -07002711 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002712 }
2713 }
2714
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002715 /**
2716 * This method has been removed due to privacy and stability concerns.
2717 */
2718 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002719 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002720 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2721 return;
Wink Saville36469e72014-06-11 15:17:00 -07002722 }
2723
Nathan Harold1f889d82020-06-04 17:05:26 -07002724 @Override
2725 public void updateServiceLocationWithPackageName(String callingPackage) {
2726 mApp.getSystemService(AppOpsManager.class)
2727 .checkPackage(Binder.getCallingUid(), callingPackage);
2728
Nathan Haroldf096d982020-11-18 17:18:06 -08002729 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002730 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2731 // Callers targeting S have no business invoking this method.
2732 return;
2733 }
2734
2735 LocationAccessPolicy.LocationPermissionResult locationResult =
2736 LocationAccessPolicy.checkLocationPermission(mApp,
2737 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2738 .setCallingPackage(callingPackage)
2739 .setCallingFeatureId(null)
2740 .setCallingPid(Binder.getCallingPid())
2741 .setCallingUid(Binder.getCallingUid())
2742 .setMethod("updateServiceLocation")
2743 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2744 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2745 .build());
2746 // Apps that lack location permission have no business calling this method;
2747 // however, because no permission was declared in the public API, denials must
2748 // all be "soft".
2749 switch (locationResult) {
2750 case DENIED_HARD: /* fall through */
2751 case DENIED_SOFT:
2752 return;
2753 }
2754
2755 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002756 final long identity = Binder.clearCallingIdentity();
2757 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002758 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002759 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002760 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002761 }
2762 } finally {
2763 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002764 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002765 }
2766
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002767 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002768 @Override
2769 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002770 return isRadioOnWithFeature(callingPackage, null);
2771 }
2772
2773
2774 @Override
2775 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2776 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2777 callingFeatureId);
2778 }
2779
2780 @Deprecated
2781 @Override
2782 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2783 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002784 }
2785
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002786 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002787 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2788 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002789 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002790 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002791 return false;
2792 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002793
2794 final long identity = Binder.clearCallingIdentity();
2795 try {
2796 return isRadioOnForSubscriber(subId);
2797 } finally {
2798 Binder.restoreCallingIdentity(identity);
2799 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002800 }
2801
2802 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002803 final long identity = Binder.clearCallingIdentity();
2804 try {
2805 final Phone phone = getPhone(subId);
2806 if (phone != null) {
2807 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2808 } else {
2809 return false;
2810 }
2811 } finally {
2812 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002813 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002814 }
2815
2816 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002817 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002818 }
Wink Saville36469e72014-06-11 15:17:00 -07002819
Wink Savilleb564aae2014-10-23 10:18:09 -07002820 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002821 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002822
2823 final long identity = Binder.clearCallingIdentity();
2824 try {
2825 final Phone phone = getPhone(subId);
2826 if (phone != null) {
2827 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2828 }
2829 } finally {
2830 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002831 }
Wink Saville36469e72014-06-11 15:17:00 -07002832 }
2833
2834 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002835 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002836 }
2837
Wink Savilleb564aae2014-10-23 10:18:09 -07002838 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002839 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002840
2841 final long identity = Binder.clearCallingIdentity();
2842 try {
2843 final Phone phone = getPhone(subId);
2844 if (phone == null) {
2845 return false;
2846 }
2847 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2848 toggleRadioOnOffForSubscriber(subId);
2849 }
2850 return true;
2851 } finally {
2852 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002853 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002854 }
Wink Saville36469e72014-06-11 15:17:00 -07002855
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002856 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002857 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002858 /*
2859 * If any of the Radios are available, it will need to be
2860 * shutdown. So return true if any Radio is available.
2861 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862 final long identity = Binder.clearCallingIdentity();
2863 try {
2864 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2865 Phone phone = PhoneFactory.getPhone(i);
2866 if (phone != null && phone.isRadioAvailable()) return true;
2867 }
2868 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2869 return false;
2870 } finally {
2871 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002872 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002873 }
2874
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002875 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002876 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002877 enforceModifyPermission();
2878
2879 final long identity = Binder.clearCallingIdentity();
2880 try {
2881 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2882 logv("Shutting down Phone " + i);
2883 shutdownRadioUsingPhoneId(i);
2884 }
2885 } finally {
2886 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002887 }
2888 }
2889
2890 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002891 Phone phone = PhoneFactory.getPhone(phoneId);
2892 if (phone != null && phone.isRadioAvailable()) {
2893 phone.shutdownRadio();
2894 }
2895 }
2896
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002897 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002898 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002899
2900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2903 if (defaultPhone != null) {
2904 defaultPhone.setRadioPower(turnOn);
2905 return true;
2906 } else {
2907 loge("There's no default phone.");
2908 return false;
2909 }
2910 } finally {
2911 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002912 }
Wink Saville36469e72014-06-11 15:17:00 -07002913 }
2914
Wink Savilleb564aae2014-10-23 10:18:09 -07002915 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002916 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002917
2918 final long identity = Binder.clearCallingIdentity();
2919 try {
2920 final Phone phone = getPhone(subId);
2921 if (phone != null) {
2922 phone.setRadioPower(turnOn);
2923 return true;
2924 } else {
2925 return false;
2926 }
2927 } finally {
2928 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002929 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 }
2931
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002932 /**
2933 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2934 * no reason to power it off. When any of the voters want to power it off, it will be turned
2935 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2936 * powering it off, and these radio off votes will be cleared.
2937 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
2938 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
2939 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
2940 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
2941 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
2942 * check its vote.
2943 *
2944 * @param subId The subscription ID.
2945 * @param reason The reason for powering off radio.
2946 * @return true on success and false on failure.
2947 */
2948 public boolean requestRadioPowerOffForReason(int subId,
2949 @TelephonyManager.RadioPowerReason int reason) {
2950 enforceModifyPermission();
2951
2952 final long identity = Binder.clearCallingIdentity();
2953 try {
2954 final Phone phone = getPhone(subId);
2955 if (phone != null) {
2956 phone.setRadioPowerForReason(false, reason);
2957 return true;
2958 } else {
2959 return false;
2960 }
2961 } finally {
2962 Binder.restoreCallingIdentity(identity);
2963 }
2964 }
2965
2966 /**
2967 * Remove the vote on powering off the radio for a reason, as requested by
2968 * {@link requestRadioPowerOffForReason}.
2969 *
2970 * @param subId The subscription ID.
2971 * @param reason The reason for powering off radio.
2972 * @return true on success and false on failure.
2973 */
2974 public boolean clearRadioPowerOffForReason(int subId,
2975 @TelephonyManager.RadioPowerReason int reason) {
2976 enforceModifyPermission();
2977
2978 final long identity = Binder.clearCallingIdentity();
2979 try {
2980 final Phone phone = getPhone(subId);
2981 if (phone != null) {
2982 phone.setRadioPowerForReason(true, reason);
2983 return true;
2984 } else {
2985 return false;
2986 }
2987 } finally {
2988 Binder.restoreCallingIdentity(identity);
2989 }
2990 }
2991
2992 /**
2993 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
2994 *
2995 * @param subId The subscription ID.
2996 * @param callingPackage The package making the call.
2997 * @param callingFeatureId The feature in the package.
2998 * @return List of reasons for powering off radio.
2999 */
3000 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3001 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3002
3003 final long identity = Binder.clearCallingIdentity();
3004 List result = new ArrayList();
3005 try {
3006 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3007 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3008 return result;
3009 }
3010
3011 final Phone phone = getPhone(subId);
3012 if (phone != null) {
3013 result.addAll(phone.getRadioPowerOffReasons());
3014 }
3015 } finally {
3016 Binder.restoreCallingIdentity(identity);
3017 }
3018 return result;
3019 }
3020
Wink Saville36469e72014-06-11 15:17:00 -07003021 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003022 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003023 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003024 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003025
3026 final long identity = Binder.clearCallingIdentity();
3027 try {
Jack Yu285100e2022-12-02 22:48:35 -08003028 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003029 final Phone phone = getPhone(subId);
3030 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003031 phone.getDataSettingsManager().setDataEnabled(
3032 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003033 return true;
3034 } else {
3035 return false;
3036 }
3037 } finally {
3038 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003039 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003040 }
3041
Wink Saville36469e72014-06-11 15:17:00 -07003042 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003043 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003044 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003045 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003046
3047 final long identity = Binder.clearCallingIdentity();
3048 try {
Jack Yu285100e2022-12-02 22:48:35 -08003049 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003050 final Phone phone = getPhone(subId);
3051 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003052 phone.getDataSettingsManager().setDataEnabled(
3053 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003054 return true;
3055 } else {
3056 return false;
3057 }
3058 } finally {
3059 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003060 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003061 }
3062
Sanket Padawe356d7632015-06-22 14:03:32 -07003063 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003064 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003065 final long identity = Binder.clearCallingIdentity();
3066 try {
3067 final Phone phone = getPhone(subId);
3068 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003069 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003070 } else {
3071 return false;
3072 }
3073 } finally {
3074 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003075 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003076 }
3077
3078 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003079 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003080 }
3081
pkanwarae03a6b2016-11-06 20:37:09 -08003082 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003083 enforceCallPermission();
3084
3085 final long identity = Binder.clearCallingIdentity();
3086 try {
3087 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3088 return;
3089 }
3090 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3091 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3092 } finally {
3093 Binder.restoreCallingIdentity(identity);
3094 }
pkanwar32d516d2016-10-14 19:37:38 -07003095 };
3096
Wink Savilleb564aae2014-10-23 10:18:09 -07003097 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003098 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003099
3100 final long identity = Binder.clearCallingIdentity();
3101 try {
3102 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3103 return false;
3104 }
3105 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3106 } finally {
3107 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003108 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003109 }
3110
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003111 /**
3112 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3113 * tag on getCallState Binder call.
3114 */
3115 @Deprecated
3116 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003117 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003118 if (CompatChanges.isChangeEnabled(
3119 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3120 Binder.getCallingUid())) {
3121 // Do not allow this API to be called on API version 31+, it should only be
3122 // called on old apps using this Binder call directly.
3123 throw new SecurityException("This method can only be used for applications "
3124 + "targeting API version 30 or less.");
3125 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003126 final long identity = Binder.clearCallingIdentity();
3127 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003128 Phone phone = getPhone(getDefaultSubscription());
3129 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3130 PhoneConstantConversions.convertCallState(phone.getState());
3131 } finally {
3132 Binder.restoreCallingIdentity(identity);
3133 }
3134 }
3135
3136 @Override
3137 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3138 if (CompatChanges.isChangeEnabled(
3139 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3140 Binder.getCallingUid())) {
3141 // Check READ_PHONE_STATE for API version 31+
3142 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3143 featureId, "getCallStateForSubscription")) {
3144 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3145 + "targeting API level 31+.");
3146 }
3147 }
3148 final long identity = Binder.clearCallingIdentity();
3149 try {
3150 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003151 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3152 PhoneConstantConversions.convertCallState(phone.getState());
3153 } finally {
3154 Binder.restoreCallingIdentity(identity);
3155 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003156 }
3157
Sanket Padawe356d7632015-06-22 14:03:32 -07003158 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003159 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003160 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003161 }
3162
3163 @Override
3164 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003165 final long identity = Binder.clearCallingIdentity();
3166 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003167 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003168 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003169 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003170 } else {
3171 return PhoneConstantConversions.convertDataState(
3172 PhoneConstants.DataState.DISCONNECTED);
3173 }
3174 } finally {
3175 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003176 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003177 }
3178
Sanket Padawe356d7632015-06-22 14:03:32 -07003179 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003180 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003181 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003182 }
3183
3184 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003185 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003186 final long identity = Binder.clearCallingIdentity();
3187 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003188 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003190 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003191 } else {
3192 return TelephonyManager.DATA_ACTIVITY_NONE;
3193 }
3194 } finally {
3195 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003197 }
3198
3199 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003200 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003201 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003202 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003203
3204 LocationAccessPolicy.LocationPermissionResult locationResult =
3205 LocationAccessPolicy.checkLocationPermission(mApp,
3206 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3207 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003208 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003209 .setCallingPid(Binder.getCallingPid())
3210 .setCallingUid(Binder.getCallingUid())
3211 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003212 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003213 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3214 .build());
3215 switch (locationResult) {
3216 case DENIED_HARD:
3217 throw new SecurityException("Not allowed to access cell location");
3218 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003219 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3220 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003221 }
3222
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003223 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003224 final long identity = Binder.clearCallingIdentity();
3225 try {
3226 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003227 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003228 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003229 } finally {
3230 Binder.restoreCallingIdentity(identity);
3231 }
Svetoslav64fad262015-04-14 14:35:21 -07003232 }
3233
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003234 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003235 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003236 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3237 // registered cell info, so return a NULL country instead.
3238 final long identity = Binder.clearCallingIdentity();
3239 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003240 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3241 // Get default phone in this case.
3242 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3243 }
Jack Yu285100e2022-12-02 22:48:35 -08003244 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003245 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003246 if (phone == null) return "";
3247 ServiceStateTracker sst = phone.getServiceStateTracker();
3248 if (sst == null) return "";
3249 LocaleTracker lt = sst.getLocaleTracker();
3250 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003251 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003252 } finally {
3253 Binder.restoreCallingIdentity(identity);
3254 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003255 }
3256
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003257 /**
3258 * This method was removed due to potential issues caused by performing partial
3259 * updates of service state, and lack of a credible use case.
3260 *
3261 * This has the ability to break the telephony implementation by disabling notification of
3262 * changes in device connectivity. DO NOT USE THIS!
3263 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003264 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003265 public void enableLocationUpdates() {
3266 mApp.enforceCallingOrSelfPermission(
3267 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003268 }
3269
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003270 /**
3271 * This method was removed due to potential issues caused by performing partial
3272 * updates of service state, and lack of a credible use case.
3273 *
3274 * This has the ability to break the telephony implementation by disabling notification of
3275 * changes in device connectivity. DO NOT USE THIS!
3276 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003277 @Override
3278 public void disableLocationUpdates() {
3279 mApp.enforceCallingOrSelfPermission(
3280 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003281 }
3282
3283 @Override
3284 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003285 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3286 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003287 try {
3288 mApp.getSystemService(AppOpsManager.class)
3289 .checkPackage(Binder.getCallingUid(), callingPackage);
3290 } catch (SecurityException e) {
3291 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3292 throw e;
3293 }
3294
Nathan Haroldf096d982020-11-18 17:18:06 -08003295 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003296 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3297 throw new SecurityException(
3298 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3299 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003300
Jordan Liu1617b712019-07-10 15:06:26 -07003301 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003302 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3303 return null;
3304 }
Svetoslav64fad262015-04-14 14:35:21 -07003305
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003306 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003307
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003308 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003309 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003310
Nathan Haroldf180aac2018-06-01 18:43:55 -07003311 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3312 for (CellInfo ci : info) {
3313 if (ci instanceof CellInfoGsm) {
3314 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3315 } else if (ci instanceof CellInfoWcdma) {
3316 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3317 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003318 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003319 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003320 }
3321
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003322 private List<CellInfo> getCachedCellInfo() {
3323 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3324 for (Phone phone : PhoneFactory.getPhones()) {
3325 List<CellInfo> info = phone.getAllCellInfo();
3326 if (info != null) cellInfos.addAll(info);
3327 }
3328 return cellInfos;
3329 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003330
3331 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003332 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003333 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003334 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003335
3336 LocationAccessPolicy.LocationPermissionResult locationResult =
3337 LocationAccessPolicy.checkLocationPermission(mApp,
3338 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3339 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003340 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003341 .setCallingPid(Binder.getCallingPid())
3342 .setCallingUid(Binder.getCallingUid())
3343 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003344 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003345 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3346 .build());
3347 switch (locationResult) {
3348 case DENIED_HARD:
3349 throw new SecurityException("Not allowed to access cell info");
3350 case DENIED_SOFT:
3351 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003352 }
3353
Nathan Haroldf096d982020-11-18 17:18:06 -08003354 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003355 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3356 return getCachedCellInfo();
3357 }
3358
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003359 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003360 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003361 final long identity = Binder.clearCallingIdentity();
3362 try {
3363 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3364 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003365 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003366 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003367 if (info != null) cellInfos.addAll(info);
3368 }
3369 return cellInfos;
3370 } finally {
3371 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003372 }
3373 }
3374
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003375 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003376 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3377 String callingFeatureId) {
3378 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3379 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003380 }
3381
3382 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003383 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3384 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003385 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003386 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003387 }
3388
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003389 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3390 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003391 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003392 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003393
3394 LocationAccessPolicy.LocationPermissionResult locationResult =
3395 LocationAccessPolicy.checkLocationPermission(mApp,
3396 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3397 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003398 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003399 .setCallingPid(Binder.getCallingPid())
3400 .setCallingUid(Binder.getCallingUid())
3401 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003402 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3403 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003404 .build());
3405 switch (locationResult) {
3406 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003407 if (TelephonyPermissions
3408 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003409 // Safetynet logging for b/154934934
3410 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3411 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003412 throw new SecurityException("Not allowed to access cell info");
3413 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003414 if (TelephonyPermissions
3415 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003416 // Safetynet logging for b/154934934
3417 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3418 }
Nathan Harold5320c422019-05-09 10:26:08 -07003419 try {
3420 cb.onCellInfo(new ArrayList<CellInfo>());
3421 } catch (RemoteException re) {
3422 // Drop without consequences
3423 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003424 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003425 }
3426
Nathan Harolda939a962019-05-09 10:13:47 -07003427
3428 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003429 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3430
3431 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3432 }
3433
3434 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003435 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003436 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003437 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003438
3439 final long identity = Binder.clearCallingIdentity();
3440 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003441 Phone phone = getPhone(subId);
3442 if (phone == null) {
3443 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3444 } else {
3445 phone.setCellInfoListRate(rateInMillis, workSource);
3446 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003447 } finally {
3448 Binder.restoreCallingIdentity(identity);
3449 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003450 }
3451
Shishir Agrawala9f32182016-04-12 12:00:16 -07003452 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003453 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003454 Phone phone = PhoneFactory.getPhone(slotIndex);
3455 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003456 return null;
3457 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003458 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003459 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003460 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003461 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003462 return null;
3463 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003464
3465 final long identity = Binder.clearCallingIdentity();
3466 try {
3467 return phone.getImei();
3468 } finally {
3469 Binder.restoreCallingIdentity(identity);
3470 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003471 }
3472
3473 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003474 public String getTypeAllocationCodeForSlot(int slotIndex) {
3475 Phone phone = PhoneFactory.getPhone(slotIndex);
3476 String tac = null;
3477 if (phone != null) {
3478 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003479 try {
3480 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3481 } catch (IndexOutOfBoundsException e) {
3482 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3483 return null;
3484 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003485 }
3486 return tac;
3487 }
3488
3489 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003490 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003491 try {
3492 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3493 } catch (SecurityException se) {
3494 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3495 throw new SecurityException("Package " + callingPackage + " does not belong to "
3496 + Binder.getCallingUid());
3497 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003498 Phone phone = PhoneFactory.getPhone(slotIndex);
3499 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003500 return null;
3501 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003502
Jeff Davidson913390f2018-02-23 17:11:49 -08003503 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003504 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003505 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003506 return null;
3507 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003508
3509 final long identity = Binder.clearCallingIdentity();
3510 try {
3511 return phone.getMeid();
3512 } finally {
3513 Binder.restoreCallingIdentity(identity);
3514 }
Jack Yu2af8d712017-03-15 17:14:14 -07003515 }
3516
3517 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003518 public String getManufacturerCodeForSlot(int slotIndex) {
3519 Phone phone = PhoneFactory.getPhone(slotIndex);
3520 String manufacturerCode = null;
3521 if (phone != null) {
3522 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003523 try {
3524 manufacturerCode =
3525 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3526 } catch (IndexOutOfBoundsException e) {
3527 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3528 return null;
3529 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003530 }
3531 return manufacturerCode;
3532 }
3533
3534 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003535 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3536 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003537 Phone phone = PhoneFactory.getPhone(slotIndex);
3538 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003539 return null;
3540 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003541 int subId = phone.getSubId();
3542 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003543 mApp, subId, callingPackage, callingFeatureId,
3544 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003545 return null;
3546 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003547
3548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 return phone.getDeviceSvn();
3551 } finally {
3552 Binder.restoreCallingIdentity(identity);
3553 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003554 }
3555
fionaxu43304da2017-11-27 22:51:16 -08003556 @Override
3557 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003558 final long identity = Binder.clearCallingIdentity();
3559 try {
3560 final Phone phone = getPhone(subId);
3561 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3562 } finally {
3563 Binder.restoreCallingIdentity(identity);
3564 }
fionaxu43304da2017-11-27 22:51:16 -08003565 }
3566
3567 @Override
3568 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003569 final long identity = Binder.clearCallingIdentity();
3570 try {
3571 final Phone phone = getPhone(subId);
3572 return phone == null ? null : phone.getCarrierName();
3573 } finally {
3574 Binder.restoreCallingIdentity(identity);
3575 }
fionaxu43304da2017-11-27 22:51:16 -08003576 }
3577
calvinpanffe225e2018-11-01 19:43:06 +08003578 @Override
chen xu0026ca62019-03-06 15:28:50 -08003579 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003580 final long identity = Binder.clearCallingIdentity();
3581 try {
3582 final Phone phone = getPhone(subId);
3583 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003584 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003585 } finally {
3586 Binder.restoreCallingIdentity(identity);
3587 }
3588 }
3589
3590 @Override
chen xu0026ca62019-03-06 15:28:50 -08003591 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003592 final long identity = Binder.clearCallingIdentity();
3593 try {
3594 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003595 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003596 } finally {
3597 Binder.restoreCallingIdentity(identity);
3598 }
3599 }
3600
chen xu651eec72018-11-11 19:03:44 -08003601 @Override
chen xu864e11c2018-12-06 22:10:03 -08003602 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3603 if (!isSubscriptionMccMnc) {
3604 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3605 }
chen xu651eec72018-11-11 19:03:44 -08003606 final Phone phone = PhoneFactory.getPhone(slotIndex);
3607 if (phone == null) {
3608 return TelephonyManager.UNKNOWN_CARRIER_ID;
3609 }
3610 final long identity = Binder.clearCallingIdentity();
3611 try {
3612 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3613 } finally {
3614 Binder.restoreCallingIdentity(identity);
3615 }
3616 }
3617
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003618 //
3619 // Internal helper methods.
3620 //
3621
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003622 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003623 * Make sure the caller is the calling package itself
3624 *
3625 * @throws SecurityException if the caller is not the calling package
3626 */
3627 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3628 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003629 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3630 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003631 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003632 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003633 } catch (PackageManager.NameNotFoundException e) {
3634 // packageUid is -1
3635 }
3636 if (packageUid != callingUid) {
3637 throw new SecurityException(message + ": Package " + callingPackage
3638 + " does not belong to " + callingUid);
3639 }
3640 }
3641
3642 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003643 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3644 *
3645 * @throws SecurityException if the caller does not have the required permission
3646 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003647 @VisibleForTesting
3648 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003649 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3650 }
3651
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003652 /**
3653 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3654 *
3655 * @throws SecurityException if the caller does not have the required permission
3656 */
3657 @VisibleForTesting
3658 public void enforceReadPermission() {
3659 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, null);
3660 }
3661
Shuo Qian3b6ee772019-11-13 17:43:31 -08003662 private void enforceActiveEmergencySessionPermission() {
3663 mApp.enforceCallingOrSelfPermission(
3664 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3665 }
3666
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003667 /**
3668 * Make sure the caller has the CALL_PHONE permission.
3669 *
3670 * @throws SecurityException if the caller does not have the required permission
3671 */
3672 private void enforceCallPermission() {
3673 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3674 }
3675
paulhu5a773602019-08-23 19:17:33 +08003676 private void enforceSettingsPermission() {
3677 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003678 }
3679
Michele Berionne5e411512020-11-13 02:36:59 +00003680 private void enforceRebootPermission() {
3681 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3682 }
3683
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003684 private String createTelUrl(String number) {
3685 if (TextUtils.isEmpty(number)) {
3686 return null;
3687 }
3688
Jake Hambye994d462014-02-03 13:10:13 -08003689 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003690 }
3691
Ihab Awadf9e92732013-12-05 18:02:52 -08003692 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003693 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3694 }
3695
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003696 private static void logv(String msg) {
3697 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3698 }
3699
Ihab Awadf9e92732013-12-05 18:02:52 -08003700 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003701 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3702 }
3703
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003704 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003705 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003706 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003707 }
3708
Sanket Padawe356d7632015-06-22 14:03:32 -07003709 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003710 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003711 final long identity = Binder.clearCallingIdentity();
3712 try {
3713 final Phone phone = PhoneFactory.getPhone(slotIndex);
3714 if (phone == null) {
3715 return PhoneConstants.PHONE_TYPE_NONE;
3716 } else {
3717 return phone.getPhoneType();
3718 }
3719 } finally {
3720 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003721 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003722 }
3723
3724 /**
3725 * Returns the CDMA ERI icon index to display
3726 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003727 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003728 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3729 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3730 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003731 }
3732
Sanket Padawe356d7632015-06-22 14:03:32 -07003733 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003734 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3735 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003736 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003737 mApp, subId, callingPackage, callingFeatureId,
3738 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003739 return -1;
3740 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003741
3742 final long identity = Binder.clearCallingIdentity();
3743 try {
3744 final Phone phone = getPhone(subId);
3745 if (phone != null) {
3746 return phone.getCdmaEriIconIndex();
3747 } else {
3748 return -1;
3749 }
3750 } finally {
3751 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003752 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003753 }
3754
3755 /**
3756 * Returns the CDMA ERI icon mode,
3757 * 0 - ON
3758 * 1 - FLASHING
3759 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003760 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003761 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3762 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3763 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003764 }
3765
Sanket Padawe356d7632015-06-22 14:03:32 -07003766 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003767 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3768 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003769 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003770 mApp, subId, callingPackage, callingFeatureId,
3771 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003772 return -1;
3773 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003774
3775 final long identity = Binder.clearCallingIdentity();
3776 try {
3777 final Phone phone = getPhone(subId);
3778 if (phone != null) {
3779 return phone.getCdmaEriIconMode();
3780 } else {
3781 return -1;
3782 }
3783 } finally {
3784 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003785 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003786 }
3787
3788 /**
3789 * Returns the CDMA ERI text,
3790 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003791 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003792 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3793 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3794 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003795 }
3796
Sanket Padawe356d7632015-06-22 14:03:32 -07003797 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003798 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3799 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003800 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003801 mApp, subId, callingPackage, callingFeatureId,
3802 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003803 return null;
3804 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003805
3806 final long identity = Binder.clearCallingIdentity();
3807 try {
3808 final Phone phone = getPhone(subId);
3809 if (phone != null) {
3810 return phone.getCdmaEriText();
3811 } else {
3812 return null;
3813 }
3814 } finally {
3815 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003816 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003817 }
3818
3819 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003820 * Returns the CDMA MDN.
3821 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003822 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003823 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3825 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003826
3827 final long identity = Binder.clearCallingIdentity();
3828 try {
3829 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003830 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003831 return phone.getLine1Number();
3832 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003833 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003834 return null;
3835 }
3836 } finally {
3837 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003838 }
3839 }
3840
3841 /**
3842 * Returns the CDMA MIN.
3843 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003844 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003845 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3847 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003848
3849 final long identity = Binder.clearCallingIdentity();
3850 try {
3851 final Phone phone = getPhone(subId);
3852 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3853 return phone.getCdmaMin();
3854 } else {
3855 return null;
3856 }
3857 } finally {
3858 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003859 }
3860 }
3861
Hall Liud892bec2018-11-30 14:51:45 -08003862 @Override
3863 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3864 INumberVerificationCallback callback, String callingPackage) {
3865 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3866 != PERMISSION_GRANTED) {
3867 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3868 }
3869 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3870
3871 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3872 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003873 throw new SecurityException("Calling package must be configured in the device config: "
3874 + "calling package: " + callingPackage
3875 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003876 }
3877
3878 if (range == null) {
3879 throw new NullPointerException("Range must be non-null");
3880 }
3881
3882 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003883 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003884
3885 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3886 }
3887
Junda Liuca05d5d2014-08-14 22:36:34 -07003888 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003889 * Returns true if CDMA provisioning needs to run.
3890 */
3891 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003892 final long identity = Binder.clearCallingIdentity();
3893 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003894 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003895 } finally {
3896 Binder.restoreCallingIdentity(identity);
3897 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003898 }
3899
3900 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003901 * Sets the voice mail number of a given subId.
3902 */
3903 @Override
3904 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003905 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3906 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003907
3908 final long identity = Binder.clearCallingIdentity();
3909 try {
3910 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3911 new Pair<String, String>(alphaTag, number), new Integer(subId));
3912 return success;
3913 } finally {
3914 Binder.restoreCallingIdentity(identity);
3915 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003916 }
3917
Ta-wei Yen87c49842016-05-13 21:19:52 -07003918 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003919 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3920 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003921 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3922 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003923 if (!TextUtils.equals(callingPackage, systemDialer)) {
3924 throw new SecurityException("caller must be system dialer");
3925 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003926
3927 final long identity = Binder.clearCallingIdentity();
3928 try {
3929 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3930 if (phoneAccountHandle == null) {
3931 return null;
3932 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003933 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003934 } finally {
3935 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003936 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003937 }
3938
3939 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003940 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3941 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003942 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003943 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003944 mApp, subId, callingPackage, callingFeatureId,
3945 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003946 return null;
3947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003948
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003949 final long identity = Binder.clearCallingIdentity();
3950 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003951 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003952 } finally {
3953 Binder.restoreCallingIdentity(identity);
3954 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003955 }
3956
3957 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003958 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3959 VisualVoicemailSmsFilterSettings settings) {
3960 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003961
3962 final long identity = Binder.clearCallingIdentity();
3963 try {
3964 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003965 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003966 } finally {
3967 Binder.restoreCallingIdentity(identity);
3968 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003969 }
3970
3971 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003972 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3973 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003974
3975 final long identity = Binder.clearCallingIdentity();
3976 try {
3977 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003978 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003979 } finally {
3980 Binder.restoreCallingIdentity(identity);
3981 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003982 }
3983
3984 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003985 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3986 String callingPackage, int subId) {
3987 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003988
3989 final long identity = Binder.clearCallingIdentity();
3990 try {
3991 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003992 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003993 } finally {
3994 Binder.restoreCallingIdentity(identity);
3995 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003996 }
3997
3998 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003999 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004000 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004001
4002 final long identity = Binder.clearCallingIdentity();
4003 try {
4004 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004005 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004006 } finally {
4007 Binder.restoreCallingIdentity(identity);
4008 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004009 }
4010
4011 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004012 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4013 String callingAttributionTag, int subId, String number, int port, String text,
4014 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004015 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004016 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004017 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004018 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004019 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4020 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004021 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004022
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004023 /**
fionaxu0152e512016-11-14 13:36:14 -08004024 * Sets the voice activation state of a given subId.
4025 */
4026 @Override
4027 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4029 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004030
4031 final long identity = Binder.clearCallingIdentity();
4032 try {
4033 final Phone phone = getPhone(subId);
4034 if (phone != null) {
4035 phone.setVoiceActivationState(activationState);
4036 } else {
4037 loge("setVoiceActivationState fails with invalid subId: " + subId);
4038 }
4039 } finally {
4040 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004041 }
4042 }
4043
4044 /**
4045 * Sets the data activation state of a given subId.
4046 */
4047 @Override
4048 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4050 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004051
4052 final long identity = Binder.clearCallingIdentity();
4053 try {
4054 final Phone phone = getPhone(subId);
4055 if (phone != null) {
4056 phone.setDataActivationState(activationState);
4057 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004058 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004059 }
4060 } finally {
4061 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004062 }
4063 }
4064
4065 /**
4066 * Returns the voice activation state of a given subId.
4067 */
4068 @Override
4069 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004070 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004071
fionaxu0152e512016-11-14 13:36:14 -08004072 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004073 final long identity = Binder.clearCallingIdentity();
4074 try {
4075 if (phone != null) {
4076 return phone.getVoiceActivationState();
4077 } else {
4078 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4079 }
4080 } finally {
4081 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004082 }
4083 }
4084
4085 /**
4086 * Returns the data activation state of a given subId.
4087 */
4088 @Override
4089 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004090 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004091
fionaxu0152e512016-11-14 13:36:14 -08004092 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004093 final long identity = Binder.clearCallingIdentity();
4094 try {
4095 if (phone != null) {
4096 return phone.getDataActivationState();
4097 } else {
4098 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4099 }
4100 } finally {
4101 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004102 }
4103 }
4104
4105 /**
Wink Saville36469e72014-06-11 15:17:00 -07004106 * Returns the unread count of voicemails for a subId
4107 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004108 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004109 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4110 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004111 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004112 mApp, subId, callingPackage, callingFeatureId,
4113 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004114 return 0;
4115 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004116 final long identity = Binder.clearCallingIdentity();
4117 try {
4118 final Phone phone = getPhone(subId);
4119 if (phone != null) {
4120 return phone.getVoiceMessageCount();
4121 } else {
4122 return 0;
4123 }
4124 } finally {
4125 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004126 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004127 }
4128
4129 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004130 * returns true, if the device is in a state where both voice and data
4131 * are supported simultaneously. This can change based on location or network condition.
4132 */
4133 @Override
4134 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004135 final long identity = Binder.clearCallingIdentity();
4136 try {
4137 final Phone phone = getPhone(subId);
4138 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4139 } finally {
4140 Binder.restoreCallingIdentity(identity);
4141 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004142 }
4143
4144 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004145 * Send the dialer code if called from the current default dialer or the caller has
4146 * carrier privilege.
4147 * @param inputCode The dialer code to send
4148 */
4149 @Override
4150 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004151 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004152 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004153 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4154 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004155 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004156 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004157 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004158 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004159
4160 final long identity = Binder.clearCallingIdentity();
4161 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004162 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004163 } finally {
4164 Binder.restoreCallingIdentity(identity);
4165 }
fionaxu235cc5e2017-03-06 22:25:57 -08004166 }
4167
Pengquan Menga1bb6272018-09-06 09:59:22 -07004168 @Override
4169 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004170 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004171 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004172 mApp, subId, "getNetworkSelectionMode");
4173 final long identity = Binder.clearCallingIdentity();
4174 try {
4175 if (!isActiveSubscription(subId)) {
4176 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4177 }
4178 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4179 } finally {
4180 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004181 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004182 }
4183
Brad Ebinger35c841c2018-10-01 10:40:55 -07004184 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004185 public boolean isInEmergencySmsMode() {
4186 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4187 final long identity = Binder.clearCallingIdentity();
4188 try {
4189 for (Phone phone : PhoneFactory.getPhones()) {
4190 if (phone.isInEmergencySmsMode()) {
4191 return true;
4192 }
4193 }
4194 } finally {
4195 Binder.restoreCallingIdentity(identity);
4196 }
4197 return false;
4198 }
4199
shilu366312e2019-12-17 09:28:10 -08004200 /**
4201 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4202 * @param subId The subscription to use to check the configuration.
4203 * @param c The callback that will be used to send the result.
4204 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004205 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004206 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4207 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004208 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004209 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004210
4211 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4212 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4213 "IMS not available on device.");
4214 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004215 final long token = Binder.clearCallingIdentity();
4216 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004217 int slotId = getSlotIndexOrException(subId);
4218 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004219
4220 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4221 if (controller != null) {
4222 ImsManager imsManager = controller.getImsManager(subId);
4223 if (imsManager != null) {
4224 imsManager.addRegistrationCallbackForSubscription(c, subId);
4225 } else {
4226 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4227 }
4228 } else {
4229 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4230 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004231 } catch (ImsException e) {
4232 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004233 } finally {
4234 Binder.restoreCallingIdentity(token);
4235 }
4236 }
4237
shilu366312e2019-12-17 09:28:10 -08004238 /**
4239 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4240 * @param subId The subscription to use to check the configuration.
4241 * @param c The callback that will be used to send the result.
4242 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004243 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004244 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004245 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004246 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004247 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4248 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4249 }
Meng Wangafbc5852019-09-19 17:37:13 -07004250 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004251
Meng Wangafbc5852019-09-19 17:37:13 -07004252 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004253 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4254 if (controller != null) {
4255 ImsManager imsManager = controller.getImsManager(subId);
4256 if (imsManager != null) {
4257 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4258 } else {
4259 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4260 + "is inactive, ignoring unregister.");
4261 // If the ImsManager is not valid, just return, since the callback
4262 // will already have been removed internally.
4263 }
4264 }
Meng Wangafbc5852019-09-19 17:37:13 -07004265 } finally {
4266 Binder.restoreCallingIdentity(token);
4267 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004268 }
4269
Brad Ebingera34a6c22019-10-22 17:36:18 -07004270 /**
4271 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4272 */
4273 @Override
4274 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4275 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4276 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4277 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4278 "IMS not available on device.");
4279 }
4280 final long token = Binder.clearCallingIdentity();
4281 try {
4282 Phone phone = getPhone(subId);
4283 if (phone == null) {
4284 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4285 + subId + "'");
4286 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4287 }
4288 phone.getImsRegistrationState(regState -> {
4289 try {
4290 consumer.accept((regState == null)
4291 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4292 } catch (RemoteException e) {
4293 // Ignore if the remote process is no longer available to call back.
4294 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4295 }
4296 });
4297 } finally {
4298 Binder.restoreCallingIdentity(token);
4299 }
4300 }
4301
4302 /**
4303 * Get the transport type for the IMS service registration state.
4304 */
4305 @Override
4306 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004307 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004308 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004309 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4310 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4311 "IMS not available on device.");
4312 }
4313 final long token = Binder.clearCallingIdentity();
4314 try {
4315 Phone phone = getPhone(subId);
4316 if (phone == null) {
4317 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4318 + subId + "'");
4319 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4320 }
4321 phone.getImsRegistrationTech(regTech -> {
4322 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4323 int regTechConverted = (regTech == null)
4324 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4325 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4326 regTechConverted);
4327 try {
4328 consumer.accept(regTechConverted);
4329 } catch (RemoteException e) {
4330 // Ignore if the remote process is no longer available to call back.
4331 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4332 }
4333 });
4334 } finally {
4335 Binder.restoreCallingIdentity(token);
4336 }
4337 }
4338
shilu366312e2019-12-17 09:28:10 -08004339 /**
4340 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4341 * @param subId The subscription to use to check the configuration.
4342 * @param c The callback that will be used to send the result.
4343 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004344 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004345 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4346 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004347 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004348 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004349 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4350 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4351 "IMS not available on device.");
4352 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004353 final long token = Binder.clearCallingIdentity();
4354 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004355 int slotId = getSlotIndexOrException(subId);
4356 verifyImsMmTelConfiguredOrThrow(slotId);
4357 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004358 } catch (ImsException e) {
4359 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004360 } finally {
4361 Binder.restoreCallingIdentity(token);
4362 }
4363 }
4364
shilu366312e2019-12-17 09:28:10 -08004365 /**
4366 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4367 * @param subId The subscription to use to check the configuration.
4368 * @param c The callback that will be used to send the result.
4369 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004370 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004371 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004372 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004373 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004374 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4375 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4376 }
Meng Wangafbc5852019-09-19 17:37:13 -07004377
4378 final long token = Binder.clearCallingIdentity();
4379 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004380 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004381 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004382 } catch (ImsException e) {
4383 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4384 + "is inactive, ignoring unregister.");
4385 // If the subscription is no longer active, just return, since the callback
4386 // will already have been removed internally.
4387 } finally {
4388 Binder.restoreCallingIdentity(token);
4389 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004390 }
4391
4392 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004393 public boolean isCapable(int subId, int capability, int regTech) {
4394 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004395 final long token = Binder.clearCallingIdentity();
4396 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004397 int slotId = getSlotIndexOrException(subId);
4398 verifyImsMmTelConfiguredOrThrow(slotId);
4399 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4400 } catch (com.android.ims.ImsException e) {
4401 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4402 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004403 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004404 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4405 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004406 } finally {
4407 Binder.restoreCallingIdentity(token);
4408 }
4409 }
4410
4411 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004412 public boolean isAvailable(int subId, int capability, int regTech) {
4413 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004414 final long token = Binder.clearCallingIdentity();
4415 try {
4416 Phone phone = getPhone(subId);
4417 if (phone == null) return false;
4418 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004419 } catch (com.android.ims.ImsException e) {
4420 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4421 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004422 } finally {
4423 Binder.restoreCallingIdentity(token);
4424 }
4425 }
4426
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004427 /**
4428 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4429 * subscription.
4430 * @param subId The subscription to use to check the configuration.
4431 * @param callback The callback that will be used to send the result.
4432 * @param capability The MmTelFeature capability that will be used to send the result.
4433 * @param transportType The transport type of the MmTelFeature capability.
4434 */
4435 @Override
4436 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4437 int transportType) {
4438 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004439 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4440 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4441 "IMS not available on device.");
4442 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004443 final long token = Binder.clearCallingIdentity();
4444 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004445 int slotId = getSlotIndex(subId);
4446 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4447 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4448 + subId + "'");
4449 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4450 }
4451 verifyImsMmTelConfiguredOrThrow(slotId);
4452 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4453 transportType, aBoolean -> {
4454 try {
4455 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4456 } catch (RemoteException e) {
4457 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4458 + "running. Ignore");
4459 }
4460 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004461 } catch (ImsException e) {
4462 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004463 } finally {
4464 Binder.restoreCallingIdentity(token);
4465 }
4466 }
4467
shilu366312e2019-12-17 09:28:10 -08004468 /**
4469 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4470 * @param subId The subscription to use to check the configuration.
4471 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004472 @Override
4473 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004474 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004475 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004476
Brad Ebinger35c841c2018-10-01 10:40:55 -07004477 final long token = Binder.clearCallingIdentity();
4478 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004479 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004480 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004481 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004482 } catch (ImsException e) {
4483 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004484 } finally {
4485 Binder.restoreCallingIdentity(token);
4486 }
4487 }
4488
4489 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004490 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004492 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004493 final long identity = Binder.clearCallingIdentity();
4494 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004495 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004496 // This setting doesn't require an active ImsService connection, so do not verify. The
4497 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004498 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004499 } catch (ImsException e) {
4500 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004501 } finally {
4502 Binder.restoreCallingIdentity(identity);
4503 }
4504 }
4505
shilu366312e2019-12-17 09:28:10 -08004506 /**
4507 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4508 * @param subId The subscription to use to check the configuration.
4509 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004510 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004511 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004512 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004513 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004514 final long identity = Binder.clearCallingIdentity();
4515 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004516 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004517 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004518 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004519 } catch (ImsException e) {
4520 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004521 } finally {
4522 Binder.restoreCallingIdentity(identity);
4523 }
4524 }
4525
4526 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004527 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004529 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004530 final long identity = Binder.clearCallingIdentity();
4531 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004532 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004533 // This setting doesn't require an active ImsService connection, so do not verify. The
4534 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004535 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004536 } catch (ImsException e) {
4537 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004538 } finally {
4539 Binder.restoreCallingIdentity(identity);
4540 }
4541 }
4542
shilu366312e2019-12-17 09:28:10 -08004543 /**
4544 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4545 * @param subId The subscription to use to check the configuration.
4546 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004547 @Override
4548 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004549 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004550 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004551 final long identity = Binder.clearCallingIdentity();
4552 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004553 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004554 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004555 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004556 } catch (ImsException e) {
4557 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004558 } finally {
4559 Binder.restoreCallingIdentity(identity);
4560 }
4561 }
4562
4563 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004564 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004565 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004566 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004567 final long identity = Binder.clearCallingIdentity();
4568 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004569 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004570 // This setting doesn't require an active ImsService connection, so do not verify. The
4571 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004572 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004573 } catch (ImsException e) {
4574 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004575 } finally {
4576 Binder.restoreCallingIdentity(identity);
4577 }
4578 }
4579
shilu366312e2019-12-17 09:28:10 -08004580 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004581 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4582 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4583 * @param subId The subscription to use to check the configuration.
4584 */
4585 @Override
4586 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004587 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004588 mApp, subId, "isCrossSimCallingEnabledByUser");
4589 final long identity = Binder.clearCallingIdentity();
4590 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004591 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004592 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004593 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004594 } catch (ImsException e) {
4595 throw new ServiceSpecificException(e.getCode());
4596 } finally {
4597 Binder.restoreCallingIdentity(identity);
4598 }
4599 }
4600
4601 /**
4602 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4603 * Requires MODIFY_PHONE_STATE permission.
4604 * @param subId The subscription to use to check the configuration.
4605 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4606 * false otherwise
4607 */
4608 @Override
4609 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4611 "setCrossSimCallingEnabled");
4612 final long identity = Binder.clearCallingIdentity();
4613 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004614 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004615 // This setting doesn't require an active ImsService connection, so do not verify. The
4616 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004617 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004618 } catch (ImsException e) {
4619 throw new ServiceSpecificException(e.getCode());
4620 } finally {
4621 Binder.restoreCallingIdentity(identity);
4622 }
4623 }
4624
4625 /**
shilu366312e2019-12-17 09:28:10 -08004626 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4627 * @param subId The subscription to use to check the configuration.
4628 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004629 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004630
Brad Ebinger35c841c2018-10-01 10:40:55 -07004631 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004632 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004633 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004634 final long identity = Binder.clearCallingIdentity();
4635 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004636 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004637 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004638 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004639 } catch (ImsException e) {
4640 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004641 } finally {
4642 Binder.restoreCallingIdentity(identity);
4643 }
4644 }
4645
4646 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004647 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004649 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004650 final long identity = Binder.clearCallingIdentity();
4651 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004652 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004653 // This setting doesn't require an active ImsService connection, so do not verify. The
4654 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004655 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004656 } catch (ImsException e) {
4657 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004658 } finally {
4659 Binder.restoreCallingIdentity(identity);
4660 }
4661 }
4662
4663 @Override
4664 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4666 "setVoWiFiNonPersistent");
4667 final long identity = Binder.clearCallingIdentity();
4668 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004669 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004670 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004671 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004672 } catch (ImsException e) {
4673 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004674 } finally {
4675 Binder.restoreCallingIdentity(identity);
4676 }
4677 }
4678
shilu366312e2019-12-17 09:28:10 -08004679 /**
4680 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4681 * @param subId The subscription to use to check the configuration.
4682 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004683 @Override
4684 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004685 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004686 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004687 final long identity = Binder.clearCallingIdentity();
4688 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004689 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004690 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004691 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004692 } catch (ImsException e) {
4693 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004694 } finally {
4695 Binder.restoreCallingIdentity(identity);
4696 }
4697 }
4698
4699 @Override
4700 public void setVoWiFiModeSetting(int subId, int mode) {
4701 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4702 "setVoWiFiModeSetting");
4703 final long identity = Binder.clearCallingIdentity();
4704 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004705 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004706 // This setting doesn't require an active ImsService connection, so do not verify. The
4707 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004708 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004709 } catch (ImsException e) {
4710 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004711 } finally {
4712 Binder.restoreCallingIdentity(identity);
4713 }
4714 }
4715
4716 @Override
4717 public int getVoWiFiRoamingModeSetting(int subId) {
4718 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4719 final long identity = Binder.clearCallingIdentity();
4720 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004721 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004722 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004723 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004724 } catch (ImsException e) {
4725 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004726 } finally {
4727 Binder.restoreCallingIdentity(identity);
4728 }
4729 }
4730
4731 @Override
4732 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4734 "setVoWiFiRoamingModeSetting");
4735 final long identity = Binder.clearCallingIdentity();
4736 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004737 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004738 // This setting doesn't require an active ImsService connection, so do not verify. The
4739 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004740 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004741 } catch (ImsException e) {
4742 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004743 } finally {
4744 Binder.restoreCallingIdentity(identity);
4745 }
4746 }
4747
4748 @Override
4749 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4750 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4751 "setRttCapabilityEnabled");
4752 final long identity = Binder.clearCallingIdentity();
4753 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004754 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004755 // This setting doesn't require an active ImsService connection, so do not verify. The
4756 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004757 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004758 } catch (ImsException e) {
4759 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004760 } finally {
4761 Binder.restoreCallingIdentity(identity);
4762 }
4763 }
4764
shilu366312e2019-12-17 09:28:10 -08004765 /**
4766 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4767 * @param subId The subscription to use to check the configuration.
4768 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004769 @Override
4770 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004771 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004772 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004773 final long identity = Binder.clearCallingIdentity();
4774 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004775 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004776 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004777 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004778 } catch (ImsException e) {
4779 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004780 } finally {
4781 Binder.restoreCallingIdentity(identity);
4782 }
4783 }
4784
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004785 @Override
4786 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4787 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004788
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004789 final long identity = Binder.clearCallingIdentity();
4790 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004791 if (!isImsAvailableOnDevice()) {
4792 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4793 "IMS not available on device.");
4794 }
4795 int slotId = getSlotIndexOrException(subId);
4796 verifyImsMmTelConfiguredOrThrow(slotId);
4797 ImsManager.getInstance(mApp, slotId)
4798 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004799 } catch (ImsException e) {
4800 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004801 } finally {
4802 Binder.restoreCallingIdentity(identity);
4803 }
4804 }
4805
4806 @Override
4807 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4808 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004809
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004810 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004811 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4812 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4813 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004814 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004815 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004816 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004817 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004818 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4819 + "is inactive, ignoring unregister.");
4820 // If the subscription is no longer active, just return, since the callback will already
4821 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004822 } finally {
4823 Binder.restoreCallingIdentity(identity);
4824 }
4825 }
4826
joonhunshincffb7fc2021-11-28 07:32:01 +00004827 @Override
4828 public void registerFeatureProvisioningChangedCallback(int subId,
4829 IFeatureProvisioningCallback callback) {
4830 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4831 mApp, subId, "registerFeatureProvisioningChangedCallback");
4832
4833 final long identity = Binder.clearCallingIdentity();
4834 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4835 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4836 }
4837
joonhunshin91bc1952022-04-29 08:47:15 +00004838 try {
4839 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4840 if (controller == null) {
4841 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4842 "Device does not support IMS");
4843 }
4844 controller.addFeatureProvisioningChangedCallback(subId, callback);
4845 } finally {
4846 Binder.restoreCallingIdentity(identity);
4847 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004848 }
4849
4850 @Override
4851 public void unregisterFeatureProvisioningChangedCallback(int subId,
4852 IFeatureProvisioningCallback callback) {
4853 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4854 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4855
4856 final long identity = Binder.clearCallingIdentity();
4857 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4858 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4859 }
4860
joonhunshin91bc1952022-04-29 08:47:15 +00004861 try {
4862 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4863 if (controller == null) {
4864 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4865 return;
4866 }
4867 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4868 } finally {
4869 Binder.restoreCallingIdentity(identity);
4870 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004871 }
allenwtsu99c623b2020-01-03 18:24:23 +08004872
4873 private void checkModifyPhoneStatePermission(int subId, String message) {
4874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4875 message);
4876 }
4877
allenwtsu99c623b2020-01-03 18:24:23 +08004878 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004879 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004880 boolean isProvisioned) {
4881 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4882
4883 final long identity = Binder.clearCallingIdentity();
4884 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004885 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4886 if (controller == null) {
4887 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4888 return;
4889 }
4890 controller.setRcsProvisioningStatusForCapability(
4891 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004892 } finally {
4893 Binder.restoreCallingIdentity(identity);
4894 }
allenwtsu99c623b2020-01-03 18:24:23 +08004895 }
4896
4897
4898 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004899 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4900 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4901 mApp, subId, "getRcsProvisioningStatusForCapability");
4902
allenwtsu99c623b2020-01-03 18:24:23 +08004903 final long identity = Binder.clearCallingIdentity();
4904 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004905 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4906 if (controller == null) {
4907 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4908
4909 // device does not support IMS, this method will return true always.
4910 return true;
4911 }
4912 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004913 } finally {
4914 Binder.restoreCallingIdentity(identity);
4915 }
4916 }
4917
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004918 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004919 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4920 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004921 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004922
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004923 final long identity = Binder.clearCallingIdentity();
4924 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004925 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4926 if (controller == null) {
4927 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4928 return;
4929 }
4930 controller.setImsProvisioningStatusForCapability(
4931 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004932 } finally {
4933 Binder.restoreCallingIdentity(identity);
4934 }
4935 }
4936
4937 @Override
4938 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004939 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4940 mApp, subId, "getProvisioningStatusForCapability");
4941
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004942 final long identity = Binder.clearCallingIdentity();
4943 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004944 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4945 if (controller == null) {
4946 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004947
joonhunshin91bc1952022-04-29 08:47:15 +00004948 // device does not support IMS, this method will return true always.
4949 return true;
4950 }
4951 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004952 } finally {
4953 Binder.restoreCallingIdentity(identity);
4954 }
4955 }
4956
4957 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004958 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4959 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4960 mApp, subId, "isProvisioningRequiredForCapability");
4961
4962 final long identity = Binder.clearCallingIdentity();
4963 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004964 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4965 if (controller == null) {
4966 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4967
4968 // device does not support IMS, this method will return false
4969 return false;
4970 }
4971 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004972 } finally {
4973 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004974 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004975 }
4976
4977 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004978 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4979 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4980 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004981
joonhunshincffb7fc2021-11-28 07:32:01 +00004982 final long identity = Binder.clearCallingIdentity();
4983 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004984 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4985 if (controller == null) {
4986 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4987
4988 // device does not support IMS, this method will return false
4989 return false;
4990 }
4991 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004992 } finally {
4993 Binder.restoreCallingIdentity(identity);
4994 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004995 }
4996
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004997 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004998 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004999 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5000 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5001 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005002 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5003 mApp, subId, "getImsProvisioningInt");
5004
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005005 final long identity = Binder.clearCallingIdentity();
5006 try {
5007 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005008 int slotId = getSlotIndex(subId);
5009 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5010 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5011 + subId + "' for key:" + key);
5012 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5013 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005014
joonhunshin91bc1952022-04-29 08:47:15 +00005015 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5016 if (controller == null) {
5017 loge("getImsProvisioningInt: Device does not support IMS");
5018
5019 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5020 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5021 }
5022 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005023 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5024 return retVal;
5025 }
5026
calvinpanb5a34062021-02-08 19:59:36 +08005027 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005028 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005029 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5030 + subId + "' for key:" + key);
5031 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005032 } finally {
5033 Binder.restoreCallingIdentity(identity);
5034 }
5035 }
5036
5037 @Override
5038 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005039 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5040 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5041 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005042 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5043 mApp, subId, "getImsProvisioningString");
5044
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005045 final long identity = Binder.clearCallingIdentity();
5046 try {
5047 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005048 int slotId = getSlotIndex(subId);
5049 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5050 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5051 + subId + "' for key:" + key);
5052 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5053 }
calvinpanb5a34062021-02-08 19:59:36 +08005054 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005055 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005056 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5057 + subId + "' for key:" + key);
5058 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005059 } finally {
5060 Binder.restoreCallingIdentity(identity);
5061 }
5062 }
5063
5064 @Override
5065 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005066 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5067 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5068 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5070 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005071
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005072 final long identity = Binder.clearCallingIdentity();
5073 try {
5074 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005075 int slotId = getSlotIndex(subId);
5076 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5077 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5078 + subId + "' for key:" + key);
5079 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5080 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005081
joonhunshin91bc1952022-04-29 08:47:15 +00005082 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5083 if (controller == null) {
5084 loge("setImsProvisioningInt: Device does not support IMS");
5085
5086 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5087 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5088 }
5089 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005090 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5091 return retVal;
5092 }
5093
calvinpanb5a34062021-02-08 19:59:36 +08005094 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5095 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005096 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005097 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005098 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005099 } finally {
5100 Binder.restoreCallingIdentity(identity);
5101 }
5102 }
5103
5104 @Override
5105 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005106 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5107 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5108 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005109 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5110 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005111 final long identity = Binder.clearCallingIdentity();
5112 try {
5113 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005114 int slotId = getSlotIndex(subId);
5115 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5116 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5117 + subId + "' for key:" + key);
5118 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5119 }
calvinpanb5a34062021-02-08 19:59:36 +08005120 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5121 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005122 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005123 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005124 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005125 } finally {
5126 Binder.restoreCallingIdentity(identity);
5127 }
5128 }
5129
Brad Ebinger919631e2021-06-02 17:46:35 -07005130 /**
5131 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5132 * for the given slot ID or no ImsResolver instance has been created.
5133 * @param slotId The slot ID that the IMS service is created for.
5134 * @throws ImsException If there is no ImsService configured for this slot.
5135 */
5136 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5137 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5138 ImsFeature.FEATURE_MMTEL)) {
5139 throw new ImsException("This subscription does not support MMTEL over IMS",
5140 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5141 }
5142 }
5143
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005144 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005145 int slotId = SubscriptionManager.getSlotIndex(subId);
5146 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005147 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5148 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005149 }
5150 return slotId;
5151 }
5152
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005153 private int getSlotIndex(int subId) {
5154 int slotId = SubscriptionManager.getSlotIndex(subId);
5155 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5156 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5157 }
5158 return slotId;
5159 }
5160
Wink Saville36469e72014-06-11 15:17:00 -07005161 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005162 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005163 */
5164 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005165 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5166 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005167 try {
5168 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5169 } catch (SecurityException se) {
5170 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5171 throw new SecurityException("Package " + callingPackage + " does not belong to "
5172 + Binder.getCallingUid());
5173 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005174 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005175 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005176 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005177 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005178 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005179 mApp, subId, callingPackage, callingFeatureId,
5180 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005181 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5182 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005183
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005184 final long identity = Binder.clearCallingIdentity();
5185 try {
5186 final Phone phone = getPhone(subId);
5187 if (phone != null) {
5188 return phone.getServiceState().getDataNetworkType();
5189 } else {
5190 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5191 }
5192 } finally {
5193 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005195 }
5196
5197 /**
5198 * Returns the data network type
5199 */
5200 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005201 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005202 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005203 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005204 }
5205
5206 /**
5207 * Returns the data network type for a subId
5208 */
5209 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005210 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5211 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005212 String functionName = "getDataNetworkTypeForSubscriber";
5213 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5214 mApp, functionName)) {
5215 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5216 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5217 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5218 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005219 }
5220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005221 final long identity = Binder.clearCallingIdentity();
5222 try {
5223 final Phone phone = getPhone(subId);
5224 if (phone != null) {
5225 return phone.getServiceState().getDataNetworkType();
5226 } else {
5227 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5228 }
5229 } finally {
5230 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005231 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005232 }
5233
5234 /**
Wink Saville36469e72014-06-11 15:17:00 -07005235 * Returns the Voice network type for a subId
5236 */
5237 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005238 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5239 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005240 String functionName = "getVoiceNetworkTypeForSubscriber";
5241 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5242 mApp, functionName)) {
5243 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5244 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5245 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5246 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005247 }
5248
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005249 final long identity = Binder.clearCallingIdentity();
5250 try {
5251 final Phone phone = getPhone(subId);
5252 if (phone != null) {
5253 return phone.getServiceState().getVoiceNetworkType();
5254 } else {
5255 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5256 }
5257 } finally {
5258 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005259 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005260 }
5261
5262 /**
5263 * @return true if a ICC card is present
5264 */
5265 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005266 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005267 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005268 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005269 }
5270
5271 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005272 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005273 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005274 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005275 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276 final long identity = Binder.clearCallingIdentity();
5277 try {
5278 final Phone phone = PhoneFactory.getPhone(slotIndex);
5279 if (phone != null) {
5280 return phone.getIccCard().hasIccCard();
5281 } else {
5282 return false;
5283 }
5284 } finally {
5285 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005286 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005287 }
5288
5289 /**
5290 * Return if the current radio is LTE on CDMA. This
5291 * is a tri-state return value as for a period of time
5292 * the mode may be unknown.
5293 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005294 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005295 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005296 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005297 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005298 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005299 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5300 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5301 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005302 }
5303
Sanket Padawe356d7632015-06-22 14:03:32 -07005304 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005305 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5306 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005307 try {
5308 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5309 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005310 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5311 }
5312
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005313 final long identity = Binder.clearCallingIdentity();
5314 try {
5315 final Phone phone = getPhone(subId);
5316 if (phone == null) {
5317 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5318 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005319 return TelephonyProperties.lte_on_cdma_device()
5320 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005321 }
5322 } finally {
5323 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005324 }
Wink Saville36469e72014-06-11 15:17:00 -07005325 }
5326
Wink Saville36469e72014-06-11 15:17:00 -07005327 /**
5328 * {@hide}
5329 * Returns Default subId, 0 in the case of single standby.
5330 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005331 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005332 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005333 }
5334
Shishir Agrawala9f32182016-04-12 12:00:16 -07005335 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005336 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005337 }
5338
Wink Savilleb564aae2014-10-23 10:18:09 -07005339 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005340 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005341 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005342
Pengquan Menge92a50d2018-09-21 15:54:48 -07005343 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08005344 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
5345 return SubscriptionManagerService.getInstance().isActiveSubId(subId,
5346 mApp.getOpPackageName(), mApp.getFeatureId());
5347 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005348 return mSubscriptionController.isActiveSubId(subId);
5349 }
5350
Ihab Awadf2177b72013-11-25 13:33:23 -08005351 /**
5352 * @see android.telephony.TelephonyManager.WifiCallingChoices
5353 */
5354 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005355 final long identity = Binder.clearCallingIdentity();
5356 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005357 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5359 getWhenToMakeWifiCallsDefaultPreference());
5360 } finally {
5361 Binder.restoreCallingIdentity(identity);
5362 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005363 }
5364
5365 /**
5366 * @see android.telephony.TelephonyManager.WifiCallingChoices
5367 */
5368 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005369 final long identity = Binder.clearCallingIdentity();
5370 try {
5371 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005372 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005373 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5374 } finally {
5375 Binder.restoreCallingIdentity(identity);
5376 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005377 }
5378
Sailesh Nepald1e68152013-12-12 19:08:02 -08005379 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005380 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005381 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005382 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005383
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005384 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5385 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5386 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005387 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005388 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5389 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005390 }
5391 return PhoneFactory.getPhone(phoneId);
5392 }
5393
Shishir Agrawal566b7612013-10-28 14:41:00 -07005394 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005395 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005396 @NonNull IccLogicalChannelRequest request) {
5397 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5398 /*message=*/ "iccOpenLogicalChannel");
5399
5400 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5401 // Verify that the callingPackage in the request belongs to the calling UID
5402 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5403
5404 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005405 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005406
Rambo Wanga1782702021-11-10 20:15:19 -08005407 private Phone getPhoneFromValidIccLogicalChannelRequest(
5408 @NonNull IccLogicalChannelRequest request, String message) {
5409 Phone phone;
5410 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5412 mApp, request.subId, message);
5413 phone = getPhoneFromSubId(request.subId);
5414 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5415 enforceModifyPermission();
5416 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5417 } else {
5418 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005419 }
Rambo Wanga1782702021-11-10 20:15:19 -08005420 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005421 }
5422
5423 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005424 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005425 final long identity = Binder.clearCallingIdentity();
5426 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005427 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005428 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005429 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5430 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005431 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5432 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005433 loge("The calling package is not allowed to access ISD-R.");
5434 throw new SecurityException(
5435 "The calling package is not allowed to access ISD-R.");
5436 }
Derek Tan740e1672017-06-27 14:56:27 -07005437 }
Derek Tan740e1672017-06-27 14:56:27 -07005438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005439 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005440 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5441 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005442 return response;
5443 } finally {
5444 Binder.restoreCallingIdentity(identity);
5445 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005446 }
5447
5448 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005449 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5450 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5451 /*message=*/"iccCloseLogicalChannel");
5452
5453 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5454
5455 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005456 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005457
Rambo Wanga1782702021-11-10 20:15:19 -08005458 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5459 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005460 // before this feature is enabled, this API should only return false if
5461 // the operation fails instead of throwing runtime exception for
5462 // backward-compatibility.
5463 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5464 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005465 final long identity = Binder.clearCallingIdentity();
5466 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005467 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005468 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005469 }
Chen Xue9d737e2022-01-01 23:41:31 -08005470 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005471 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005472 Boolean success = false;
5473 if (result instanceof RuntimeException) {
5474 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005475 if (shouldThrowExceptionOnFailure) {
5476 throw (RuntimeException) result;
5477 } else {
5478 return false;
5479 }
Chen Xue9d737e2022-01-01 23:41:31 -08005480 } else if (result instanceof Boolean) {
5481 success = (Boolean) result;
5482 } else {
5483 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5484 }
Rambo Wanga1782702021-11-10 20:15:19 -08005485 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005486 return success;
5487 } finally {
5488 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005489 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005490 }
5491
5492 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005493 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005494 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005495 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5496 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005497 if (DBG) {
5498 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5499 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5500 + p3 + " data=" + data);
5501 }
5502 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5503 command, p1, p2, p3, data);
5504 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005505
Jordan Liu4c733742019-02-28 12:03:40 -08005506 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005507 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5508 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005509 enforceModifyPermission();
5510 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005511 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5512 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5513 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005514 }
5515 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005516 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5517 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005518 }
5519
5520 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5521 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005522 final long identity = Binder.clearCallingIdentity();
5523 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005524 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005525 return "";
5526 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005527
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005528 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005529 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5530 null /* workSource */);
5531 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005532
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005533 // Append the returned status code to the end of the response payload.
5534 String s = Integer.toHexString(
5535 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5536 if (response.payload != null) {
5537 s = IccUtils.bytesToHexString(response.payload) + s;
5538 }
5539 return s;
5540 } finally {
5541 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005542 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005543 }
Jake Hambye994d462014-02-03 13:10:13 -08005544
Evan Charltonc66da362014-05-16 14:06:40 -07005545 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005546 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5547 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5549 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005550 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005551 if (DBG) {
5552 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5553 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5554 }
5555 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5556 cla, command, p1, p2, p3, data);
5557 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005558
Jordan Liu4c733742019-02-28 12:03:40 -08005559 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005560 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5561 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005562 enforceModifyPermission();
5563 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5564 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005565 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5566 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5567 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005568 }
5569
5570 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005571 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5572 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005573 }
5574
5575 // open APDU basic channel assuming the caller has sufficient permissions
5576 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5577 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578 final long identity = Binder.clearCallingIdentity();
5579 try {
5580 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5581 && TextUtils.equals(ISDR_AID, data)) {
5582 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005583 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5584 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005585 if (bestComponent == null
5586 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5587 loge("The calling package is not allowed to select ISD-R.");
5588 throw new SecurityException(
5589 "The calling package is not allowed to select ISD-R.");
5590 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005591 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005592
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005593 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005594 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5595 null /* workSource */);
5596 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005597
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005598 // Append the returned status code to the end of the response payload.
5599 String s = Integer.toHexString(
5600 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5601 if (response.payload != null) {
5602 s = IccUtils.bytesToHexString(response.payload) + s;
5603 }
5604 return s;
5605 } finally {
5606 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005607 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005608 }
5609
5610 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005611 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005612 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5614 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005615
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005616 final long identity = Binder.clearCallingIdentity();
5617 try {
5618 if (DBG) {
5619 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5620 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5621 }
5622
5623 IccIoResult response =
5624 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5625 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5626 subId);
5627
5628 if (DBG) {
5629 log("Exchange SIM_IO [R]" + response);
5630 }
5631
5632 byte[] result = null;
5633 int length = 2;
5634 if (response.payload != null) {
5635 length = 2 + response.payload.length;
5636 result = new byte[length];
5637 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5638 } else {
5639 result = new byte[length];
5640 }
5641
5642 result[length - 1] = (byte) response.sw2;
5643 result[length - 2] = (byte) response.sw1;
5644 return result;
5645 } finally {
5646 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005647 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005648 }
5649
Nathan Haroldb3014052017-01-25 15:57:32 -08005650 /**
5651 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5652 * on a particular subscription
5653 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005654 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5655 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005656 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005657 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005658 return null;
5659 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005660
5661 final long identity = Binder.clearCallingIdentity();
5662 try {
5663 if (appType != TelephonyManager.APPTYPE_USIM
5664 && appType != TelephonyManager.APPTYPE_SIM) {
5665 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5666 return null;
5667 }
5668 Object response = sendRequest(
5669 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5670 if (response instanceof String[]) {
5671 return (String[]) response;
5672 }
yincheng zhao2737e882019-09-06 17:06:54 -07005673 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005675 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676 } finally {
5677 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005678 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005679 }
5680
yincheng zhao2737e882019-09-06 17:06:54 -07005681 /**
5682 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5683 * subscription.
5684 *
5685 * @param subId the id of the subscription.
5686 * @param appType the uicc app type, must be USIM or SIM.
5687 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5688 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005689 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005690 * @return number of fplmns that is successfully written to the SIM.
5691 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005692 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5693 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5695 mApp, subId, "setForbiddenPlmns");
5696
yincheng zhao2737e882019-09-06 17:06:54 -07005697 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5698 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5699 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5700 }
5701 if (fplmns == null) {
5702 throw new IllegalArgumentException("Fplmn List provided is null");
5703 }
5704 for (String fplmn : fplmns) {
5705 if (!CellIdentity.isValidPlmn(fplmn)) {
5706 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5707 }
5708 }
5709 final long identity = Binder.clearCallingIdentity();
5710 try {
5711 Object response = sendRequest(
5712 CMD_SET_FORBIDDEN_PLMNS,
5713 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5714 subId);
5715 return (int) response;
5716 } finally {
5717 Binder.restoreCallingIdentity(identity);
5718 }
5719 }
5720
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005721 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005722 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005723 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5724 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005725
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005726 final long identity = Binder.clearCallingIdentity();
5727 try {
5728 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5729 if (response.payload == null) {
5730 return "";
5731 }
Evan Charltonc66da362014-05-16 14:06:40 -07005732
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005733 // Append the returned status code to the end of the response payload.
5734 String s = Integer.toHexString(
5735 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5736 s = IccUtils.bytesToHexString(response.payload) + s;
5737 return s;
5738 } finally {
5739 Binder.restoreCallingIdentity(identity);
5740 }
Evan Charltonc66da362014-05-16 14:06:40 -07005741 }
5742
Jake Hambye994d462014-02-03 13:10:13 -08005743 /**
5744 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5745 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5746 *
5747 * @param itemID the ID of the item to read
5748 * @return the NV item as a String, or null on error.
5749 */
5750 @Override
5751 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005752 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005753 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5754 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005755
5756 final long identity = Binder.clearCallingIdentity();
5757 try {
5758 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005759 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005760 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5761 return value;
5762 } finally {
5763 Binder.restoreCallingIdentity(identity);
5764 }
Jake Hambye994d462014-02-03 13:10:13 -08005765 }
5766
5767 /**
5768 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5769 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5770 *
5771 * @param itemID the ID of the item to read
5772 * @param itemValue the value to write, as a String
5773 * @return true on success; false on any failure
5774 */
5775 @Override
5776 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005777 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5779 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780
5781 final long identity = Binder.clearCallingIdentity();
5782 try {
5783 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5784 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005785 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5787 return success;
5788 } finally {
5789 Binder.restoreCallingIdentity(identity);
5790 }
Jake Hambye994d462014-02-03 13:10:13 -08005791 }
5792
5793 /**
5794 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5795 * Used for device configuration by some CDMA operators.
5796 *
5797 * @param preferredRoamingList byte array containing the new PRL
5798 * @return true on success; false on any failure
5799 */
5800 @Override
5801 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005802 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5803 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005804
5805 final long identity = Binder.clearCallingIdentity();
5806 try {
5807 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5808 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5809 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5810 return success;
5811 } finally {
5812 Binder.restoreCallingIdentity(identity);
5813 }
Jake Hambye994d462014-02-03 13:10:13 -08005814 }
5815
5816 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005817 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005818 * Used for device configuration by some CDMA operators.
5819 *
chen xu6dac5ab2018-10-26 17:39:23 -07005820 * @param slotIndex - device slot.
5821 *
Jake Hambye994d462014-02-03 13:10:13 -08005822 * @return true on success; false on any failure
5823 */
5824 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005825 public boolean resetModemConfig(int slotIndex) {
5826 Phone phone = PhoneFactory.getPhone(slotIndex);
5827 if (phone != null) {
5828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5829 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005830
chen xu6dac5ab2018-10-26 17:39:23 -07005831 final long identity = Binder.clearCallingIdentity();
5832 try {
5833 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5834 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5835 return success;
5836 } finally {
5837 Binder.restoreCallingIdentity(identity);
5838 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005839 }
chen xu6dac5ab2018-10-26 17:39:23 -07005840 return false;
5841 }
5842
5843 /**
5844 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5845 *
5846 * @param slotIndex - device slot.
5847 *
5848 * @return true on success; false on any failure
5849 */
5850 @Override
5851 public boolean rebootModem(int slotIndex) {
5852 Phone phone = PhoneFactory.getPhone(slotIndex);
5853 if (phone != null) {
5854 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5855 mApp, phone.getSubId(), "rebootModem");
5856
5857 final long identity = Binder.clearCallingIdentity();
5858 try {
5859 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5860 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5861 return success;
5862 } finally {
5863 Binder.restoreCallingIdentity(identity);
5864 }
5865 }
5866 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005867 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005868
Brad Ebinger51f743a2017-01-23 13:50:20 -08005869 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005870 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5871 * {@link #disableIms(int)}.
5872 * @param slotIndex device slot.
5873 */
5874 public void resetIms(int slotIndex) {
5875 enforceModifyPermission();
5876
5877 final long identity = Binder.clearCallingIdentity();
5878 try {
5879 if (mImsResolver == null) {
5880 // may happen if the does not support IMS.
5881 return;
5882 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00005883 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005884 } finally {
5885 Binder.restoreCallingIdentity(identity);
5886 }
5887 }
5888
5889 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005890 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5891 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005892 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005893 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005894 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005895
5896 final long identity = Binder.clearCallingIdentity();
5897 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005898 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005899 // may happen if the device does not support IMS.
5900 return;
5901 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005902 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005903 } finally {
5904 Binder.restoreCallingIdentity(identity);
5905 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005906 }
5907
5908 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005909 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5910 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005911 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005912 public void disableIms(int slotId) {
5913 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005914
5915 final long identity = Binder.clearCallingIdentity();
5916 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005917 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005918 // may happen if the device does not support IMS.
5919 return;
5920 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005921 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005922 } finally {
5923 Binder.restoreCallingIdentity(identity);
5924 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005925 }
5926
5927 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005928 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5929 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005930 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005931 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005932 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005933 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005934
5935 final long identity = Binder.clearCallingIdentity();
5936 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005937 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005938 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5939 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005940 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005941 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005942 } finally {
5943 Binder.restoreCallingIdentity(identity);
5944 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005945 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005946 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005947 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5948 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005949 @Override
5950 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005951 enforceModifyPermission();
5952
5953 final long identity = Binder.clearCallingIdentity();
5954 try {
5955 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005956 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005957 } finally {
5958 Binder.restoreCallingIdentity(identity);
5959 }
5960 }
5961
5962 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005963 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005964 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005965 */
5966 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5967 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005968
5969 final long identity = Binder.clearCallingIdentity();
5970 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005971 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005972 // may happen if the device does not support IMS.
5973 return null;
5974 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005975 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005976 } finally {
5977 Binder.restoreCallingIdentity(identity);
5978 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005979 }
5980
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005981 /**
5982 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005983 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005984 */
5985 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5986 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005987
5988 final long identity = Binder.clearCallingIdentity();
5989 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005990 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005991 // may happen if the device does not support IMS.
5992 return null;
5993 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005994 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005995 } finally {
5996 Binder.restoreCallingIdentity(identity);
5997 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005998 }
5999
Brad Ebinger884c07b2018-02-15 16:17:40 -08006000 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006001 * Sets the ImsService Package Name that Telephony will bind to.
6002 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006003 * @param slotIndex the slot ID that the ImsService should bind for.
6004 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006005 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006006 * @param featureTypes An integer array of feature types associated with a packageName.
6007 * @param packageName The name of the package that the current configuration will be replaced
6008 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006009 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006010 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006011 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6012 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006013 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006015 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 final long identity = Binder.clearCallingIdentity();
6018 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006019 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006020 // may happen if the device does not support IMS.
6021 return false;
6022 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006023 Map<Integer, String> featureConfig = new HashMap<>();
6024 for (int featureType : featureTypes) {
6025 featureConfig.put(featureType, packageName);
6026 }
6027 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6028 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006029 } finally {
6030 Binder.restoreCallingIdentity(identity);
6031 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006032 }
6033
6034 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006035 * Clears any carrier ImsService overrides for the slot index specified that were previously
6036 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6037 *
6038 * This should only be used for testing.
6039 *
6040 * @param slotIndex the slot ID that the ImsService should bind for.
6041 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6042 */
6043 @Override
6044 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006045 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6046 "clearCarrierImsServiceOverride");
6047 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006048 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006049
6050 final long identity = Binder.clearCallingIdentity();
6051 try {
6052 if (mImsResolver == null) {
6053 // may happen if the device does not support IMS.
6054 return false;
6055 }
6056 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6057 } finally {
6058 Binder.restoreCallingIdentity(identity);
6059 }
6060 }
6061
6062 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006063 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006064 *
6065 * @param slotId The slot that the ImsService is associated with.
6066 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6067 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006068 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006069 * @return the package name of the ImsService configuration.
6070 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006071 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6072 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006073 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006074 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6075 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006076
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006077 final long identity = Binder.clearCallingIdentity();
6078 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006079 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006080 // may happen if the device does not support IMS.
6081 return "";
6082 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006083 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006084 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6085 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006086 } finally {
6087 Binder.restoreCallingIdentity(identity);
6088 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006089 }
6090
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006091 /**
6092 * Get the MmTelFeature state associated with the requested subscription id.
6093 * @param subId The subscription that the MmTelFeature is associated with.
6094 * @param callback A callback with an integer containing the
6095 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6096 */
6097 @Override
6098 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6099 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006100 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6101 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6102 "IMS not available on device.");
6103 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006104 final long token = Binder.clearCallingIdentity();
6105 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006106 int slotId = getSlotIndex(subId);
6107 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6108 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6109 + subId + "'");
6110 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6111 }
6112 verifyImsMmTelConfiguredOrThrow(slotId);
6113 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6114 try {
6115 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6116 } catch (RemoteException e) {
6117 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6118 + "Ignore");
6119 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006120 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006121 } catch (ImsException e) {
6122 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006123 } finally {
6124 Binder.restoreCallingIdentity(token);
6125 }
6126 }
6127
Daniel Brightbb5840b2021-01-12 15:48:18 -08006128 /**
6129 * Sets the ims registration state on all valid {@link Phone}s.
6130 */
6131 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006132 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133
6134 final long identity = Binder.clearCallingIdentity();
6135 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006136 // NOTE: Before S, this method only set the default phone.
6137 for (final Phone phone : PhoneFactory.getPhones()) {
6138 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6139 phone.setImsRegistrationState(registered);
6140 }
6141 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006142 } finally {
6143 Binder.restoreCallingIdentity(identity);
6144 }
Wink Saville36469e72014-06-11 15:17:00 -07006145 }
6146
6147 /**
Stuart Scott54788802015-03-30 13:18:01 -07006148 * Set the network selection mode to automatic.
6149 *
6150 */
6151 @Override
6152 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006153 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6154 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006155
6156 final long identity = Binder.clearCallingIdentity();
6157 try {
shilufc958392020-01-20 11:36:01 -08006158 if (!isActiveSubscription(subId)) {
6159 return;
6160 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006161 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006162 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6163 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164 } finally {
6165 Binder.restoreCallingIdentity(identity);
6166 }
Stuart Scott54788802015-03-30 13:18:01 -07006167 }
6168
Jack Yud10cdd42020-09-28 20:28:01 -07006169 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006170 * Ask the radio to connect to the input network and change selection mode to manual.
6171 *
6172 * @param subId the id of the subscription.
6173 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6174 * the operator to attach to.
6175 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6176 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6177 * normal network selection next time.
6178 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006179 */
6180 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006181 public boolean setNetworkSelectionModeManual(
6182 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006183 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6184 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006185
Jack Yu285100e2022-12-02 22:48:35 -08006186 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006187 if (!isActiveSubscription(subId)) {
6188 return false;
6189 }
6190
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006191 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006192 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006193 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006194 if (DBG) {
6195 log("setNetworkSelectionModeManual: subId: " + subId
6196 + " operator: " + operatorInfo);
6197 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006198 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6199 } finally {
6200 Binder.restoreCallingIdentity(identity);
6201 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006202 }
shilu84f6e8b2019-12-19 13:58:01 -08006203 /**
6204 * Get the manual network selection
6205 *
6206 * @param subId the id of the subscription.
6207 *
6208 * @return the previously saved user selected PLMN
6209 */
6210 @Override
6211 public String getManualNetworkSelectionPlmn(int subId) {
6212 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006213 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006214 mApp, subId, "getManualNetworkSelectionPlmn");
6215
6216 final long identity = Binder.clearCallingIdentity();
6217 try {
6218 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006219 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006220 }
6221
6222 final Phone phone = getPhone(subId);
6223 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006224 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006225 }
6226 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6227 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6228 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6229 } finally {
6230 Binder.restoreCallingIdentity(identity);
6231 }
6232 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006233
6234 /**
6235 * Scans for available networks.
6236 */
6237 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006238 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6239 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006240 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6241 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006242 LocationAccessPolicy.LocationPermissionResult locationResult =
6243 LocationAccessPolicy.checkLocationPermission(mApp,
6244 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6245 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006246 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006247 .setCallingPid(Binder.getCallingPid())
6248 .setCallingUid(Binder.getCallingUid())
6249 .setMethod("getCellNetworkScanResults")
6250 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006251 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6252 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006253 .build());
6254 switch (locationResult) {
6255 case DENIED_HARD:
6256 throw new SecurityException("Not allowed to access scan results -- location");
6257 case DENIED_SOFT:
6258 return null;
6259 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006260
Pengquan Menga1bb6272018-09-06 09:59:22 -07006261 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006262 try {
6263 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006264 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006265 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006266 } finally {
6267 Binder.restoreCallingIdentity(identity);
6268 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006269 }
6270
6271 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006272 * Get the call forwarding info, given the call forwarding reason.
6273 */
6274 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006275 public void getCallForwarding(int subId, int callForwardingReason,
6276 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006277 enforceReadPrivilegedPermission("getCallForwarding");
6278 long identity = Binder.clearCallingIdentity();
6279 try {
6280 if (DBG) {
6281 log("getCallForwarding: subId " + subId
6282 + " callForwardingReason" + callForwardingReason);
6283 }
Hall Liu27d24262020-09-18 19:04:59 -07006284
6285 Phone phone = getPhone(subId);
6286 if (phone == null) {
6287 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006288 callback.onError(
6289 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006290 } catch (RemoteException e) {
6291 // ignore
6292 }
6293 return;
6294 }
6295
6296 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6297 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6298 @Override
6299 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6300 try {
6301 callback.onCallForwardingInfoAvailable(info);
6302 } catch (RemoteException e) {
6303 // ignore
6304 }
6305 }
6306
6307 @Override
6308 public void onError(int error) {
6309 try {
6310 callback.onError(error);
6311 } catch (RemoteException e) {
6312 // ignore
6313 }
6314 }
6315 });
6316 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006317 } finally {
6318 Binder.restoreCallingIdentity(identity);
6319 }
6320 }
6321
6322 /**
6323 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6324 * reason, the number to forward, and the timeout before the forwarding is attempted.
6325 */
6326 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006327 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6328 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006329 enforceModifyPermission();
6330 long identity = Binder.clearCallingIdentity();
6331 try {
6332 if (DBG) {
6333 log("setCallForwarding: subId " + subId
6334 + " callForwardingInfo" + callForwardingInfo);
6335 }
Hall Liu27d24262020-09-18 19:04:59 -07006336
6337 Phone phone = getPhone(subId);
6338 if (phone == null) {
6339 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006340 callback.accept(
6341 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006342 } catch (RemoteException e) {
6343 // ignore
6344 }
6345 return;
6346 }
6347
6348 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6349 FunctionalUtils.ignoreRemoteException(callback::accept));
6350
6351 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006352 } finally {
6353 Binder.restoreCallingIdentity(identity);
6354 }
6355 }
6356
6357 /**
Hall Liu27d24262020-09-18 19:04:59 -07006358 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006359 */
6360 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006361 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006362 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006363 long identity = Binder.clearCallingIdentity();
6364 try {
Hall Liu27d24262020-09-18 19:04:59 -07006365 Phone phone = getPhone(subId);
6366 if (phone == null) {
6367 try {
6368 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6369 } catch (RemoteException e) {
6370 // ignore
6371 }
6372 return;
6373 }
SongFerngWang0e767992021-03-31 22:08:45 +08006374 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6375 PersistableBundle c = configManager.getConfigForSubId(subId);
6376 boolean requireUssd = c.getBoolean(
6377 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006378
Shuo Qian4a594052020-01-23 11:59:30 -08006379 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006380 if (requireUssd) {
6381 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6382 getSubscriptionCarrierId(subId));
6383 String newUssdCommand = "";
6384 try {
6385 newUssdCommand = carrierXmlParser.getFeature(
6386 CarrierXmlParser.FEATURE_CALL_WAITING)
6387 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6388 } catch (NullPointerException e) {
6389 loge("Failed to generate USSD number" + e);
6390 }
6391 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6392 mMainThreadHandler, callback, carrierXmlParser,
6393 CarrierXmlParser.SsEntry.SSAction.QUERY);
6394 final String ussdCommand = newUssdCommand;
6395 Executors.newSingleThreadExecutor().execute(() -> {
6396 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6397 });
6398 } else {
6399 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6400 callback::accept);
6401 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6402 }
Shuo Qian4a594052020-01-23 11:59:30 -08006403 } finally {
6404 Binder.restoreCallingIdentity(identity);
6405 }
6406 }
6407
6408 /**
Hall Liu27d24262020-09-18 19:04:59 -07006409 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006410 */
6411 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006412 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006413 enforceModifyPermission();
6414 long identity = Binder.clearCallingIdentity();
6415 try {
Hall Liu27d24262020-09-18 19:04:59 -07006416 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6417
6418 Phone phone = getPhone(subId);
6419 if (phone == null) {
6420 try {
6421 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6422 } catch (RemoteException e) {
6423 // ignore
6424 }
6425 return;
6426 }
6427
SongFerngWang0e767992021-03-31 22:08:45 +08006428 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6429 PersistableBundle c = configManager.getConfigForSubId(subId);
6430 boolean requireUssd = c.getBoolean(
6431 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006432
SongFerngWang0e767992021-03-31 22:08:45 +08006433 if (DBG) log("getCallWaitingStatus: subId " + subId);
6434 if (requireUssd) {
6435 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6436 getSubscriptionCarrierId(subId));
6437 CarrierXmlParser.SsEntry.SSAction ssAction =
6438 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6439 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6440 String newUssdCommand = "";
6441 try {
6442 newUssdCommand = carrierXmlParser.getFeature(
6443 CarrierXmlParser.FEATURE_CALL_WAITING)
6444 .makeCommand(ssAction, null);
6445 } catch (NullPointerException e) {
6446 loge("Failed to generate USSD number" + e);
6447 }
6448 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6449 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6450 final String ussdCommand = newUssdCommand;
6451 Executors.newSingleThreadExecutor().execute(() -> {
6452 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6453 });
6454 } else {
6455 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6456 FunctionalUtils.ignoreRemoteException(callback::accept));
6457
6458 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6459 }
Shuo Qian4a594052020-01-23 11:59:30 -08006460 } finally {
6461 Binder.restoreCallingIdentity(identity);
6462 }
6463 }
6464
6465 /**
yinxub1bed742017-04-17 11:45:04 -07006466 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006467 *
yinxub1bed742017-04-17 11:45:04 -07006468 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006469 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6470 * location related information which will be sent if the caller already possess
6471 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006472 * @param request contains the radio access networks with bands/channels to scan
6473 * @param messenger callback messenger for scan results or errors
6474 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006475 * @return the id of the requested scan which can be used to stop the scan.
6476 */
6477 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006478 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6479 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006480 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006481 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6482 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006483 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006484 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6485 if (!renounceFineLocationAccess) {
6486 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6487 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6488 .setCallingPackage(callingPackage)
6489 .setCallingFeatureId(callingFeatureId)
6490 .setCallingPid(Binder.getCallingPid())
6491 .setCallingUid(Binder.getCallingUid())
6492 .setMethod("requestNetworkScan")
6493 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6494 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6495 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6496 .build());
6497 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006498 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006499 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6500 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006501 if (e != null) {
6502 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6503 throw e;
6504 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006505 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006506 return TelephonyScanManager.INVALID_SCAN_ID;
6507 }
6508 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006509 }
Hall Liu912dfd32019-04-25 14:02:26 -07006510 int callingUid = Binder.getCallingUid();
6511 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006512 final long identity = Binder.clearCallingIdentity();
6513 try {
6514 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006515 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006516 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006517 } finally {
6518 Binder.restoreCallingIdentity(identity);
6519 }
yinxu504e1392017-04-12 16:03:22 -07006520 }
6521
Hall Liub2ac8ef2019-02-28 15:56:23 -08006522 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006523 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006524 boolean hasCarrierPriv;
6525 final long identity = Binder.clearCallingIdentity();
6526 try {
6527 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6528 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6529 } finally {
6530 Binder.restoreCallingIdentity(identity);
6531 }
Hall Liu558027f2019-05-15 19:14:05 -07006532 boolean hasNetworkScanPermission =
6533 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6534 == PERMISSION_GRANTED;
6535
6536 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6537 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6538 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006539 }
6540
6541 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6542 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006543 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6544 return new SecurityException("Specific channels must not be"
6545 + " scanned without location access.");
6546 }
6547 }
6548 }
6549
Hall Liub2ac8ef2019-02-28 15:56:23 -08006550 return null;
6551 }
6552
yinxu504e1392017-04-12 16:03:22 -07006553 /**
6554 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006555 *
6556 * @param subId id of the subscription
6557 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006558 */
6559 @Override
6560 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006561 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6562 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006563
Hall Liu912dfd32019-04-25 14:02:26 -07006564 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006565 final long identity = Binder.clearCallingIdentity();
6566 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006567 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006568 } finally {
6569 Binder.restoreCallingIdentity(identity);
6570 }
yinxu504e1392017-04-12 16:03:22 -07006571 }
6572
6573 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006574 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006575 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006576 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006577 */
6578 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006579 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006580 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006581 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006582 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006583
6584 final long identity = Binder.clearCallingIdentity();
6585 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006586 if (DBG) log("getAllowedNetworkTypesBitmask");
6587 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6588 int networkTypesBitmask = (result != null ? result[0] : -1);
6589 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6590 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006591 } finally {
6592 Binder.restoreCallingIdentity(identity);
6593 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006594 }
6595
6596 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006597 * Get the allowed network types for certain reason.
6598 *
6599 * @param subId the id of the subscription.
6600 * @param reason the reason the allowed network type change is taking place
6601 * @return the allowed network types.
6602 */
6603 @Override
6604 public long getAllowedNetworkTypesForReason(int subId,
6605 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006606 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006607 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006608 final long identity = Binder.clearCallingIdentity();
6609 try {
6610 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6611 } finally {
6612 Binder.restoreCallingIdentity(identity);
6613 }
6614 }
6615
6616 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006617 * Enable/Disable E-UTRA-NR Dual Connectivity
6618 * @param subId subscription id of the sim card
6619 * @param nrDualConnectivityState expected NR dual connectivity state
6620 * This can be passed following states
6621 * <ol>
6622 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6623 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6624 * <li>Disable NR dual connectivity and force secondary cell to be released
6625 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6626 * </ol>
6627 * @return operation result.
6628 */
6629 @Override
6630 public int setNrDualConnectivityState(int subId,
6631 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6633 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006634 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006635 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6636 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6637 }
6638
Sooraj Sasindran37444802020-08-11 10:40:43 -07006639 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6640 final long identity = Binder.clearCallingIdentity();
6641 try {
6642 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6643 nrDualConnectivityState, subId,
6644 workSource);
6645 if (DBG) log("enableNRDualConnectivity result: " + result);
6646 return result;
6647 } finally {
6648 Binder.restoreCallingIdentity(identity);
6649 }
6650 }
6651
6652 /**
6653 * Is E-UTRA-NR Dual Connectivity enabled
6654 * @return true if dual connectivity is enabled else false
6655 */
6656 @Override
6657 public boolean isNrDualConnectivityEnabled(int subId) {
6658 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006659 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006660 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006661 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006662 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6663 return false;
6664 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006665 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6666 final long identity = Binder.clearCallingIdentity();
6667 try {
6668 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6669 null, subId, workSource);
6670 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6671 return isEnabled;
6672 } finally {
6673 Binder.restoreCallingIdentity(identity);
6674 }
6675 }
6676
6677 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006678 * Set the allowed network types of the device and
6679 * provide the reason triggering the allowed network change.
6680 *
6681 * @param subId the id of the subscription.
6682 * @param reason the reason the allowed network type change is taking place
6683 * @param allowedNetworkTypes the allowed network types.
6684 * @return true on success; false on any failure.
6685 */
6686 @Override
6687 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006688 @TelephonyManager.AllowedNetworkTypesReason int reason,
6689 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6691 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006692 // If the caller only has carrier privileges, then they should not be able to override
6693 // any network types which were set for security reasons.
6694 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6695 != PERMISSION_GRANTED
6696 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6697 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6698 throw new SecurityException(
6699 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6700 + " reason "
6701 + reason);
6702 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006703 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006704 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6705 return false;
6706 }
6707 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6708 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006709 return false;
6710 }
6711
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006712 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6713 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6714
6715
6716 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6717 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6718 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006719 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006720
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006721 final long identity = Binder.clearCallingIdentity();
6722 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006723 Boolean success = (Boolean) sendRequest(
6724 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6725 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6726
6727 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6728 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006729 } finally {
6730 Binder.restoreCallingIdentity(identity);
6731 }
6732 }
6733
6734 /**
Miaoa84611c2019-03-15 09:21:10 +08006735 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006736 *
Miaoa84611c2019-03-15 09:21:10 +08006737 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006738 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006739 * @hide
6740 */
6741 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006742 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006743 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006744 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006745 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006746 try {
Miaoa84611c2019-03-15 09:21:10 +08006747 if (phone != null) {
6748 return phone.hasMatchedTetherApnSetting();
6749 } else {
6750 return false;
6751 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006752 } finally {
6753 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006754 }
Junda Liu475951f2014-11-07 16:45:03 -08006755 }
6756
6757 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006758 * Get the user enabled state of Mobile Data.
6759 *
6760 * TODO: remove and use isUserDataEnabled.
6761 * This can't be removed now because some vendor codes
6762 * calls through ITelephony directly while they should
6763 * use TelephonyManager.
6764 *
6765 * @return true on enabled
6766 */
6767 @Override
6768 public boolean getDataEnabled(int subId) {
6769 return isUserDataEnabled(subId);
6770 }
6771
6772 /**
6773 * Get whether mobile data is enabled per user setting.
6774 *
6775 * There are other factors deciding whether mobile data is actually enabled, but they are
6776 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006777 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006778 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6779 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006780 *
6781 * @return {@code true} if data is enabled else {@code false}
6782 */
6783 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006784 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006785 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006786 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006787 try {
6788 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6789 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006790 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006791 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6792 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006793 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006795 mApp, subId, functionName);
6796
Robert Greenwalt646120a2014-05-23 11:54:03 -07006797 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006798
6799 final long identity = Binder.clearCallingIdentity();
6800 try {
Jack Yu285100e2022-12-02 22:48:35 -08006801 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006802 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6803 Phone phone = PhoneFactory.getPhone(phoneId);
6804 if (phone != null) {
6805 boolean retVal = phone.isUserDataEnabled();
6806 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6807 return retVal;
6808 } else {
6809 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6810 return false;
6811 }
6812 } finally {
6813 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006814 }
6815 }
6816
6817 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006818 * Checks if the device is capable of mobile data by considering whether whether the
6819 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6820 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006821 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006822 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006823 */
6824 @Override
6825 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006826 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006827 try {
6828 try {
6829 mApp.enforceCallingOrSelfPermission(
6830 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006831 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006832 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006833 try {
6834 mApp.enforceCallingOrSelfPermission(
6835 android.Manifest.permission.READ_PHONE_STATE,
6836 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006837 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006838 mApp.enforceCallingOrSelfPermission(
6839 permission.READ_BASIC_PHONE_STATE, functionName);
6840 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006841 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006842 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006843 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006844 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006845
6846 final long identity = Binder.clearCallingIdentity();
6847 try {
Jack Yu285100e2022-12-02 22:48:35 -08006848 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006849 Phone phone = PhoneFactory.getPhone(phoneId);
6850 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006851 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006852 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006853 return retVal;
6854 } else {
6855 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6856 return false;
6857 }
6858 } finally {
6859 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006860 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006861 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006862
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006863 /**
6864 * Check if data is enabled for a specific reason
6865 * @param subId Subscription index
6866 * @param reason the reason the data enable change is taking place
6867 * @return {@code true} if the overall data is enabled; {@code false} if not.
6868 */
6869 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006870 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006871 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006872 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006873 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006874 try {
6875 mApp.enforceCallingOrSelfPermission(
6876 android.Manifest.permission.ACCESS_NETWORK_STATE,
6877 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006878 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006879 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6880 functionName);
6881 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006882 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006883 try {
6884 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006885 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006886 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006888 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006889 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006890 }
6891
6892
6893 final long identity = Binder.clearCallingIdentity();
6894 try {
Jack Yu285100e2022-12-02 22:48:35 -08006895 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006896 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006897 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006898 + " reason=" + reason);
6899 }
6900 Phone phone = PhoneFactory.getPhone(phoneId);
6901 if (phone != null) {
6902 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006903 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006904 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006905 return retVal;
6906 } else {
6907 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006908 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006909 + subId + " retVal=false");
6910 }
6911 return false;
6912 }
6913 } finally {
6914 Binder.restoreCallingIdentity(identity);
6915 }
6916 }
6917
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006918 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006919 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006920 // No permission needed; this only lets the caller inspect their own status.
6921 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006922 }
Junda Liu29340342014-07-10 15:23:27 -07006923
6924 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006925 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006926 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006927 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6928 }
6929
6930 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6931 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006932 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006933 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006934 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6935 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006936 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6937 if (cpt == null) {
6938 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006939 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6940 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006941 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006942 }
6943
6944 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006945 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006946 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006947 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006948 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006949 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006950 Phone phone = getPhone(subId);
6951 if (phone == null) {
6952 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6953 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6954 }
6955 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6956 if (cpt == null) {
6957 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006958 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6959 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006960 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006961 }
6962
6963 @Override
6964 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006965 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006966 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6967 }
6968
6969 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006970 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006971 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006972 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006973 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006974 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6975 Phone phone = PhoneFactory.getPhone(phoneId);
6976 if (phone == null) {
6977 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006978 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006979 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6980 if (cpt == null) {
6981 continue;
6982 }
6983 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006984 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6985 break;
6986 }
6987 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006988 return result;
Junda Liu29340342014-07-10 15:23:27 -07006989 }
Derek Tan89e89d42014-07-08 17:00:10 -07006990
6991 @Override
Junda Liue64de782015-04-16 17:19:16 -07006992 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006993 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006994 Phone phone = PhoneFactory.getPhone(phoneId);
6995 if (phone == null) {
6996 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006997 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006998 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6999 if (cpt == null) {
7000 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007001 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007002 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007003 }
7004
Amith Yamasani6e118872016-02-19 12:53:51 -08007005 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007006 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007007 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007008 Phone phone = PhoneFactory.getPhone(phoneId);
7009 if (phone == null) {
7010 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007011 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007012 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7013 if (cpt == null) {
7014 return Collections.emptyList();
7015 }
7016 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007017 }
7018
chen xuf7e9fe82019-05-09 19:31:02 -07007019 @Override
7020 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007021 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007022 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007023 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007024 try {
7025 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7026 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7027 }
7028 } finally {
7029 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007030 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007031 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007032 }
7033
Rambo Wang6812ffb2022-03-15 16:54:17 -07007034 @Override
7035 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7036 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7037
7038 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7039 if (phone == null) {
7040 return null;
7041 }
7042 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7043 if (cpt == null) {
7044 return null;
7045 }
7046 return cpt.getCarrierServicePackageName();
7047 }
7048
Wink Savilleb564aae2014-10-23 10:18:09 -07007049 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007050 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007051 UiccPort port = phone == null ? null : phone.getUiccPort();
7052 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007053 return null;
7054 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007055 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007056 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007057 return null;
7058 }
7059 return iccId;
7060 }
7061
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007062 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007063 public void setCallComposerStatus(int subId, int status) {
7064 enforceModifyPermission();
7065
7066 final long identity = Binder.clearCallingIdentity();
7067 try {
7068 Phone phone = getPhone(subId);
7069 if (phone != null) {
7070 Phone defaultPhone = phone.getImsPhone();
7071 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7072 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7073 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007074 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7075 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007076 }
7077 }
Shuo Qian284ae752020-12-22 19:10:14 -08007078 } catch (ImsException e) {
7079 throw new ServiceSpecificException(e.getCode());
7080 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007081 Binder.restoreCallingIdentity(identity);
7082 }
7083 }
7084
7085 @Override
7086 public int getCallComposerStatus(int subId) {
7087 enforceReadPrivilegedPermission("getCallComposerStatus");
7088
7089 final long identity = Binder.clearCallingIdentity();
7090 try {
7091 Phone phone = getPhone(subId);
7092 if (phone != null) {
7093 Phone defaultPhone = phone.getImsPhone();
7094 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7095 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7096 return imsPhone.getCallComposerStatus();
7097 }
7098 }
7099 } finally {
7100 Binder.restoreCallingIdentity(identity);
7101 }
7102 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7103 }
7104
7105 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007106 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7107 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007108 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007109 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007110
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007111 final long identity = Binder.clearCallingIdentity();
7112 try {
7113 final String iccId = getIccId(subId);
7114 final Phone phone = getPhone(subId);
7115 if (phone == null) {
7116 return false;
7117 }
7118 final String subscriberId = phone.getSubscriberId();
7119
7120 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007121 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007122 + subscriberId + " to " + number);
7123 }
7124
7125 if (TextUtils.isEmpty(iccId)) {
7126 return false;
7127 }
7128
7129 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7130
7131 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7132 if (alphaTag == null) {
7133 editor.remove(alphaTagPrefKey);
7134 } else {
7135 editor.putString(alphaTagPrefKey, alphaTag);
7136 }
7137
7138 // Record both the line number and IMSI for this ICCID, since we need to
7139 // track all merged IMSIs based on line number
7140 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7141 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7142 if (number == null) {
7143 editor.remove(numberPrefKey);
7144 editor.remove(subscriberPrefKey);
7145 } else {
7146 editor.putString(numberPrefKey, number);
7147 editor.putString(subscriberPrefKey, subscriberId);
7148 }
7149
7150 editor.commit();
7151 return true;
7152 } finally {
7153 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007154 }
Derek Tan7226c842014-07-02 17:42:23 -07007155 }
7156
7157 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007158 public String getLine1NumberForDisplay(int subId, String callingPackage,
7159 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007160 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007161 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007162 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007163 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007164 return null;
7165 }
Derek Tan97ebb422014-09-05 16:55:38 -07007166
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007167 final long identity = Binder.clearCallingIdentity();
7168 try {
7169 String iccId = getIccId(subId);
7170 if (iccId != null) {
7171 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7172 if (DBG_MERGE) {
7173 log("getLine1NumberForDisplay returning "
7174 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7175 }
7176 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007177 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007178 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7179 return null;
7180 } finally {
7181 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007182 }
Derek Tan7226c842014-07-02 17:42:23 -07007183 }
7184
7185 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007186 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7187 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007188 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007189 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007190 return null;
7191 }
Derek Tan97ebb422014-09-05 16:55:38 -07007192
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007193 final long identity = Binder.clearCallingIdentity();
7194 try {
7195 String iccId = getIccId(subId);
7196 if (iccId != null) {
7197 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7198 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7199 }
7200 return null;
7201 } finally {
7202 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007203 }
Derek Tan7226c842014-07-02 17:42:23 -07007204 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007205
7206 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007207 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7208 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007209 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7210 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007211 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007212 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007213 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007214 return null;
7215 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007216
Jordan Liub49b04b2019-05-06 14:45:15 -07007217 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7218 // the process, where TelephonyManager was instantiated.
7219 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007220 final long identity = Binder.clearCallingIdentity();
7221 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007222 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007223 final TelephonyManager tele = TelephonyManager.from(context);
7224 final SubscriptionManager sub = SubscriptionManager.from(context);
7225
7226 // Figure out what subscribers are currently active
7227 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007228
Jordan Liub49b04b2019-05-06 14:45:15 -07007229 // Only consider subs which match the current subId
7230 // This logic can be simplified. See b/131189269 for progress.
7231 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007232 activeSubscriberIds.add(tele.getSubscriberId(subId));
7233 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007234
7235 // First pass, find a number override for an active subscriber
7236 String mergeNumber = null;
7237 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7238 for (String key : prefs.keySet()) {
7239 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7240 final String subscriberId = (String) prefs.get(key);
7241 if (activeSubscriberIds.contains(subscriberId)) {
7242 final String iccId = key.substring(
7243 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7244 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7245 mergeNumber = (String) prefs.get(numberKey);
7246 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007247 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007248 + " for active subscriber " + subscriberId);
7249 }
7250 if (!TextUtils.isEmpty(mergeNumber)) {
7251 break;
7252 }
7253 }
7254 }
7255 }
7256
7257 // Shortcut when no active merged subscribers
7258 if (TextUtils.isEmpty(mergeNumber)) {
7259 return null;
7260 }
7261
7262 // Second pass, find all subscribers under that line override
7263 final ArraySet<String> result = new ArraySet<>();
7264 for (String key : prefs.keySet()) {
7265 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7266 final String number = (String) prefs.get(key);
7267 if (mergeNumber.equals(number)) {
7268 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7269 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7270 final String subscriberId = (String) prefs.get(subscriberKey);
7271 if (!TextUtils.isEmpty(subscriberId)) {
7272 result.add(subscriberId);
7273 }
7274 }
7275 }
7276 }
7277
7278 final String[] resultArray = result.toArray(new String[result.size()]);
7279 Arrays.sort(resultArray);
7280 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007281 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007282 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7283 }
7284 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007285 } finally {
7286 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007287 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007288 }
7289
7290 @Override
zoey chen38003472019-12-13 17:16:31 +08007291 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7292 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007293
7294 final long identity = Binder.clearCallingIdentity();
7295 try {
7296 final TelephonyManager telephonyManager = mApp.getSystemService(
7297 TelephonyManager.class);
7298 String subscriberId = telephonyManager.getSubscriberId(subId);
7299 if (subscriberId == null) {
7300 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007301 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007302 + subId);
7303 }
7304 return null;
7305 }
7306
Jack Yu285100e2022-12-02 22:48:35 -08007307 ParcelUuid groupUuid;
7308 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7309 final SubscriptionInfo info = SubscriptionManagerService.getInstance()
7310 .getSubscriptionInfo(subId);
7311 groupUuid = info.getGroupUuid();
7312 } else {
7313 final SubscriptionInfo info = mSubscriptionController
7314 .getSubscriptionInfo(subId);
7315 groupUuid = info.getGroupUuid();
7316 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007317 // If it doesn't belong to any group, return just subscriberId of itself.
7318 if (groupUuid == null) {
7319 return new String[]{subscriberId};
7320 }
7321
7322 // Get all subscriberIds from the group.
7323 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007324 List<SubscriptionInfo> groupInfos;
7325 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7326 groupInfos = SubscriptionManagerService.getInstance()
7327 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7328 mApp.getAttributionTag());
7329 } else {
7330 groupInfos = mSubscriptionController
7331 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7332 mApp.getAttributionTag());
7333 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007334 for (SubscriptionInfo subInfo : groupInfos) {
7335 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7336 if (subscriberId != null) {
7337 mergedSubscriberIds.add(subscriberId);
7338 }
7339 }
7340
7341 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7342 } finally {
7343 Binder.restoreCallingIdentity(identity);
7344
7345 }
7346 }
7347
7348 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007349 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007350 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007351 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007352
7353 final long identity = Binder.clearCallingIdentity();
7354 try {
7355 final Phone phone = getPhone(subId);
7356 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7357 } finally {
7358 Binder.restoreCallingIdentity(identity);
7359 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007360 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007361
7362 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007363 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007364 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7365 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007366 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7367 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007368
7369 final long identity = Binder.clearCallingIdentity();
7370 try {
7371 final Phone phone = getPhone(subId);
7372 if (phone == null) {
7373 return false;
7374 }
7375 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7376 cdmaNonRoamingList);
7377 } finally {
7378 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007379 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007380 }
7381
7382 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007383 @Deprecated
7384 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7385 enforceModifyPermission();
7386
7387 int returnValue = 0;
7388 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007389 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007390 if(result.exception == null) {
7391 if (result.result != null) {
7392 byte[] responseData = (byte[])(result.result);
7393 if(responseData.length > oemResp.length) {
7394 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7395 responseData.length + "bytes. Buffer Size is " +
7396 oemResp.length + "bytes.");
7397 }
7398 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7399 returnValue = responseData.length;
7400 }
7401 } else {
7402 CommandException ex = (CommandException) result.exception;
7403 returnValue = ex.getCommandError().ordinal();
7404 if(returnValue > 0) returnValue *= -1;
7405 }
7406 } catch (RuntimeException e) {
7407 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7408 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7409 if(returnValue > 0) returnValue *= -1;
7410 }
7411
7412 return returnValue;
7413 }
7414
7415 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007416 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007417 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007418 try {
7419 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007420 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007421 mApp, phone.getSubId(), "getRadioAccessFamily");
7422 } catch (SecurityException e) {
7423 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7424 throw e;
7425 }
chen xub97461a2018-10-26 14:17:57 -07007426 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007427 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007428 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007429 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007430 final long identity = Binder.clearCallingIdentity();
7431 try {
chen xub97461a2018-10-26 14:17:57 -07007432 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007433 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007434 mApp, phone.getSubId(), "getRadioAccessFamily");
7435 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007436 } finally {
7437 Binder.restoreCallingIdentity(identity);
7438 }
chen xub97461a2018-10-26 14:17:57 -07007439 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007440 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007441
7442 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007443 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007444 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007445 try {
7446 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7447 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007448 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007449 }
7450 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007451 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007452 }
7453 RoleManager rm = mApp.getSystemService(RoleManager.class);
7454 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7455 if (!dialerRoleHolders.contains(callingPackage)) {
7456 throw new SecurityException("App must be the dialer role holder to"
7457 + " upload a call composer pic");
7458 }
7459
7460 Executors.newSingleThreadExecutor().execute(() -> {
7461 ByteArrayOutputStream output = new ByteArrayOutputStream(
7462 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7463 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7464 boolean readUntilEnd = false;
7465 int totalBytesRead = 0;
7466 byte[] buffer = new byte[16 * 1024];
7467 while (true) {
7468 int numRead;
7469 try {
7470 numRead = input.read(buffer);
7471 } catch (IOException e) {
7472 try {
7473 fd.checkError();
7474 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7475 null);
7476 } catch (IOException e1) {
7477 // This means that the other side closed explicitly with an error. If this
7478 // happens, log and ignore.
7479 loge("Remote end of call composer picture pipe closed: " + e1);
7480 }
7481 break;
7482 }
7483 if (numRead == -1) {
7484 readUntilEnd = true;
7485 break;
7486 }
7487 totalBytesRead += numRead;
7488 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7489 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7490 try {
7491 input.close();
7492 } catch (IOException e) {
7493 // ignore
7494 }
7495 break;
7496 }
7497 output.write(buffer, 0, numRead);
7498 }
7499 // Generally, the remote end will close the file descriptors. The only case where we
7500 // close is above, where the picture size is too big.
7501
7502 try {
7503 fd.checkError();
7504 } catch (IOException e) {
7505 loge("Remote end for call composer closed with an error: " + e);
7506 return;
7507 }
7508
Hall Liuaa4211e2021-01-20 15:43:39 -08007509 if (!readUntilEnd) {
7510 loge("Did not finish reading entire image; aborting");
7511 return;
7512 }
Hall Liu82694d52020-12-11 18:22:04 -08007513
Hall Liuaa4211e2021-01-20 15:43:39 -08007514 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7515 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7516 new CallComposerPictureTransfer.Factory() {},
7517 imageData,
7518 (result) -> {
7519 if (result.first != null) {
7520 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7521 Bundle outputResult = new Bundle();
7522 outputResult.putParcelable(
7523 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7524 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7525 outputResult);
7526 } else {
7527 callback.send(result.second, null);
7528 }
7529 }
7530 );
Hall Liu82694d52020-12-11 18:22:04 -08007531 });
7532 }
7533
7534 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007535 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007536 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007537 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538
7539 final long identity = Binder.clearCallingIdentity();
7540 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007541 ImsManager.getInstance(defaultPhone.getContext(),
7542 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007543 } finally {
7544 Binder.restoreCallingIdentity(identity);
7545 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007546 }
7547
7548 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007549 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007550 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007551 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7552 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007553 return false;
7554 }
Svet Ganovb320e182015-04-16 12:30:10 -07007555
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007556 final long identity = Binder.clearCallingIdentity();
7557 try {
7558 // Check the user preference and the system-level IMS setting. Even if the user has
7559 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7560 // In the long run, we may instead need to check if there exists a connection service
7561 // which can support video calling.
7562 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007563 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564 return imsManager.isVtEnabledByPlatform()
7565 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7566 && imsManager.isVtEnabledByUser();
7567 } finally {
7568 Binder.restoreCallingIdentity(identity);
7569 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007570 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007571
Andrew Leea1239f22015-03-02 17:44:07 -08007572 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007573 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7574 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007575 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007576 mApp, subId, callingPackage, callingFeatureId,
7577 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007578 return false;
7579 }
7580
7581 final long identity = Binder.clearCallingIdentity();
7582 try {
7583 CarrierConfigManager configManager =
7584 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007585 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007586 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7587 } finally {
7588 Binder.restoreCallingIdentity(identity);
7589 }
Andrew Leea1239f22015-03-02 17:44:07 -08007590 }
7591
7592 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007593 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007594 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007595 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007596 return false;
7597 }
7598
7599 final long identity = Binder.clearCallingIdentity();
7600 try {
7601 CarrierConfigManager configManager =
7602 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007603 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007604 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7605 } finally {
7606 Binder.restoreCallingIdentity(identity);
7607 }
Andrew Leea1239f22015-03-02 17:44:07 -08007608 }
7609
Andrew Lee9431b832015-03-09 18:46:45 -07007610 @Override
7611 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007612 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007613 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007614 }
7615
7616 @Override
7617 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007618 final long identity = Binder.clearCallingIdentity();
7619 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007620 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007621 } finally {
7622 Binder.restoreCallingIdentity(identity);
7623 }
Andrew Lee9431b832015-03-09 18:46:45 -07007624 }
7625
Hall Liuf6668912018-10-31 17:05:23 -07007626 /**
7627 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7628 * support for the feature and device firmware support.
7629 *
7630 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7631 */
7632 @Override
7633 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007634 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007635 final Phone phone = getPhone(subscriptionId);
7636 if (phone == null) {
7637 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7638 return false;
7639 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007640 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007641 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007642 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7643 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007644 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007645 return isCarrierSupported && isDeviceSupported;
7646 } finally {
7647 Binder.restoreCallingIdentity(identity);
7648 }
Hall Liu98187582018-01-22 19:15:32 -08007649 }
7650
Hall Liuf6668912018-10-31 17:05:23 -07007651 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007652 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7653 * RTT setting, will return true if the device and carrier both support RTT.
7654 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007655 */
7656 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007657 final long identity = Binder.clearCallingIdentity();
7658 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007659 boolean isRttSupported = isRttSupported(subscriptionId);
7660 boolean isUserRttSettingOn = Settings.Secure.getInt(
7661 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7662 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7663 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7664 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007665 } finally {
7666 Binder.restoreCallingIdentity(identity);
7667 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007668 }
7669
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007670 @Deprecated
7671 @Override
7672 public String getDeviceId(String callingPackage) {
7673 return getDeviceIdWithFeature(callingPackage, null);
7674 }
7675
Sanket Padawe7310cc72015-01-14 09:53:20 -08007676 /**
7677 * Returns the unique device ID of phone, for example, the IMEI for
7678 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7679 *
7680 * <p>Requires Permission:
7681 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7682 */
7683 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007684 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007685 try {
7686 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7687 } catch (SecurityException se) {
7688 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7689 throw new SecurityException("Package " + callingPackage + " does not belong to "
7690 + Binder.getCallingUid());
7691 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007692 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007693 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007694 return null;
7695 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007696 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007697 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007698 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007699 return null;
7700 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007701
7702 final long identity = Binder.clearCallingIdentity();
7703 try {
7704 return phone.getDeviceId();
7705 } finally {
7706 Binder.restoreCallingIdentity(identity);
7707 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007708 }
7709
Ping Sunc67b7c22016-03-02 19:16:45 +08007710 /**
7711 * {@hide}
7712 * Returns the IMS Registration Status on a particular subid
7713 *
7714 * @param subId
7715 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007716 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007717 Phone phone = getPhone(subId);
7718 if (phone != null) {
7719 return phone.isImsRegistered();
7720 } else {
7721 return false;
7722 }
7723 }
7724
Santos Cordon7a1885b2015-02-03 11:15:19 -08007725 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007726 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007727 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007728 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007729 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007730 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7731 }
7732 final long identity = Binder.clearCallingIdentity();
7733 try {
7734 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7735 } finally {
7736 Binder.restoreCallingIdentity(identity);
7737 }
7738 }
7739
7740 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007741 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007742 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007743 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007744 mApp,
7745 subscriptionId,
7746 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007747 final long identity = Binder.clearCallingIdentity();
7748 try {
7749 Phone phone = getPhone(subscriptionId);
7750 if (phone == null) {
7751 return null;
7752 }
7753 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7754 } finally {
7755 Binder.restoreCallingIdentity(identity);
7756 }
7757 }
7758
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007759 /**
7760 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007761 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007762 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007763 final long identity = Binder.clearCallingIdentity();
7764 try {
7765 Phone phone = getPhone(subId);
7766 if (phone != null) {
7767 return phone.isWifiCallingEnabled();
7768 } else {
7769 return false;
7770 }
7771 } finally {
7772 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007773 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007774 }
7775
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007776 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007777 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007778 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007779 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007780 final long identity = Binder.clearCallingIdentity();
7781 try {
7782 Phone phone = getPhone(subId);
7783 if (phone != null) {
7784 return phone.isVideoEnabled();
7785 } else {
7786 return false;
7787 }
7788 } finally {
7789 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007790 }
7791 }
7792
7793 /**
7794 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7795 * defined in {@link ImsRegistrationImplBase}.
7796 */
7797 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007798 final long identity = Binder.clearCallingIdentity();
7799 try {
7800 Phone phone = getPhone(subId);
7801 if (phone != null) {
7802 return phone.getImsRegistrationTech();
7803 } else {
7804 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7805 }
7806 } finally {
7807 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007808 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007809 }
7810
Stuart Scott8eef64f2015-04-08 15:13:54 -07007811 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007812 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007813 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007814 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7815 return;
7816 }
Kai Shif70f46f2021-03-03 13:59:46 -08007817 Phone defaultPhone = getDefaultPhone();
7818 if (defaultPhone != null) {
7819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7820 mApp, getDefaultPhone().getSubId(), "factoryReset");
7821 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007822 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007823
Svet Ganovcc087f82015-05-12 20:35:54 -07007824 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007825 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7826 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007827 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007828 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007829 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007830 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007831 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007832 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007833 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007834 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007835 // There has been issues when Sms raw table somehow stores orphan
7836 // fragments. They lead to garbled message when new fragments come
7837 // in and combined with those stale ones. In case this happens again,
7838 // user can reset all network settings which will clean up this table.
7839 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007840 // Clean up IMS settings as well here.
7841 int slotId = getSlotIndex(subId);
7842 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7843 ImsManager.getInstance(mApp, slotId).factoryReset();
7844 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007845
Kai Shif70f46f2021-03-03 13:59:46 -08007846 if (defaultPhone == null) {
7847 return;
7848 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007849 // Erase modem config if erase modem on network setting is enabled.
7850 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7851 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7852 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007853 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007854 }
Kai Shif70f46f2021-03-03 13:59:46 -08007855
7856 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007857 } finally {
7858 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007859 }
7860 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007861
SongFerngWangfd89b102021-05-27 22:44:54 +08007862 @VisibleForTesting
7863 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7864 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7865 return;
7866 }
7867 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7868 RILConstants.PREFERRED_NETWORK_MODE);
7869 SubscriptionManager.setSubscriptionProperty(subId,
7870 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7871 "user=" + defaultNetworkType);
7872 phone.loadAllowedNetworksFromSubscriptionDatabase();
7873 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7874 defaultNetworkType, null);
7875 }
7876
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007877 private void cleanUpSmsRawTable(Context context) {
7878 ContentResolver resolver = context.getContentResolver();
7879 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7880 resolver.delete(uri, null, null);
7881 }
7882
Narayan Kamath1c496c22015-04-16 14:40:19 +01007883 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007884 public String getSimLocaleForSubscriber(int subId) {
7885 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7886 final Phone phone = getPhone(subId);
7887 if (phone == null) {
7888 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007889 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007890 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007891 final long identity = Binder.clearCallingIdentity();
7892 try {
Jack Yu285100e2022-12-02 22:48:35 -08007893 SubscriptionInfo info;
7894 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7895 info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId,
7896 phone.getContext().getOpPackageName(),
7897 phone.getContext().getAttributionTag());
7898 if (info == null) {
7899 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7900 return null;
7901 }
7902 } else {
7903 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
7904 phone.getContext().getOpPackageName(),
7905 phone.getContext().getAttributionTag());
7906 if (info == null) {
7907 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7908 return null;
7909 }
chen xu6291c472019-02-04 12:55:53 -08007910 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007911 // Try and fetch the locale from the carrier properties or from the SIM language
7912 // preferences (EF-PL and EF-LI)...
7913 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007914 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007915 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7916 if (localeFromDefaultSim != null) {
7917 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7918 if (DBG) log("Using locale from subId: " + subId + " locale: "
7919 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08007920 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007921 } else {
7922 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007923 }
7924 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007925
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007926 // The SIM language preferences only store a language (e.g. fr = French), not an
7927 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7928 // the SIM and carrier preferences does not include a country we add the country
7929 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007930 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007931 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007932 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08007933 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007934 }
7935
7936 if (DBG) log("No locale found - returning null");
7937 return null;
7938 } finally {
7939 Binder.restoreCallingIdentity(identity);
7940 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007941 }
7942
tom hsu0b59d292022-09-29 23:49:21 +08007943 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08007944 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08007945 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08007946 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08007947 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08007948 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
7949 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08007950 Locale.forLanguageTag(localeTag).getCountry())) {
7951 return localeTag;
7952 }
7953 }
7954 return inputLocale.toLanguageTag();
7955 }
7956
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007957 /**
7958 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7959 */
7960 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08007961 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7962 return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList(
7963 mApp.getOpPackageName(), mApp.getAttributionTag());
7964 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007965 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007966 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007967 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007968
Gary Jian3aa9a762022-01-24 16:41:19 +08007969 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7970 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007971
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007972 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007973 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7974 * representing the state of the modem.
7975 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007976 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7977 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007978 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007979 */
7980 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007981 public void requestModemActivityInfo(ResultReceiver result) {
7982 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007983 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007984
7985 final long identity = Binder.clearCallingIdentity();
7986 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007987 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007988 } finally {
7989 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007990 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007991 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007992
Siddharth Rayb8114062018-06-17 15:02:38 -07007993 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7994 // less than total activity duration.
7995 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7996 if (info == null) {
7997 return false;
7998 }
7999 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008000 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
8001 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8002
Siddharth Rayb8114062018-06-17 15:02:38 -07008003 return (info.isValid()
8004 && (info.getSleepTimeMillis() <= activityDurationMs)
8005 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07008006 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07008007 && (totalTxTimeMs <= activityDurationMs));
8008 }
8009
Gary Jian3aa9a762022-01-24 16:41:19 +08008010 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8011 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8012 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8013 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8014
8015 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8016 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8017 }
8018
8019 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8020 mLastModemActivityInfo.setReceiveTimeMillis(
8021 rat,
8022 freq,
8023 info.getReceiveTimeMillis(rat, freq)
8024 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8025 }
8026
8027 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8028 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8029 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8030 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8031
8032 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8033 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8034 }
8035 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8036 mLastModemActivityInfo.setReceiveTimeMillis(
8037 rat,
8038 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8039 }
8040
8041 /**
8042 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8043 * @param info recent ModemActivityInfo
8044 */
8045 private void mergeModemActivityInfo(ModemActivityInfo info) {
8046 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008047 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008048 boolean matched;
8049 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8050 matched = false;
8051 int rat = info.getSpecificInfoRat(i);
8052 int freq = info.getSpecificInfoFrequencyRange(i);
8053 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8054 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8055 //if it already exists
8056 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8057 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8058 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8059 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8060 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8061 updateLastModemActivityInfo(info, rat, freq);
8062 matched = true;
8063 }
8064 } else {
8065 updateLastModemActivityInfo(info, rat);
8066 matched = true;
8067 }
8068 }
8069 }
8070
8071 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008072 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008073 new ActivityStatsTechSpecificInfo(
8074 rat,
8075 freq,
8076 info.getTransmitTimeMillis(rat, freq),
8077 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008078 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008079 }
8080 }
8081 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8082 mLastModemActivitySpecificInfo =
8083 new ActivityStatsTechSpecificInfo[merged.size()];
8084 merged.toArray(mLastModemActivitySpecificInfo);
8085
8086 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8087 mLastModemActivityInfo.setSleepTimeMillis(
8088 info.getSleepTimeMillis()
8089 + mLastModemActivityInfo.getSleepTimeMillis());
8090 mLastModemActivityInfo.setIdleTimeMillis(
8091 info.getIdleTimeMillis()
8092 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008093
8094 mLastModemActivityInfo =
8095 new ModemActivityInfo(
8096 mLastModemActivityInfo.getTimestampMillis(),
8097 mLastModemActivityInfo.getSleepTimeMillis(),
8098 mLastModemActivityInfo.getIdleTimeMillis(),
8099 mLastModemActivitySpecificInfo);
8100 }
8101
8102 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8103 ActivityStatsTechSpecificInfo[] info) {
8104 int infoSize = info.length;
8105 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8106 for (int i = 0; i < infoSize; i++) {
8107 ret[i] = new ActivityStatsTechSpecificInfo(
8108 info[i].getRat(), info[i].getFrequencyRange(),
8109 info[i].getTransmitTimeMillis(),
8110 (int) info[i].getReceiveTimeMillis());
8111 }
8112 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008113 }
8114
Jack Yu85bd38a2015-11-09 11:34:32 -08008115 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008116 * Returns the service state information on specified subscription.
8117 */
8118 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008119 public ServiceState getServiceStateForSubscriber(int subId,
8120 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8121 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008122 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008123 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008124 return null;
8125 }
8126
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008127 boolean hasFinePermission = false;
8128 boolean hasCoarsePermission = false;
8129 if (!renounceFineLocationAccess) {
8130 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8131 LocationAccessPolicy.checkLocationPermission(mApp,
8132 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8133 .setCallingPackage(callingPackage)
8134 .setCallingFeatureId(callingFeatureId)
8135 .setCallingPid(Binder.getCallingPid())
8136 .setCallingUid(Binder.getCallingUid())
8137 .setMethod("getServiceStateForSubscriber")
8138 .setLogAsInfo(true)
8139 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8140 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8141 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8142 .build());
8143 hasFinePermission =
8144 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8145 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008146
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008147 if (!renounceCoarseLocationAccess) {
8148 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8149 LocationAccessPolicy.checkLocationPermission(mApp,
8150 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8151 .setCallingPackage(callingPackage)
8152 .setCallingFeatureId(callingFeatureId)
8153 .setCallingPid(Binder.getCallingPid())
8154 .setCallingUid(Binder.getCallingUid())
8155 .setMethod("getServiceStateForSubscriber")
8156 .setLogAsInfo(true)
8157 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8158 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8159 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8160 .build());
8161 hasCoarsePermission =
8162 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8163 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008164
Jack Yu479f40e2020-10-27 21:29:25 -07008165 final Phone phone = getPhone(subId);
8166 if (phone == null) {
8167 return null;
8168 }
8169
Jordan Liu0f2bc442020-11-18 16:47:37 -08008170 final long identity = Binder.clearCallingIdentity();
8171
Jack Yu479f40e2020-10-27 21:29:25 -07008172 boolean isCallingPackageDataService = phone.getDataServicePackages()
8173 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008174 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008175 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008176 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8177 SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance()
8178 .getSubscriptionInfoInternal(subId);
8179 if (subInfo == null || !subInfo.isActive()) {
8180 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8181 + "subId=" + subId);
8182 return null;
8183 }
8184 } else {
8185 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8186 callingFeatureId)) {
8187 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8188 + "subId=" + subId);
8189 return null;
8190 }
Jordan Liuc437b192020-08-17 10:59:12 -07008191 }
8192
Hall Liuf19c44f2018-11-27 14:38:17 -08008193 ServiceState ss = phone.getServiceState();
8194
8195 // Scrub out the location info in ServiceState depending on what level of access
8196 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008197 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008198 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8199 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008200 } finally {
8201 Binder.restoreCallingIdentity(identity);
8202 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008203 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008204
8205 /**
8206 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8207 *
8208 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8209 * voicemail ringtone.
8210 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8211 * PhoneAccount.
8212 */
8213 @Override
8214 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008215 final long identity = Binder.clearCallingIdentity();
8216 try {
8217 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8218 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008219 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008220 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008222 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8223 } finally {
8224 Binder.restoreCallingIdentity(identity);
8225 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008226 }
8227
8228 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008229 * Sets the per-account voicemail ringtone.
8230 *
8231 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8232 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8233 *
8234 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8235 * voicemail ringtone.
8236 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8237 * PhoneAccount.
8238 */
8239 @Override
8240 public void setVoicemailRingtoneUri(String callingPackage,
8241 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008242 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008243 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008244 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8245 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8247 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8248 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008249 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008250
8251 final long identity = Binder.clearCallingIdentity();
8252 try {
8253 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8254 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008255 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008256 }
8257 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8258 } finally {
8259 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008260 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008261 }
8262
8263 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008264 * Returns whether vibration is set for voicemail notification in Phone settings.
8265 *
8266 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8267 * voicemail vibration setting.
8268 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8269 */
8270 @Override
8271 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008272 final long identity = Binder.clearCallingIdentity();
8273 try {
8274 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8275 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008276 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008277 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008278
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008279 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8280 } finally {
8281 Binder.restoreCallingIdentity(identity);
8282 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008283 }
8284
Youhan Wange64578a2016-05-02 15:32:42 -07008285 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008286 * Sets the per-account voicemail vibration.
8287 *
8288 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8289 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8290 *
8291 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8292 * voicemail vibration setting.
8293 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8294 * specific PhoneAccount.
8295 */
8296 @Override
8297 public void setVoicemailVibrationEnabled(String callingPackage,
8298 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008299 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008300 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008301 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8302 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8304 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8305 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008306 }
8307
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008308 final long identity = Binder.clearCallingIdentity();
8309 try {
8310 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8311 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008312 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008313 }
8314 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8315 } finally {
8316 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008317 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008318 }
8319
8320 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008321 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8322 *
8323 * @throws SecurityException if the caller does not have the required permission
8324 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008325 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008326 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008327 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008328 }
8329
8330 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008331 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8332 * permission.
8333 *
8334 * @throws SecurityException if the caller does not have the required permission
8335 */
8336 private void enforceSendSmsPermission() {
8337 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8338 }
8339
8340 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008341 * Make sure either called from same process as self (phone) or IPC caller has interact across
8342 * users permission.
8343 *
8344 * @throws SecurityException if the caller does not have the required permission
8345 */
8346 private void enforceInteractAcrossUsersPermission(String message) {
8347 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8348 }
8349
8350 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008351 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008352 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008353 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008354 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008355 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008356 final long identity = Binder.clearCallingIdentity();
8357 try {
8358 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008359 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008360 if (componentName == null) {
8361 throw new SecurityException(
8362 "Caller not current active visual voicemail package[null]");
8363 }
8364 String vvmPackage = componentName.getPackageName();
8365 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008366 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008367 }
8368 } finally {
8369 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008370 }
8371 }
8372
8373 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008374 * Return the application ID for the app type.
8375 *
8376 * @param subId the subscription ID that this request applies to.
8377 * @param appType the uicc app type.
8378 * @return Application ID for specificied app type, or null if no uicc.
8379 */
8380 @Override
8381 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008382 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008383 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008384
8385 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008386 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008387 if (phone == null) {
8388 return null;
8389 }
8390 String aid = null;
8391 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008392 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008393 .getApplicationByType(appType).getAid();
8394 } catch (Exception e) {
8395 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8396 }
8397 return aid;
8398 } finally {
8399 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008400 }
Youhan Wange64578a2016-05-02 15:32:42 -07008401 }
8402
Youhan Wang4001d252016-05-11 10:29:41 -07008403 /**
8404 * Return the Electronic Serial Number.
8405 *
8406 * @param subId the subscription ID that this request applies to.
8407 * @return ESN or null if error.
8408 */
8409 @Override
8410 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008411 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008412 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008413
8414 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008415 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008416 if (phone == null) {
8417 return null;
8418 }
8419 String esn = null;
8420 try {
8421 esn = phone.getEsn();
8422 } catch (Exception e) {
8423 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8424 }
8425 return esn;
8426 } finally {
8427 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008428 }
Youhan Wang4001d252016-05-11 10:29:41 -07008429 }
8430
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008431 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008432 * Return the Preferred Roaming List Version.
8433 *
8434 * @param subId the subscription ID that this request applies to.
8435 * @return PRLVersion or null if error.
8436 */
8437 @Override
8438 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008439 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008440 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008441
8442 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008443 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008444 if (phone == null) {
8445 return null;
8446 }
8447 String cdmaPrlVersion = null;
8448 try {
8449 cdmaPrlVersion = phone.getCdmaPrlVersion();
8450 } catch (Exception e) {
8451 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8452 }
8453 return cdmaPrlVersion;
8454 } finally {
8455 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008456 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008457 }
8458
8459 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008460 * Get snapshot of Telephony histograms
8461 * @return List of Telephony histograms
8462 * @hide
8463 */
8464 @Override
8465 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8467 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008468
8469 final long identity = Binder.clearCallingIdentity();
8470 try {
8471 return RIL.getTelephonyRILTimingHistograms();
8472 } finally {
8473 Binder.restoreCallingIdentity(identity);
8474 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008475 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008476
8477 /**
8478 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008479 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8480 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008481 * Require system privileges. In the future we may add this to carrier APIs.
8482 *
Michele Berionne482f8202018-11-27 18:57:59 -08008483 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008484 */
8485 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008486 @TelephonyManager.SetCarrierRestrictionResult
8487 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008488 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008489 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008490
Michele Berionne482f8202018-11-27 18:57:59 -08008491 if (carrierRestrictionRules == null) {
8492 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008493 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008494
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008495 final long identity = Binder.clearCallingIdentity();
8496 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008497 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008498 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008499 } finally {
8500 Binder.restoreCallingIdentity(identity);
8501 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008502 }
8503
8504 /**
8505 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008506 * Get the allowed carrier list and the excluded carrier list, including the priority between
8507 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008508 * Require system privileges. In the future we may add this to carrier APIs.
8509 *
Michele Berionne482f8202018-11-27 18:57:59 -08008510 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008511 */
8512 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008513 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008514 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008515 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008516
8517 final long identity = Binder.clearCallingIdentity();
8518 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008519 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8520 if (response instanceof CarrierRestrictionRules) {
8521 return (CarrierRestrictionRules) response;
8522 }
8523 // Response is an Exception of some kind,
8524 // which is signalled to the user as a NULL retval
8525 return null;
8526 } catch (Exception e) {
8527 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8528 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008529 } finally {
8530 Binder.restoreCallingIdentity(identity);
8531 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008532 }
8533
fionaxu59545b42016-05-25 15:53:37 -07008534 /**
fionaxu59545b42016-05-25 15:53:37 -07008535 * Action set from carrier signalling broadcast receivers to enable/disable radio
8536 * @param subId the subscription ID that this action applies to.
8537 * @param enabled control enable or disable radio.
8538 * {@hide}
8539 */
8540 @Override
8541 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8542 enforceModifyPermission();
8543 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008544
8545 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008546 if (phone == null) {
8547 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8548 return;
8549 }
8550 try {
8551 phone.carrierActionSetRadioEnabled(enabled);
8552 } catch (Exception e) {
8553 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008554 } finally {
8555 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008556 }
8557 }
8558
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008559 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008560 * Enable or disable Voice over NR (VoNR)
8561 * @param subId the subscription ID that this action applies to.
8562 * @param enabled enable or disable VoNR.
8563 * @return operation result.
8564 */
8565 @Override
8566 public int setVoNrEnabled(int subId, boolean enabled) {
8567 enforceModifyPermission();
8568 final Phone phone = getPhone(subId);
8569
8570 final long identity = Binder.clearCallingIdentity();
8571 if (phone == null) {
8572 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8573 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8574 }
8575
8576 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8577 try {
8578 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8579 workSource);
8580 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008581
8582 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8583 if (DBG) {
8584 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8585 }
8586 SubscriptionManager.setSubscriptionProperty(
8587 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8588 (enabled ? "1" : "0"));
8589 }
8590
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008591 return result;
8592 } finally {
8593 Binder.restoreCallingIdentity(identity);
8594 }
8595 }
8596
8597 /**
8598 * Is voice over NR enabled
8599 * @return true if VoNR is enabled else false
8600 */
8601 @Override
8602 public boolean isVoNrEnabled(int subId) {
8603 enforceReadPrivilegedPermission("isVoNrEnabled");
8604 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8605 final long identity = Binder.clearCallingIdentity();
8606 try {
8607 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8608 null, subId, workSource);
8609 if (DBG) log("isVoNrEnabled: " + isEnabled);
8610 return isEnabled;
8611 } finally {
8612 Binder.restoreCallingIdentity(identity);
8613 }
8614 }
8615
8616 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008617 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8618 * network status based on which carrier apps could apply actions accordingly,
8619 * enable/disable default url handler for example.
8620 *
8621 * @param subId the subscription ID that this action applies to.
8622 * @param report control start/stop reporting the default network status.
8623 * {@hide}
8624 */
8625 @Override
8626 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8627 enforceModifyPermission();
8628 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008629
8630 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008631 if (phone == null) {
8632 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8633 return;
8634 }
8635 try {
8636 phone.carrierActionReportDefaultNetworkStatus(report);
8637 } catch (Exception e) {
8638 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008639 } finally {
8640 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008641 }
8642 }
8643
8644 /**
fionaxud9622282017-07-17 17:51:30 -07008645 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8646 * @param subId the subscription ID that this action applies to.
8647 * {@hide}
8648 */
8649 @Override
8650 public void carrierActionResetAll(int subId) {
8651 enforceModifyPermission();
8652 final Phone phone = getPhone(subId);
8653 if (phone == null) {
8654 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8655 return;
8656 }
8657 try {
8658 phone.carrierActionResetAll();
8659 } catch (Exception e) {
8660 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8661 }
8662 }
8663
8664 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008665 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8666 * bug report is being generated.
8667 */
8668 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008669 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008670 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8671 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008672 writer.println("Permission Denial: can't dump Phone from pid="
8673 + Binder.getCallingPid()
8674 + ", uid=" + Binder.getCallingUid()
8675 + "without permission "
8676 + android.Manifest.permission.DUMP);
8677 return;
8678 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008679 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008680 }
Jack Yueb89b242016-06-22 13:27:47 -07008681
Brad Ebingerdac2f002018-04-03 15:17:52 -07008682 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008683 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8684 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8685 @NonNull String[] args) {
8686 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8687 this, in.getFileDescriptor(), out.getFileDescriptor(),
8688 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008689 }
8690
Jack Yueb89b242016-06-22 13:27:47 -07008691 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008692 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008693 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008694 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008695 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008696 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008697 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008698 */
8699 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008700 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008701 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008702 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8703 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8704 try {
8705 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008706 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008707 } catch (SecurityException se) {
8708 enforceModifyPermission();
8709 }
8710 } else {
8711 enforceModifyPermission();
8712 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008713
8714 final long identity = Binder.clearCallingIdentity();
8715 try {
8716 Phone phone = getPhone(subId);
8717 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008718 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8719 phone.carrierActionSetMeteredApnsEnabled(enabled);
8720 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008721 phone.getDataSettingsManager().setDataEnabled(
8722 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008723 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008724 }
8725 } finally {
8726 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008727 }
8728 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008729
8730 /**
8731 * Get Client request stats
8732 * @return List of Client Request Stats
8733 * @hide
8734 */
8735 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008736 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8737 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008738 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008739 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008740 return null;
8741 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008742 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008743
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008744 final long identity = Binder.clearCallingIdentity();
8745 try {
8746 if (phone != null) {
8747 return phone.getClientRequestStats();
8748 }
8749
8750 return null;
8751 } finally {
8752 Binder.restoreCallingIdentity(identity);
8753 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008754 }
8755
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008756 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008757 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008758 if (uid == Process.ROOT_UID && packageName == null) {
8759 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8760 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8761 // exception. ROOT_UID seems not to have a valid package name returned by
8762 // PackageManager, so just fake it here to avoid issues when running telephony shell
8763 // commands that plumb through the RIL as root, like so:
8764 // $ adb root
8765 // $ adb shell cmd phone ...
8766 packageName = "root";
8767 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008768 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008769 }
Jack Yueb4124c2017-02-16 15:32:43 -08008770
8771 /**
Grace Chen70990072017-03-24 17:21:30 -07008772 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008773 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008774 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008775 * @param state State of SIM (power down, power up, pass through)
8776 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8777 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8778 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008779 *
8780 **/
8781 @Override
Grace Chen70990072017-03-24 17:21:30 -07008782 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008783 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008784 Phone phone = PhoneFactory.getPhone(slotIndex);
8785
vagdeviaf9a5b92018-08-15 16:01:53 -07008786 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8787
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008788 final long identity = Binder.clearCallingIdentity();
8789 try {
8790 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008791 phone.setSimPowerState(state, null, workSource);
8792 }
8793 } finally {
8794 Binder.restoreCallingIdentity(identity);
8795 }
8796 }
8797
8798 /**
8799 * Set SIM card power state.
8800 *
8801 * @param slotIndex SIM slot id.
8802 * @param state State of SIM (power down, power up, pass through)
8803 * @param callback callback to trigger after success or failure
8804 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8805 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8806 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8807 *
8808 **/
8809 @Override
8810 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8811 IIntegerConsumer callback) {
8812 enforceModifyPermission();
8813 Phone phone = PhoneFactory.getPhone(slotIndex);
8814
8815 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8816
8817 final long identity = Binder.clearCallingIdentity();
8818 try {
8819 if (phone != null) {
8820 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8821 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008822 }
8823 } finally {
8824 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008825 }
8826 }
Shuo Qiandd210312017-04-12 22:11:33 +00008827
Tyler Gunn65d45c22017-06-05 11:22:26 -07008828 private boolean isUssdApiAllowed(int subId) {
8829 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008830 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008831 if (configManager == null) {
8832 return false;
8833 }
8834 PersistableBundle pb = configManager.getConfigForSubId(subId);
8835 if (pb == null) {
8836 return false;
8837 }
8838 return pb.getBoolean(
8839 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8840 }
8841
Shuo Qiandd210312017-04-12 22:11:33 +00008842 /**
8843 * Check if phone is in emergency callback mode
8844 * @return true if phone is in emergency callback mode
8845 * @param subId sub id
8846 */
goneil9c5f4872017-12-05 14:07:56 -08008847 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008848 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008849 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008850 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008851
8852 final long identity = Binder.clearCallingIdentity();
8853 try {
8854 if (phone != null) {
8855 return phone.isInEcm();
8856 } else {
8857 return false;
8858 }
8859 } finally {
8860 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008861 }
8862 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008863
8864 /**
8865 * Get the current signal strength information for the given subscription.
8866 * Because this information is not updated when the device is in a low power state
8867 * it should not be relied-upon to be current.
8868 * @param subId Subscription index
8869 * @return the most recent cached signal strength info from the modem
8870 */
8871 @Override
8872 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008873 final long identity = Binder.clearCallingIdentity();
8874 try {
8875 Phone p = getPhone(subId);
8876 if (p == null) {
8877 return null;
8878 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008879
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008880 return p.getSignalStrength();
8881 } finally {
8882 Binder.restoreCallingIdentity(identity);
8883 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008884 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008885
Pengquan Meng77b7f132018-08-22 14:49:57 -07008886 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008887 * Get the current modem radio state for the given slot.
8888 * @param slotIndex slot index.
8889 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008890 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008891 * @return the current radio power state from the modem
8892 */
8893 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008894 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008895 Phone phone = PhoneFactory.getPhone(slotIndex);
8896 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008897 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8898 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008899 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8900 }
8901
8902 final long identity = Binder.clearCallingIdentity();
8903 try {
8904 return phone.getRadioPowerState();
8905 } finally {
8906 Binder.restoreCallingIdentity(identity);
8907 }
8908 }
8909 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8910 }
8911
8912 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008913 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8914 *
8915 * <p>Requires one of the following permissions:
8916 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008917 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008918 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8919 * privileges.
8920 *
8921 * @param subId subscription id
8922 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8923 * {@code false}.
8924 */
8925 @Override
8926 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008927 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008928 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008929 try {
8930 mApp.enforceCallingOrSelfPermission(
8931 android.Manifest.permission.ACCESS_NETWORK_STATE,
8932 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008933 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008934 mApp.enforceCallingOrSelfPermission(
8935 permission.READ_BASIC_PHONE_STATE, functionName);
8936 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008937 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008938 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008939 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008940 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008941
Pengquan Menga1bb6272018-09-06 09:59:22 -07008942 boolean isEnabled = false;
8943 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008944 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008945 Phone phone = getPhone(subId);
8946 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008947 } finally {
8948 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008949 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008950 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008951 }
8952
8953
8954 /**
8955 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8956 *
8957 * <p> Requires permission:
8958 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8959 * privileges.
8960 *
8961 * @param subId subscription id
8962 * @param isEnabled {@code true} means enable, {@code false} means disable.
8963 */
8964 @Override
8965 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008966 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8967 mApp, subId, "setDataRoamingEnabled");
8968
Pengquan Menga1bb6272018-09-06 09:59:22 -07008969 final long identity = Binder.clearCallingIdentity();
8970 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008971 Phone phone = getPhone(subId);
8972 if (phone != null) {
8973 phone.setDataRoamingEnabled(isEnabled);
8974 }
8975 } finally {
8976 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008977 }
8978 }
8979
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008980 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008981 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008982 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008983 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008984 mApp, subId, "isManualNetworkSelectionAllowed");
8985
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008986 boolean isAllowed = true;
8987 final long identity = Binder.clearCallingIdentity();
8988 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008989 Phone phone = getPhone(subId);
8990 if (phone != null) {
8991 isAllowed = phone.isCspPlmnEnabled();
8992 }
8993 } finally {
8994 Binder.restoreCallingIdentity(identity);
8995 }
8996 return isAllowed;
8997 }
8998
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008999 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9000 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009001 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009002 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009003 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009004 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9005 if (phone == null) {
9006 return false;
9007 }
9008 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9009 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9010 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009011 }
9012
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009013 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009014 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009015 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009016 mApp.getSystemService(AppOpsManager.class)
9017 .checkPackage(Binder.getCallingUid(), callingPackage);
9018
Jordan Liu1e142fc2019-04-22 15:10:43 -07009019 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009020 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009021 try {
9022 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009023 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009024 } catch (SecurityException e) {
9025 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9026 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009027 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08009028 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009029 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009030 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009031 }
sandeepjsb6c87872021-09-27 15:34:44 +00009032 // checking compatibility, if calling app's target SDK is T and beyond.
9033 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9034 Binder.getCallingUid())) {
9035 isIccIdAccessRestricted = true;
9036 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009037 final long identity = Binder.clearCallingIdentity();
9038 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009039 UiccController uiccController = UiccController.getInstance();
9040 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009041 if (hasReadPermission) {
9042 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009043 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009044
9045 // Remove private info if the caller doesn't have access
9046 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9047 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009048 //setting the value after compatibility check
9049 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009050 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9051 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009052 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009053 if (card == null) {
9054 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009055 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009056 continue;
9057 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009058 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9059 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009060 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009061 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009062 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009063 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9064 for (UiccPortInfo portInfo : portInfos) {
9065 UiccPort port = uiccController.getUiccPortForSlot(
9066 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9067 if (port == null) {
9068 // assume no access if port is null
9069 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9070 continue;
9071 }
9072 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9073 uiccPortInfos.add(portInfo);
9074 } else {
9075 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9076 }
9077 }
9078 filteredInfos.add(new UiccCardInfo(
9079 cardInfo.isEuicc(),
9080 cardInfo.getCardId(),
9081 null,
9082 cardInfo.getPhysicalSlotIndex(),
9083 cardInfo.isRemovable(),
9084 cardInfo.isMultipleEnabledProfilesSupported(),
9085 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009086 }
9087 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009088 } finally {
9089 Binder.restoreCallingIdentity(identity);
9090 }
9091 }
9092
sandeepjsb6c87872021-09-27 15:34:44 +00009093 /**
9094 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9095 * generally private and require carrier privileges to view.
9096 *
9097 * @hide
9098 */
9099 @NonNull
9100 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9101 List<UiccPortInfo> portinfo = new ArrayList<>();
9102 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9103 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9104 }
9105 return new UiccCardInfo(
9106 cardInfo.isEuicc(),
9107 cardInfo.getCardId(),
9108 null,
9109 cardInfo.getPhysicalSlotIndex(),
9110 cardInfo.isRemovable(),
9111 cardInfo.isMultipleEnabledProfilesSupported(),
9112 portinfo
9113 );
9114 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009115
sandeepjsb6c87872021-09-27 15:34:44 +00009116 /**
9117 * @hide
9118 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9119 * These values are generally private and require carrier privileges to view.
9120 */
9121 @NonNull
9122 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9123 return new UiccPortInfo(
9124 UiccPortInfo.ICCID_REDACTED,
9125 portInfo.getPortIndex(),
9126 portInfo.getLogicalSlotIndex(),
9127 portInfo.isActive()
9128 );
9129 }
9130 @Override
9131 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009132 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009133 mApp.getSystemService(AppOpsManager.class)
9134 .checkPackage(Binder.getCallingUid(), callingPackage);
9135
sandeepjsb6c87872021-09-27 15:34:44 +00009136 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009137
Aman Guptaf3c90b32022-03-17 04:54:16 +00009138 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9139 // we are reading iccId which is PII data.
9140 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009141
9142 // checking compatibility, if calling app's target SDK is T and beyond.
9143 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9144 Binder.getCallingUid())) {
9145 isLogicalSlotAccessRestricted = true;
9146 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009147 final long identity = Binder.clearCallingIdentity();
9148 try {
9149 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009150 if (slots == null || slots.length == 0) {
9151 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009152 return null;
9153 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009154 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9155 for (int i = 0; i < slots.length; i++) {
9156 UiccSlot slot = slots[i];
9157 if (slot == null) {
9158 continue;
9159 }
9160
Jordan Liu7be7e652019-05-06 18:55:02 +00009161 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009162 UiccCard card = slot.getUiccCard();
9163 if (card != null) {
9164 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009165 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009166 cardId = slot.getEid();
9167 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009168 // If cardId is null, use iccId of default port as cardId.
9169 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009170 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009171 }
9172
Jordan Liu857451f2019-05-09 16:35:35 -07009173 if (cardId != null) {
9174 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9175 // if cardId is an EID, it's all digits so this is fine
9176 cardId = IccUtils.stripTrailingFs(cardId);
9177 }
9178
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009179 int cardState = 0;
9180 switch (slot.getCardState()) {
9181 case CARDSTATE_ABSENT:
9182 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9183 break;
9184 case CARDSTATE_PRESENT:
9185 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9186 break;
9187 case CARDSTATE_ERROR:
9188 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9189 break;
9190 case CARDSTATE_RESTRICTED:
9191 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9192 break;
9193 default:
9194 break;
9195
9196 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009197 List<UiccPortInfo> portInfos = new ArrayList<>();
9198 int[] portIndexes = slot.getPortList();
9199 for (int portIdx : portIndexes) {
9200 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009201 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009202 portInfos.add(new UiccPortInfo(iccId, portIdx,
9203 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009204 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009205 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009206 slot.isEuicc(),
9207 cardId,
9208 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009209 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009210 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009211 //setting the value after compatibility check
9212 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009213 }
9214 return infos;
9215 } finally {
9216 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009217 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009218 }
9219
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009220 /* Returns null if doesn't have read permission or carrier privilege access. */
9221 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9222 boolean hasReadPermission) {
9223 String iccId = slot.getIccId(portIndex);
9224 if (hasReadPermission) { // if has read permission
9225 return iccId;
9226 } else {
9227 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9228 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9229 // if no read permission, checking carrier privilege access
9230 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9231 return iccId;
9232 }
9233 }
9234 }
9235 // No read permission or carrier privilege access.
9236 return UiccPortInfo.ICCID_REDACTED;
9237 }
9238
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009239 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009240 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009241 public boolean switchSlots(int[] physicalSlots) {
9242 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009243
9244 final long identity = Binder.clearCallingIdentity();
9245 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009246 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9247 for (int i = 0; i < physicalSlots.length; i++) {
9248 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9249 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9250 physicalSlots[i], i));
9251 }
9252 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009253 } finally {
9254 Binder.restoreCallingIdentity(identity);
9255 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009256 }
Jack Yu4c988042018-02-27 15:30:01 -08009257
9258 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009259 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9260 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9261 enforceModifyPermission();
9262
9263 final long identity = Binder.clearCallingIdentity();
9264 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009265 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009266 } finally {
9267 Binder.restoreCallingIdentity(identity);
9268 }
9269 }
9270
9271 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009272 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009273 final long identity = Binder.clearCallingIdentity();
9274 try {
9275 return UiccController.getInstance().getCardIdForDefaultEuicc();
9276 } finally {
9277 Binder.restoreCallingIdentity(identity);
9278 }
9279 }
9280
Pengquan Meng85728fb2018-03-12 16:31:21 -07009281 /**
goneil47ffb6e2018-04-06 15:40:58 -07009282 * A test API to reload the UICC profile.
9283 *
9284 * <p>Requires that the calling app has permission
9285 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9286 * @hide
9287 */
9288 @Override
9289 public void refreshUiccProfile(int subId) {
9290 enforceModifyPermission();
9291
9292 final long identity = Binder.clearCallingIdentity();
9293 try {
9294 Phone phone = getPhone(subId);
9295 if (phone == null) {
9296 return;
9297 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009298 UiccPort uiccPort = phone.getUiccPort();
9299 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009300 return;
9301 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009302 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009303 if (uiccProfile == null) {
9304 return;
9305 }
9306 uiccProfile.refresh();
9307 } finally {
9308 Binder.restoreCallingIdentity(identity);
9309 }
9310 }
9311
9312 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009313 * Returns false if the mobile data is disabled by default, otherwise return true.
9314 */
9315 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009316 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009317 }
9318
9319 /**
9320 * Returns true if the data roaming is enabled by default, i.e the system property
9321 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9322 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9323 */
9324 private boolean getDefaultDataRoamingEnabled(int subId) {
9325 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009326 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009327 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009328 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9329 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9330 return isDataRoamingEnabled;
9331 }
9332
9333 /**
9334 * Returns the default network type for the given {@code subId}, if the default network type is
9335 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9336 */
9337 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009338 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009339 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009340 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9341 return list.get(phoneId);
9342 }
9343 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009344 }
fionaxua13278b2018-03-21 00:08:13 -07009345
9346 @Override
9347 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009348 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009349 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009350
9351 final long identity = Binder.clearCallingIdentity();
9352 try {
9353 final Phone phone = getPhone(subId);
9354 if (phone == null) {
9355 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9356 return;
9357 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009358 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9359 if (cpt != null) {
9360 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9361 }
9362 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009363 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9364 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009365 if (carrierPrivilegeRules == null) {
9366 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9367 } else {
9368 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9369 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009370 } finally {
9371 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009372 }
fionaxua13278b2018-03-21 00:08:13 -07009373 }
9374
9375 @Override
9376 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009377 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009378
9379 final long identity = Binder.clearCallingIdentity();
9380 try {
9381 final Phone phone = getPhone(subId);
9382 if (phone == null) {
9383 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9384 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9385 }
9386 return phone.getCarrierIdListVersion();
9387 } finally {
9388 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009389 }
fionaxua13278b2018-03-21 00:08:13 -07009390 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009391
9392 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009393 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9394 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009395 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009396 mApp, subId, callingPackage, callingFeatureId,
9397 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009398 return -1;
9399 }
9400
9401 final long identity = Binder.clearCallingIdentity();
9402 try {
9403 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9404 } finally {
9405 Binder.restoreCallingIdentity(identity);
9406 }
9407 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009408
9409 @Override
9410 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009411 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009412 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009413 mApp, subId, "getCdmaRoamingMode");
9414
9415 final long identity = Binder.clearCallingIdentity();
9416 try {
9417 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9418 } finally {
9419 Binder.restoreCallingIdentity(identity);
9420 }
9421 }
9422
9423 @Override
9424 public boolean setCdmaRoamingMode(int subId, int mode) {
9425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9426 mApp, subId, "setCdmaRoamingMode");
9427
9428 final long identity = Binder.clearCallingIdentity();
9429 try {
9430 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9431 } finally {
9432 Binder.restoreCallingIdentity(identity);
9433 }
9434 }
9435
9436 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009437 public int getCdmaSubscriptionMode(int subId) {
9438 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009439 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009440 mApp, subId, "getCdmaSubscriptionMode");
9441
9442 final long identity = Binder.clearCallingIdentity();
9443 try {
9444 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9445 } finally {
9446 Binder.restoreCallingIdentity(identity);
9447 }
9448 }
9449
9450 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009451 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9453 mApp, subId, "setCdmaSubscriptionMode");
9454
9455 final long identity = Binder.clearCallingIdentity();
9456 try {
9457 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9458 } finally {
9459 Binder.restoreCallingIdentity(identity);
9460 }
9461 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009462
sqianc5eccab2018-10-19 18:46:41 -07009463 @Override
sqian8c685422019-02-22 15:55:18 -08009464 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009465 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009466 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009467 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9468 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009469 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9470 }
9471 final long identity = Binder.clearCallingIdentity();
9472 try {
sqian854d44b2018-12-12 16:48:18 -08009473 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9474 for (Phone phone: PhoneFactory.getPhones()) {
9475 if (phone.getEmergencyNumberTracker() != null
9476 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9477 emergencyNumberListInternal.put(
9478 phone.getSubId(),
9479 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9480 }
sqian11b7a0e2018-12-05 18:48:28 -08009481 }
sqian854d44b2018-12-12 16:48:18 -08009482 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009483 } finally {
9484 Binder.restoreCallingIdentity(identity);
9485 }
sqianc5eccab2018-10-19 18:46:41 -07009486 }
9487
9488 @Override
sqian8c685422019-02-22 15:55:18 -08009489 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009490 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009491 if (!exactMatch) {
9492 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009493 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009494 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009495 }
9496 final long identity = Binder.clearCallingIdentity();
9497 try {
sqian854d44b2018-12-12 16:48:18 -08009498 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009499 //Note: we ignore passed in param exactMatch. We can remove it once
9500 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009501 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009502 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009503 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009504 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009505 }
sqian11b7a0e2018-12-05 18:48:28 -08009506 }
9507 return false;
9508 } finally {
9509 Binder.restoreCallingIdentity(identity);
9510 }
9511 }
9512
sqianf4ca7ed2019-01-15 18:32:07 -08009513 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009514 * Start emergency callback mode for GsmCdmaPhone for testing.
9515 */
9516 @Override
9517 public void startEmergencyCallbackMode() {
9518 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9519 "startEmergencyCallbackMode");
9520 enforceModifyPermission();
9521 final long identity = Binder.clearCallingIdentity();
9522 try {
9523 for (Phone phone : PhoneFactory.getPhones()) {
9524 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9525 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9526 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9527 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9528 gsmCdmaPhone.obtainMessage(
9529 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9530 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9531 }
9532 }
9533 } finally {
9534 Binder.restoreCallingIdentity(identity);
9535 }
9536 }
9537
9538 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009539 * Update emergency number list for test mode.
9540 */
9541 @Override
9542 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9543 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9544 "updateEmergencyNumberListTestMode");
9545
9546 final long identity = Binder.clearCallingIdentity();
9547 try {
9548 for (Phone phone: PhoneFactory.getPhones()) {
9549 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9550 if (tracker != null) {
9551 tracker.executeEmergencyNumberTestModeCommand(action, num);
9552 }
9553 }
9554 } finally {
9555 Binder.restoreCallingIdentity(identity);
9556 }
9557 }
9558
9559 /**
9560 * Get the full emergency number list for test mode.
9561 */
9562 @Override
9563 public List<String> getEmergencyNumberListTestMode() {
9564 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9565 "getEmergencyNumberListTestMode");
9566
9567 final long identity = Binder.clearCallingIdentity();
9568 try {
9569 Set<String> emergencyNumbers = new HashSet<>();
9570 for (Phone phone: PhoneFactory.getPhones()) {
9571 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9572 if (tracker != null) {
9573 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9574 emergencyNumbers.add(num.getNumber());
9575 }
9576 }
9577 }
9578 return new ArrayList<>(emergencyNumbers);
9579 } finally {
9580 Binder.restoreCallingIdentity(identity);
9581 }
9582 }
9583
chen xud6b45bd2018-10-30 22:27:10 -07009584 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009585 public int getEmergencyNumberDbVersion(int subId) {
9586 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9587
9588 final long identity = Binder.clearCallingIdentity();
9589 try {
9590 final Phone phone = getPhone(subId);
9591 if (phone == null) {
9592 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9593 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9594 }
9595 return phone.getEmergencyNumberDbVersion();
9596 } finally {
9597 Binder.restoreCallingIdentity(identity);
9598 }
9599 }
9600
9601 @Override
9602 public void notifyOtaEmergencyNumberDbInstalled() {
9603 enforceModifyPermission();
9604
9605 final long identity = Binder.clearCallingIdentity();
9606 try {
9607 for (Phone phone: PhoneFactory.getPhones()) {
9608 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9609 if (tracker != null) {
9610 tracker.updateOtaEmergencyNumberDatabase();
9611 }
9612 }
9613 } finally {
9614 Binder.restoreCallingIdentity(identity);
9615 }
9616 }
9617
9618 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009619 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009620 enforceActiveEmergencySessionPermission();
9621
9622 final long identity = Binder.clearCallingIdentity();
9623 try {
9624 for (Phone phone: PhoneFactory.getPhones()) {
9625 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9626 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009627 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9628 }
9629 }
9630 } finally {
9631 Binder.restoreCallingIdentity(identity);
9632 }
9633 }
9634
9635 @Override
9636 public void resetOtaEmergencyNumberDbFilePath() {
9637 enforceActiveEmergencySessionPermission();
9638
9639 final long identity = Binder.clearCallingIdentity();
9640 try {
9641 for (Phone phone: PhoneFactory.getPhones()) {
9642 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9643 if (tracker != null) {
9644 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009645 }
9646 }
9647 } finally {
9648 Binder.restoreCallingIdentity(identity);
9649 }
9650 }
9651
9652 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009653 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9654 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9655 Phone phone = getPhone(subId);
9656 if (phone == null) {
9657 return null;
9658 }
9659 final long identity = Binder.clearCallingIdentity();
9660 try {
9661 UiccProfile profile = UiccController.getInstance()
9662 .getUiccProfileForPhone(phone.getPhoneId());
9663 if (profile != null) {
9664 return profile.getCertsFromCarrierPrivilegeAccessRules();
9665 }
9666 } finally {
9667 Binder.restoreCallingIdentity(identity);
9668 }
9669 return null;
9670 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009671
9672 /**
9673 * Enable or disable a modem stack.
9674 */
9675 @Override
9676 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9677 enforceModifyPermission();
9678
9679 final long identity = Binder.clearCallingIdentity();
9680 try {
9681 Phone phone = PhoneFactory.getPhone(slotIndex);
9682 if (phone == null) {
9683 return false;
9684 } else {
9685 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9686 }
9687 } finally {
9688 Binder.restoreCallingIdentity(identity);
9689 }
9690 }
Michelecea4cf22018-12-21 15:00:11 -08009691
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009692 /**
9693 * Whether a modem stack is enabled or not.
9694 */
9695 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009696 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9697 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009698 Phone phone = PhoneFactory.getPhone(slotIndex);
9699 if (phone == null) return false;
9700
9701 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009702 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9703 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009704 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9705 }
9706
9707 final long identity = Binder.clearCallingIdentity();
9708 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009709 try {
9710 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9711 } catch (NoSuchElementException ex) {
9712 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9713 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009714 } finally {
9715 Binder.restoreCallingIdentity(identity);
9716 }
9717 }
9718
Michelecea4cf22018-12-21 15:00:11 -08009719 @Override
Michele0ea7d782019-03-19 14:58:42 -07009720 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009721 enforceModifyPermission();
9722
9723 final long identity = Binder.clearCallingIdentity();
9724 try {
9725 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009726 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009727 .commit();
9728 } finally {
9729 Binder.restoreCallingIdentity(identity);
9730 }
9731 }
9732
9733 @Override
Michele0ea7d782019-03-19 14:58:42 -07009734 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009735 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009736 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009737 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9738 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009739 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009740 }
Michelecea4cf22018-12-21 15:00:11 -08009741
9742 final long identity = Binder.clearCallingIdentity();
9743 try {
Michele0ea7d782019-03-19 14:58:42 -07009744 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009745 } finally {
9746 Binder.restoreCallingIdentity(identity);
9747 }
9748 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009749
Michele0ea7d782019-03-19 14:58:42 -07009750 @TelephonyManager.IsMultiSimSupportedResult
9751 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009752 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9753 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9754 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009755 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9756 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009757 }
9758 // Check if the hardware supports multisim functionality. If usage of multisim is not
9759 // supported by the modem, indicate that it is restricted.
9760 PhoneCapability staticCapability =
9761 mPhoneConfigurationManager.getStaticPhoneCapability();
9762 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009763 loge("isMultiSimSupportedInternal: no static configuration available");
9764 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009765 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009766 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009767 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9768 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009769 }
9770 // Check if support of multiple SIMs is restricted by carrier
9771 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009772 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009773 }
9774
Michele0ea7d782019-03-19 14:58:42 -07009775 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009776 }
9777
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009778 /**
9779 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009780 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9781 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9782 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009783 * @param numOfSims number of active sims we want to switch to
9784 */
9785 @Override
9786 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009787 if (numOfSims == 1) {
9788 enforceModifyPermission();
9789 } else {
9790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9791 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9792 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009793 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009794
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009795 try {
Michele30b57b22019-03-01 12:01:14 -08009796 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009797 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009798 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9799 return;
9800 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009801 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9802 } finally {
9803 Binder.restoreCallingIdentity(identity);
9804 }
9805 }
9806
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009807 @Override
9808 public boolean isApplicationOnUicc(int subId, int appType) {
9809 enforceReadPrivilegedPermission("isApplicationOnUicc");
9810 Phone phone = getPhone(subId);
9811 if (phone == null) {
9812 return false;
9813 }
9814 final long identity = Binder.clearCallingIdentity();
9815 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009816 UiccPort uiccPort = phone.getUiccPort();
9817 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009818 return false;
9819 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009820 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009821 if (uiccProfile == null) {
9822 return false;
9823 }
9824 if (TelephonyManager.APPTYPE_SIM <= appType
9825 && appType <= TelephonyManager.APPTYPE_ISIM) {
9826 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9827 }
9828 return false;
9829 } finally {
9830 Binder.restoreCallingIdentity(identity);
9831 }
9832 }
9833
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009834 /**
chen xub4baa772019-04-03 10:23:41 -07009835 * Get whether making changes to modem configurations will trigger reboot.
9836 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009837 */
9838 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009839 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9840 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009841 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009842 mApp, subId, callingPackage, callingFeatureId,
9843 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009844 return false;
9845 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009846 final long identity = Binder.clearCallingIdentity();
9847 try {
9848 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9849 } finally {
9850 Binder.restoreCallingIdentity(identity);
9851 }
9852 }
9853
Nathan Harold29f5f052019-02-15 13:41:57 -08009854 private void updateModemStateMetrics() {
9855 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9856 // TODO: check the state for each modem if the api is ready.
9857 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9858 }
9859
Pengquan Meng3889a572019-01-23 11:16:29 -08009860 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009861 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009862 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009863 // Verify that the callingPackage belongs to the calling UID
9864 mApp.getSystemService(AppOpsManager.class)
9865 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009866 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009867 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009868 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009869 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9870 if (slotInfos != null) {
9871 for (int i = 0; i < slotInfos.length; i++) {
9872 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9873 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9874 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9875 portInfo.getLogicalSlotIndex()));
9876 }
9877 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009878 }
9879 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009880 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009881 } finally {
9882 Binder.restoreCallingIdentity(identity);
9883 }
9884 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009885
9886 /**
9887 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +08009888 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -08009889 */
jimsunf9ec1622022-09-13 21:18:43 +08009890 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -08009891 @Override
9892 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +08009893 return getHalVersion(HAL_SERVICE_RADIO);
9894 }
9895
9896 /**
9897 * Get the HAL Version of a specific service
9898 */
9899 @Override
9900 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -08009901 Phone phone = getDefaultPhone();
9902 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +08009903 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -08009904 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9905 return hv.major * 100 + hv.minor;
9906 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009907
9908 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009909 * Get the current calling package name.
9910 * @return the current calling package name
9911 */
9912 @Override
9913 public String getCurrentPackageName() {
9914 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9915 }
9916
9917 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009918 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9919 * corresponding network requests on a subId.
9920 *
9921 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009922 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009923 * 2) APN is un-metered for this subscription, or
9924 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009925 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009926 *
9927 * @return whether data is allowed for a apn type.
9928 *
9929 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009930 */
9931 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009932 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009933 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9934 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009935
9936 // Now that all security checks passes, perform the operation as ourselves.
9937 final long identity = Binder.clearCallingIdentity();
9938 try {
9939 Phone phone = getPhone(subId);
9940 if (phone == null) return false;
9941
Jack Yu27422a52022-03-21 10:38:05 -07009942 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009943 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -07009944 isMetered = phone.getDataNetworkController().getDataConfigManager()
9945 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9946 phone.getServiceState().getDataRoaming());
9947 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009948 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009949 } finally {
9950 Binder.restoreCallingIdentity(identity);
9951 }
9952 }
9953
9954 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009955 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009956 enforceReadPrivilegedPermission("isApnMetered");
9957
9958 // Now that all security checks passes, perform the operation as ourselves.
9959 final long identity = Binder.clearCallingIdentity();
9960 try {
9961 Phone phone = getPhone(subId);
9962 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -07009963 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9964 DataUtils.apnTypeToNetworkCapability(apnType),
9965 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009966 } finally {
9967 Binder.restoreCallingIdentity(identity);
9968 }
9969 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009970
9971 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009972 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9973 int subscriptionId, IBooleanConsumer resultCallback) {
9974 enforceModifyPermission();
9975 long token = Binder.clearCallingIdentity();
9976 try {
9977 Phone phone = getPhone(subscriptionId);
9978 if (phone == null) {
9979 try {
9980 if (resultCallback != null) {
9981 resultCallback.accept(false);
9982 }
9983 } catch (RemoteException e) {
9984 // ignore
9985 }
9986 return;
9987 }
9988 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9989 Pair.create(specifiers, (x) -> {
9990 try {
9991 if (resultCallback != null) {
9992 resultCallback.accept(x);
9993 }
9994 } catch (RemoteException e) {
9995 // ignore
9996 }
9997 });
9998 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9999 } finally {
10000 Binder.restoreCallingIdentity(token);
10001 }
10002 }
10003
10004 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010005 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10006 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010007 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010008 mApp, subId, "getSystemSelectionChannels");
10009 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10010 final long identity = Binder.clearCallingIdentity();
10011 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010012 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10013 if (result instanceof IllegalStateException) {
10014 throw (IllegalStateException) result;
10015 }
10016 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010017 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10018 return specifiers;
10019 } finally {
10020 Binder.restoreCallingIdentity(identity);
10021 }
10022 }
10023
10024 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010025 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010026 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010027 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010028 }
10029
10030 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010031 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10032 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010033 if (callingPackage == null) {
10034 callingPackage = getCurrentPackageName();
10035 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010036 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10037 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010038 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10039 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010040 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10041 }
10042 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10043 Intent intent = new Intent();
10044 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10045 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10046 // Bring up choose default SMS subscription dialog right now
10047 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10048 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10049 mApp.startActivity(intent);
10050 }
chen xud5ca2d52019-05-28 15:20:57 -070010051
10052 @Override
10053 public String getMmsUAProfUrl(int subId) {
10054 //TODO investigate if this API should require proper permission check in R b/133791609
10055 final long identity = Binder.clearCallingIdentity();
10056 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010057 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10058 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10059 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10060 return carrierUAProfUrl;
10061 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010062 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10063 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010064 } finally {
10065 Binder.restoreCallingIdentity(identity);
10066 }
10067 }
10068
10069 @Override
10070 public String getMmsUserAgent(int subId) {
10071 //TODO investigate if this API should require proper permission check in R b/133791609
10072 final long identity = Binder.clearCallingIdentity();
10073 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010074 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10075 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10076 if (!TextUtils.isEmpty(carrierUserAgent)) {
10077 return carrierUserAgent;
10078 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010079 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10080 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010081 } finally {
10082 Binder.restoreCallingIdentity(identity);
10083 }
10084 }
Jack Yub07d4972019-05-28 16:12:25 -070010085
10086 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010087 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10088 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010089
Jack Yub07d4972019-05-28 16:12:25 -070010090 final long identity = Binder.clearCallingIdentity();
10091 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010092 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010093 if (phone == null) return false;
10094
Ling Maf188d502022-09-16 15:22:36 -070010095 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010096 } finally {
10097 Binder.restoreCallingIdentity(identity);
10098 }
10099 }
10100
10101 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010102 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010103 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010104 enforceModifyPermission();
10105
changbettyd5c246e2019-12-24 15:40:37 +080010106 final long identity = Binder.clearCallingIdentity();
10107 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010108 Phone phone = getPhone(subscriptionId);
10109 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010110
Ling Maf188d502022-09-16 15:22:36 -070010111 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010112 } finally {
10113 Binder.restoreCallingIdentity(identity);
10114 }
10115 }
10116
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010117 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010118 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010119 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10120 * otherwise.
10121 */
10122 @Override
10123 public void setCepEnabled(boolean isCepEnabled) {
10124 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10125
10126 final long identity = Binder.clearCallingIdentity();
10127 try {
10128 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10129 for (Phone phone : PhoneFactory.getPhones()) {
10130 Phone defaultPhone = phone.getImsPhone();
10131 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10132 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10133 ImsPhoneCallTracker imsPhoneCallTracker =
10134 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10135 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10136 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10137 + imsPhone.getMsisdn());
10138 }
10139 }
10140 } finally {
10141 Binder.restoreCallingIdentity(identity);
10142 }
10143 }
allenwtsu46dcc572020-01-08 18:24:03 +080010144
10145 /**
10146 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10147 *
10148 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10149 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10150 * before being read.
10151 */
10152 @Override
10153 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10154 isCompressed) {
10155 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10156 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010157 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10158 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10159 }
10160 if (!isImsAvailableOnDevice()) {
10161 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10162 "IMS not available on device.");
10163 }
10164
10165 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010166 try {
Hui Wang761a6682020-10-31 05:12:53 +000010167 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10168 } finally {
10169 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010170 }
10171 }
zoey chene02881a2019-12-30 16:11:23 +080010172
10173 @Override
10174 public boolean isIccLockEnabled(int subId) {
10175 enforceReadPrivilegedPermission("isIccLockEnabled");
10176
10177 // Now that all security checks passes, perform the operation as ourselves.
10178 final long identity = Binder.clearCallingIdentity();
10179 try {
10180 Phone phone = getPhone(subId);
10181 if (phone != null && phone.getIccCard() != null) {
10182 return phone.getIccCard().getIccLockEnabled();
10183 } else {
10184 return false;
10185 }
10186 } finally {
10187 Binder.restoreCallingIdentity(identity);
10188 }
10189 }
10190
10191 /**
10192 * Set the ICC pin lock enabled or disabled.
10193 *
10194 * @return an integer representing the status of IccLock enabled or disabled in the following
10195 * three cases:
10196 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10197 * successfully.
10198 * - Positive number and zero for remaining password attempts.
10199 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10200 *
10201 */
10202 @Override
10203 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10204 enforceModifyPermission();
10205
10206 Phone phone = getPhone(subId);
10207 if (phone == null) {
10208 return 0;
10209 }
10210 // Now that all security checks passes, perform the operation as ourselves.
10211 final long identity = Binder.clearCallingIdentity();
10212 try {
10213 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10214 new Pair<Boolean, String>(enabled, password), phone, null);
10215 return attemptsRemaining;
10216
10217 } catch (Exception e) {
10218 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10219 } finally {
10220 Binder.restoreCallingIdentity(identity);
10221 }
10222 return 0;
10223 }
10224
10225 /**
10226 * Change the ICC password used in ICC pin lock.
10227 *
10228 * @return an integer representing the status of IccLock changed in the following three cases:
10229 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10230 * - Positive number and zero for remaining password attempts.
10231 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10232 *
10233 */
10234 @Override
10235 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10236 enforceModifyPermission();
10237
10238 Phone phone = getPhone(subId);
10239 if (phone == null) {
10240 return 0;
10241 }
10242 // Now that all security checks passes, perform the operation as ourselves.
10243 final long identity = Binder.clearCallingIdentity();
10244 try {
10245 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10246 new Pair<String, String>(oldPassword, newPassword), phone, null);
10247 return attemptsRemaining;
10248
10249 } catch (Exception e) {
10250 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10251 } finally {
10252 Binder.restoreCallingIdentity(identity);
10253 }
10254 return 0;
10255 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010256
10257 /**
10258 * Request for receiving user activity notification
10259 */
10260 @Override
10261 public void requestUserActivityNotification() {
10262 if (!mNotifyUserActivity.get()
10263 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10264 mNotifyUserActivity.set(true);
10265 }
10266 }
10267
10268 /**
10269 * Called when userActivity is signalled in the power manager.
10270 * This is safe to call from any thread, with any window manager locks held or not.
10271 */
10272 @Override
10273 public void userActivity() {
10274 // ***************************************
10275 // * Inherited from PhoneWindowManager *
10276 // ***************************************
10277 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10278 // WITH ITS LOCKS HELD.
10279 //
10280 // This code must be VERY careful about the locks
10281 // it acquires.
10282 // In fact, the current code acquires way too many,
10283 // and probably has lurking deadlocks.
10284
10285 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10286 throw new SecurityException("Only the OS may call notifyUserActivity()");
10287 }
10288
10289 if (mNotifyUserActivity.getAndSet(false)) {
10290 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10291 USER_ACTIVITY_NOTIFICATION_DELAY);
10292 }
10293 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010294
10295 @Override
10296 public boolean canConnectTo5GInDsdsMode() {
10297 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10298 }
Jack Yud10cdd42020-09-28 20:28:01 -070010299
10300 @Override
10301 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10302 String callingFeatureId) {
10303 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10304 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10305 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10306 }
10307
10308 Phone phone = getPhone(subId);
10309 if (phone == null) {
10310 throw new RuntimeException("phone is not available");
10311 }
10312 // Now that all security checks passes, perform the operation as ourselves.
10313 final long identity = Binder.clearCallingIdentity();
10314 try {
10315 return phone.getEquivalentHomePlmns();
10316 } finally {
10317 Binder.restoreCallingIdentity(identity);
10318 }
10319 }
Daniel Bright59e67312020-11-13 11:49:37 -080010320
10321 @Override
10322 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010323 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10324 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010325 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010326 if (radioInterfaceCapabilities == null) {
10327 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010328 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010329 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010330 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010331
Hui Wang641e81c2020-10-12 12:14:23 -070010332 @Override
10333 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10334 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010335 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10336 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10337 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10338 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10339 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010340 if (DBG) {
10341 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10342 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10343 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10344 }
10345
10346 if (!SubscriptionManager.isValidSubscriptionId(subId)
10347 || appType < TelephonyManager.APPTYPE_UNKNOWN
10348 || appType > TelephonyManager.APPTYPE_ISIM
10349 || nafUrl == null || securityProtocol == null || callback == null) {
10350 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10351 if (callback != null) {
10352 try {
10353 callback.onAuthenticationFailure(
10354 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10355 } catch (RemoteException exception) {
10356 log("Fail to notify onAuthenticationFailure due to " + exception);
10357 }
10358 return;
10359 }
10360 }
10361
10362 final long token = Binder.clearCallingIdentity();
10363 try {
10364 getGbaManager(subId).bootstrapAuthenticationRequest(
10365 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10366 forceBootStrapping, callback));
10367 } finally {
10368 Binder.restoreCallingIdentity(token);
10369 }
10370 }
10371
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010372 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010373 * Attempts to set the radio power state for all phones for thermal reason.
10374 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010375 * requested radio power state will actually be set. See {@link
10376 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10377 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010378 * @param enable {@code true} if trying to turn radio on.
10379 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10380 * false}.
10381 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010382 private boolean setRadioPowerForThermal(boolean enable) {
10383 boolean isPhoneAvailable = false;
10384 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10385 Phone phone = PhoneFactory.getPhone(i);
10386 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010387 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010388 isPhoneAvailable = true;
10389 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010390 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010391
10392 // return true if successfully informed the phone object about the thermal radio power
10393 // request.
10394 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010395 }
10396
10397 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010398 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010399 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10400 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10401 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10402 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10403 throw new IllegalArgumentException("modem does not support data throttling");
10404 }
10405
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010406 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10407 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010408 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010409 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10410 }
10411
Sarah Chinecc78c42022-03-31 21:16:48 -070010412 setDataEnabledForReason(
10413 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010414
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010415 if (isDataThrottlingSupported) {
10416 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010417 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010418 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10419 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10420 } else if (thermalMitigationResult
10421 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010422 log("Modem likely does not support data throttling on secondary carrier. Data " +
10423 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10424 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010425 }
10426 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010427 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010428
10429 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010430 }
10431
Jack Nudelman644b91a2021-03-12 14:09:48 -080010432 private static List<String> getThermalMitigationAllowlist(Context context) {
10433 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10434 for (String pckg : context.getResources()
10435 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10436 sThermalMitigationAllowlistedPackages.add(pckg);
10437 }
10438 }
10439
10440 return sThermalMitigationAllowlistedPackages;
10441 }
10442
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010443 private boolean isAnyPhoneInEmergencyState() {
10444 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10445 if (tm.isInEmergencyCall()) {
10446 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10447 return true;
10448 }
10449 for (Phone phone : PhoneFactory.getPhones()) {
10450 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10451 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10452 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10453 + phone.isInEcm());
10454 return true;
10455 }
10456 }
10457
10458 return false;
10459 }
10460
Jack Nudelman644b91a2021-03-12 14:09:48 -080010461 /**
10462 * Used by shell commands to add an authorized package name for thermal mitigation.
10463 * @param packageName name of package to be allowlisted
10464 * @param context
10465 */
10466 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10467 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10468 sThermalMitigationAllowlistedPackages.add(packageName);
10469 }
10470
10471 /**
10472 * Used by shell commands to remove an authorized package name for thermal mitigation.
10473 * @param packageName name of package to remove from allowlist
10474 * @param context
10475 */
10476 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10477 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10478 sThermalMitigationAllowlistedPackages.remove(packageName);
10479 }
10480
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010481 /**
10482 * Thermal mitigation request to control functionalities at modem.
10483 *
10484 * @param subId the id of the subscription.
10485 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010486 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010487 *
10488 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10489 */
10490 @Override
10491 @ThermalMitigationResult
10492 public int sendThermalMitigationRequest(
10493 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010494 ThermalMitigationRequest thermalMitigationRequest,
10495 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010496 enforceModifyPermission();
10497
Jack Nudelman644b91a2021-03-12 14:09:48 -080010498 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10499 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10500 .contains(callingPackage)) {
10501 throw new SecurityException("Calling package must be configured in the device config. "
10502 + "calling package: " + callingPackage);
10503 }
10504
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010505 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10506 final long identity = Binder.clearCallingIdentity();
10507
10508 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10509 try {
10510 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10511 switch (thermalMitigationAction) {
10512 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10513 thermalMitigationResult =
10514 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010515 thermalMitigationRequest.getDataThrottlingRequest(),
10516 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010517 break;
10518 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10519 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10520 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10521 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10522 }
10523
10524 // Ensure that radio is on. If not able to power on due to phone being
10525 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010526 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010527 thermalMitigationResult =
10528 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10529 break;
10530 }
10531
10532 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010533 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010534 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10535 break;
10536 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10537 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10538 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10539 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10540 }
10541
10542 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10543 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010544 Phone phone = getPhone(subId);
10545 if (phone == null) {
10546 thermalMitigationResult =
10547 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10548 break;
10549 }
10550
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010551 TelephonyConnectionService service =
10552 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010553 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010554 Log.e(LOG_TAG, "An emergency call is pending");
10555 thermalMitigationResult =
10556 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10557 break;
10558 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010559 thermalMitigationResult =
10560 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10561 break;
10562 }
10563 } else {
10564 thermalMitigationResult =
10565 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10566 break;
10567 }
10568
10569 // Turn radio off. If not able to power off due to phone being unavailable,
10570 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010571 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010572 thermalMitigationResult =
10573 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10574 break;
10575 }
10576 thermalMitigationResult =
10577 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10578 break;
10579 default:
10580 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10581 + "not exist. Requested action: " + thermalMitigationAction);
10582 }
10583 } catch (IllegalArgumentException e) {
10584 throw e;
10585 } catch (Exception e) {
10586 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10587 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10588 } finally {
10589 Binder.restoreCallingIdentity(identity);
10590 }
10591
10592 if (DBG) {
10593 log("thermalMitigationRequest returning with thermalMitigationResult: "
10594 + thermalMitigationResult);
10595 }
10596
10597 return thermalMitigationResult;
10598 }
Hui Wang641e81c2020-10-12 12:14:23 -070010599
10600 /**
10601 * Set the GbaService Package Name that Telephony will bind to.
10602 *
10603 * @param subId The sim that the GbaService is associated with.
10604 * @param packageName The name of the package to be replaced with.
10605 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10606 */
10607 @Override
10608 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10609 enforceModifyPermission();
10610
10611 final long identity = Binder.clearCallingIdentity();
10612 try {
10613 return getGbaManager(subId).overrideServicePackage(packageName);
10614 } finally {
10615 Binder.restoreCallingIdentity(identity);
10616 }
10617 }
10618
10619 /**
10620 * Return the package name of the currently bound GbaService.
10621 *
10622 * @param subId The sim that the GbaService is associated with.
10623 * @return the package name of the GbaService configuration, null if GBA is not supported.
10624 */
10625 @Override
10626 public String getBoundGbaService(int subId) {
10627 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10628
10629 final long identity = Binder.clearCallingIdentity();
10630 try {
10631 return getGbaManager(subId).getServicePackage();
10632 } finally {
10633 Binder.restoreCallingIdentity(identity);
10634 }
10635 }
10636
10637 /**
10638 * Set the release time for telephony to unbind GbaService.
10639 *
10640 * @param subId The sim that the GbaService is associated with.
10641 * @param interval The release time to unbind GbaService by millisecond.
10642 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10643 */
10644 @Override
10645 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10646 enforceModifyPermission();
10647
10648 final long identity = Binder.clearCallingIdentity();
10649 try {
10650 return getGbaManager(subId).overrideReleaseTime(interval);
10651 } finally {
10652 Binder.restoreCallingIdentity(identity);
10653 }
10654 }
10655
10656 /**
10657 * Return the release time for telephony to unbind GbaService.
10658 *
10659 * @param subId The sim that the GbaService is associated with.
10660 * @return The release time to unbind GbaService by millisecond.
10661 */
10662 @Override
10663 public int getGbaReleaseTime(int subId) {
10664 enforceReadPrivilegedPermission("getGbaReleaseTime");
10665
10666 final long identity = Binder.clearCallingIdentity();
10667 try {
10668 return getGbaManager(subId).getReleaseTime();
10669 } finally {
10670 Binder.restoreCallingIdentity(identity);
10671 }
10672 }
10673
10674 private GbaManager getGbaManager(int subId) {
10675 GbaManager instance = GbaManager.getInstance(subId);
10676 if (instance == null) {
10677 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10678 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10679 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10680 }
10681 return instance;
10682 }
Hui Wang761a6682020-10-31 05:12:53 +000010683
10684 /**
10685 * indicate whether the device and the carrier can support
10686 * RCS VoLTE single registration.
10687 */
10688 @Override
10689 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010690 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10691 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10692 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10693 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010694
10695 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10696 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10697 }
10698
10699 final long identity = Binder.clearCallingIdentity();
10700 try {
10701 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10702 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010703 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10704 if (isCapable != null) {
10705 return isCapable;
10706 }
Hui Wang761a6682020-10-31 05:12:53 +000010707 }
Hui Wang67af90e2021-06-04 16:57:15 -070010708 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10709 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010710 } finally {
10711 Binder.restoreCallingIdentity(identity);
10712 }
10713 }
10714
10715 /**
10716 * Register RCS provisioning callback.
10717 */
10718 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010719 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010720 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010721 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010722 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010723 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10724 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010725
10726 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10727 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10728 }
10729 if (!isImsAvailableOnDevice()) {
10730 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10731 "IMS not available on device.");
10732 }
10733
10734 final long identity = Binder.clearCallingIdentity();
10735 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010736 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010737 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010738 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10739 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010740 }
Hui Wang761a6682020-10-31 05:12:53 +000010741 } finally {
10742 Binder.restoreCallingIdentity(identity);
10743 }
10744 }
10745
10746 /**
10747 * Unregister RCS provisioning callback.
10748 */
10749 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010750 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010751 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010752 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010753 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010754 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10755 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010756
10757 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10758 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10759 }
10760 if (!isImsAvailableOnDevice()) {
10761 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10762 "IMS not available on device.");
10763 }
10764
10765 final long identity = Binder.clearCallingIdentity();
10766 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010767 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010768 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010769 } finally {
10770 Binder.restoreCallingIdentity(identity);
10771 }
10772 }
10773
10774 /**
10775 * trigger RCS reconfiguration.
10776 */
10777 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010778 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10779 "triggerRcsReconfiguration",
10780 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010781
10782 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10783 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10784 }
10785 if (!isImsAvailableOnDevice()) {
10786 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10787 "IMS not available on device.");
10788 }
10789
10790 final long identity = Binder.clearCallingIdentity();
10791 try {
10792 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10793 } finally {
10794 Binder.restoreCallingIdentity(identity);
10795 }
10796 }
10797
10798 /**
10799 * Provide the client configuration parameters of the RCS application.
10800 */
10801 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010802 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10803 "setRcsClientConfiguration",
10804 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010805
10806 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10807 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10808 }
10809 if (!isImsAvailableOnDevice()) {
10810 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10811 "IMS not available on device.");
10812 }
10813
10814 final long identity = Binder.clearCallingIdentity();
10815
10816 try {
10817 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10818 if (configBinder == null) {
10819 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010820 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10821 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010822 } else {
10823 configBinder.setRcsClientConfiguration(rcc);
10824 }
joonhunshin3e154242021-09-17 06:33:39 +000010825
10826 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10827 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010828 } catch (RemoteException e) {
10829 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010830 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10831 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010832 } finally {
10833 Binder.restoreCallingIdentity(identity);
10834 }
10835 }
10836
10837 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010838 * Enables or disables the test mode for RCS VoLTE single registration.
10839 */
10840 @Override
10841 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10842 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10843 "setRcsSingleRegistrationTestModeEnabled");
10844
10845 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10846 }
10847
10848 /**
10849 * Gets the test mode for RCS VoLTE single registration.
10850 */
10851 @Override
10852 public boolean getRcsSingleRegistrationTestModeEnabled() {
10853 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10854 "getRcsSingleRegistrationTestModeEnabled");
10855
10856 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10857 }
10858
10859 /**
Hui Wang761a6682020-10-31 05:12:53 +000010860 * Overrides the config of RCS VoLTE single registration enabled for the device.
10861 */
10862 @Override
10863 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10864 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10865 "setDeviceSingleRegistrationEnabledOverride");
10866 enforceModifyPermission();
10867
10868 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10869 : Boolean.parseBoolean(enabledStr);
10870 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010871 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010872 }
10873
10874 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010875 * Sends a device to device communication message. Only usable via shell.
10876 * @param message message to send.
10877 * @param value message value.
10878 */
10879 @Override
10880 public void sendDeviceToDeviceMessage(int message, int value) {
10881 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010882 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010883 enforceModifyPermission();
10884
10885 final long identity = Binder.clearCallingIdentity();
10886 try {
10887 TelephonyConnectionService service =
10888 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10889 if (service == null) {
10890 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10891 return;
10892 }
10893 service.sendTestDeviceToDeviceMessage(message, value);
10894 } finally {
10895 Binder.restoreCallingIdentity(identity);
10896 }
10897 }
10898
Tyler Gunnbabbda02021-02-10 11:05:02 -080010899 /**
10900 * Sets the specified device to device transport active.
10901 * @param transport The transport to set active.
10902 */
10903 @Override
10904 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10905 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10906 "setActiveDeviceToDeviceTransport");
10907 enforceModifyPermission();
10908
10909 final long identity = Binder.clearCallingIdentity();
10910 try {
10911 TelephonyConnectionService service =
10912 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10913 if (service == null) {
10914 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10915 return;
10916 }
10917 service.setActiveDeviceToDeviceTransport(transport);
10918 } finally {
10919 Binder.restoreCallingIdentity(identity);
10920 }
10921 }
Tyler Gunn92479152021-01-20 16:30:10 -080010922
Tyler Gunnd4339262021-05-03 14:46:49 -070010923 @Override
10924 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10925 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10926 "setDeviceToDeviceForceEnabled");
10927
10928 final long identity = Binder.clearCallingIdentity();
10929 try {
10930 Arrays.stream(PhoneFactory.getPhones()).forEach(
10931 p -> {
10932 Phone thePhone = p.getImsPhone();
10933 if (thePhone != null && thePhone instanceof ImsPhone) {
10934 ImsPhone imsPhone = (ImsPhone) thePhone;
10935 CallTracker tracker = imsPhone.getCallTracker();
10936 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10937 ImsPhoneCallTracker imsPhoneCallTracker =
10938 (ImsPhoneCallTracker) tracker;
10939 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10940 }
10941 }
10942 }
10943 );
10944 } finally {
10945 Binder.restoreCallingIdentity(identity);
10946 }
10947 }
10948
Tyler Gunn92479152021-01-20 16:30:10 -080010949 /**
Hui Wang761a6682020-10-31 05:12:53 +000010950 * Gets the config of RCS VoLTE single registration enabled for the device.
10951 */
10952 @Override
10953 public boolean getDeviceSingleRegistrationEnabled() {
10954 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10955 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10956 }
10957
10958 /**
10959 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10960 */
10961 @Override
10962 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10963 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10964 "setCarrierSingleRegistrationEnabledOverride");
10965 enforceModifyPermission();
10966
10967 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10968 : Boolean.parseBoolean(enabledStr);
10969 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10970 subId, enabled);
10971 }
10972
10973 /**
10974 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10975 */
10976 @Override
10977 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10978 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10979 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10980 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010981
10982 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010983 * Overrides the ims feature validation result
10984 */
10985 @Override
10986 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10987 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10988 "setImsFeatureValidationOverride");
10989
10990 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10991 : Boolean.parseBoolean(enabledStr);
10992 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10993 subId, enabled);
10994 }
10995
10996 /**
10997 * Gets the ims feature validation override value
10998 */
10999 @Override
11000 public boolean getImsFeatureValidationOverride(int subId) {
11001 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11002 "getImsFeatureValidationOverride");
11003 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11004 }
11005
11006 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011007 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11008 * their mobile plan.
11009 */
11010 @Override
11011 public String getMobileProvisioningUrl() {
11012 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11013 final long identity = Binder.clearCallingIdentity();
11014 try {
11015 return getDefaultPhone().getMobileProvisioningUrl();
11016 } finally {
11017 Binder.restoreCallingIdentity(identity);
11018 }
11019 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011020
James.cf Linbcdf8b32021-01-14 16:44:13 +080011021 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011022 * Get the EAB contact from the EAB database.
11023 */
11024 @Override
11025 public String getContactFromEab(String contact) {
11026 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11027 enforceModifyPermission();
11028 final long identity = Binder.clearCallingIdentity();
11029 try {
11030 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11031 } finally {
11032 Binder.restoreCallingIdentity(identity);
11033 }
11034 }
11035
11036 /**
Calvin Pana1434322021-07-01 19:27:01 +080011037 * Get the EAB capability from the EAB database.
11038 */
11039 @Override
11040 public String getCapabilityFromEab(String contact) {
11041 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11042 enforceModifyPermission();
11043 final long identity = Binder.clearCallingIdentity();
11044 try {
11045 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11046 } finally {
11047 Binder.restoreCallingIdentity(identity);
11048 }
11049 }
11050
11051 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011052 * Remove the EAB contacts from the EAB database.
11053 */
11054 @Override
11055 public int removeContactFromEab(int subId, String contacts) {
11056 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11057 enforceModifyPermission();
11058 final long identity = Binder.clearCallingIdentity();
11059 try {
11060 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11061 } finally {
11062 Binder.restoreCallingIdentity(identity);
11063 }
11064 }
11065
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011066 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011067 public boolean getDeviceUceEnabled() {
11068 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11069 final long identity = Binder.clearCallingIdentity();
11070 try {
11071 return mApp.getDeviceUceEnabled();
11072 } finally {
11073 Binder.restoreCallingIdentity(identity);
11074 }
11075 }
11076
11077 @Override
11078 public void setDeviceUceEnabled(boolean isEnabled) {
11079 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11080 final long identity = Binder.clearCallingIdentity();
11081 try {
11082 mApp.setDeviceUceEnabled(isEnabled);
11083 } finally {
11084 Binder.restoreCallingIdentity(identity);
11085 }
11086 }
11087
Brad Ebinger14d467f2021-02-12 06:18:28 +000011088 /**
11089 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11090 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11091 */
11092 // Used for SHELL command only right now.
11093 @Override
11094 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11095 List<String> featureTags) {
11096 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11097 "addUceRegistrationOverrideShell");
11098 final long identity = Binder.clearCallingIdentity();
11099 try {
11100 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11101 new ArraySet<>(featureTags));
11102 } catch (ImsException e) {
11103 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11104 } finally {
11105 Binder.restoreCallingIdentity(identity);
11106 }
11107 }
11108
11109 /**
11110 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11111 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11112 */
11113 // Used for SHELL command only right now.
11114 @Override
11115 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11116 List<String> featureTags) {
11117 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11118 "removeUceRegistrationOverrideShell");
11119 final long identity = Binder.clearCallingIdentity();
11120 try {
11121 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11122 new ArraySet<>(featureTags));
11123 } catch (ImsException e) {
11124 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11125 } finally {
11126 Binder.restoreCallingIdentity(identity);
11127 }
11128 }
11129
11130 /**
11131 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11132 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11133 */
11134 // Used for SHELL command only right now.
11135 @Override
11136 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11137 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11138 "clearUceRegistrationOverrideShell");
11139 final long identity = Binder.clearCallingIdentity();
11140 try {
11141 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11142 } catch (ImsException e) {
11143 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11144 } finally {
11145 Binder.restoreCallingIdentity(identity);
11146 }
11147 }
11148
11149 /**
11150 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11151 */
11152 // Used for SHELL command only right now.
11153 @Override
11154 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11155 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11156 "getLatestRcsContactUceCapabilityShell");
11157 final long identity = Binder.clearCallingIdentity();
11158 try {
11159 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11160 } catch (ImsException e) {
11161 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11162 } finally {
11163 Binder.restoreCallingIdentity(identity);
11164 }
11165 }
11166
11167 /**
11168 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11169 * device does not have an active PUBLISH.
11170 */
11171 // Used for SHELL command only right now.
11172 @Override
11173 public String getLastUcePidfXmlShell(int subId) {
11174 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11175 final long identity = Binder.clearCallingIdentity();
11176 try {
11177 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11178 } catch (ImsException e) {
11179 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11180 } finally {
11181 Binder.restoreCallingIdentity(identity);
11182 }
11183 }
11184
James.cf Line8713a42021-04-29 16:04:26 +080011185 /**
11186 * Remove UCE requests cannot be sent to the network status.
11187 */
11188 // Used for SHELL command only right now.
11189 @Override
11190 public boolean removeUceRequestDisallowedStatus(int subId) {
11191 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11192 final long identity = Binder.clearCallingIdentity();
11193 try {
11194 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11195 } catch (ImsException e) {
11196 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11197 } finally {
11198 Binder.restoreCallingIdentity(identity);
11199 }
11200 }
11201
James.cf Lin18bb9002021-05-25 01:37:38 +080011202 /**
11203 * Remove UCE requests cannot be sent to the network status.
11204 */
11205 // Used for SHELL command only.
11206 @Override
11207 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11208 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11209 final long identity = Binder.clearCallingIdentity();
11210 try {
11211 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11212 } catch (ImsException e) {
11213 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11214 } finally {
11215 Binder.restoreCallingIdentity(identity);
11216 }
11217 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011218
James.cf Lin4b784aa2021-01-31 03:25:15 +080011219 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011220 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11221 String callingPackage) {
11222 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11223 mApp, subId, "setSignalStrengthUpdateRequest");
11224
11225 final int callingUid = Binder.getCallingUid();
11226 // Verify that tha callingPackage belongs to the calling UID
11227 mApp.getSystemService(AppOpsManager.class)
11228 .checkPackage(callingUid, callingPackage);
11229
Rambo Wang3607f502021-02-01 21:51:40 -080011230 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011231
11232 final long identity = Binder.clearCallingIdentity();
11233 try {
11234 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11235 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11236
11237 if (result instanceof IllegalStateException) {
11238 throw (IllegalStateException) result;
11239 }
11240 } finally {
11241 Binder.restoreCallingIdentity(identity);
11242 }
11243 }
11244
11245 @Override
11246 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11247 String callingPackage) {
11248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11249 mApp, subId, "clearSignalStrengthUpdateRequest");
11250
11251 final int callingUid = Binder.getCallingUid();
11252 // Verify that tha callingPackage belongs to the calling UID
11253 mApp.getSystemService(AppOpsManager.class)
11254 .checkPackage(callingUid, callingPackage);
11255
11256 final long identity = Binder.clearCallingIdentity();
11257 try {
11258 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11259 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11260
11261 if (result instanceof IllegalStateException) {
11262 throw (IllegalStateException) result;
11263 }
11264 } finally {
11265 Binder.restoreCallingIdentity(identity);
11266 }
11267 }
11268
Rambo Wang3607f502021-02-01 21:51:40 -080011269 private static void validateSignalStrengthUpdateRequest(Context context,
11270 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011271 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11272 // phone/system process do not have further restriction on request
11273 return;
11274 }
11275
11276 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011277 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011278 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011279 context.enforceCallingOrSelfPermission(
11280 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11281 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011282 }
11283
11284 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11285 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11286 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11287 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11288 || info.isEnabled()) {
11289 throw new IllegalArgumentException(
11290 "Only system can set hide fields in SignalThresholdInfo");
11291 }
11292
11293 // Thresholds length for each RAN need in range. This has been validated in
11294 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11295 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11296 final int[] thresholds = info.getThresholds();
11297 Objects.requireNonNull(thresholds);
11298 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11299 || thresholds.length
11300 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11301 throw new IllegalArgumentException(
11302 "thresholds length is out of range: " + thresholds.length);
11303 }
11304 }
11305 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011306
11307 /**
11308 * Gets the current phone capability.
11309 *
11310 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11311 * @return the PhoneCapability which describes the data connection capability of modem.
11312 * It's used to evaluate possible phone config change, for example from single
11313 * SIM device to multi-SIM device.
11314 */
11315 @Override
11316 public PhoneCapability getPhoneCapability() {
11317 enforceReadPrivilegedPermission("getPhoneCapability");
11318 final long identity = Binder.clearCallingIdentity();
11319 try {
11320 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11321 } finally {
11322 Binder.restoreCallingIdentity(identity);
11323 }
11324 }
Michele Berionne5e411512020-11-13 02:36:59 +000011325
11326 /**
11327 * Prepare TelephonyManager for an unattended reboot. The reboot is
11328 * required to be done shortly after the API is invoked.
11329 */
11330 @Override
11331 @TelephonyManager.PrepareUnattendedRebootResult
11332 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011333 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011334 enforceRebootPermission();
11335
11336 final long identity = Binder.clearCallingIdentity();
11337 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011338 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011339 } finally {
11340 Binder.restoreCallingIdentity(identity);
11341 }
11342 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011343
11344 /**
11345 * Request to get the current slicing configuration including URSP rules and
11346 * NSSAIs (configured, allowed and rejected).
11347 *
11348 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11349 */
11350 @Override
11351 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011352 TelephonyPermissions
11353 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11354 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011355
11356 final long identity = Binder.clearCallingIdentity();
11357 try {
11358 Phone phone = getDefaultPhone();
11359 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11360 } finally {
11361 Binder.restoreCallingIdentity(identity);
11362 }
11363 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011364
11365 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011366 * Check whether the given premium capability is available for purchase from the carrier.
11367 *
11368 * @param capability The premium capability to check.
11369 * @param subId The subId to check the premium capability for.
11370 *
11371 * @return Whether the given premium capability is available to purchase.
11372 */
11373 @Override
11374 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11375 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11376 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11377 log("Premium capability "
11378 + TelephonyManager.convertPremiumCapabilityToString(capability)
11379 + " is not available for purchase due to missing permissions.");
11380 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11381 + "permission READ_BASIC_PHONE_STATE.");
11382 }
11383
11384 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011385 if (phone == null) {
11386 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11387 return false;
11388 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011389 final long identity = Binder.clearCallingIdentity();
11390 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011391 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011392 .isPremiumCapabilityAvailableForPurchase(capability);
11393 } finally {
11394 Binder.restoreCallingIdentity(identity);
11395 }
11396 }
11397
11398 /**
11399 * Purchase the given premium capability from the carrier.
11400 *
11401 * @param capability The premium capability to purchase.
11402 * @param callback The result of the purchase request.
11403 * @param subId The subId to purchase the premium capability for.
11404 */
11405 @Override
11406 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11407 log("purchasePremiumCapability: capability="
11408 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11409 + getCurrentPackageName());
11410
11411 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11412 mApp, "purchasePremiumCapability")) {
11413 log("purchasePremiumCapability "
11414 + TelephonyManager.convertPremiumCapabilityToString(capability)
11415 + " failed due to missing permissions.");
11416 throw new SecurityException("purchasePremiumCapability requires permission "
11417 + "READ_BASIC_PHONE_STATE.");
11418 }
11419
11420 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011421 if (phone == null) {
11422 try {
11423 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11424 callback.accept(result);
11425 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11426 } catch (RemoteException e) {
11427 String logStr = "Purchase premium capability "
11428 + TelephonyManager.convertPremiumCapabilityToString(capability)
11429 + " failed due to RemoteException handling null phone: " + e;
11430 if (DBG) log(logStr);
11431 AnomalyReporter.reportAnomaly(
11432 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11433 }
11434 return;
11435 }
Sarah Chin71b3a852022-09-28 15:54:19 -070011436 String appName;
11437 try {
11438 appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager()
11439 .getApplicationInfo(getCurrentPackageName(), 0)).toString();
11440 } catch (PackageManager.NameNotFoundException e) {
11441 appName = "An application";
11442 }
11443 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
11444 new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011445 }
11446
11447 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011448 * Register an IMS connection state callback
11449 */
11450 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011451 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11452 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011453 if (feature == ImsFeature.FEATURE_MMTEL) {
11454 // ImsMmTelManager
11455 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11456 TelephonyPermissions
11457 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11458 mApp, subId, "registerImsStateCallback");
11459 } else if (feature == ImsFeature.FEATURE_RCS) {
11460 // ImsRcsManager or SipDelegateManager
11461 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11462 Binder.getCallingUid(), "registerImsStateCallback",
11463 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11464 Manifest.permission.READ_PRECISE_PHONE_STATE,
11465 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11466 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11467 }
11468
11469 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11470 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11471 "IMS not available on device.");
11472 }
11473
11474 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11475 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11476 }
11477
11478 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11479 if (controller == null) {
11480 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11481 "IMS not available on device.");
11482 }
11483
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011484 if (callingPackage == null) {
11485 callingPackage = getCurrentPackageName();
11486 }
11487
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011488 final long token = Binder.clearCallingIdentity();
11489 try {
11490 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011491 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011492 } catch (ImsException e) {
11493 throw new ServiceSpecificException(e.getCode());
11494 } finally {
11495 Binder.restoreCallingIdentity(token);
11496 }
11497 }
11498
11499 /**
11500 * Unregister an IMS connection state callback
11501 */
11502 @Override
11503 public void unregisterImsStateCallback(IImsStateCallback cb) {
11504 final long token = Binder.clearCallingIdentity();
11505 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11506 if (controller == null) {
11507 return;
11508 }
11509 try {
11510 controller.unregisterImsStateCallback(cb);
11511 } finally {
11512 Binder.restoreCallingIdentity(token);
11513 }
11514 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011515
11516 /**
11517 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11518 *
11519 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11520 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11521 * SecurityException.
11522 * If there is current registered network this value will be same as the registered cell
11523 * identity. If the device goes out of service the previous cell identity is cached and
11524 * will be returned. If the cache age of the Cell identity is more than 24 hours
11525 * it will be cleared and null will be returned.
11526 *
11527 */
11528 @Override
11529 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11530 String callingFeatureId) {
11531 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11532 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11533 LocationAccessPolicy.checkLocationPermission(mApp,
11534 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11535 .setCallingPackage(callingPackage)
11536 .setCallingFeatureId(callingFeatureId)
11537 .setCallingPid(Binder.getCallingPid())
11538 .setCallingUid(Binder.getCallingUid())
11539 .setMethod("getLastKnownCellIdentity")
11540 .setLogAsInfo(true)
11541 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11542 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11543 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11544 .build());
11545
11546 boolean hasFinePermission =
11547 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11548 if (!hasFinePermission
11549 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11550 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011551 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011552 }
11553
11554 final long identity = Binder.clearCallingIdentity();
11555 try {
11556 Phone phone = getPhone(subId);
11557 if (phone == null) return null;
11558 ServiceStateTracker sst = phone.getServiceStateTracker();
11559 if (sst == null) return null;
11560 return sst.getLastKnownCellIdentity();
11561 } finally {
11562 Binder.restoreCallingIdentity(identity);
11563 }
11564 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011565
jimsun3b9ccac2021-10-26 15:01:23 +080011566 /**
11567 * Sets the modem service class Name that Telephony will bind to.
11568 *
11569 * @param serviceName The class name of the modem service.
11570 * @return true if the operation is succeed, otherwise false.
11571 */
11572 public boolean setModemService(String serviceName) {
11573 Log.d(LOG_TAG, "setModemService - " + serviceName);
11574 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11576 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11577 "setModemService");
11578 return mPhoneConfigurationManager.setModemService(serviceName);
11579 }
11580
11581 /**
11582 * Return the class name of the currently bounded modem service.
11583 *
11584 * @return the class name of the modem service.
11585 */
11586 public String getModemService() {
11587 String result;
11588 Log.d(LOG_TAG, "getModemService");
11589 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11590 TelephonyPermissions
11591 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11592 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11593 "getModemService");
11594 result = mPhoneConfigurationManager.getModemService();
11595 Log.d(LOG_TAG, "result = " + result);
11596 return result;
11597 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011598
11599 @Override
11600 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11601 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11602 mApp.enforceCallingOrSelfPermission(
11603 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11604 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11605
11606 final long identity = Binder.clearCallingIdentity();
11607 try {
11608 Phone phone = getPhone(subId);
11609 if (phone == null) return;
11610 phone.setVoiceServiceStateOverride(hasService);
11611 } finally {
11612 Binder.restoreCallingIdentity(identity);
11613 }
11614 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011615
11616 /**
11617 * set removable eSIM as default eUICC.
11618 *
11619 * @hide
11620 */
11621 @Override
11622 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11623 enforceModifyPermission();
11624 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11625
11626 final long identity = Binder.clearCallingIdentity();
11627 try {
11628 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11629 } finally {
11630 Binder.restoreCallingIdentity(identity);
11631 }
11632 }
11633
11634 /**
11635 * Returns whether the removable eSIM is default eUICC or not.
11636 *
11637 * @hide
11638 */
11639 @Override
11640 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11641 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11642 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11643
11644 final long identity = Binder.clearCallingIdentity();
11645 try {
11646 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11647 } finally {
11648 Binder.restoreCallingIdentity(identity);
11649 }
11650 }
11651
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011652 /**
11653 * Get the component name of the default app to direct respond-via-message intent for the
11654 * user associated with this subscription, update the cache if there is no respond-via-message
11655 * application currently configured for this user.
11656 * @return component name of the app and class to direct Respond Via Message intent to, or
11657 * {@code null} if the functionality is not supported.
11658 * @hide
11659 */
11660 @Override
11661 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11662 boolean updateIfNeeded) {
11663 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011664
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011665 Context context = getPhone(subId).getContext();
11666 UserHandle userHandle = null;
11667 final long identity = Binder.clearCallingIdentity();
11668 try {
11669 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11670 } finally {
11671 Binder.restoreCallingIdentity(identity);
11672 }
11673 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11674 updateIfNeeded, userHandle);
11675 }
Jack Yuf5badd92022-12-08 00:50:53 -080011676
11677 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011678 * Set whether the device is able to connect with null ciphering or integrity
11679 * algorithms. This is a global setting and will apply to all active subscriptions
11680 * and all new subscriptions after this.
11681 *
11682 * @param enabled when true, null cipher and integrity algorithms are allowed.
11683 * @hide
11684 */
11685 @Override
11686 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11687 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11688 enforceModifyPermission();
11689 checkForNullCipherAndIntegritySupport();
11690
11691 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11692 // for listening to these preference changes and applying them immediately.
11693 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11694 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11695 editor.apply();
11696
11697 for (Phone phone: PhoneFactory.getPhones()) {
11698 phone.handleNullCipherEnabledChange();
11699 }
11700 }
11701
11702
11703 /**
11704 * Get whether the device is able to connect with null ciphering or integrity
11705 * algorithms. Note that this retrieves the phone-global preference and not
11706 * the state of the radio.
11707 *
11708 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11709 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11710 * version for this feature.
11711 * @hide
11712 */
11713 @Override
11714 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11715 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11716 enforceReadPermission();
11717 checkForNullCipherAndIntegritySupport();
11718 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11719 }
11720
11721 private void checkForNullCipherAndIntegritySupport() {
11722 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11723 throw new UnsupportedOperationException(
11724 "Null cipher and integrity operations require HAL 2.1 or above");
11725 }
11726 }
11727
11728 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011729 * Get the SIM state for the slot index.
11730 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11731 *
11732 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11733 */
11734 @Override
11735 @SimState
11736 public int getSimStateForSlotIndex(int slotIndex) {
11737 IccCardConstants.State simState;
11738 if (slotIndex < 0) {
11739 simState = IccCardConstants.State.UNKNOWN;
11740 } else {
11741 Phone phone = null;
11742 try {
11743 phone = PhoneFactory.getPhone(slotIndex);
11744 } catch (IllegalStateException e) {
11745 // ignore
11746 }
11747 if (phone == null) {
11748 simState = IccCardConstants.State.UNKNOWN;
11749 } else {
11750 IccCard icc = phone.getIccCard();
11751 if (icc == null) {
11752 simState = IccCardConstants.State.UNKNOWN;
11753 } else {
11754 simState = icc.getState();
11755 }
11756 }
11757 }
11758 return simState.ordinal();
11759 }
Hui Wang9b5793a2022-12-05 14:38:06 -060011760
11761 /**
11762 * Get current cell broadcast ranges.
11763 */
11764 @Override
11765 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
11766 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
11767 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
11768 "getCellBroadcastIdRanges");
11769 final long identity = Binder.clearCallingIdentity();
11770 try {
11771 return getPhone(subId).getCellBroadcastIdRanges();
11772 } finally {
11773 Binder.restoreCallingIdentity(identity);
11774 }
11775 }
11776
11777 /**
11778 * Set reception of cell broadcast messages with the list of the given ranges
11779 *
11780 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
11781 */
11782 @Override
11783 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
11784 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
11785 @Nullable IIntegerConsumer callback) {
11786 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
11787 "setCellBroadcastIdRanges");
11788 final long identity = Binder.clearCallingIdentity();
11789 try {
11790 Phone phone = getPhoneFromSubId(subId);
11791 if (DBG) {
11792 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
11793 }
11794 phone.setCellBroadcastIdRanges(ranges, result -> {
11795 if (callback != null) {
11796 try {
11797 callback.accept(result);
11798 } catch (RemoteException e) {
11799 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
11800 }
11801 }
11802 });
11803 } finally {
11804 Binder.restoreCallingIdentity(identity);
11805 }
11806 }
11807}