blob: f1cff81fdcfee5b4d43ba75f486bf5063f977f3d [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;
jimsunf9ec1622022-09-13 21:18:43 +080020import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Hall Liud892bec2018-11-30 14:51:45 -080021
Shuo Qianccbaf742021-02-22 18:32:21 -080022import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
23import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070024import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070025import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000026import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070027
Brad Ebinger34c09a52021-02-17 23:23:21 +000028import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080029import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080030import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070031import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000032import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080034import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070035import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000036import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080037import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000038import android.compat.annotation.ChangeId;
39import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070040import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070041import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.content.Context;
43import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070044import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070045import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070046import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.net.Uri;
48import android.os.AsyncResult;
49import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080050import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.os.Bundle;
52import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070053import android.os.IBinder;
tom hsu0b59d292022-09-29 23:49:21 +080054import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.Looper;
56import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070057import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080058import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070059import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070060import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080061import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080062import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070063import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070064import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080065import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070067import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070068import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070069import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070070import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080071import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070072import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090073import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080074import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080075import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070076import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080077import android.telephony.AccessNetworkConstants;
78import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070079import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070080import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080081import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070082import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080083import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070084import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080085import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070086import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080087import android.telephony.CellIdentityCdma;
88import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070090import android.telephony.CellInfoGsm;
91import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070092import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080093import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070094import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070095import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070096import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080097import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070098import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080099import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700100import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800101import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800102import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700103import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800104import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700105import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800106import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800107import android.telephony.SignalStrengthUpdateRequest;
108import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800109import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800110import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800111import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700112import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700113import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800114import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800115import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800116import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800117import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000118import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000119import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000120import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700121import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700122import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800123import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800124import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700125import android.telephony.gba.GbaAuthRequest;
126import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700127import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800128import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000129import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000130import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700131import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000132import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700133import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800134import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700135import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800136import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700137import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000138import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700139import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800140import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800141import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800143import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700144import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700145import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800146import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800147
Andrew Lee312e8172014-10-23 17:01:36 -0700148import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800149import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800150import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800151import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800152import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700153import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700154import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700155import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800156import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800157import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700158import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700159import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800160import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700161import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800162import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800163import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800164import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700165import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000166import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700167import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800168import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700169import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800170import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800171import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800172import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700173import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700174import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700175import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700176import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700177import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800178import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700179import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700180import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700181import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700182import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800183import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800184import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700185import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000186import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700187import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700188import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800189import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800190import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800191import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700192import com.android.internal.telephony.data.DataUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800193import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700194import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800195import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700196import com.android.internal.telephony.imsphone.ImsPhone;
197import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000198import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800199import com.android.internal.telephony.metrics.TelephonyMetrics;
Jack Yu285100e2022-12-02 22:48:35 -0800200import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
201import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700202import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700203import com.android.internal.telephony.uicc.IccIoResult;
204import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800205import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700206import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800207import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700208import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000209import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800210import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000211import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800212import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000213import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700214import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700215import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800216import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800217import com.android.phone.callcomposer.CallComposerPictureManager;
218import com.android.phone.callcomposer.CallComposerPictureTransfer;
219import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700220import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700221import com.android.phone.slice.SlicePurchaseController;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700222import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800223import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700224import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700225import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800226import com.android.services.telephony.TelecomAccountRegistry;
227import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800228import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800229
Hall Liu82694d52020-12-11 18:22:04 -0800230import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700231import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800232import java.io.IOException;
233import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700234import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700235import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800236import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000237import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800238import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800239import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800240import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800241import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100242import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800243import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700244import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800245import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800246import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700247import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800248import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800249import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800250import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700251
252/**
253 * Implementation of the ITelephony interface.
254 */
Santos Cordon117fee72014-05-16 17:56:12 -0700255public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700256 private static final String LOG_TAG = "PhoneInterfaceManager";
257 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
258 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800259 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700260
261 // Message codes used with mMainThreadHandler
262 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700263 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
264 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700265 private static final int CMD_OPEN_CHANNEL = 9;
266 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
267 private static final int CMD_CLOSE_CHANNEL = 11;
268 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800269 private static final int CMD_NV_READ_ITEM = 13;
270 private static final int EVENT_NV_READ_ITEM_DONE = 14;
271 private static final int CMD_NV_WRITE_ITEM = 15;
272 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
273 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
274 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700275 private static final int CMD_RESET_MODEM_CONFIG = 19;
276 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800277 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
278 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800279 private static final int CMD_SEND_ENVELOPE = 25;
280 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000281 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
282 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700283 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
284 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
285 private static final int CMD_EXCHANGE_SIM_IO = 31;
286 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800287 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
288 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700289 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
290 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700291 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
292 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700293 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
294 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
295 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
296 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700297 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
298 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
299 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
300 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700301 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800302 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
303 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000304 private static final int CMD_SWITCH_SLOTS = 50;
305 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700306 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
307 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
308 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
309 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
310 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
311 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
312 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
313 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700314 private static final int CMD_GET_ALL_CELL_INFO = 60;
315 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
316 private static final int CMD_GET_CELL_LOCATION = 62;
317 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700318 private static final int CMD_MODEM_REBOOT = 64;
319 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700320 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
321 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800322 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
323 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700324 private static final int CMD_GET_MODEM_STATUS = 70;
325 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700326 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
327 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700328 private static final int CMD_ERASE_MODEM_CONFIG = 74;
329 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800330 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
331 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
332 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
333 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800334 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
335 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800336 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800337 private static final int CMD_GET_CALL_FORWARDING = 83;
338 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
339 private static final int CMD_SET_CALL_FORWARDING = 85;
340 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
341 private static final int CMD_GET_CALL_WAITING = 87;
342 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
343 private static final int CMD_SET_CALL_WAITING = 89;
344 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700345 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
346 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
347 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
348 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700349 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
350 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800351 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
352 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800353 private static final int CMD_SET_DATA_THROTTLING = 99;
354 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800355 private static final int CMD_SET_SIM_POWER = 101;
356 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800357 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
358 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
359 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
360 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800361 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
362 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000363 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800364 private static final int CMD_GET_SLICING_CONFIG = 110;
365 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800366 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700367 private static final int CMD_ENABLE_VONR = 113;
368 private static final int EVENT_ENABLE_VONR_DONE = 114;
369 private static final int CMD_IS_VONR_ENABLED = 115;
370 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700371 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
372 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800374 // Parameters of select command.
375 private static final int SELECT_COMMAND = 0xA4;
376 private static final int SELECT_P1 = 0x04;
377 private static final int SELECT_P2 = 0;
378 private static final int SELECT_P3 = 0x10;
379
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 /** The singleton instance. */
381 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800382 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383
Wink Saville3ab207e2014-11-20 13:07:20 -0800384 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800385 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800386 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700387 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800388 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700389 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800390 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800391 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800392 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700393 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800394 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Gil Cukierman6dac5eb2022-09-19 16:09:04 +0000395 private final Telephony2gUpdater mTelephony2gUpdater;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700396
Peter Wangdafb9ac2020-01-15 14:13:38 -0800397 /** User Activity */
398 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800399 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
400
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700401 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
402
Derek Tan97ebb422014-09-05 16:55:38 -0700403 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
404 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800405 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800406 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700407
Michelecea4cf22018-12-21 15:00:11 -0800408 // String to store multi SIM allowed
409 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
410
Derek Tan740e1672017-06-27 14:56:27 -0700411 // The AID of ISD-R.
412 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
413
yinxub1bed742017-04-17 11:45:04 -0700414 private NetworkScanRequestTracker mNetworkScanRequestTracker;
415
David Kelly5e06a7f2018-03-12 14:10:59 +0000416 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
417 private static final int MANUFACTURER_CODE_LENGTH = 8;
418
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800419 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800420 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800421
Sarah Chin2ec39f62022-08-31 17:03:26 -0700422 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
423 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
424
Derek Tan89e89d42014-07-08 17:00:10 -0700425 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700426 * Experiment flag to enable erase modem config on reset network, default value is false
427 */
428 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
429 "reset_network_erase_modem_config_enabled";
430
Rambo Wang0f050d82021-02-12 11:43:36 -0800431 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800432
sandeepjsb6c87872021-09-27 15:34:44 +0000433 /**
434 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
435 * one ICCID active at the same time.
436 * Apps should use below API signatures if targeting SDK is T and beyond.
437 *
438 * @hide
439 */
440 @ChangeId
441 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
442 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800443
Naina Nallurid63128d2019-09-17 14:10:30 -0700444 /**
Chen Xu540470b2021-12-14 17:15:47 -0800445 * Apps targeting on Android T and beyond will get exception whenever icc close channel
446 * operation fails.
447 */
448 @ChangeId
449 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
450 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
451
452 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700453 * A request object to use for transmitting data to an ICC.
454 */
455 private static final class IccAPDUArgument {
456 public int channel, cla, command, p1, p2, p3;
457 public String data;
458
459 public IccAPDUArgument(int channel, int cla, int command,
460 int p1, int p2, int p3, String data) {
461 this.channel = channel;
462 this.cla = cla;
463 this.command = command;
464 this.p1 = p1;
465 this.p2 = p2;
466 this.p3 = p3;
467 this.data = data;
468 }
469 }
470
471 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700472 * A request object to use for transmitting data to an ICC.
473 */
474 private static final class ManualNetworkSelectionArgument {
475 public OperatorInfo operatorInfo;
476 public boolean persistSelection;
477
478 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
479 this.operatorInfo = operatorInfo;
480 this.persistSelection = persistSelection;
481 }
482 }
483
Sarah Chin71b3a852022-09-28 15:54:19 -0700484 private static final class PurchasePremiumCapabilityArgument {
485 public @TelephonyManager.PremiumCapability int capability;
486 public @NonNull String appName;
487 public @NonNull IIntegerConsumer callback;
488
489 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
490 @NonNull String appName, @NonNull IIntegerConsumer callback) {
491 this.capability = capability;
492 this.appName = appName;
493 this.callback = callback;
494 }
495 }
496
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700497 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700498 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
499 * request after sending. The main thread will notify the request when it is complete.
500 */
501 private static final class MainThreadRequest {
502 /** The argument to use for the request */
503 public Object argument;
504 /** The result of the request that is run on the main thread */
505 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800506 // The subscriber id that this request applies to. Defaults to
507 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
508 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700509
Nathan Harold92bed182018-10-12 18:16:49 -0700510 // In cases where subId is unavailable, the caller needs to specify the phone.
511 public Phone phone;
512
vagdeviaf9a5b92018-08-15 16:01:53 -0700513 public WorkSource workSource;
514
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700515 public MainThreadRequest(Object argument) {
516 this.argument = argument;
517 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800518
Nathan Harold92bed182018-10-12 18:16:49 -0700519 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
520 this.argument = argument;
521 if (phone != null) {
522 this.phone = phone;
523 }
524 this.workSource = workSource;
525 }
526
vagdeviaf9a5b92018-08-15 16:01:53 -0700527 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800528 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800529 if (subId != null) {
530 this.subId = subId;
531 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700532 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800533 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700534 }
535
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800536 private static final class IncomingThirdPartyCallArgs {
537 public final ComponentName component;
538 public final String callId;
539 public final String callerDisplayName;
540
541 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
542 String callerDisplayName) {
543 this.component = component;
544 this.callId = callId;
545 this.callerDisplayName = callerDisplayName;
546 }
547 }
548
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700549 /**
550 * A handler that processes messages on the main thread in the phone process. Since many
551 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
552 * inbound binder threads to the main thread in the phone process. The Binder thread
553 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
554 * on, which will be notified when the operation completes and will contain the result of the
555 * request.
556 *
557 * <p>If a MainThreadRequest object is provided in the msg.obj field,
558 * note that request.result must be set to something non-null for the calling thread to
559 * unblock.
560 */
561 private final class MainThreadHandler extends Handler {
562 @Override
563 public void handleMessage(Message msg) {
564 MainThreadRequest request;
565 Message onCompleted;
566 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000567 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800569 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700570
571 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700572 case CMD_HANDLE_USSD_REQUEST: {
573 request = (MainThreadRequest) msg.obj;
574 final Phone phone = getPhoneFromRequest(request);
575 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800576 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700577 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700578
Pengquan Menga1bb6272018-09-06 09:59:22 -0700579 if (!isUssdApiAllowed(request.subId)) {
580 // Carrier does not support use of this API, return failure.
581 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
582 UssdResponse response = new UssdResponse(ussdRequest, null);
583 Bundle returnData = new Bundle();
584 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
585 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700586
Pengquan Menga1bb6272018-09-06 09:59:22 -0700587 request.result = true;
588 notifyRequester(request);
589 return;
590 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700591
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 try {
593 request.result = phone != null
594 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
595 } catch (CallStateException cse) {
596 request.result = false;
597 }
598 // Wake up the requesting thread
599 notifyRequester(request);
600 break;
pkanwar32d516d2016-10-14 19:37:38 -0700601 }
602
Yorke Lee716f67e2015-06-17 15:39:16 -0700603 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700604 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700605 final Phone phone = getPhoneFromRequest(request);
606 request.result = phone != null ?
607 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
608 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700609 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700610 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700611 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700612 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700613
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000617 uiccPort = getUiccPortFromRequest(request);
618 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700619 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800620 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700621 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700622 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800624 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000625 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800626 iccArgument.channel, iccArgument.cla, iccArgument.command,
627 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
628 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700629 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 break;
631
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700632 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 ar = (AsyncResult) msg.obj;
634 request = (MainThreadRequest) ar.userObj;
635 if (ar.exception == null && ar.result != null) {
636 request.result = ar.result;
637 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800638 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 if (ar.result == null) {
640 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800641 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700642 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800643 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 } else {
645 loge("iccTransmitApduLogicalChannel: Unknown exception");
646 }
647 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700648 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 break;
650
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700651 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
652 request = (MainThreadRequest) msg.obj;
653 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000654 uiccPort = getUiccPortFromRequest(request);
655 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700656 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800657 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700658 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700659 } else {
660 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800661 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000662 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800663 iccArgument.cla, iccArgument.command, iccArgument.p1,
664 iccArgument.p2,
665 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700666 }
667 break;
668
669 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
670 ar = (AsyncResult) msg.obj;
671 request = (MainThreadRequest) ar.userObj;
672 if (ar.exception == null && ar.result != null) {
673 request.result = ar.result;
674 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800675 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700676 if (ar.result == null) {
677 loge("iccTransmitApduBasicChannel: Empty response");
678 } else if (ar.exception instanceof CommandException) {
679 loge("iccTransmitApduBasicChannel: CommandException: " +
680 ar.exception);
681 } else {
682 loge("iccTransmitApduBasicChannel: Unknown exception");
683 }
684 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700685 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700686 break;
687
688 case CMD_EXCHANGE_SIM_IO:
689 request = (MainThreadRequest) msg.obj;
690 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000691 uiccPort = getUiccPortFromRequest(request);
692 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700693 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800694 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700695 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700696 } else {
697 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
698 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000699 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700700 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
701 iccArgument.data, onCompleted);
702 }
703 break;
704
705 case EVENT_EXCHANGE_SIM_IO_DONE:
706 ar = (AsyncResult) msg.obj;
707 request = (MainThreadRequest) ar.userObj;
708 if (ar.exception == null && ar.result != null) {
709 request.result = ar.result;
710 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800711 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700712 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700713 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700714 break;
715
Derek Tan4d5e5c12014-02-04 11:54:58 -0800716 case CMD_SEND_ENVELOPE:
717 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000718 uiccPort = getUiccPortFromRequest(request);
719 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700720 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800721 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700722 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700723 } else {
724 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800725 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700726 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800727 break;
728
729 case EVENT_SEND_ENVELOPE_DONE:
730 ar = (AsyncResult) msg.obj;
731 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700732 if (ar.exception == null && ar.result != null) {
733 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800734 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800735 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700736 if (ar.result == null) {
737 loge("sendEnvelopeWithStatus: Empty response");
738 } else if (ar.exception instanceof CommandException) {
739 loge("sendEnvelopeWithStatus: CommandException: " +
740 ar.exception);
741 } else {
742 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
743 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800744 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700745 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800746 break;
747
Shishir Agrawal566b7612013-10-28 14:41:00 -0700748 case CMD_OPEN_CHANNEL:
749 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000750 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800751 IccLogicalChannelRequest openChannelRequest =
752 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000753 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700754 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800755 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800756 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700757 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700758 } else {
759 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800760 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
761 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700762 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700763 break;
764
765 case EVENT_OPEN_CHANNEL_DONE:
766 ar = (AsyncResult) msg.obj;
767 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700768 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700769 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700770 int[] result = (int[]) ar.result;
771 int channelId = result[0];
772 byte[] selectResponse = null;
773 if (result.length > 1) {
774 selectResponse = new byte[result.length - 1];
775 for (int i = 1; i < result.length; ++i) {
776 selectResponse[i - 1] = (byte) result[i];
777 }
778 }
779 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800780 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800781
782 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700783 if (uiccPort == null) {
784 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
785 } else {
786 IccLogicalChannelRequest channelRequest =
787 (IccLogicalChannelRequest) request.argument;
788 channelRequest.channel = channelId;
789 uiccPort.onLogicalChannelOpened(channelRequest);
790 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700791 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700792 if (ar.result == null) {
793 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700794 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700795 if (ar.exception != null) {
796 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
797 }
798
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700799 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700800 if (ar.exception instanceof CommandException) {
801 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800802 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700803 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700804 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700805 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700806 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700807 }
808 }
809 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800810 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700811 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700812 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700813 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700814 break;
815
816 case CMD_CLOSE_CHANNEL:
817 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000818 uiccPort = getUiccPortFromRequest(request);
819 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700820 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800821 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800822 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800823 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700824 } else {
825 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000826 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700827 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700828 break;
829
830 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800831 ar = (AsyncResult) msg.obj;
832 request = (MainThreadRequest) ar.userObj;
833 if (ar.exception == null) {
834 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800835 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700836 if (uiccPort == null) {
837 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
838 } else {
839 final int channelId = (Integer) request.argument;
840 uiccPort.onLogicalChannelClosed(channelId);
841 }
Chen Xu540470b2021-12-14 17:15:47 -0800842 } else {
843 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800844 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800845 if (ar.exception instanceof CommandException) {
846 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
847 CommandException.Error error =
848 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800849 if (error == CommandException.Error.INVALID_ARGUMENTS) {
850 // should only throw exceptions from the binder threads.
851 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800852 "iccCloseLogicalChannel: invalid argument ");
853 }
854 } else {
855 loge("iccCloseLogicalChannel: Unknown exception");
856 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800857 request.result = (exception != null) ? exception :
858 new IllegalStateException(
859 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800860 }
861 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800862 break;
863
864 case CMD_NV_READ_ITEM:
865 request = (MainThreadRequest) msg.obj;
866 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800867 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
868 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800869 break;
870
871 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700872 ar = (AsyncResult) msg.obj;
873 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800874 if (ar.exception == null && ar.result != null) {
875 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700876 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800877 request.result = "";
878 if (ar.result == null) {
879 loge("nvReadItem: Empty response");
880 } else if (ar.exception instanceof CommandException) {
881 loge("nvReadItem: CommandException: " +
882 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700883 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800884 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700885 }
886 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700887 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700888 break;
889
Jake Hambye994d462014-02-03 13:10:13 -0800890 case CMD_NV_WRITE_ITEM:
891 request = (MainThreadRequest) msg.obj;
892 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
893 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800894 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700895 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800896 break;
897
898 case EVENT_NV_WRITE_ITEM_DONE:
899 handleNullReturnEvent(msg, "nvWriteItem");
900 break;
901
902 case CMD_NV_WRITE_CDMA_PRL:
903 request = (MainThreadRequest) msg.obj;
904 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800905 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800906 break;
907
908 case EVENT_NV_WRITE_CDMA_PRL_DONE:
909 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
910 break;
911
chen xu6dac5ab2018-10-26 17:39:23 -0700912 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800913 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700914 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800915 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800916 break;
917
chen xu6dac5ab2018-10-26 17:39:23 -0700918 case EVENT_RESET_MODEM_CONFIG_DONE:
919 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800920 break;
921
Sooraj Sasindran37444802020-08-11 10:40:43 -0700922 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
923 request = (MainThreadRequest) msg.obj;
924 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
925 request);
926 Phone phone = getPhoneFromRequest(request);
927 if (phone != null) {
928 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
929 } else {
930 loge("isNRDualConnectivityEnabled: No phone object");
931 request.result = false;
932 notifyRequester(request);
933 }
934 break;
935 }
936
937 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
938 ar = (AsyncResult) msg.obj;
939 request = (MainThreadRequest) ar.userObj;
940 if (ar.exception == null && ar.result != null) {
941 request.result = ar.result;
942 } else {
943 // request.result must be set to something non-null
944 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700945 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700946 request.result = ar.result;
947 } else {
948 request.result = false;
949 }
950 if (ar.result == null) {
951 loge("isNRDualConnectivityEnabled: Empty response");
952 } else if (ar.exception instanceof CommandException) {
953 loge("isNRDualConnectivityEnabled: CommandException: "
954 + ar.exception);
955 } else {
956 loge("isNRDualConnectivityEnabled: Unknown exception");
957 }
958 }
959 notifyRequester(request);
960 break;
961
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700962 case CMD_IS_VONR_ENABLED: {
963 request = (MainThreadRequest) msg.obj;
964 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
965 request);
966 Phone phone = getPhoneFromRequest(request);
967 if (phone != null) {
968 phone.isVoNrEnabled(onCompleted, request.workSource);
969 } else {
970 loge("isVoNrEnabled: No phone object");
971 request.result = false;
972 notifyRequester(request);
973 }
974 break;
975 }
976
977 case EVENT_IS_VONR_ENABLED_DONE:
978 ar = (AsyncResult) msg.obj;
979 request = (MainThreadRequest) ar.userObj;
980 if (ar.exception == null && ar.result != null) {
981 request.result = ar.result;
982 } else {
983 // request.result must be set to something non-null
984 // for the calling thread to unblock
985 if (ar.result != null) {
986 request.result = ar.result;
987 } else {
988 request.result = false;
989 }
990 if (ar.result == null) {
991 loge("isVoNrEnabled: Empty response");
992 } else if (ar.exception instanceof CommandException) {
993 loge("isVoNrEnabled: CommandException: "
994 + ar.exception);
995 } else {
996 loge("isVoNrEnabled: Unknown exception");
997 }
998 }
999 notifyRequester(request);
1000 break;
1001
Sooraj Sasindran37444802020-08-11 10:40:43 -07001002 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1003 request = (MainThreadRequest) msg.obj;
1004 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1005 Phone phone = getPhoneFromRequest(request);
1006 if (phone != null) {
1007 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1008 request.workSource);
1009 } else {
1010 loge("enableNrDualConnectivity: No phone object");
1011 request.result =
1012 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1013 notifyRequester(request);
1014 }
1015 break;
1016 }
1017
1018 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1019 ar = (AsyncResult) msg.obj;
1020 request = (MainThreadRequest) ar.userObj;
1021 if (ar.exception == null) {
1022 request.result =
1023 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1024 } else {
1025 request.result =
1026 TelephonyManager
1027 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1028 if (ar.exception instanceof CommandException) {
1029 CommandException.Error error =
1030 ((CommandException) (ar.exception)).getCommandError();
1031 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1032 request.result =
1033 TelephonyManager
1034 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001035 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1036 request.result =
1037 TelephonyManager
1038 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001039 }
1040 loge("enableNrDualConnectivity" + ": CommandException: "
1041 + ar.exception);
1042 } else {
1043 loge("enableNrDualConnectivity" + ": Unknown exception");
1044 }
1045 }
1046 notifyRequester(request);
1047 break;
1048 }
1049
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001050 case CMD_ENABLE_VONR: {
1051 request = (MainThreadRequest) msg.obj;
1052 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1053 Phone phone = getPhoneFromRequest(request);
1054 if (phone != null) {
1055 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1056 request.workSource);
1057 } else {
1058 loge("setVoNrEnabled: No phone object");
1059 request.result =
1060 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1061 notifyRequester(request);
1062 }
1063 break;
1064 }
1065
1066 case EVENT_ENABLE_VONR_DONE: {
1067 ar = (AsyncResult) msg.obj;
1068 request = (MainThreadRequest) ar.userObj;
1069 if (ar.exception == null) {
1070 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1071 } else {
1072 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1073 if (ar.exception instanceof CommandException) {
1074 CommandException.Error error =
1075 ((CommandException) (ar.exception)).getCommandError();
1076 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1077 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1078 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1079 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1080 } else {
1081 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1082 }
1083 loge("setVoNrEnabled" + ": CommandException: "
1084 + ar.exception);
1085 } else {
1086 loge("setVoNrEnabled" + ": Unknown exception");
1087 }
1088 }
1089 notifyRequester(request);
1090 break;
1091 }
1092
SongFerngWang3ef3e072020-12-21 16:41:52 +08001093 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001094 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001095 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1096 request);
1097 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001098 break;
1099
SongFerngWang3ef3e072020-12-21 16:41:52 +08001100 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001101 ar = (AsyncResult) msg.obj;
1102 request = (MainThreadRequest) ar.userObj;
1103 if (ar.exception == null && ar.result != null) {
1104 request.result = ar.result; // Integer
1105 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301106 // request.result must be set to something non-null
1107 // for the calling thread to unblock
1108 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001109 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001110 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001111 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001112 loge("getAllowedNetworkTypesBitmask: CommandException: "
1113 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001114 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001115 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001116 }
1117 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001118 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001119 break;
1120
SongFerngWang3ef3e072020-12-21 16:41:52 +08001121 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001122 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001123 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1124 request);
1125 Pair<Integer, Long> reasonWithNetworkTypes =
1126 (Pair<Integer, Long>) request.argument;
1127 getPhoneFromRequest(request).setAllowedNetworkTypes(
1128 reasonWithNetworkTypes.first,
1129 reasonWithNetworkTypes.second,
1130 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001131 break;
1132
SongFerngWang3ef3e072020-12-21 16:41:52 +08001133 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1134 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001135 break;
1136
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001137 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1138 request = (MainThreadRequest)msg.obj;
1139 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001140 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001141 break;
1142
1143 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1144 ar = (AsyncResult)msg.obj;
1145 request = (MainThreadRequest)ar.userObj;
1146 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001147 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001148 break;
1149
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001150 case CMD_SET_VOICEMAIL_NUMBER:
1151 request = (MainThreadRequest) msg.obj;
1152 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1153 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001154 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1155 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001156 break;
1157
1158 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1159 handleNullReturnEvent(msg, "setVoicemailNumber");
1160 break;
1161
Stuart Scott54788802015-03-30 13:18:01 -07001162 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1163 request = (MainThreadRequest) msg.obj;
1164 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1165 request);
1166 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1167 break;
1168
1169 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1170 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1171 break;
1172
Shishir Agrawal302c8692015-06-19 13:49:39 -07001173 case CMD_PERFORM_NETWORK_SCAN:
1174 request = (MainThreadRequest) msg.obj;
1175 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1176 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1177 break;
1178
Hall Liu27d24262020-09-18 19:04:59 -07001179 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001180 request = (MainThreadRequest) msg.obj;
1181 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001182 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1183 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1184 request.argument;
1185 int callForwardingReason = args.first;
1186 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001187 break;
Hall Liu27d24262020-09-18 19:04:59 -07001188 }
1189 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001190 ar = (AsyncResult) msg.obj;
1191 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001192 TelephonyManager.CallForwardingInfoCallback callback =
1193 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1194 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001195 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001196 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001197 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1198 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1199 // Service Class is a bit mask per 3gpp 27.007. Search for
1200 // any service for voice call.
1201 if ((callForwardInfo.serviceClass
1202 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001203 callForwardingInfo = new CallForwardingInfo(
1204 callForwardInfo.status
1205 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001206 callForwardInfo.reason,
1207 callForwardInfo.number,
1208 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001209 break;
1210 }
1211 }
1212 // Didn't find a call forward info for voice call.
1213 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001214 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1215 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001216 }
Hall Liu27d24262020-09-18 19:04:59 -07001217 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001218 } else {
1219 if (ar.result == null) {
1220 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1221 }
1222 if (ar.exception != null) {
1223 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1224 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001225 int errorCode = TelephonyManager
1226 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001227 if (ar.exception instanceof CommandException) {
1228 CommandException.Error error =
1229 ((CommandException) (ar.exception)).getCommandError();
1230 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001231 errorCode = TelephonyManager
1232 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001233 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001234 errorCode = TelephonyManager
1235 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001236 }
1237 }
Hall Liu27d24262020-09-18 19:04:59 -07001238 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001239 }
Shuo Qian4a594052020-01-23 11:59:30 -08001240 break;
Hall Liu27d24262020-09-18 19:04:59 -07001241 }
Shuo Qian4a594052020-01-23 11:59:30 -08001242
Hall Liu27d24262020-09-18 19:04:59 -07001243 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001244 request = (MainThreadRequest) msg.obj;
1245 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001246 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001247 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001248 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1249 request.argument).first;
1250 request.phone.setCallForwardingOption(
1251 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001252 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001253 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001254 callForwardingInfoToSet.getReason(),
1255 callForwardingInfoToSet.getNumber(),
1256 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1257 break;
Hall Liu27d24262020-09-18 19:04:59 -07001258 }
Shuo Qian4a594052020-01-23 11:59:30 -08001259
Hall Liu27d24262020-09-18 19:04:59 -07001260 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001261 ar = (AsyncResult) msg.obj;
1262 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001263 Consumer<Integer> callback =
1264 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1265 request.argument).second;
1266 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001267 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001268 int errorCode = TelephonyManager.CallForwardingInfoCallback
1269 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001270 if (ar.exception instanceof CommandException) {
1271 CommandException.Error error =
1272 ((CommandException) (ar.exception)).getCommandError();
1273 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001274 errorCode = TelephonyManager.CallForwardingInfoCallback
1275 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001276 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001277 errorCode = TelephonyManager.CallForwardingInfoCallback
1278 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001279 }
1280 }
1281 callback.accept(errorCode);
1282 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001283 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001284 }
Shuo Qian4a594052020-01-23 11:59:30 -08001285 break;
Hall Liu27d24262020-09-18 19:04:59 -07001286 }
Shuo Qian4a594052020-01-23 11:59:30 -08001287
Hall Liu27d24262020-09-18 19:04:59 -07001288 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001289 request = (MainThreadRequest) msg.obj;
1290 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1291 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1292 break;
Hall Liu27d24262020-09-18 19:04:59 -07001293 }
Shuo Qian4a594052020-01-23 11:59:30 -08001294
Hall Liu27d24262020-09-18 19:04:59 -07001295 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001296 ar = (AsyncResult) msg.obj;
1297 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001298 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001299 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001300 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001301 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001302 // Service Class is a bit mask per 3gpp 27.007.
1303 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001304 if (callForwardResults.length > 1
1305 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001306 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001307 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001308 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1309 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001310 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001311 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001312 }
1313 } else {
1314 if (ar.result == null) {
1315 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1316 }
1317 if (ar.exception != null) {
1318 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1319 }
1320 if (ar.exception instanceof CommandException) {
1321 CommandException.Error error =
1322 ((CommandException) (ar.exception)).getCommandError();
1323 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001324 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001325 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001326 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1327 callWaitingStatus =
1328 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001329 }
1330 }
1331 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001332 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001333 break;
Hall Liu27d24262020-09-18 19:04:59 -07001334 }
Shuo Qian4a594052020-01-23 11:59:30 -08001335
Hall Liu27d24262020-09-18 19:04:59 -07001336 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001337 request = (MainThreadRequest) msg.obj;
1338 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001339 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1340 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001341 break;
Hall Liu27d24262020-09-18 19:04:59 -07001342 }
Shuo Qian4a594052020-01-23 11:59:30 -08001343
Hall Liu27d24262020-09-18 19:04:59 -07001344 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001345 ar = (AsyncResult) msg.obj;
1346 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001347 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1348 Consumer<Integer> callback =
1349 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1350 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001351 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001352 if (ar.exception instanceof CommandException) {
1353 CommandException.Error error =
1354 ((CommandException) (ar.exception)).getCommandError();
1355 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1356 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001357 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1358 callback.accept(
1359 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001360 } else {
1361 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1362 }
1363 } else {
1364 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1365 }
1366 } else {
1367 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1368 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001369 }
Shuo Qian4a594052020-01-23 11:59:30 -08001370 break;
Hall Liu27d24262020-09-18 19:04:59 -07001371 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001372 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1373 ar = (AsyncResult) msg.obj;
1374 request = (MainThreadRequest) ar.userObj;
1375 CellNetworkScanResult cellScanResult;
1376 if (ar.exception == null && ar.result != null) {
1377 cellScanResult = new CellNetworkScanResult(
1378 CellNetworkScanResult.STATUS_SUCCESS,
1379 (List<OperatorInfo>) ar.result);
1380 } else {
1381 if (ar.result == null) {
1382 loge("getCellNetworkScanResults: Empty response");
1383 }
1384 if (ar.exception != null) {
1385 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1386 }
1387 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1388 if (ar.exception instanceof CommandException) {
1389 CommandException.Error error =
1390 ((CommandException) (ar.exception)).getCommandError();
1391 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1392 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1393 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1394 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1395 }
1396 }
1397 cellScanResult = new CellNetworkScanResult(errorCode, null);
1398 }
1399 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001400 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001401 break;
1402
1403 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1404 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001405 ManualNetworkSelectionArgument selArg =
1406 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001407 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1408 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001409 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1410 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001411 break;
1412
1413 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001414 ar = (AsyncResult) msg.obj;
1415 request = (MainThreadRequest) ar.userObj;
1416 if (ar.exception == null) {
1417 request.result = true;
1418 } else {
1419 request.result = false;
1420 loge("setNetworkSelectionModeManual " + ar.exception);
1421 }
1422 notifyRequester(request);
1423 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001424 break;
1425
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001426 case CMD_GET_MODEM_ACTIVITY_INFO:
1427 request = (MainThreadRequest) msg.obj;
1428 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001429 if (defaultPhone != null) {
1430 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001431 } else {
1432 ResultReceiver result = (ResultReceiver) request.argument;
1433 Bundle bundle = new Bundle();
1434 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001435 new ModemActivityInfo(0, 0, 0,
1436 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001437 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001438 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001439 break;
1440
Hall Liud0f208c2020-10-14 16:54:44 -07001441 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001442 ar = (AsyncResult) msg.obj;
1443 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001444 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001445 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001446 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001447 if (mLastModemActivityInfo == null) {
1448 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1449 mLastModemActivitySpecificInfo[0] =
1450 new ActivityStatsTechSpecificInfo(
1451 0,
1452 0,
1453 new int[ModemActivityInfo.getNumTxPowerLevels()],
1454 0);
1455 mLastModemActivityInfo =
1456 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1457 }
1458
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001459 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001460 // Update the last modem activity info and the result of the request.
1461 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1462 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001463 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001464 }
Kai Shi917fdc62022-11-28 14:01:02 -08001465 // This is needed to decouple ret from mLastModemActivityInfo
1466 // We don't want to return mLastModemActivityInfo which is updated
1467 // inside mergeModemActivityInfo()
1468 ret = new ModemActivityInfo(
1469 mLastModemActivityInfo.getTimestampMillis(),
1470 mLastModemActivityInfo.getSleepTimeMillis(),
1471 mLastModemActivityInfo.getIdleTimeMillis(),
1472 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001473
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001474 } else {
1475 if (ar.result == null) {
1476 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001477 error = TelephonyManager.ModemActivityInfoException
1478 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001479 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001480 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001481 error = TelephonyManager.ModemActivityInfoException
1482 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001483 } else {
1484 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001485 error = TelephonyManager.ModemActivityInfoException
1486 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001487 }
1488 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001489 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001490 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001491 bundle.putParcelable(
1492 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001493 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001494 } else {
1495 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1496 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001497 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001498 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001499 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001500 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001501
Meng Wang1a7c35a2016-05-05 20:56:15 -07001502 case CMD_SET_ALLOWED_CARRIERS:
1503 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001504 CarrierRestrictionRules argument =
1505 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001506 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001507 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001508 break;
1509
1510 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1511 ar = (AsyncResult) msg.obj;
1512 request = (MainThreadRequest) ar.userObj;
1513 if (ar.exception == null && ar.result != null) {
1514 request.result = ar.result;
1515 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001516 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1517 if (ar.exception instanceof CommandException) {
1518 loge("setAllowedCarriers: CommandException: " + ar.exception);
1519 CommandException.Error error =
1520 ((CommandException) (ar.exception)).getCommandError();
1521 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1522 request.result =
1523 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1524 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001525 } else {
1526 loge("setAllowedCarriers: Unknown exception");
1527 }
1528 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001529 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001530 break;
1531
1532 case CMD_GET_ALLOWED_CARRIERS:
1533 request = (MainThreadRequest) msg.obj;
1534 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001535 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001536 break;
1537
1538 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1539 ar = (AsyncResult) msg.obj;
1540 request = (MainThreadRequest) ar.userObj;
1541 if (ar.exception == null && ar.result != null) {
1542 request.result = ar.result;
1543 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001544 request.result = new IllegalStateException(
1545 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001546 if (ar.result == null) {
1547 loge("getAllowedCarriers: Empty response");
1548 } else if (ar.exception instanceof CommandException) {
1549 loge("getAllowedCarriers: CommandException: " +
1550 ar.exception);
1551 } else {
1552 loge("getAllowedCarriers: Unknown exception");
1553 }
1554 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001555 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001556 break;
1557
Nathan Haroldb3014052017-01-25 15:57:32 -08001558 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1559 ar = (AsyncResult) msg.obj;
1560 request = (MainThreadRequest) ar.userObj;
1561 if (ar.exception == null && ar.result != null) {
1562 request.result = ar.result;
1563 } else {
1564 request.result = new IllegalArgumentException(
1565 "Failed to retrieve Forbidden Plmns");
1566 if (ar.result == null) {
1567 loge("getForbiddenPlmns: Empty response");
1568 } else {
1569 loge("getForbiddenPlmns: Unknown exception");
1570 }
1571 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001572 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001573 break;
1574
1575 case CMD_GET_FORBIDDEN_PLMNS:
1576 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001577 uiccPort = getUiccPortFromRequest(request);
1578 if (uiccPort == null) {
1579 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001580 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001581 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001582 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001583 break;
1584 }
1585 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001586 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001587 if (uiccApp == null) {
1588 loge("getForbiddenPlmns() no app with specified type -- "
1589 + appType);
1590 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001591 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001592 break;
1593 } else {
1594 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1595 + " specified type -- " + appType);
1596 }
1597 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1598 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1599 onCompleted);
1600 break;
1601
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001602 case CMD_SWITCH_SLOTS:
1603 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001604 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001605 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001606 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001607 break;
1608
1609 case EVENT_SWITCH_SLOTS_DONE:
1610 ar = (AsyncResult) msg.obj;
1611 request = (MainThreadRequest) ar.userObj;
1612 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001613 notifyRequester(request);
1614 break;
1615 case CMD_GET_NETWORK_SELECTION_MODE:
1616 request = (MainThreadRequest) msg.obj;
1617 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1618 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1619 break;
1620
1621 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1622 ar = (AsyncResult) msg.obj;
1623 request = (MainThreadRequest) ar.userObj;
1624 if (ar.exception != null) {
1625 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1626 } else {
1627 int mode = ((int[]) ar.result)[0];
1628 if (mode == 0) {
1629 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1630 } else {
1631 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1632 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001633 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001634 notifyRequester(request);
1635 break;
1636 case CMD_GET_CDMA_ROAMING_MODE:
1637 request = (MainThreadRequest) msg.obj;
1638 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1639 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1640 break;
1641 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1642 ar = (AsyncResult) msg.obj;
1643 request = (MainThreadRequest) ar.userObj;
1644 if (ar.exception != null) {
1645 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1646 } else {
1647 request.result = ((int[]) ar.result)[0];
1648 }
1649 notifyRequester(request);
1650 break;
1651 case CMD_SET_CDMA_ROAMING_MODE:
1652 request = (MainThreadRequest) msg.obj;
1653 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1654 int mode = (int) request.argument;
1655 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1656 break;
1657 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1658 ar = (AsyncResult) msg.obj;
1659 request = (MainThreadRequest) ar.userObj;
1660 request.result = ar.exception == null;
1661 notifyRequester(request);
1662 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001663 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1664 request = (MainThreadRequest) msg.obj;
1665 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1666 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1667 break;
1668 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1669 ar = (AsyncResult) msg.obj;
1670 request = (MainThreadRequest) ar.userObj;
1671 if (ar.exception != null) {
1672 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1673 } else {
1674 request.result = ((int[]) ar.result)[0];
1675 }
1676 notifyRequester(request);
1677 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001678 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1679 request = (MainThreadRequest) msg.obj;
1680 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1681 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001682 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1683 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001684 break;
1685 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1686 ar = (AsyncResult) msg.obj;
1687 request = (MainThreadRequest) ar.userObj;
1688 request.result = ar.exception == null;
1689 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001690 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001691 case CMD_GET_ALL_CELL_INFO:
1692 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001693 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001694 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001695 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001696 case EVENT_GET_ALL_CELL_INFO_DONE:
1697 ar = (AsyncResult) msg.obj;
1698 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001699 // If a timeout occurs, the response will be null
1700 request.result = (ar.exception == null && ar.result != null)
1701 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001702 synchronized (request) {
1703 request.notifyAll();
1704 }
1705 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001706 case CMD_REQUEST_CELL_INFO_UPDATE:
1707 request = (MainThreadRequest) msg.obj;
1708 request.phone.requestCellInfoUpdate(request.workSource,
1709 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1710 break;
1711 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1712 ar = (AsyncResult) msg.obj;
1713 request = (MainThreadRequest) ar.userObj;
1714 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1715 try {
1716 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001717 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001718 cb.onError(
1719 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1720 ar.exception.getClass().getName(),
1721 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001722 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001723 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001724 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001725 } else {
1726 // use the result as returned
1727 cb.onCellInfo((List<CellInfo>) ar.result);
1728 }
1729 } catch (RemoteException re) {
1730 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1731 }
1732 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001733 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001734 request = (MainThreadRequest) msg.obj;
1735 WorkSource ws = (WorkSource) request.argument;
1736 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001737 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001738 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001739 }
1740 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001741 ar = (AsyncResult) msg.obj;
1742 request = (MainThreadRequest) ar.userObj;
1743 if (ar.exception == null) {
1744 request.result = ar.result;
1745 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001746 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001747 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001748 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001749 }
1750
1751 synchronized (request) {
1752 request.notifyAll();
1753 }
1754 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001755 }
chen xu6dac5ab2018-10-26 17:39:23 -07001756 case CMD_MODEM_REBOOT:
1757 request = (MainThreadRequest) msg.obj;
1758 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001759 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001760 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001761 case EVENT_CMD_MODEM_REBOOT_DONE:
1762 handleNullReturnEvent(msg, "rebootModem");
1763 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001764 case CMD_REQUEST_ENABLE_MODEM:
1765 request = (MainThreadRequest) msg.obj;
1766 boolean enable = (boolean) request.argument;
1767 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001768 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001769 PhoneConfigurationManager.getInstance()
1770 .enablePhone(request.phone, enable, onCompleted);
1771 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001772 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001773 ar = (AsyncResult) msg.obj;
1774 request = (MainThreadRequest) ar.userObj;
1775 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001776 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001777 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001778 if ((boolean) request.result) {
1779 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1780 updateModemStateMetrics();
1781 } else {
1782 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1783 + ar.exception);
1784 }
1785 notifyRequester(request);
1786 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001787 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001788 case CMD_GET_MODEM_STATUS:
1789 request = (MainThreadRequest) msg.obj;
1790 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1791 PhoneConfigurationManager.getInstance()
1792 .getPhoneStatusFromModem(request.phone, onCompleted);
1793 break;
1794 case EVENT_GET_MODEM_STATUS_DONE:
1795 ar = (AsyncResult) msg.obj;
1796 request = (MainThreadRequest) ar.userObj;
1797 int id = request.phone.getPhoneId();
1798 if (ar.exception == null && ar.result != null) {
1799 request.result = ar.result;
1800 //update the cache as modem status has changed
1801 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1802 (boolean) request.result);
1803 } else {
1804 // Return true if modem status cannot be retrieved. For most cases,
1805 // modem status is on. And for older version modems, GET_MODEM_STATUS
1806 // and disable modem are not supported. Modem is always on.
1807 // TODO: this should be fixed in R to support a third
1808 // status UNKNOWN b/131631629
1809 request.result = true;
1810 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1811 + ar.exception);
1812 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001813 notifyRequester(request);
1814 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001815 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1816 request = (MainThreadRequest) msg.obj;
1817 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1818 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1819 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1820 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1821 break;
1822 }
1823 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1824 ar = (AsyncResult) msg.obj;
1825 request = (MainThreadRequest) ar.userObj;
1826 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1827 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1828 args.second.accept(ar.exception == null);
1829 notifyRequester(request);
1830 break;
1831 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001832 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1833 request = (MainThreadRequest) msg.obj;
1834 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1835 Phone phone = getPhoneFromRequest(request);
1836 if (phone != null) {
1837 phone.getSystemSelectionChannels(onCompleted);
1838 } else {
1839 loge("getSystemSelectionChannels: No phone object");
1840 request.result = new ArrayList<RadioAccessSpecifier>();
1841 notifyRequester(request);
1842 }
1843 break;
1844 }
1845 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1846 ar = (AsyncResult) msg.obj;
1847 request = (MainThreadRequest) ar.userObj;
1848 if (ar.exception == null && ar.result != null) {
1849 request.result = ar.result;
1850 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001851 request.result = new IllegalStateException(
1852 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001853 if (ar.result == null) {
1854 loge("getSystemSelectionChannels: Empty response");
1855 } else {
1856 loge("getSystemSelectionChannels: Unknown exception");
1857 }
1858 }
1859 notifyRequester(request);
1860 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001861 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1862 ar = (AsyncResult) msg.obj;
1863 request = (MainThreadRequest) ar.userObj;
1864 if (ar.exception == null && ar.result != null) {
1865 request.result = ar.result;
1866 } else {
1867 request.result = -1;
1868 loge("Failed to set Forbidden Plmns");
1869 if (ar.result == null) {
1870 loge("setForbidenPlmns: Empty response");
1871 } else if (ar.exception != null) {
1872 loge("setForbiddenPlmns: Exception: " + ar.exception);
1873 request.result = -1;
1874 } else {
1875 loge("setForbiddenPlmns: Unknown exception");
1876 }
1877 }
1878 notifyRequester(request);
1879 break;
1880 case CMD_SET_FORBIDDEN_PLMNS:
1881 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001882 uiccPort = getUiccPortFromRequest(request);
1883 if (uiccPort == null) {
1884 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001885 request.result = -1;
1886 notifyRequester(request);
1887 break;
1888 }
1889 Pair<Integer, List<String>> setFplmnsArgs =
1890 (Pair<Integer, List<String>>) request.argument;
1891 appType = setFplmnsArgs.first;
1892 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001893 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001894 if (uiccApp == null) {
1895 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1896 request.result = -1;
1897 loge("Failed to get UICC App");
1898 notifyRequester(request);
1899 } else {
1900 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1901 ((SIMRecords) uiccApp.getIccRecords())
1902 .setForbiddenPlmns(onCompleted, fplmns);
1903 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001904 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001905 case CMD_ERASE_MODEM_CONFIG:
1906 request = (MainThreadRequest) msg.obj;
1907 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1908 defaultPhone.eraseModemConfig(onCompleted);
1909 break;
1910 case EVENT_ERASE_MODEM_CONFIG_DONE:
1911 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001912 break;
zoey chene02881a2019-12-30 16:11:23 +08001913
Kai Shif70f46f2021-03-03 13:59:46 -08001914 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1915 request = (MainThreadRequest) msg.obj;
1916 request.result = defaultPhone.eraseDataInSharedPreferences();
1917 notifyRequester(request);
1918 break;
1919
zoey chene02881a2019-12-30 16:11:23 +08001920 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1921 request = (MainThreadRequest) msg.obj;
1922 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1923 Pair<String, String> changed = (Pair<String, String>) request.argument;
1924 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1925 changed.first, changed.second, onCompleted);
1926 break;
1927 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1928 ar = (AsyncResult) msg.obj;
1929 request = (MainThreadRequest) ar.userObj;
1930 if (ar.exception == null) {
1931 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001932 // If the operation is successful, update the PIN storage
1933 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1934 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001935 UiccController.getInstance().getPinStorage()
1936 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001937 } else {
1938 request.result = msg.arg1;
1939 }
1940 notifyRequester(request);
1941 break;
1942
Michele Berionne5e411512020-11-13 02:36:59 +00001943 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001944 request = (MainThreadRequest) msg.obj;
1945 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1946 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1947 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1948 enabled.first, enabled.second, onCompleted);
1949 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001950 }
zoey chene02881a2019-12-30 16:11:23 +08001951 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1952 ar = (AsyncResult) msg.obj;
1953 request = (MainThreadRequest) ar.userObj;
1954 if (ar.exception == null) {
1955 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001956 // If the operation is successful, update the PIN storage
1957 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1958 int phoneId = getPhoneFromRequest(request).getPhoneId();
1959 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001960 UiccController.getInstance().getPinStorage()
1961 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001962 } else {
1963 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1964 }
zoey chene02881a2019-12-30 16:11:23 +08001965 } else {
1966 request.result = msg.arg1;
1967 }
Michele Berionne5e411512020-11-13 02:36:59 +00001968
1969
zoey chene02881a2019-12-30 16:11:23 +08001970 notifyRequester(request);
1971 break;
1972
Peter Wangdafb9ac2020-01-15 14:13:38 -08001973 case MSG_NOTIFY_USER_ACTIVITY:
1974 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001975 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001976 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1977 getDefaultPhone().getContext().sendBroadcastAsUser(
1978 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1979 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001980
1981 case CMD_SET_DATA_THROTTLING: {
1982 request = (MainThreadRequest) msg.obj;
1983 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1984 DataThrottlingRequest dataThrottlingRequest =
1985 (DataThrottlingRequest) request.argument;
1986 Phone phone = getPhoneFromRequest(request);
1987 if (phone != null) {
1988 phone.setDataThrottling(onCompleted,
1989 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1990 dataThrottlingRequest.getCompletionDurationMillis());
1991 } else {
1992 loge("setDataThrottling: No phone object");
1993 request.result =
1994 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1995 notifyRequester(request);
1996 }
1997
1998 break;
1999 }
2000 case EVENT_SET_DATA_THROTTLING_DONE:
2001 ar = (AsyncResult) msg.obj;
2002 request = (MainThreadRequest) ar.userObj;
2003
2004 if (ar.exception == null) {
2005 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2006 } else if (ar.exception instanceof CommandException) {
2007 loge("setDataThrottling: CommandException: " + ar.exception);
2008 CommandException.Error error =
2009 ((CommandException) (ar.exception)).getCommandError();
2010
2011 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2012 request.result = TelephonyManager
2013 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2014 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2015 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002016 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2017 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002018 } else {
2019 request.result =
2020 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2021 }
2022 } else {
2023 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2024 }
2025 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2026 notifyRequester(request);
2027 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002028
2029 case CMD_SET_SIM_POWER: {
2030 request = (MainThreadRequest) msg.obj;
2031 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2032 request = (MainThreadRequest) msg.obj;
2033 int stateToSet =
2034 ((Pair<Integer, IIntegerConsumer>)
2035 request.argument).first;
2036 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2037 break;
2038 }
2039 case EVENT_SET_SIM_POWER_DONE: {
2040 ar = (AsyncResult) msg.obj;
2041 request = (MainThreadRequest) ar.userObj;
2042 IIntegerConsumer callback =
2043 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2044 if (ar.exception != null) {
2045 loge("setSimPower exception: " + ar.exception);
2046 int errorCode = TelephonyManager.CallForwardingInfoCallback
2047 .RESULT_ERROR_UNKNOWN;
2048 if (ar.exception instanceof CommandException) {
2049 CommandException.Error error =
2050 ((CommandException) (ar.exception)).getCommandError();
2051 if (error == CommandException.Error.SIM_ERR) {
2052 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2053 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2054 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2055 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2056 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2057 } else {
2058 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2059 }
2060 }
2061 try {
2062 callback.accept(errorCode);
2063 } catch (RemoteException e) {
2064 // Ignore if the remote process is no longer available to call back.
2065 Log.w(LOG_TAG, "setSimPower: callback not available.");
2066 }
2067 } else {
2068 try {
2069 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2070 } catch (RemoteException e) {
2071 // Ignore if the remote process is no longer available to call back.
2072 Log.w(LOG_TAG, "setSimPower: callback not available.");
2073 }
2074 }
2075 break;
2076 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002077 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2078 request = (MainThreadRequest) msg.obj;
2079
2080 final Phone phone = getPhoneFromRequest(request);
2081 if (phone == null || phone.getServiceStateTracker() == null) {
2082 request.result = new IllegalStateException("Phone or SST is null");
2083 notifyRequester(request);
2084 break;
2085 }
2086
2087 Pair<Integer, SignalStrengthUpdateRequest> pair =
2088 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2089 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2090 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002091 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002092 request.subId, pair.first /*callingUid*/,
2093 pair.second /*request*/, onCompleted);
2094 break;
2095 }
2096 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2097 ar = (AsyncResult) msg.obj;
2098 request = (MainThreadRequest) ar.userObj;
2099 // request.result will be the exception of ar if present, true otherwise.
2100 // Be cautious not to leave result null which will wait() forever
2101 request.result = ar.exception != null ? ar.exception : true;
2102 notifyRequester(request);
2103 break;
2104 }
2105 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2106 request = (MainThreadRequest) msg.obj;
2107
2108 Phone phone = getPhoneFromRequest(request);
2109 if (phone == null || phone.getServiceStateTracker() == null) {
2110 request.result = new IllegalStateException("Phone or SST is null");
2111 notifyRequester(request);
2112 break;
2113 }
2114
2115 Pair<Integer, SignalStrengthUpdateRequest> pair =
2116 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2117 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2118 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002119 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002120 request.subId, pair.first /*callingUid*/,
2121 pair.second /*request*/, onCompleted);
2122 break;
2123 }
2124 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2125 ar = (AsyncResult) msg.obj;
2126 request = (MainThreadRequest) ar.userObj;
2127 request.result = ar.exception != null ? ar.exception : true;
2128 notifyRequester(request);
2129 break;
2130 }
Jordan Liu109698e2020-11-24 14:50:34 -08002131
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002132 case CMD_GET_SLICING_CONFIG: {
2133 request = (MainThreadRequest) msg.obj;
2134 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2135 request.phone.getSlicingConfig(onCompleted);
2136 break;
2137 }
2138 case EVENT_GET_SLICING_CONFIG_DONE: {
2139 ar = (AsyncResult) msg.obj;
2140 request = (MainThreadRequest) ar.userObj;
2141 ResultReceiver result = (ResultReceiver) request.argument;
2142
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002143 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002144 Bundle bundle = new Bundle();
2145 int resultCode = 0;
2146 if (ar.exception != null) {
2147 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2148 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002149 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002150 } else if (ar.result == null) {
2151 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002152 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002153 } else {
2154 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002155 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2156 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002157 }
2158
2159 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002160 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002161 }
2162 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2163 result.send(resultCode, bundle);
2164 notifyRequester(request);
2165 break;
2166 }
2167
Sarah Chin71b3a852022-09-28 15:54:19 -07002168 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002169 request = (MainThreadRequest) msg.obj;
2170 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002171 PurchasePremiumCapabilityArgument arg =
2172 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002173 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chin71b3a852022-09-28 15:54:19 -07002174 arg.capability, arg.appName, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002175 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002176 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002177
Sarah Chin71b3a852022-09-28 15:54:19 -07002178 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002179 ar = (AsyncResult) msg.obj;
2180 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002181 PurchasePremiumCapabilityArgument arg =
2182 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002183 try {
2184 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002185 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002186 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002187 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002188 + ", result= "
2189 + TelephonyManager.convertPurchaseResultToString(result));
2190 } catch (RemoteException e) {
2191 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002192 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002193 + " failed: " + e;
2194 if (DBG) log(logStr);
2195 AnomalyReporter.reportAnomaly(
2196 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2197 }
2198 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002199 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002200
Michele Berionne5e411512020-11-13 02:36:59 +00002201 case CMD_PREPARE_UNATTENDED_REBOOT:
2202 request = (MainThreadRequest) msg.obj;
2203 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002204 UiccController.getInstance().getPinStorage()
2205 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002206 notifyRequester(request);
2207 break;
2208
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002209 default:
2210 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2211 break;
2212 }
2213 }
Jake Hambye994d462014-02-03 13:10:13 -08002214
Pengquan Menga1bb6272018-09-06 09:59:22 -07002215 private void notifyRequester(MainThreadRequest request) {
2216 synchronized (request) {
2217 request.notifyAll();
2218 }
2219 }
2220
Jake Hambye994d462014-02-03 13:10:13 -08002221 private void handleNullReturnEvent(Message msg, String command) {
2222 AsyncResult ar = (AsyncResult) msg.obj;
2223 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2224 if (ar.exception == null) {
2225 request.result = true;
2226 } else {
2227 request.result = false;
2228 if (ar.exception instanceof CommandException) {
2229 loge(command + ": CommandException: " + ar.exception);
2230 } else {
2231 loge(command + ": Unknown exception");
2232 }
2233 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002234 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002235 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002236 }
2237
2238 /**
2239 * Posts the specified command to be executed on the main thread,
2240 * waits for the request to complete, and returns the result.
2241 * @see #sendRequestAsync
2242 */
2243 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002244 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2245 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002246 }
2247
2248 /**
2249 * Posts the specified command to be executed on the main thread,
2250 * waits for the request to complete, and returns the result.
2251 * @see #sendRequestAsync
2252 */
2253 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2254 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002255 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002256 }
2257
2258 /**
2259 * Posts the specified command to be executed on the main thread,
2260 * waits for the request to complete, and returns the result.
2261 * @see #sendRequestAsync
2262 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002263 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002264 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2265 }
2266
2267 /**
2268 * Posts the specified command to be executed on the main thread,
2269 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2270 * if not timeout or null otherwise.
2271 * @see #sendRequestAsync
2272 */
2273 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2274 long timeoutInMs) {
2275 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002276 }
2277
2278 /**
2279 * Posts the specified command to be executed on the main thread,
2280 * waits for the request to complete, and returns the result.
2281 * @see #sendRequestAsync
2282 */
Nathan Harold92bed182018-10-12 18:16:49 -07002283 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002284 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002285 }
2286
2287 /**
2288 * Posts the specified command to be executed on the main thread,
2289 * waits for the request to complete, and returns the result.
2290 * @see #sendRequestAsync
2291 */
2292 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002293 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2294 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002295 }
2296
2297 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002298 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2299 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2300 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002301 * @see #sendRequestAsync
2302 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002303 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2304 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002305 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2306 throw new RuntimeException("This method will deadlock if called from the main thread.");
2307 }
2308
Nathan Harold92bed182018-10-12 18:16:49 -07002309 MainThreadRequest request = null;
2310 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2311 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2312 } else if (phone != null) {
2313 request = new MainThreadRequest(argument, phone, workSource);
2314 } else {
2315 request = new MainThreadRequest(argument, subId, workSource);
2316 }
2317
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 Message msg = mMainThreadHandler.obtainMessage(command, request);
2319 msg.sendToTarget();
2320
Rambo Wang0f050d82021-02-12 11:43:36 -08002321
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002322 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002323 if (timeoutInMs >= 0) {
2324 // Wait for at least timeoutInMs before returning null request result
2325 long now = SystemClock.elapsedRealtime();
2326 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002327 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002328 try {
2329 request.wait(deadline - now);
2330 } catch (InterruptedException e) {
2331 // Do nothing, go back and check if request is completed or timeout
2332 } finally {
2333 now = SystemClock.elapsedRealtime();
2334 }
2335 }
2336 } else {
2337 // Wait for the request to complete
2338 while (request.result == null) {
2339 try {
2340 request.wait();
2341 } catch (InterruptedException e) {
2342 // Do nothing, go back and wait until the request is complete
2343 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002344 }
2345 }
2346 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002347 if (request.result == null) {
2348 Log.wtf(LOG_TAG,
2349 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2350 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002351 return request.result;
2352 }
2353
2354 /**
2355 * Asynchronous ("fire and forget") version of sendRequest():
2356 * Posts the specified command to be executed on the main thread, and
2357 * returns immediately.
2358 * @see #sendRequest
2359 */
2360 private void sendRequestAsync(int command) {
2361 mMainThreadHandler.sendEmptyMessage(command);
2362 }
2363
2364 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002365 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002366 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002367 */
2368 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002369 sendRequestAsync(command, argument, null, null);
2370 }
2371
2372 /**
2373 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2374 * @see {@link #sendRequest(int,Object)}
2375 */
2376 private void sendRequestAsync(
2377 int command, Object argument, Phone phone, WorkSource workSource) {
2378 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002379 Message msg = mMainThreadHandler.obtainMessage(command, request);
2380 msg.sendToTarget();
2381 }
2382
2383 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002384 * Initialize the singleton PhoneInterfaceManager instance.
2385 * This is only done once, at startup, from PhoneApp.onCreate().
2386 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002387 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002388 synchronized (PhoneInterfaceManager.class) {
2389 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002390 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 } else {
2392 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2393 }
2394 return sInstance;
2395 }
2396 }
2397
2398 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002399 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002400 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002401 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002402 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002403 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002405 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002407 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002408 mTelephonySharedPreferences =
2409 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002410 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002411 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002412 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002413 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002414 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002415 mTelephony2gUpdater = new Telephony2gUpdater(
2416 Executors.newSingleThreadExecutor(), mApp);
2417 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002418 publish();
2419 }
2420
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002421 private Phone getDefaultPhone() {
2422 Phone thePhone = getPhone(getDefaultSubscription());
2423 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2424 }
2425
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002426 private void publish() {
2427 if (DBG) log("publish: " + this);
2428
Peter Wangc035ce42020-01-08 21:00:22 -08002429 TelephonyFrameworkInitializer
2430 .getTelephonyServiceManager()
2431 .getTelephonyServiceRegisterer()
2432 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002433 }
2434
Stuart Scott584921c2015-01-15 17:10:34 -08002435 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002436 if (request.phone != null) {
2437 return request.phone;
2438 } else {
2439 return getPhoneFromSubId(request.subId);
2440 }
2441 }
2442
2443 private Phone getPhoneFromSubId(int subId) {
2444 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2445 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002446 }
2447
Rambo Wange53e07d2022-05-10 13:01:13 -07002448 @Nullable
2449 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002450 Phone phone = getPhoneFromRequest(request);
2451 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002452 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002453 }
2454
Wink Saville36469e72014-06-11 15:17:00 -07002455 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002456 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002457 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002458 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459
Kai Shif70f46f2021-03-03 13:59:46 -08002460 private void sendEraseModemConfig(@NonNull Phone phone) {
2461 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2462 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2463 }
2464
2465 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2466 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2467 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002468 }
2469
Peter Wang44b186e2020-01-13 23:33:09 -08002470 private boolean isImsAvailableOnDevice() {
2471 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2472 if (pm == null) {
2473 // For some reason package manger is not available.. This will fail internally anyway,
2474 // so do not throw error and allow.
2475 return true;
2476 }
2477 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2478 }
2479
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002481 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002482 }
2483
Wink Savilleb564aae2014-10-23 10:18:09 -07002484 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 if (DBG) log("dial: " + number);
2486 // No permission check needed here: This is just a wrapper around the
2487 // ACTION_DIAL intent, which is available to any app since it puts up
2488 // the UI before it does anything.
2489
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002490 final long identity = Binder.clearCallingIdentity();
2491 try {
2492 String url = createTelUrl(number);
2493 if (url == null) {
2494 return;
2495 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002496
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002497 // PENDING: should we just silently fail if phone is offhook or ringing?
2498 PhoneConstants.State state = mCM.getState(subId);
2499 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2500 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2501 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2502 mApp.startActivity(intent);
2503 }
2504 } finally {
2505 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002506 }
2507 }
2508
2509 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002510 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002511 }
2512
Wink Savilleb564aae2014-10-23 10:18:09 -07002513 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002514 if (DBG) log("call: " + number);
2515
2516 // This is just a wrapper around the ACTION_CALL intent, but we still
2517 // need to do a permission check since we're calling startActivity()
2518 // from the context of the phone app.
2519 enforceCallPermission();
2520
Jordan Liu1617b712019-07-10 15:06:26 -07002521 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002522 != AppOpsManager.MODE_ALLOWED) {
2523 return;
2524 }
2525
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002526 final long identity = Binder.clearCallingIdentity();
2527 try {
2528 String url = createTelUrl(number);
2529 if (url == null) {
2530 return;
2531 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002532
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002533 boolean isValid = false;
2534 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2535 if (slist != null) {
2536 for (SubscriptionInfo subInfoRecord : slist) {
2537 if (subInfoRecord.getSubscriptionId() == subId) {
2538 isValid = true;
2539 break;
2540 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002541 }
Wink Saville08874612014-08-31 19:19:58 -07002542 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002543 if (!isValid) {
2544 return;
2545 }
Wink Saville08874612014-08-31 19:19:58 -07002546
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002547 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2548 intent.putExtra(SUBSCRIPTION_KEY, subId);
2549 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2550 mApp.startActivity(intent);
2551 } finally {
2552 Binder.restoreCallingIdentity(identity);
2553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002554 }
2555
Wink Savilleb564aae2014-10-23 10:18:09 -07002556 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002557 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002558 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2559 }
2560
Wink Savilleb564aae2014-10-23 10:18:09 -07002561 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002562 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002563 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2564 }
2565
Wink Savilleb564aae2014-10-23 10:18:09 -07002566 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002567 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002568
2569 final long identity = Binder.clearCallingIdentity();
2570 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002571 Phone phone = getPhone(subId);
2572 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002573 checkSimPin.start();
2574 return checkSimPin.unlockSim(null, pin);
2575 } finally {
2576 Binder.restoreCallingIdentity(identity);
2577 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002578 }
2579
Wink Savilleb564aae2014-10-23 10:18:09 -07002580 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002582
2583 final long identity = Binder.clearCallingIdentity();
2584 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002585 Phone phone = getPhone(subId);
2586 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002587 checkSimPuk.start();
2588 return checkSimPuk.unlockSim(puk, pin);
2589 } finally {
2590 Binder.restoreCallingIdentity(identity);
2591 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002592 }
2593
2594 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002595 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002596 * a synchronous one.
2597 */
2598 private static class UnlockSim extends Thread {
2599
2600 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002601 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002602
2603 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002604 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2605 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002606
2607 // For replies from SimCard interface
2608 private Handler mHandler;
2609
2610 // For async handler to identify request type
2611 private static final int SUPPLY_PIN_COMPLETE = 100;
2612
Michele Berionne5e411512020-11-13 02:36:59 +00002613 UnlockSim(int phoneId, IccCard simCard) {
2614 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002615 mSimCard = simCard;
2616 }
2617
2618 @Override
2619 public void run() {
2620 Looper.prepare();
2621 synchronized (UnlockSim.this) {
2622 mHandler = new Handler() {
2623 @Override
2624 public void handleMessage(Message msg) {
2625 AsyncResult ar = (AsyncResult) msg.obj;
2626 switch (msg.what) {
2627 case SUPPLY_PIN_COMPLETE:
2628 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2629 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002630 mRetryCount = msg.arg1;
2631 if (ar.exception != null) {
2632 if (ar.exception instanceof CommandException &&
2633 ((CommandException)(ar.exception)).getCommandError()
2634 == CommandException.Error.PASSWORD_INCORRECT) {
2635 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002636 } //When UiccCardApp dispose,handle message and return exception
2637 else if (ar.exception instanceof CommandException &&
2638 ((CommandException) (ar.exception)).getCommandError()
2639 == CommandException.Error.ABORTED) {
2640 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002641 } else {
2642 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2643 }
2644 } else {
2645 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2646 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647 mDone = true;
2648 UnlockSim.this.notifyAll();
2649 }
2650 break;
2651 }
2652 }
2653 };
2654 UnlockSim.this.notifyAll();
2655 }
2656 Looper.loop();
2657 }
2658
2659 /*
2660 * Use PIN or PUK to unlock SIM card
2661 *
2662 * If PUK is null, unlock SIM card with PIN
2663 *
2664 * If PUK is not null, unlock SIM card with PUK and set PIN code
2665 */
Wink Saville9de0f752013-10-22 19:04:03 -07002666 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002667
2668 while (mHandler == null) {
2669 try {
2670 wait();
2671 } catch (InterruptedException e) {
2672 Thread.currentThread().interrupt();
2673 }
2674 }
2675 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2676
2677 if (puk == null) {
2678 mSimCard.supplyPin(pin, callback);
2679 } else {
2680 mSimCard.supplyPuk(puk, pin, callback);
2681 }
2682
2683 while (!mDone) {
2684 try {
2685 Log.d(LOG_TAG, "wait for done");
2686 wait();
2687 } catch (InterruptedException e) {
2688 // Restore the interrupted status
2689 Thread.currentThread().interrupt();
2690 }
2691 }
2692 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002693 int[] resultArray = new int[2];
2694 resultArray[0] = mResult;
2695 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002696
2697 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002698 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002699 }
2700
Wink Saville9de0f752013-10-22 19:04:03 -07002701 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002702 }
2703 }
2704
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002705 /**
2706 * This method has been removed due to privacy and stability concerns.
2707 */
2708 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002709 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002710 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2711 return;
Wink Saville36469e72014-06-11 15:17:00 -07002712 }
2713
Nathan Harold1f889d82020-06-04 17:05:26 -07002714 @Override
2715 public void updateServiceLocationWithPackageName(String callingPackage) {
2716 mApp.getSystemService(AppOpsManager.class)
2717 .checkPackage(Binder.getCallingUid(), callingPackage);
2718
Nathan Haroldf096d982020-11-18 17:18:06 -08002719 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002720 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2721 // Callers targeting S have no business invoking this method.
2722 return;
2723 }
2724
2725 LocationAccessPolicy.LocationPermissionResult locationResult =
2726 LocationAccessPolicy.checkLocationPermission(mApp,
2727 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2728 .setCallingPackage(callingPackage)
2729 .setCallingFeatureId(null)
2730 .setCallingPid(Binder.getCallingPid())
2731 .setCallingUid(Binder.getCallingUid())
2732 .setMethod("updateServiceLocation")
2733 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2734 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2735 .build());
2736 // Apps that lack location permission have no business calling this method;
2737 // however, because no permission was declared in the public API, denials must
2738 // all be "soft".
2739 switch (locationResult) {
2740 case DENIED_HARD: /* fall through */
2741 case DENIED_SOFT:
2742 return;
2743 }
2744
2745 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002746 final long identity = Binder.clearCallingIdentity();
2747 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002748 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002749 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002750 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002751 }
2752 } finally {
2753 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002754 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002755 }
2756
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002757 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002758 @Override
2759 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002760 return isRadioOnWithFeature(callingPackage, null);
2761 }
2762
2763
2764 @Override
2765 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2766 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2767 callingFeatureId);
2768 }
2769
2770 @Deprecated
2771 @Override
2772 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2773 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002774 }
2775
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002776 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002777 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2778 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002779 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002780 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002781 return false;
2782 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002783
2784 final long identity = Binder.clearCallingIdentity();
2785 try {
2786 return isRadioOnForSubscriber(subId);
2787 } finally {
2788 Binder.restoreCallingIdentity(identity);
2789 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002790 }
2791
2792 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002793 final long identity = Binder.clearCallingIdentity();
2794 try {
2795 final Phone phone = getPhone(subId);
2796 if (phone != null) {
2797 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2798 } else {
2799 return false;
2800 }
2801 } finally {
2802 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002803 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002804 }
2805
2806 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002807 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002808 }
Wink Saville36469e72014-06-11 15:17:00 -07002809
Wink Savilleb564aae2014-10-23 10:18:09 -07002810 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002811 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002812
2813 final long identity = Binder.clearCallingIdentity();
2814 try {
2815 final Phone phone = getPhone(subId);
2816 if (phone != null) {
2817 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2818 }
2819 } finally {
2820 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002821 }
Wink Saville36469e72014-06-11 15:17:00 -07002822 }
2823
2824 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002825 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002826 }
2827
Wink Savilleb564aae2014-10-23 10:18:09 -07002828 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002829 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002830
2831 final long identity = Binder.clearCallingIdentity();
2832 try {
2833 final Phone phone = getPhone(subId);
2834 if (phone == null) {
2835 return false;
2836 }
2837 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2838 toggleRadioOnOffForSubscriber(subId);
2839 }
2840 return true;
2841 } finally {
2842 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002843 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002844 }
Wink Saville36469e72014-06-11 15:17:00 -07002845
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002846 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002847 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002848 /*
2849 * If any of the Radios are available, it will need to be
2850 * shutdown. So return true if any Radio is available.
2851 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852 final long identity = Binder.clearCallingIdentity();
2853 try {
2854 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2855 Phone phone = PhoneFactory.getPhone(i);
2856 if (phone != null && phone.isRadioAvailable()) return true;
2857 }
2858 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2859 return false;
2860 } finally {
2861 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002862 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002863 }
2864
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002866 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002867 enforceModifyPermission();
2868
2869 final long identity = Binder.clearCallingIdentity();
2870 try {
2871 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2872 logv("Shutting down Phone " + i);
2873 shutdownRadioUsingPhoneId(i);
2874 }
2875 } finally {
2876 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002877 }
2878 }
2879
2880 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002881 Phone phone = PhoneFactory.getPhone(phoneId);
2882 if (phone != null && phone.isRadioAvailable()) {
2883 phone.shutdownRadio();
2884 }
2885 }
2886
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002887 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002888 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002889
2890 final long identity = Binder.clearCallingIdentity();
2891 try {
2892 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2893 if (defaultPhone != null) {
2894 defaultPhone.setRadioPower(turnOn);
2895 return true;
2896 } else {
2897 loge("There's no default phone.");
2898 return false;
2899 }
2900 } finally {
2901 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002902 }
Wink Saville36469e72014-06-11 15:17:00 -07002903 }
2904
Wink Savilleb564aae2014-10-23 10:18:09 -07002905 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002906 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002907
2908 final long identity = Binder.clearCallingIdentity();
2909 try {
2910 final Phone phone = getPhone(subId);
2911 if (phone != null) {
2912 phone.setRadioPower(turnOn);
2913 return true;
2914 } else {
2915 return false;
2916 }
2917 } finally {
2918 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002919 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002920 }
2921
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002922 /**
2923 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2924 * no reason to power it off. When any of the voters want to power it off, it will be turned
2925 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2926 * powering it off, and these radio off votes will be cleared.
2927 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
2928 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
2929 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
2930 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
2931 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
2932 * check its vote.
2933 *
2934 * @param subId The subscription ID.
2935 * @param reason The reason for powering off radio.
2936 * @return true on success and false on failure.
2937 */
2938 public boolean requestRadioPowerOffForReason(int subId,
2939 @TelephonyManager.RadioPowerReason int reason) {
2940 enforceModifyPermission();
2941
2942 final long identity = Binder.clearCallingIdentity();
2943 try {
2944 final Phone phone = getPhone(subId);
2945 if (phone != null) {
2946 phone.setRadioPowerForReason(false, reason);
2947 return true;
2948 } else {
2949 return false;
2950 }
2951 } finally {
2952 Binder.restoreCallingIdentity(identity);
2953 }
2954 }
2955
2956 /**
2957 * Remove the vote on powering off the radio for a reason, as requested by
2958 * {@link requestRadioPowerOffForReason}.
2959 *
2960 * @param subId The subscription ID.
2961 * @param reason The reason for powering off radio.
2962 * @return true on success and false on failure.
2963 */
2964 public boolean clearRadioPowerOffForReason(int subId,
2965 @TelephonyManager.RadioPowerReason int reason) {
2966 enforceModifyPermission();
2967
2968 final long identity = Binder.clearCallingIdentity();
2969 try {
2970 final Phone phone = getPhone(subId);
2971 if (phone != null) {
2972 phone.setRadioPowerForReason(true, reason);
2973 return true;
2974 } else {
2975 return false;
2976 }
2977 } finally {
2978 Binder.restoreCallingIdentity(identity);
2979 }
2980 }
2981
2982 /**
2983 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
2984 *
2985 * @param subId The subscription ID.
2986 * @param callingPackage The package making the call.
2987 * @param callingFeatureId The feature in the package.
2988 * @return List of reasons for powering off radio.
2989 */
2990 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
2991 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
2992
2993 final long identity = Binder.clearCallingIdentity();
2994 List result = new ArrayList();
2995 try {
2996 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
2997 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
2998 return result;
2999 }
3000
3001 final Phone phone = getPhone(subId);
3002 if (phone != null) {
3003 result.addAll(phone.getRadioPowerOffReasons());
3004 }
3005 } finally {
3006 Binder.restoreCallingIdentity(identity);
3007 }
3008 return result;
3009 }
3010
Wink Saville36469e72014-06-11 15:17:00 -07003011 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003012 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003013 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003014 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015
3016 final long identity = Binder.clearCallingIdentity();
3017 try {
Jack Yu285100e2022-12-02 22:48:35 -08003018 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019 final Phone phone = getPhone(subId);
3020 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003021 phone.getDataSettingsManager().setDataEnabled(
3022 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003023 return true;
3024 } else {
3025 return false;
3026 }
3027 } finally {
3028 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003029 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003030 }
3031
Wink Saville36469e72014-06-11 15:17:00 -07003032 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003033 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003034 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003035 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003036
3037 final long identity = Binder.clearCallingIdentity();
3038 try {
Jack Yu285100e2022-12-02 22:48:35 -08003039 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003040 final Phone phone = getPhone(subId);
3041 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003042 phone.getDataSettingsManager().setDataEnabled(
3043 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003044 return true;
3045 } else {
3046 return false;
3047 }
3048 } finally {
3049 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003050 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003051 }
3052
Sanket Padawe356d7632015-06-22 14:03:32 -07003053 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003054 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003055 final long identity = Binder.clearCallingIdentity();
3056 try {
3057 final Phone phone = getPhone(subId);
3058 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003059 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003060 } else {
3061 return false;
3062 }
3063 } finally {
3064 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003065 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003066 }
3067
3068 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003069 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003070 }
3071
pkanwarae03a6b2016-11-06 20:37:09 -08003072 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003073 enforceCallPermission();
3074
3075 final long identity = Binder.clearCallingIdentity();
3076 try {
3077 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3078 return;
3079 }
3080 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3081 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3082 } finally {
3083 Binder.restoreCallingIdentity(identity);
3084 }
pkanwar32d516d2016-10-14 19:37:38 -07003085 };
3086
Wink Savilleb564aae2014-10-23 10:18:09 -07003087 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003088 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003089
3090 final long identity = Binder.clearCallingIdentity();
3091 try {
3092 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3093 return false;
3094 }
3095 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3096 } finally {
3097 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003098 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003099 }
3100
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003101 /**
3102 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3103 * tag on getCallState Binder call.
3104 */
3105 @Deprecated
3106 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003107 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003108 if (CompatChanges.isChangeEnabled(
3109 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3110 Binder.getCallingUid())) {
3111 // Do not allow this API to be called on API version 31+, it should only be
3112 // called on old apps using this Binder call directly.
3113 throw new SecurityException("This method can only be used for applications "
3114 + "targeting API version 30 or less.");
3115 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003116 final long identity = Binder.clearCallingIdentity();
3117 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003118 Phone phone = getPhone(getDefaultSubscription());
3119 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3120 PhoneConstantConversions.convertCallState(phone.getState());
3121 } finally {
3122 Binder.restoreCallingIdentity(identity);
3123 }
3124 }
3125
3126 @Override
3127 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3128 if (CompatChanges.isChangeEnabled(
3129 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3130 Binder.getCallingUid())) {
3131 // Check READ_PHONE_STATE for API version 31+
3132 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3133 featureId, "getCallStateForSubscription")) {
3134 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3135 + "targeting API level 31+.");
3136 }
3137 }
3138 final long identity = Binder.clearCallingIdentity();
3139 try {
3140 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003141 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3142 PhoneConstantConversions.convertCallState(phone.getState());
3143 } finally {
3144 Binder.restoreCallingIdentity(identity);
3145 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003146 }
3147
Sanket Padawe356d7632015-06-22 14:03:32 -07003148 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003149 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003150 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003151 }
3152
3153 @Override
3154 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003155 final long identity = Binder.clearCallingIdentity();
3156 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003157 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003158 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003159 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003160 } else {
3161 return PhoneConstantConversions.convertDataState(
3162 PhoneConstants.DataState.DISCONNECTED);
3163 }
3164 } finally {
3165 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003166 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003167 }
3168
Sanket Padawe356d7632015-06-22 14:03:32 -07003169 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003170 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003171 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003172 }
3173
3174 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003175 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003176 final long identity = Binder.clearCallingIdentity();
3177 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003178 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003179 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003180 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003181 } else {
3182 return TelephonyManager.DATA_ACTIVITY_NONE;
3183 }
3184 } finally {
3185 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003186 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003187 }
3188
3189 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003190 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003191 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003192 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003193
3194 LocationAccessPolicy.LocationPermissionResult locationResult =
3195 LocationAccessPolicy.checkLocationPermission(mApp,
3196 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3197 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003198 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003199 .setCallingPid(Binder.getCallingPid())
3200 .setCallingUid(Binder.getCallingUid())
3201 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003202 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003203 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3204 .build());
3205 switch (locationResult) {
3206 case DENIED_HARD:
3207 throw new SecurityException("Not allowed to access cell location");
3208 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003209 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3210 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003211 }
3212
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003213 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003214 final long identity = Binder.clearCallingIdentity();
3215 try {
3216 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003217 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003218 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003219 } finally {
3220 Binder.restoreCallingIdentity(identity);
3221 }
Svetoslav64fad262015-04-14 14:35:21 -07003222 }
3223
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003224 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003225 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003226 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3227 // registered cell info, so return a NULL country instead.
3228 final long identity = Binder.clearCallingIdentity();
3229 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003230 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3231 // Get default phone in this case.
3232 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3233 }
Jack Yu285100e2022-12-02 22:48:35 -08003234 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003235 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003236 if (phone == null) return "";
3237 ServiceStateTracker sst = phone.getServiceStateTracker();
3238 if (sst == null) return "";
3239 LocaleTracker lt = sst.getLocaleTracker();
3240 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003241 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003242 } finally {
3243 Binder.restoreCallingIdentity(identity);
3244 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003245 }
3246
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003247 /**
3248 * This method was removed due to potential issues caused by performing partial
3249 * updates of service state, and lack of a credible use case.
3250 *
3251 * This has the ability to break the telephony implementation by disabling notification of
3252 * changes in device connectivity. DO NOT USE THIS!
3253 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003254 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003255 public void enableLocationUpdates() {
3256 mApp.enforceCallingOrSelfPermission(
3257 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003258 }
3259
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003260 /**
3261 * This method was removed due to potential issues caused by performing partial
3262 * updates of service state, and lack of a credible use case.
3263 *
3264 * This has the ability to break the telephony implementation by disabling notification of
3265 * changes in device connectivity. DO NOT USE THIS!
3266 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003267 @Override
3268 public void disableLocationUpdates() {
3269 mApp.enforceCallingOrSelfPermission(
3270 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003271 }
3272
3273 @Override
3274 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003275 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3276 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003277 try {
3278 mApp.getSystemService(AppOpsManager.class)
3279 .checkPackage(Binder.getCallingUid(), callingPackage);
3280 } catch (SecurityException e) {
3281 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3282 throw e;
3283 }
3284
Nathan Haroldf096d982020-11-18 17:18:06 -08003285 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003286 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3287 throw new SecurityException(
3288 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3289 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003290
Jordan Liu1617b712019-07-10 15:06:26 -07003291 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003292 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3293 return null;
3294 }
Svetoslav64fad262015-04-14 14:35:21 -07003295
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003296 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003297
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003298 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003299 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003300
Nathan Haroldf180aac2018-06-01 18:43:55 -07003301 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3302 for (CellInfo ci : info) {
3303 if (ci instanceof CellInfoGsm) {
3304 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3305 } else if (ci instanceof CellInfoWcdma) {
3306 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3307 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003308 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003309 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003310 }
3311
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003312 private List<CellInfo> getCachedCellInfo() {
3313 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3314 for (Phone phone : PhoneFactory.getPhones()) {
3315 List<CellInfo> info = phone.getAllCellInfo();
3316 if (info != null) cellInfos.addAll(info);
3317 }
3318 return cellInfos;
3319 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003320
3321 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003322 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003323 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003324 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003325
3326 LocationAccessPolicy.LocationPermissionResult locationResult =
3327 LocationAccessPolicy.checkLocationPermission(mApp,
3328 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3329 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003330 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003331 .setCallingPid(Binder.getCallingPid())
3332 .setCallingUid(Binder.getCallingUid())
3333 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003334 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003335 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3336 .build());
3337 switch (locationResult) {
3338 case DENIED_HARD:
3339 throw new SecurityException("Not allowed to access cell info");
3340 case DENIED_SOFT:
3341 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003342 }
3343
Nathan Haroldf096d982020-11-18 17:18:06 -08003344 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003345 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3346 return getCachedCellInfo();
3347 }
3348
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003349 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003350 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003351 final long identity = Binder.clearCallingIdentity();
3352 try {
3353 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3354 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003355 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003356 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003357 if (info != null) cellInfos.addAll(info);
3358 }
3359 return cellInfos;
3360 } finally {
3361 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003362 }
3363 }
3364
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003365 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003366 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3367 String callingFeatureId) {
3368 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3369 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003370 }
3371
3372 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003373 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3374 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003375 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003376 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003377 }
3378
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003379 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3380 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003381 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003382 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003383
3384 LocationAccessPolicy.LocationPermissionResult locationResult =
3385 LocationAccessPolicy.checkLocationPermission(mApp,
3386 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3387 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003388 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003389 .setCallingPid(Binder.getCallingPid())
3390 .setCallingUid(Binder.getCallingUid())
3391 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003392 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3393 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003394 .build());
3395 switch (locationResult) {
3396 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003397 if (TelephonyPermissions
3398 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003399 // Safetynet logging for b/154934934
3400 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3401 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003402 throw new SecurityException("Not allowed to access cell info");
3403 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003404 if (TelephonyPermissions
3405 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003406 // Safetynet logging for b/154934934
3407 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3408 }
Nathan Harold5320c422019-05-09 10:26:08 -07003409 try {
3410 cb.onCellInfo(new ArrayList<CellInfo>());
3411 } catch (RemoteException re) {
3412 // Drop without consequences
3413 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003414 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003415 }
3416
Nathan Harolda939a962019-05-09 10:13:47 -07003417
3418 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003419 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3420
3421 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3422 }
3423
3424 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003425 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003426 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003427 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003428
3429 final long identity = Binder.clearCallingIdentity();
3430 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003431 Phone phone = getPhone(subId);
3432 if (phone == null) {
3433 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3434 } else {
3435 phone.setCellInfoListRate(rateInMillis, workSource);
3436 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003437 } finally {
3438 Binder.restoreCallingIdentity(identity);
3439 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003440 }
3441
Shishir Agrawala9f32182016-04-12 12:00:16 -07003442 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003443 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003444 Phone phone = PhoneFactory.getPhone(slotIndex);
3445 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003446 return null;
3447 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003448 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003449 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003450 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003451 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003452 return null;
3453 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003454
3455 final long identity = Binder.clearCallingIdentity();
3456 try {
3457 return phone.getImei();
3458 } finally {
3459 Binder.restoreCallingIdentity(identity);
3460 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003461 }
3462
3463 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003464 public String getTypeAllocationCodeForSlot(int slotIndex) {
3465 Phone phone = PhoneFactory.getPhone(slotIndex);
3466 String tac = null;
3467 if (phone != null) {
3468 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003469 try {
3470 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3471 } catch (IndexOutOfBoundsException e) {
3472 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3473 return null;
3474 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003475 }
3476 return tac;
3477 }
3478
3479 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003480 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003481 try {
3482 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3483 } catch (SecurityException se) {
3484 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3485 throw new SecurityException("Package " + callingPackage + " does not belong to "
3486 + Binder.getCallingUid());
3487 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003488 Phone phone = PhoneFactory.getPhone(slotIndex);
3489 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003490 return null;
3491 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003492
Jeff Davidson913390f2018-02-23 17:11:49 -08003493 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003494 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003495 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003496 return null;
3497 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003498
3499 final long identity = Binder.clearCallingIdentity();
3500 try {
3501 return phone.getMeid();
3502 } finally {
3503 Binder.restoreCallingIdentity(identity);
3504 }
Jack Yu2af8d712017-03-15 17:14:14 -07003505 }
3506
3507 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003508 public String getManufacturerCodeForSlot(int slotIndex) {
3509 Phone phone = PhoneFactory.getPhone(slotIndex);
3510 String manufacturerCode = null;
3511 if (phone != null) {
3512 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003513 try {
3514 manufacturerCode =
3515 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3516 } catch (IndexOutOfBoundsException e) {
3517 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3518 return null;
3519 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003520 }
3521 return manufacturerCode;
3522 }
3523
3524 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003525 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3526 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003527 Phone phone = PhoneFactory.getPhone(slotIndex);
3528 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003529 return null;
3530 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003531 int subId = phone.getSubId();
3532 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003533 mApp, subId, callingPackage, callingFeatureId,
3534 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003535 return null;
3536 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003537
3538 final long identity = Binder.clearCallingIdentity();
3539 try {
3540 return phone.getDeviceSvn();
3541 } finally {
3542 Binder.restoreCallingIdentity(identity);
3543 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003544 }
3545
fionaxu43304da2017-11-27 22:51:16 -08003546 @Override
3547 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 final Phone phone = getPhone(subId);
3551 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3552 } finally {
3553 Binder.restoreCallingIdentity(identity);
3554 }
fionaxu43304da2017-11-27 22:51:16 -08003555 }
3556
3557 @Override
3558 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003559 final long identity = Binder.clearCallingIdentity();
3560 try {
3561 final Phone phone = getPhone(subId);
3562 return phone == null ? null : phone.getCarrierName();
3563 } finally {
3564 Binder.restoreCallingIdentity(identity);
3565 }
fionaxu43304da2017-11-27 22:51:16 -08003566 }
3567
calvinpanffe225e2018-11-01 19:43:06 +08003568 @Override
chen xu0026ca62019-03-06 15:28:50 -08003569 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003570 final long identity = Binder.clearCallingIdentity();
3571 try {
3572 final Phone phone = getPhone(subId);
3573 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003574 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003575 } finally {
3576 Binder.restoreCallingIdentity(identity);
3577 }
3578 }
3579
3580 @Override
chen xu0026ca62019-03-06 15:28:50 -08003581 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003582 final long identity = Binder.clearCallingIdentity();
3583 try {
3584 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003585 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003586 } finally {
3587 Binder.restoreCallingIdentity(identity);
3588 }
3589 }
3590
chen xu651eec72018-11-11 19:03:44 -08003591 @Override
chen xu864e11c2018-12-06 22:10:03 -08003592 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3593 if (!isSubscriptionMccMnc) {
3594 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3595 }
chen xu651eec72018-11-11 19:03:44 -08003596 final Phone phone = PhoneFactory.getPhone(slotIndex);
3597 if (phone == null) {
3598 return TelephonyManager.UNKNOWN_CARRIER_ID;
3599 }
3600 final long identity = Binder.clearCallingIdentity();
3601 try {
3602 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3603 } finally {
3604 Binder.restoreCallingIdentity(identity);
3605 }
3606 }
3607
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003608 //
3609 // Internal helper methods.
3610 //
3611
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003612 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003613 * Make sure the caller is the calling package itself
3614 *
3615 * @throws SecurityException if the caller is not the calling package
3616 */
3617 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3618 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003619 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3620 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003621 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003622 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003623 } catch (PackageManager.NameNotFoundException e) {
3624 // packageUid is -1
3625 }
3626 if (packageUid != callingUid) {
3627 throw new SecurityException(message + ": Package " + callingPackage
3628 + " does not belong to " + callingUid);
3629 }
3630 }
3631
3632 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003633 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3634 *
3635 * @throws SecurityException if the caller does not have the required permission
3636 */
3637 private void enforceModifyPermission() {
3638 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3639 }
3640
Shuo Qian3b6ee772019-11-13 17:43:31 -08003641 private void enforceActiveEmergencySessionPermission() {
3642 mApp.enforceCallingOrSelfPermission(
3643 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3644 }
3645
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003646 /**
3647 * Make sure the caller has the CALL_PHONE permission.
3648 *
3649 * @throws SecurityException if the caller does not have the required permission
3650 */
3651 private void enforceCallPermission() {
3652 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3653 }
3654
paulhu5a773602019-08-23 19:17:33 +08003655 private void enforceSettingsPermission() {
3656 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003657 }
3658
Michele Berionne5e411512020-11-13 02:36:59 +00003659 private void enforceRebootPermission() {
3660 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3661 }
3662
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003663 private String createTelUrl(String number) {
3664 if (TextUtils.isEmpty(number)) {
3665 return null;
3666 }
3667
Jake Hambye994d462014-02-03 13:10:13 -08003668 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003669 }
3670
Ihab Awadf9e92732013-12-05 18:02:52 -08003671 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003672 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3673 }
3674
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003675 private static void logv(String msg) {
3676 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3677 }
3678
Ihab Awadf9e92732013-12-05 18:02:52 -08003679 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003680 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3681 }
3682
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003683 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003684 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003685 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003686 }
3687
Sanket Padawe356d7632015-06-22 14:03:32 -07003688 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003689 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003690 final long identity = Binder.clearCallingIdentity();
3691 try {
3692 final Phone phone = PhoneFactory.getPhone(slotIndex);
3693 if (phone == null) {
3694 return PhoneConstants.PHONE_TYPE_NONE;
3695 } else {
3696 return phone.getPhoneType();
3697 }
3698 } finally {
3699 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003700 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003701 }
3702
3703 /**
3704 * Returns the CDMA ERI icon index to display
3705 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003706 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003707 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3708 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3709 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003710 }
3711
Sanket Padawe356d7632015-06-22 14:03:32 -07003712 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003713 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3714 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003715 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003716 mApp, subId, callingPackage, callingFeatureId,
3717 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003718 return -1;
3719 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003720
3721 final long identity = Binder.clearCallingIdentity();
3722 try {
3723 final Phone phone = getPhone(subId);
3724 if (phone != null) {
3725 return phone.getCdmaEriIconIndex();
3726 } else {
3727 return -1;
3728 }
3729 } finally {
3730 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003731 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003732 }
3733
3734 /**
3735 * Returns the CDMA ERI icon mode,
3736 * 0 - ON
3737 * 1 - FLASHING
3738 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003739 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003740 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3741 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3742 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003743 }
3744
Sanket Padawe356d7632015-06-22 14:03:32 -07003745 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003746 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3747 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003748 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003749 mApp, subId, callingPackage, callingFeatureId,
3750 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003751 return -1;
3752 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003753
3754 final long identity = Binder.clearCallingIdentity();
3755 try {
3756 final Phone phone = getPhone(subId);
3757 if (phone != null) {
3758 return phone.getCdmaEriIconMode();
3759 } else {
3760 return -1;
3761 }
3762 } finally {
3763 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003764 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003765 }
3766
3767 /**
3768 * Returns the CDMA ERI text,
3769 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003770 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003771 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3772 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3773 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003774 }
3775
Sanket Padawe356d7632015-06-22 14:03:32 -07003776 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003777 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3778 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003779 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003780 mApp, subId, callingPackage, callingFeatureId,
3781 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003782 return null;
3783 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003784
3785 final long identity = Binder.clearCallingIdentity();
3786 try {
3787 final Phone phone = getPhone(subId);
3788 if (phone != null) {
3789 return phone.getCdmaEriText();
3790 } else {
3791 return null;
3792 }
3793 } finally {
3794 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003795 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003796 }
3797
3798 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003799 * Returns the CDMA MDN.
3800 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003801 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003802 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3804 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003805
3806 final long identity = Binder.clearCallingIdentity();
3807 try {
3808 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003809 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003810 return phone.getLine1Number();
3811 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003812 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813 return null;
3814 }
3815 } finally {
3816 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003817 }
3818 }
3819
3820 /**
3821 * Returns the CDMA MIN.
3822 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003823 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003824 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3826 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003827
3828 final long identity = Binder.clearCallingIdentity();
3829 try {
3830 final Phone phone = getPhone(subId);
3831 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3832 return phone.getCdmaMin();
3833 } else {
3834 return null;
3835 }
3836 } finally {
3837 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003838 }
3839 }
3840
Hall Liud892bec2018-11-30 14:51:45 -08003841 @Override
3842 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3843 INumberVerificationCallback callback, String callingPackage) {
3844 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3845 != PERMISSION_GRANTED) {
3846 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3847 }
3848 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3849
3850 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3851 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003852 throw new SecurityException("Calling package must be configured in the device config: "
3853 + "calling package: " + callingPackage
3854 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003855 }
3856
3857 if (range == null) {
3858 throw new NullPointerException("Range must be non-null");
3859 }
3860
3861 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003862 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003863
3864 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3865 }
3866
Junda Liuca05d5d2014-08-14 22:36:34 -07003867 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003868 * Returns true if CDMA provisioning needs to run.
3869 */
3870 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003871 final long identity = Binder.clearCallingIdentity();
3872 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003873 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003874 } finally {
3875 Binder.restoreCallingIdentity(identity);
3876 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003877 }
3878
3879 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003880 * Sets the voice mail number of a given subId.
3881 */
3882 @Override
3883 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003884 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3885 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003886
3887 final long identity = Binder.clearCallingIdentity();
3888 try {
3889 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3890 new Pair<String, String>(alphaTag, number), new Integer(subId));
3891 return success;
3892 } finally {
3893 Binder.restoreCallingIdentity(identity);
3894 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003895 }
3896
Ta-wei Yen87c49842016-05-13 21:19:52 -07003897 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003898 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3899 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003900 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3901 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003902 if (!TextUtils.equals(callingPackage, systemDialer)) {
3903 throw new SecurityException("caller must be system dialer");
3904 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003905
3906 final long identity = Binder.clearCallingIdentity();
3907 try {
3908 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3909 if (phoneAccountHandle == null) {
3910 return null;
3911 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003912 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003913 } finally {
3914 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003915 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003916 }
3917
3918 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003919 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3920 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003921 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003922 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003923 mApp, subId, callingPackage, callingFeatureId,
3924 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003925 return null;
3926 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003927
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003928 final long identity = Binder.clearCallingIdentity();
3929 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003930 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003931 } finally {
3932 Binder.restoreCallingIdentity(identity);
3933 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003934 }
3935
3936 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003937 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3938 VisualVoicemailSmsFilterSettings settings) {
3939 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003940
3941 final long identity = Binder.clearCallingIdentity();
3942 try {
3943 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003944 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003945 } finally {
3946 Binder.restoreCallingIdentity(identity);
3947 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003948 }
3949
3950 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003951 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3952 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003953
3954 final long identity = Binder.clearCallingIdentity();
3955 try {
3956 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003957 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003958 } finally {
3959 Binder.restoreCallingIdentity(identity);
3960 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003961 }
3962
3963 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003964 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3965 String callingPackage, int subId) {
3966 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003967
3968 final long identity = Binder.clearCallingIdentity();
3969 try {
3970 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003971 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003972 } finally {
3973 Binder.restoreCallingIdentity(identity);
3974 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003975 }
3976
3977 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003978 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003979 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003980
3981 final long identity = Binder.clearCallingIdentity();
3982 try {
3983 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003984 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003985 } finally {
3986 Binder.restoreCallingIdentity(identity);
3987 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003988 }
3989
3990 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003991 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3992 String callingAttributionTag, int subId, String number, int port, String text,
3993 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003994 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003995 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003996 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003997 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003998 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3999 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004000 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004001
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004002 /**
fionaxu0152e512016-11-14 13:36:14 -08004003 * Sets the voice activation state of a given subId.
4004 */
4005 @Override
4006 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4008 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004009
4010 final long identity = Binder.clearCallingIdentity();
4011 try {
4012 final Phone phone = getPhone(subId);
4013 if (phone != null) {
4014 phone.setVoiceActivationState(activationState);
4015 } else {
4016 loge("setVoiceActivationState fails with invalid subId: " + subId);
4017 }
4018 } finally {
4019 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004020 }
4021 }
4022
4023 /**
4024 * Sets the data activation state of a given subId.
4025 */
4026 @Override
4027 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4029 mApp, subId, "setDataActivationState");
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.setDataActivationState(activationState);
4036 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004037 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004038 }
4039 } finally {
4040 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004041 }
4042 }
4043
4044 /**
4045 * Returns the voice activation state of a given subId.
4046 */
4047 @Override
4048 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004049 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004050
fionaxu0152e512016-11-14 13:36:14 -08004051 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004052 final long identity = Binder.clearCallingIdentity();
4053 try {
4054 if (phone != null) {
4055 return phone.getVoiceActivationState();
4056 } else {
4057 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4058 }
4059 } finally {
4060 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004061 }
4062 }
4063
4064 /**
4065 * Returns the data activation state of a given subId.
4066 */
4067 @Override
4068 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004069 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004070
fionaxu0152e512016-11-14 13:36:14 -08004071 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004072 final long identity = Binder.clearCallingIdentity();
4073 try {
4074 if (phone != null) {
4075 return phone.getDataActivationState();
4076 } else {
4077 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4078 }
4079 } finally {
4080 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004081 }
4082 }
4083
4084 /**
Wink Saville36469e72014-06-11 15:17:00 -07004085 * Returns the unread count of voicemails for a subId
4086 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004087 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004088 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4089 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004090 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004091 mApp, subId, callingPackage, callingFeatureId,
4092 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004093 return 0;
4094 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004095 final long identity = Binder.clearCallingIdentity();
4096 try {
4097 final Phone phone = getPhone(subId);
4098 if (phone != null) {
4099 return phone.getVoiceMessageCount();
4100 } else {
4101 return 0;
4102 }
4103 } finally {
4104 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004105 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004106 }
4107
4108 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004109 * returns true, if the device is in a state where both voice and data
4110 * are supported simultaneously. This can change based on location or network condition.
4111 */
4112 @Override
4113 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004114 final long identity = Binder.clearCallingIdentity();
4115 try {
4116 final Phone phone = getPhone(subId);
4117 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4118 } finally {
4119 Binder.restoreCallingIdentity(identity);
4120 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004121 }
4122
4123 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004124 * Send the dialer code if called from the current default dialer or the caller has
4125 * carrier privilege.
4126 * @param inputCode The dialer code to send
4127 */
4128 @Override
4129 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004130 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004131 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004132 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4133 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004134 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004135 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004136 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004137 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004138
4139 final long identity = Binder.clearCallingIdentity();
4140 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004141 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004142 } finally {
4143 Binder.restoreCallingIdentity(identity);
4144 }
fionaxu235cc5e2017-03-06 22:25:57 -08004145 }
4146
Pengquan Menga1bb6272018-09-06 09:59:22 -07004147 @Override
4148 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004149 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004150 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004151 mApp, subId, "getNetworkSelectionMode");
4152 final long identity = Binder.clearCallingIdentity();
4153 try {
4154 if (!isActiveSubscription(subId)) {
4155 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4156 }
4157 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4158 } finally {
4159 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004160 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004161 }
4162
Brad Ebinger35c841c2018-10-01 10:40:55 -07004163 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004164 public boolean isInEmergencySmsMode() {
4165 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4166 final long identity = Binder.clearCallingIdentity();
4167 try {
4168 for (Phone phone : PhoneFactory.getPhones()) {
4169 if (phone.isInEmergencySmsMode()) {
4170 return true;
4171 }
4172 }
4173 } finally {
4174 Binder.restoreCallingIdentity(identity);
4175 }
4176 return false;
4177 }
4178
shilu366312e2019-12-17 09:28:10 -08004179 /**
4180 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4181 * @param subId The subscription to use to check the configuration.
4182 * @param c The callback that will be used to send the result.
4183 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004184 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004185 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4186 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004187 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004188 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004189
4190 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4191 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4192 "IMS not available on device.");
4193 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004194 final long token = Binder.clearCallingIdentity();
4195 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004196 int slotId = getSlotIndexOrException(subId);
4197 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004198
4199 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4200 if (controller != null) {
4201 ImsManager imsManager = controller.getImsManager(subId);
4202 if (imsManager != null) {
4203 imsManager.addRegistrationCallbackForSubscription(c, subId);
4204 } else {
4205 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4206 }
4207 } else {
4208 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4209 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004210 } catch (ImsException e) {
4211 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004212 } finally {
4213 Binder.restoreCallingIdentity(token);
4214 }
4215 }
4216
shilu366312e2019-12-17 09:28:10 -08004217 /**
4218 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4219 * @param subId The subscription to use to check the configuration.
4220 * @param c The callback that will be used to send the result.
4221 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004222 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004223 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004224 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004225 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004226 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4227 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4228 }
Meng Wangafbc5852019-09-19 17:37:13 -07004229 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004230
Meng Wangafbc5852019-09-19 17:37:13 -07004231 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004232 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4233 if (controller != null) {
4234 ImsManager imsManager = controller.getImsManager(subId);
4235 if (imsManager != null) {
4236 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4237 } else {
4238 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4239 + "is inactive, ignoring unregister.");
4240 // If the ImsManager is not valid, just return, since the callback
4241 // will already have been removed internally.
4242 }
4243 }
Meng Wangafbc5852019-09-19 17:37:13 -07004244 } finally {
4245 Binder.restoreCallingIdentity(token);
4246 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004247 }
4248
Brad Ebingera34a6c22019-10-22 17:36:18 -07004249 /**
4250 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4251 */
4252 @Override
4253 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4254 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4255 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4256 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4257 "IMS not available on device.");
4258 }
4259 final long token = Binder.clearCallingIdentity();
4260 try {
4261 Phone phone = getPhone(subId);
4262 if (phone == null) {
4263 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4264 + subId + "'");
4265 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4266 }
4267 phone.getImsRegistrationState(regState -> {
4268 try {
4269 consumer.accept((regState == null)
4270 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4271 } catch (RemoteException e) {
4272 // Ignore if the remote process is no longer available to call back.
4273 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4274 }
4275 });
4276 } finally {
4277 Binder.restoreCallingIdentity(token);
4278 }
4279 }
4280
4281 /**
4282 * Get the transport type for the IMS service registration state.
4283 */
4284 @Override
4285 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004286 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004287 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004288 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4289 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4290 "IMS not available on device.");
4291 }
4292 final long token = Binder.clearCallingIdentity();
4293 try {
4294 Phone phone = getPhone(subId);
4295 if (phone == null) {
4296 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4297 + subId + "'");
4298 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4299 }
4300 phone.getImsRegistrationTech(regTech -> {
4301 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4302 int regTechConverted = (regTech == null)
4303 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4304 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4305 regTechConverted);
4306 try {
4307 consumer.accept(regTechConverted);
4308 } catch (RemoteException e) {
4309 // Ignore if the remote process is no longer available to call back.
4310 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4311 }
4312 });
4313 } finally {
4314 Binder.restoreCallingIdentity(token);
4315 }
4316 }
4317
shilu366312e2019-12-17 09:28:10 -08004318 /**
4319 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4320 * @param subId The subscription to use to check the configuration.
4321 * @param c The callback that will be used to send the result.
4322 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004323 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004324 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4325 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004326 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004327 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004328 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4329 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4330 "IMS not available on device.");
4331 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004332 final long token = Binder.clearCallingIdentity();
4333 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004334 int slotId = getSlotIndexOrException(subId);
4335 verifyImsMmTelConfiguredOrThrow(slotId);
4336 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004337 } catch (ImsException e) {
4338 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004339 } finally {
4340 Binder.restoreCallingIdentity(token);
4341 }
4342 }
4343
shilu366312e2019-12-17 09:28:10 -08004344 /**
4345 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4346 * @param subId The subscription to use to check the configuration.
4347 * @param c The callback that will be used to send the result.
4348 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004349 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004350 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004351 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004352 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004353 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4354 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4355 }
Meng Wangafbc5852019-09-19 17:37:13 -07004356
4357 final long token = Binder.clearCallingIdentity();
4358 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004359 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004360 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004361 } catch (ImsException e) {
4362 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4363 + "is inactive, ignoring unregister.");
4364 // If the subscription is no longer active, just return, since the callback
4365 // will already have been removed internally.
4366 } finally {
4367 Binder.restoreCallingIdentity(token);
4368 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004369 }
4370
4371 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004372 public boolean isCapable(int subId, int capability, int regTech) {
4373 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004374 final long token = Binder.clearCallingIdentity();
4375 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004376 int slotId = getSlotIndexOrException(subId);
4377 verifyImsMmTelConfiguredOrThrow(slotId);
4378 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4379 } catch (com.android.ims.ImsException e) {
4380 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4381 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004382 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004383 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4384 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004385 } finally {
4386 Binder.restoreCallingIdentity(token);
4387 }
4388 }
4389
4390 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004391 public boolean isAvailable(int subId, int capability, int regTech) {
4392 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004393 final long token = Binder.clearCallingIdentity();
4394 try {
4395 Phone phone = getPhone(subId);
4396 if (phone == null) return false;
4397 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004398 } catch (com.android.ims.ImsException e) {
4399 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4400 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004401 } finally {
4402 Binder.restoreCallingIdentity(token);
4403 }
4404 }
4405
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004406 /**
4407 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4408 * subscription.
4409 * @param subId The subscription to use to check the configuration.
4410 * @param callback The callback that will be used to send the result.
4411 * @param capability The MmTelFeature capability that will be used to send the result.
4412 * @param transportType The transport type of the MmTelFeature capability.
4413 */
4414 @Override
4415 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4416 int transportType) {
4417 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004418 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4419 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4420 "IMS not available on device.");
4421 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004422 final long token = Binder.clearCallingIdentity();
4423 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004424 int slotId = getSlotIndex(subId);
4425 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4426 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4427 + subId + "'");
4428 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4429 }
4430 verifyImsMmTelConfiguredOrThrow(slotId);
4431 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4432 transportType, aBoolean -> {
4433 try {
4434 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4435 } catch (RemoteException e) {
4436 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4437 + "running. Ignore");
4438 }
4439 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004440 } catch (ImsException e) {
4441 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004442 } finally {
4443 Binder.restoreCallingIdentity(token);
4444 }
4445 }
4446
shilu366312e2019-12-17 09:28:10 -08004447 /**
4448 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4449 * @param subId The subscription to use to check the configuration.
4450 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004451 @Override
4452 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004453 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004454 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004455
Brad Ebinger35c841c2018-10-01 10:40:55 -07004456 final long token = Binder.clearCallingIdentity();
4457 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004458 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004459 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004460 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004461 } catch (ImsException e) {
4462 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004463 } finally {
4464 Binder.restoreCallingIdentity(token);
4465 }
4466 }
4467
4468 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004469 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004470 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004471 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004472 final long identity = Binder.clearCallingIdentity();
4473 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004474 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004475 // This setting doesn't require an active ImsService connection, so do not verify. The
4476 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004477 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004478 } catch (ImsException e) {
4479 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004480 } finally {
4481 Binder.restoreCallingIdentity(identity);
4482 }
4483 }
4484
shilu366312e2019-12-17 09:28:10 -08004485 /**
4486 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4487 * @param subId The subscription to use to check the configuration.
4488 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004489 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004490 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004491 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004492 mApp, subId, "isVtSettingEnabled");
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.
Brad Ebinger919631e2021-06-02 17:46:35 -07004497 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004498 } catch (ImsException e) {
4499 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004500 } finally {
4501 Binder.restoreCallingIdentity(identity);
4502 }
4503 }
4504
4505 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004506 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004507 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004508 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004509 final long identity = Binder.clearCallingIdentity();
4510 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004511 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004512 // This setting doesn't require an active ImsService connection, so do not verify. The
4513 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004514 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004515 } catch (ImsException e) {
4516 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004517 } finally {
4518 Binder.restoreCallingIdentity(identity);
4519 }
4520 }
4521
shilu366312e2019-12-17 09:28:10 -08004522 /**
4523 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4524 * @param subId The subscription to use to check the configuration.
4525 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004526 @Override
4527 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004528 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004529 mApp, subId, "isVoWiFiSettingEnabled");
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.
Brad Ebinger919631e2021-06-02 17:46:35 -07004534 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004535 } catch (ImsException e) {
4536 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004537 } finally {
4538 Binder.restoreCallingIdentity(identity);
4539 }
4540 }
4541
4542 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004543 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004544 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004545 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004546 final long identity = Binder.clearCallingIdentity();
4547 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004548 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004549 // This setting doesn't require an active ImsService connection, so do not verify. The
4550 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004551 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004552 } catch (ImsException e) {
4553 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004554 } finally {
4555 Binder.restoreCallingIdentity(identity);
4556 }
4557 }
4558
shilu366312e2019-12-17 09:28:10 -08004559 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004560 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4561 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4562 * @param subId The subscription to use to check the configuration.
4563 */
4564 @Override
4565 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004566 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004567 mApp, subId, "isCrossSimCallingEnabledByUser");
4568 final long identity = Binder.clearCallingIdentity();
4569 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004570 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004571 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004572 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004573 } catch (ImsException e) {
4574 throw new ServiceSpecificException(e.getCode());
4575 } finally {
4576 Binder.restoreCallingIdentity(identity);
4577 }
4578 }
4579
4580 /**
4581 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4582 * Requires MODIFY_PHONE_STATE permission.
4583 * @param subId The subscription to use to check the configuration.
4584 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4585 * false otherwise
4586 */
4587 @Override
4588 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4590 "setCrossSimCallingEnabled");
4591 final long identity = Binder.clearCallingIdentity();
4592 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004593 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004594 // This setting doesn't require an active ImsService connection, so do not verify. The
4595 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004596 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004597 } catch (ImsException e) {
4598 throw new ServiceSpecificException(e.getCode());
4599 } finally {
4600 Binder.restoreCallingIdentity(identity);
4601 }
4602 }
4603
4604 /**
shilu366312e2019-12-17 09:28:10 -08004605 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4606 * @param subId The subscription to use to check the configuration.
4607 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004608 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004609
Brad Ebinger35c841c2018-10-01 10:40:55 -07004610 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004611 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004612 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004613 final long identity = Binder.clearCallingIdentity();
4614 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004615 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004616 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004617 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004618 } catch (ImsException e) {
4619 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004620 } finally {
4621 Binder.restoreCallingIdentity(identity);
4622 }
4623 }
4624
4625 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004626 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004628 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004629 final long identity = Binder.clearCallingIdentity();
4630 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004631 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004632 // This setting doesn't require an active ImsService connection, so do not verify. The
4633 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004634 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004635 } catch (ImsException e) {
4636 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004637 } finally {
4638 Binder.restoreCallingIdentity(identity);
4639 }
4640 }
4641
4642 @Override
4643 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4645 "setVoWiFiNonPersistent");
4646 final long identity = Binder.clearCallingIdentity();
4647 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004648 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004649 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004650 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004651 } catch (ImsException e) {
4652 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004653 } finally {
4654 Binder.restoreCallingIdentity(identity);
4655 }
4656 }
4657
shilu366312e2019-12-17 09:28:10 -08004658 /**
4659 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4660 * @param subId The subscription to use to check the configuration.
4661 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004662 @Override
4663 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004664 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004665 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004666 final long identity = Binder.clearCallingIdentity();
4667 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004668 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004669 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004670 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004671 } catch (ImsException e) {
4672 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004673 } finally {
4674 Binder.restoreCallingIdentity(identity);
4675 }
4676 }
4677
4678 @Override
4679 public void setVoWiFiModeSetting(int subId, int mode) {
4680 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4681 "setVoWiFiModeSetting");
4682 final long identity = Binder.clearCallingIdentity();
4683 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004684 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004685 // This setting doesn't require an active ImsService connection, so do not verify. The
4686 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004687 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004688 } catch (ImsException e) {
4689 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004690 } finally {
4691 Binder.restoreCallingIdentity(identity);
4692 }
4693 }
4694
4695 @Override
4696 public int getVoWiFiRoamingModeSetting(int subId) {
4697 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4698 final long identity = Binder.clearCallingIdentity();
4699 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004700 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004701 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004702 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004703 } catch (ImsException e) {
4704 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004705 } finally {
4706 Binder.restoreCallingIdentity(identity);
4707 }
4708 }
4709
4710 @Override
4711 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4713 "setVoWiFiRoamingModeSetting");
4714 final long identity = Binder.clearCallingIdentity();
4715 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004716 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004717 // This setting doesn't require an active ImsService connection, so do not verify. The
4718 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004719 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004720 } catch (ImsException e) {
4721 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004722 } finally {
4723 Binder.restoreCallingIdentity(identity);
4724 }
4725 }
4726
4727 @Override
4728 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4729 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4730 "setRttCapabilityEnabled");
4731 final long identity = Binder.clearCallingIdentity();
4732 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004733 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004734 // This setting doesn't require an active ImsService connection, so do not verify. The
4735 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004736 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004737 } catch (ImsException e) {
4738 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004739 } finally {
4740 Binder.restoreCallingIdentity(identity);
4741 }
4742 }
4743
shilu366312e2019-12-17 09:28:10 -08004744 /**
4745 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4746 * @param subId The subscription to use to check the configuration.
4747 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004748 @Override
4749 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004750 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004751 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004752 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.
Brad Ebinger919631e2021-06-02 17:46:35 -07004756 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004757 } catch (ImsException e) {
4758 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004759 } finally {
4760 Binder.restoreCallingIdentity(identity);
4761 }
4762 }
4763
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004764 @Override
4765 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4766 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004767
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004768 final long identity = Binder.clearCallingIdentity();
4769 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004770 if (!isImsAvailableOnDevice()) {
4771 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4772 "IMS not available on device.");
4773 }
4774 int slotId = getSlotIndexOrException(subId);
4775 verifyImsMmTelConfiguredOrThrow(slotId);
4776 ImsManager.getInstance(mApp, slotId)
4777 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004778 } catch (ImsException e) {
4779 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004780 } finally {
4781 Binder.restoreCallingIdentity(identity);
4782 }
4783 }
4784
4785 @Override
4786 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4787 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004788
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004789 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004790 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4791 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4792 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004793 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004794 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004795 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004796 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004797 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4798 + "is inactive, ignoring unregister.");
4799 // If the subscription is no longer active, just return, since the callback will already
4800 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004801 } finally {
4802 Binder.restoreCallingIdentity(identity);
4803 }
4804 }
4805
joonhunshincffb7fc2021-11-28 07:32:01 +00004806 @Override
4807 public void registerFeatureProvisioningChangedCallback(int subId,
4808 IFeatureProvisioningCallback callback) {
4809 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4810 mApp, subId, "registerFeatureProvisioningChangedCallback");
4811
4812 final long identity = Binder.clearCallingIdentity();
4813 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4814 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4815 }
4816
joonhunshin91bc1952022-04-29 08:47:15 +00004817 try {
4818 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4819 if (controller == null) {
4820 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4821 "Device does not support IMS");
4822 }
4823 controller.addFeatureProvisioningChangedCallback(subId, callback);
4824 } finally {
4825 Binder.restoreCallingIdentity(identity);
4826 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004827 }
4828
4829 @Override
4830 public void unregisterFeatureProvisioningChangedCallback(int subId,
4831 IFeatureProvisioningCallback callback) {
4832 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4833 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4834
4835 final long identity = Binder.clearCallingIdentity();
4836 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4837 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4838 }
4839
joonhunshin91bc1952022-04-29 08:47:15 +00004840 try {
4841 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4842 if (controller == null) {
4843 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4844 return;
4845 }
4846 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4847 } finally {
4848 Binder.restoreCallingIdentity(identity);
4849 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004850 }
allenwtsu99c623b2020-01-03 18:24:23 +08004851
4852 private void checkModifyPhoneStatePermission(int subId, String message) {
4853 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4854 message);
4855 }
4856
allenwtsu99c623b2020-01-03 18:24:23 +08004857 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004858 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004859 boolean isProvisioned) {
4860 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4861
4862 final long identity = Binder.clearCallingIdentity();
4863 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004864 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4865 if (controller == null) {
4866 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4867 return;
4868 }
4869 controller.setRcsProvisioningStatusForCapability(
4870 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004871 } finally {
4872 Binder.restoreCallingIdentity(identity);
4873 }
allenwtsu99c623b2020-01-03 18:24:23 +08004874 }
4875
4876
4877 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004878 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4879 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4880 mApp, subId, "getRcsProvisioningStatusForCapability");
4881
allenwtsu99c623b2020-01-03 18:24:23 +08004882 final long identity = Binder.clearCallingIdentity();
4883 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004884 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4885 if (controller == null) {
4886 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4887
4888 // device does not support IMS, this method will return true always.
4889 return true;
4890 }
4891 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004892 } finally {
4893 Binder.restoreCallingIdentity(identity);
4894 }
4895 }
4896
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004897 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004898 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4899 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004900 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004901
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004902 final long identity = Binder.clearCallingIdentity();
4903 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004904 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4905 if (controller == null) {
4906 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4907 return;
4908 }
4909 controller.setImsProvisioningStatusForCapability(
4910 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004911 } finally {
4912 Binder.restoreCallingIdentity(identity);
4913 }
4914 }
4915
4916 @Override
4917 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004918 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4919 mApp, subId, "getProvisioningStatusForCapability");
4920
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004921 final long identity = Binder.clearCallingIdentity();
4922 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004923 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4924 if (controller == null) {
4925 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004926
joonhunshin91bc1952022-04-29 08:47:15 +00004927 // device does not support IMS, this method will return true always.
4928 return true;
4929 }
4930 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004931 } finally {
4932 Binder.restoreCallingIdentity(identity);
4933 }
4934 }
4935
4936 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004937 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4938 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4939 mApp, subId, "isProvisioningRequiredForCapability");
4940
4941 final long identity = Binder.clearCallingIdentity();
4942 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004943 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4944 if (controller == null) {
4945 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4946
4947 // device does not support IMS, this method will return false
4948 return false;
4949 }
4950 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004951 } finally {
4952 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004953 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004954 }
4955
4956 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004957 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4958 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4959 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004960
joonhunshincffb7fc2021-11-28 07:32:01 +00004961 final long identity = Binder.clearCallingIdentity();
4962 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004963 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4964 if (controller == null) {
4965 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4966
4967 // device does not support IMS, this method will return false
4968 return false;
4969 }
4970 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004971 } finally {
4972 Binder.restoreCallingIdentity(identity);
4973 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004974 }
4975
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004976 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004977 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004978 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4979 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4980 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004981 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4982 mApp, subId, "getImsProvisioningInt");
4983
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004984 final long identity = Binder.clearCallingIdentity();
4985 try {
4986 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004987 int slotId = getSlotIndex(subId);
4988 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4989 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4990 + subId + "' for key:" + key);
4991 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4992 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004993
joonhunshin91bc1952022-04-29 08:47:15 +00004994 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4995 if (controller == null) {
4996 loge("getImsProvisioningInt: Device does not support IMS");
4997
4998 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4999 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5000 }
5001 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005002 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5003 return retVal;
5004 }
5005
calvinpanb5a34062021-02-08 19:59:36 +08005006 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005007 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005008 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5009 + subId + "' for key:" + key);
5010 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005011 } finally {
5012 Binder.restoreCallingIdentity(identity);
5013 }
5014 }
5015
5016 @Override
5017 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005018 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5019 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5020 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005021 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5022 mApp, subId, "getImsProvisioningString");
5023
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005024 final long identity = Binder.clearCallingIdentity();
5025 try {
5026 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005027 int slotId = getSlotIndex(subId);
5028 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5029 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5030 + subId + "' for key:" + key);
5031 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5032 }
calvinpanb5a34062021-02-08 19:59:36 +08005033 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005034 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005035 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5036 + subId + "' for key:" + key);
5037 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005038 } finally {
5039 Binder.restoreCallingIdentity(identity);
5040 }
5041 }
5042
5043 @Override
5044 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005045 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5046 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5047 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5049 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005050
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005051 final long identity = Binder.clearCallingIdentity();
5052 try {
5053 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005054 int slotId = getSlotIndex(subId);
5055 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5056 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5057 + subId + "' for key:" + key);
5058 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5059 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005060
joonhunshin91bc1952022-04-29 08:47:15 +00005061 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5062 if (controller == null) {
5063 loge("setImsProvisioningInt: Device does not support IMS");
5064
5065 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5066 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5067 }
5068 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005069 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5070 return retVal;
5071 }
5072
calvinpanb5a34062021-02-08 19:59:36 +08005073 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5074 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005075 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005076 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005077 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005078 } finally {
5079 Binder.restoreCallingIdentity(identity);
5080 }
5081 }
5082
5083 @Override
5084 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005085 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5086 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5087 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005088 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5089 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005090 final long identity = Binder.clearCallingIdentity();
5091 try {
5092 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005093 int slotId = getSlotIndex(subId);
5094 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5095 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5096 + subId + "' for key:" + key);
5097 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5098 }
calvinpanb5a34062021-02-08 19:59:36 +08005099 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5100 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005101 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005102 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005103 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005104 } finally {
5105 Binder.restoreCallingIdentity(identity);
5106 }
5107 }
5108
Brad Ebinger919631e2021-06-02 17:46:35 -07005109 /**
5110 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5111 * for the given slot ID or no ImsResolver instance has been created.
5112 * @param slotId The slot ID that the IMS service is created for.
5113 * @throws ImsException If there is no ImsService configured for this slot.
5114 */
5115 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5116 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5117 ImsFeature.FEATURE_MMTEL)) {
5118 throw new ImsException("This subscription does not support MMTEL over IMS",
5119 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5120 }
5121 }
5122
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005123 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005124 int slotId = SubscriptionManager.getSlotIndex(subId);
5125 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005126 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5127 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005128 }
5129 return slotId;
5130 }
5131
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005132 private int getSlotIndex(int subId) {
5133 int slotId = SubscriptionManager.getSlotIndex(subId);
5134 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5135 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5136 }
5137 return slotId;
5138 }
5139
Wink Saville36469e72014-06-11 15:17:00 -07005140 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005141 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005142 */
5143 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005144 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5145 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005146 try {
5147 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5148 } catch (SecurityException se) {
5149 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5150 throw new SecurityException("Package " + callingPackage + " does not belong to "
5151 + Binder.getCallingUid());
5152 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005153 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005154 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005155 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005156 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005157 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005158 mApp, subId, callingPackage, callingFeatureId,
5159 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005160 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5161 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005162
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005163 final long identity = Binder.clearCallingIdentity();
5164 try {
5165 final Phone phone = getPhone(subId);
5166 if (phone != null) {
5167 return phone.getServiceState().getDataNetworkType();
5168 } else {
5169 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5170 }
5171 } finally {
5172 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005173 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005174 }
5175
5176 /**
5177 * Returns the data network type
5178 */
5179 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005180 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005181 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005182 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005183 }
5184
5185 /**
5186 * Returns the data network type for a subId
5187 */
5188 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005189 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5190 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005191 String functionName = "getDataNetworkTypeForSubscriber";
5192 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5193 mApp, functionName)) {
5194 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5195 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5196 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5197 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005198 }
5199
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005200 final long identity = Binder.clearCallingIdentity();
5201 try {
5202 final Phone phone = getPhone(subId);
5203 if (phone != null) {
5204 return phone.getServiceState().getDataNetworkType();
5205 } else {
5206 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5207 }
5208 } finally {
5209 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005210 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005211 }
5212
5213 /**
Wink Saville36469e72014-06-11 15:17:00 -07005214 * Returns the Voice network type for a subId
5215 */
5216 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005217 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5218 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005219 String functionName = "getVoiceNetworkTypeForSubscriber";
5220 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5221 mApp, functionName)) {
5222 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5223 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5224 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5225 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005226 }
5227
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 final long identity = Binder.clearCallingIdentity();
5229 try {
5230 final Phone phone = getPhone(subId);
5231 if (phone != null) {
5232 return phone.getServiceState().getVoiceNetworkType();
5233 } else {
5234 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5235 }
5236 } finally {
5237 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005239 }
5240
5241 /**
5242 * @return true if a ICC card is present
5243 */
5244 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005245 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005246 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005247 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005248 }
5249
5250 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005251 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005252 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005253 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005254 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005255 final long identity = Binder.clearCallingIdentity();
5256 try {
5257 final Phone phone = PhoneFactory.getPhone(slotIndex);
5258 if (phone != null) {
5259 return phone.getIccCard().hasIccCard();
5260 } else {
5261 return false;
5262 }
5263 } finally {
5264 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005265 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005266 }
5267
5268 /**
5269 * Return if the current radio is LTE on CDMA. This
5270 * is a tri-state return value as for a period of time
5271 * the mode may be unknown.
5272 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005273 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005274 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005275 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005276 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005277 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005278 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5279 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5280 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005281 }
5282
Sanket Padawe356d7632015-06-22 14:03:32 -07005283 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005284 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5285 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005286 try {
5287 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5288 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005289 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5290 }
5291
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005292 final long identity = Binder.clearCallingIdentity();
5293 try {
5294 final Phone phone = getPhone(subId);
5295 if (phone == null) {
5296 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5297 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005298 return TelephonyProperties.lte_on_cdma_device()
5299 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005300 }
5301 } finally {
5302 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005303 }
Wink Saville36469e72014-06-11 15:17:00 -07005304 }
5305
Wink Saville36469e72014-06-11 15:17:00 -07005306 /**
5307 * {@hide}
5308 * Returns Default subId, 0 in the case of single standby.
5309 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005310 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005311 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005312 }
5313
Shishir Agrawala9f32182016-04-12 12:00:16 -07005314 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005315 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005316 }
5317
Wink Savilleb564aae2014-10-23 10:18:09 -07005318 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005319 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005320 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005321
Pengquan Menge92a50d2018-09-21 15:54:48 -07005322 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08005323 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
5324 return SubscriptionManagerService.getInstance().isActiveSubId(subId,
5325 mApp.getOpPackageName(), mApp.getFeatureId());
5326 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005327 return mSubscriptionController.isActiveSubId(subId);
5328 }
5329
Ihab Awadf2177b72013-11-25 13:33:23 -08005330 /**
5331 * @see android.telephony.TelephonyManager.WifiCallingChoices
5332 */
5333 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005334 final long identity = Binder.clearCallingIdentity();
5335 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005336 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005337 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5338 getWhenToMakeWifiCallsDefaultPreference());
5339 } finally {
5340 Binder.restoreCallingIdentity(identity);
5341 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005342 }
5343
5344 /**
5345 * @see android.telephony.TelephonyManager.WifiCallingChoices
5346 */
5347 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005348 final long identity = Binder.clearCallingIdentity();
5349 try {
5350 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005351 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005352 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5353 } finally {
5354 Binder.restoreCallingIdentity(identity);
5355 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005356 }
5357
Sailesh Nepald1e68152013-12-12 19:08:02 -08005358 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005359 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005360 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005361 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005362
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005363 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5364 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5365 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005366 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005367 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5368 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005369 }
5370 return PhoneFactory.getPhone(phoneId);
5371 }
5372
Shishir Agrawal566b7612013-10-28 14:41:00 -07005373 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005374 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005375 @NonNull IccLogicalChannelRequest request) {
5376 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5377 /*message=*/ "iccOpenLogicalChannel");
5378
5379 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5380 // Verify that the callingPackage in the request belongs to the calling UID
5381 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5382
5383 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005384 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005385
Rambo Wanga1782702021-11-10 20:15:19 -08005386 private Phone getPhoneFromValidIccLogicalChannelRequest(
5387 @NonNull IccLogicalChannelRequest request, String message) {
5388 Phone phone;
5389 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5390 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5391 mApp, request.subId, message);
5392 phone = getPhoneFromSubId(request.subId);
5393 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5394 enforceModifyPermission();
5395 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5396 } else {
5397 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005398 }
Rambo Wanga1782702021-11-10 20:15:19 -08005399 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005400 }
5401
5402 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005403 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005404 final long identity = Binder.clearCallingIdentity();
5405 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005406 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005407 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005408 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5409 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005410 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5411 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005412 loge("The calling package is not allowed to access ISD-R.");
5413 throw new SecurityException(
5414 "The calling package is not allowed to access ISD-R.");
5415 }
Derek Tan740e1672017-06-27 14:56:27 -07005416 }
Derek Tan740e1672017-06-27 14:56:27 -07005417
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005418 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005419 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5420 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421 return response;
5422 } finally {
5423 Binder.restoreCallingIdentity(identity);
5424 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005425 }
5426
5427 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005428 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5429 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5430 /*message=*/"iccCloseLogicalChannel");
5431
5432 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5433
5434 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005435 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005436
Rambo Wanga1782702021-11-10 20:15:19 -08005437 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5438 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005439 // before this feature is enabled, this API should only return false if
5440 // the operation fails instead of throwing runtime exception for
5441 // backward-compatibility.
5442 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5443 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005444 final long identity = Binder.clearCallingIdentity();
5445 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005446 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005447 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005448 }
Chen Xue9d737e2022-01-01 23:41:31 -08005449 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005450 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005451 Boolean success = false;
5452 if (result instanceof RuntimeException) {
5453 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005454 if (shouldThrowExceptionOnFailure) {
5455 throw (RuntimeException) result;
5456 } else {
5457 return false;
5458 }
Chen Xue9d737e2022-01-01 23:41:31 -08005459 } else if (result instanceof Boolean) {
5460 success = (Boolean) result;
5461 } else {
5462 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5463 }
Rambo Wanga1782702021-11-10 20:15:19 -08005464 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005465 return success;
5466 } finally {
5467 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005468 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005469 }
5470
5471 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005472 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005473 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5475 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005476 if (DBG) {
5477 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5478 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5479 + p3 + " data=" + data);
5480 }
5481 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5482 command, p1, p2, p3, data);
5483 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005484
Jordan Liu4c733742019-02-28 12:03:40 -08005485 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005486 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5487 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005488 enforceModifyPermission();
5489 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005490 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5491 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5492 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005493 }
5494 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005495 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5496 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005497 }
5498
5499 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5500 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005501 final long identity = Binder.clearCallingIdentity();
5502 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005503 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005504 return "";
5505 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005506
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005507 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005508 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5509 null /* workSource */);
5510 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005511
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005512 // Append the returned status code to the end of the response payload.
5513 String s = Integer.toHexString(
5514 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5515 if (response.payload != null) {
5516 s = IccUtils.bytesToHexString(response.payload) + s;
5517 }
5518 return s;
5519 } finally {
5520 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005521 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005522 }
Jake Hambye994d462014-02-03 13:10:13 -08005523
Evan Charltonc66da362014-05-16 14:06:40 -07005524 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005525 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5526 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5528 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005529 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005530 if (DBG) {
5531 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5532 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5533 }
5534 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5535 cla, command, p1, p2, p3, data);
5536 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005537
Jordan Liu4c733742019-02-28 12:03:40 -08005538 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005539 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5540 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005541 enforceModifyPermission();
5542 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5543 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005544 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5545 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5546 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005547 }
5548
5549 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005550 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5551 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005552 }
5553
5554 // open APDU basic channel assuming the caller has sufficient permissions
5555 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5556 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005557 final long identity = Binder.clearCallingIdentity();
5558 try {
5559 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5560 && TextUtils.equals(ISDR_AID, data)) {
5561 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005562 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5563 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564 if (bestComponent == null
5565 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5566 loge("The calling package is not allowed to select ISD-R.");
5567 throw new SecurityException(
5568 "The calling package is not allowed to select ISD-R.");
5569 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005570 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005571
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005572 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005573 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5574 null /* workSource */);
5575 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005576
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005577 // Append the returned status code to the end of the response payload.
5578 String s = Integer.toHexString(
5579 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5580 if (response.payload != null) {
5581 s = IccUtils.bytesToHexString(response.payload) + s;
5582 }
5583 return s;
5584 } finally {
5585 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005586 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005587 }
5588
5589 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005590 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005591 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5593 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005594
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005595 final long identity = Binder.clearCallingIdentity();
5596 try {
5597 if (DBG) {
5598 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5599 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5600 }
5601
5602 IccIoResult response =
5603 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5604 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5605 subId);
5606
5607 if (DBG) {
5608 log("Exchange SIM_IO [R]" + response);
5609 }
5610
5611 byte[] result = null;
5612 int length = 2;
5613 if (response.payload != null) {
5614 length = 2 + response.payload.length;
5615 result = new byte[length];
5616 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5617 } else {
5618 result = new byte[length];
5619 }
5620
5621 result[length - 1] = (byte) response.sw2;
5622 result[length - 2] = (byte) response.sw1;
5623 return result;
5624 } finally {
5625 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005626 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005627 }
5628
Nathan Haroldb3014052017-01-25 15:57:32 -08005629 /**
5630 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5631 * on a particular subscription
5632 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005633 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5634 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005635 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005636 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005637 return null;
5638 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005639
5640 final long identity = Binder.clearCallingIdentity();
5641 try {
5642 if (appType != TelephonyManager.APPTYPE_USIM
5643 && appType != TelephonyManager.APPTYPE_SIM) {
5644 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5645 return null;
5646 }
5647 Object response = sendRequest(
5648 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5649 if (response instanceof String[]) {
5650 return (String[]) response;
5651 }
yincheng zhao2737e882019-09-06 17:06:54 -07005652 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005653 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005654 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005655 } finally {
5656 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005657 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005658 }
5659
yincheng zhao2737e882019-09-06 17:06:54 -07005660 /**
5661 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5662 * subscription.
5663 *
5664 * @param subId the id of the subscription.
5665 * @param appType the uicc app type, must be USIM or SIM.
5666 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5667 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005668 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005669 * @return number of fplmns that is successfully written to the SIM.
5670 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005671 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5672 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005673 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5674 mApp, subId, "setForbiddenPlmns");
5675
yincheng zhao2737e882019-09-06 17:06:54 -07005676 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5677 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5678 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5679 }
5680 if (fplmns == null) {
5681 throw new IllegalArgumentException("Fplmn List provided is null");
5682 }
5683 for (String fplmn : fplmns) {
5684 if (!CellIdentity.isValidPlmn(fplmn)) {
5685 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5686 }
5687 }
5688 final long identity = Binder.clearCallingIdentity();
5689 try {
5690 Object response = sendRequest(
5691 CMD_SET_FORBIDDEN_PLMNS,
5692 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5693 subId);
5694 return (int) response;
5695 } finally {
5696 Binder.restoreCallingIdentity(identity);
5697 }
5698 }
5699
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005700 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005701 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5703 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005704
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005705 final long identity = Binder.clearCallingIdentity();
5706 try {
5707 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5708 if (response.payload == null) {
5709 return "";
5710 }
Evan Charltonc66da362014-05-16 14:06:40 -07005711
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005712 // Append the returned status code to the end of the response payload.
5713 String s = Integer.toHexString(
5714 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5715 s = IccUtils.bytesToHexString(response.payload) + s;
5716 return s;
5717 } finally {
5718 Binder.restoreCallingIdentity(identity);
5719 }
Evan Charltonc66da362014-05-16 14:06:40 -07005720 }
5721
Jake Hambye994d462014-02-03 13:10:13 -08005722 /**
5723 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5724 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5725 *
5726 * @param itemID the ID of the item to read
5727 * @return the NV item as a String, or null on error.
5728 */
5729 @Override
5730 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005731 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005732 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5733 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005734
5735 final long identity = Binder.clearCallingIdentity();
5736 try {
5737 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005738 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005739 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5740 return value;
5741 } finally {
5742 Binder.restoreCallingIdentity(identity);
5743 }
Jake Hambye994d462014-02-03 13:10:13 -08005744 }
5745
5746 /**
5747 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5748 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5749 *
5750 * @param itemID the ID of the item to read
5751 * @param itemValue the value to write, as a String
5752 * @return true on success; false on any failure
5753 */
5754 @Override
5755 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005756 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005757 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5758 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005759
5760 final long identity = Binder.clearCallingIdentity();
5761 try {
5762 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5763 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005764 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5766 return success;
5767 } finally {
5768 Binder.restoreCallingIdentity(identity);
5769 }
Jake Hambye994d462014-02-03 13:10:13 -08005770 }
5771
5772 /**
5773 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5774 * Used for device configuration by some CDMA operators.
5775 *
5776 * @param preferredRoamingList byte array containing the new PRL
5777 * @return true on success; false on any failure
5778 */
5779 @Override
5780 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5782 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005783
5784 final long identity = Binder.clearCallingIdentity();
5785 try {
5786 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5787 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5788 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5789 return success;
5790 } finally {
5791 Binder.restoreCallingIdentity(identity);
5792 }
Jake Hambye994d462014-02-03 13:10:13 -08005793 }
5794
5795 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005796 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005797 * Used for device configuration by some CDMA operators.
5798 *
chen xu6dac5ab2018-10-26 17:39:23 -07005799 * @param slotIndex - device slot.
5800 *
Jake Hambye994d462014-02-03 13:10:13 -08005801 * @return true on success; false on any failure
5802 */
5803 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005804 public boolean resetModemConfig(int slotIndex) {
5805 Phone phone = PhoneFactory.getPhone(slotIndex);
5806 if (phone != null) {
5807 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5808 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005809
chen xu6dac5ab2018-10-26 17:39:23 -07005810 final long identity = Binder.clearCallingIdentity();
5811 try {
5812 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5813 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5814 return success;
5815 } finally {
5816 Binder.restoreCallingIdentity(identity);
5817 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005818 }
chen xu6dac5ab2018-10-26 17:39:23 -07005819 return false;
5820 }
5821
5822 /**
5823 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5824 *
5825 * @param slotIndex - device slot.
5826 *
5827 * @return true on success; false on any failure
5828 */
5829 @Override
5830 public boolean rebootModem(int slotIndex) {
5831 Phone phone = PhoneFactory.getPhone(slotIndex);
5832 if (phone != null) {
5833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5834 mApp, phone.getSubId(), "rebootModem");
5835
5836 final long identity = Binder.clearCallingIdentity();
5837 try {
5838 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5839 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5840 return success;
5841 } finally {
5842 Binder.restoreCallingIdentity(identity);
5843 }
5844 }
5845 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005846 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005847
Brad Ebinger51f743a2017-01-23 13:50:20 -08005848 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005849 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5850 * {@link #disableIms(int)}.
5851 * @param slotIndex device slot.
5852 */
5853 public void resetIms(int slotIndex) {
5854 enforceModifyPermission();
5855
5856 final long identity = Binder.clearCallingIdentity();
5857 try {
5858 if (mImsResolver == null) {
5859 // may happen if the does not support IMS.
5860 return;
5861 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00005862 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005863 } finally {
5864 Binder.restoreCallingIdentity(identity);
5865 }
5866 }
5867
5868 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005869 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5870 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005871 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005872 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005873 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005874
5875 final long identity = Binder.clearCallingIdentity();
5876 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005877 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005878 // may happen if the device does not support IMS.
5879 return;
5880 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005881 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882 } finally {
5883 Binder.restoreCallingIdentity(identity);
5884 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005885 }
5886
5887 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005888 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5889 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005890 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005891 public void disableIms(int slotId) {
5892 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005893
5894 final long identity = Binder.clearCallingIdentity();
5895 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005896 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005897 // may happen if the device does not support IMS.
5898 return;
5899 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005900 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005901 } finally {
5902 Binder.restoreCallingIdentity(identity);
5903 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005904 }
5905
5906 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005907 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5908 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005909 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005910 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005911 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005912 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005913
5914 final long identity = Binder.clearCallingIdentity();
5915 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005916 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005917 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5918 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005919 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005920 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005921 } finally {
5922 Binder.restoreCallingIdentity(identity);
5923 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005924 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005925 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005926 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5927 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005928 @Override
5929 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005930 enforceModifyPermission();
5931
5932 final long identity = Binder.clearCallingIdentity();
5933 try {
5934 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005935 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005936 } finally {
5937 Binder.restoreCallingIdentity(identity);
5938 }
5939 }
5940
5941 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005942 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005943 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005944 */
5945 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5946 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005947
5948 final long identity = Binder.clearCallingIdentity();
5949 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005950 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005951 // may happen if the device does not support IMS.
5952 return null;
5953 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005954 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005955 } finally {
5956 Binder.restoreCallingIdentity(identity);
5957 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005958 }
5959
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005960 /**
5961 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005962 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005963 */
5964 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5965 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005966
5967 final long identity = Binder.clearCallingIdentity();
5968 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005969 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005970 // may happen if the device does not support IMS.
5971 return null;
5972 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005973 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005974 } finally {
5975 Binder.restoreCallingIdentity(identity);
5976 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005977 }
5978
Brad Ebinger884c07b2018-02-15 16:17:40 -08005979 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005980 * Sets the ImsService Package Name that Telephony will bind to.
5981 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005982 * @param slotIndex the slot ID that the ImsService should bind for.
5983 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005984 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005985 * @param featureTypes An integer array of feature types associated with a packageName.
5986 * @param packageName The name of the package that the current configuration will be replaced
5987 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005988 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005989 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005990 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5991 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08005992 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005993 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08005994 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005995
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005996 final long identity = Binder.clearCallingIdentity();
5997 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005998 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005999 // may happen if the device does not support IMS.
6000 return false;
6001 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006002 Map<Integer, String> featureConfig = new HashMap<>();
6003 for (int featureType : featureTypes) {
6004 featureConfig.put(featureType, packageName);
6005 }
6006 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6007 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006008 } finally {
6009 Binder.restoreCallingIdentity(identity);
6010 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006011 }
6012
6013 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006014 * Clears any carrier ImsService overrides for the slot index specified that were previously
6015 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6016 *
6017 * This should only be used for testing.
6018 *
6019 * @param slotIndex the slot ID that the ImsService should bind for.
6020 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6021 */
6022 @Override
6023 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006024 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6025 "clearCarrierImsServiceOverride");
6026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006027 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006028
6029 final long identity = Binder.clearCallingIdentity();
6030 try {
6031 if (mImsResolver == null) {
6032 // may happen if the device does not support IMS.
6033 return false;
6034 }
6035 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6036 } finally {
6037 Binder.restoreCallingIdentity(identity);
6038 }
6039 }
6040
6041 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006042 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006043 *
6044 * @param slotId The slot that the ImsService is associated with.
6045 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6046 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006047 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006048 * @return the package name of the ImsService configuration.
6049 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006050 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6051 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006052 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006053 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6054 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006056 final long identity = Binder.clearCallingIdentity();
6057 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006058 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006059 // may happen if the device does not support IMS.
6060 return "";
6061 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006062 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006063 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6064 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006065 } finally {
6066 Binder.restoreCallingIdentity(identity);
6067 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006068 }
6069
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006070 /**
6071 * Get the MmTelFeature state associated with the requested subscription id.
6072 * @param subId The subscription that the MmTelFeature is associated with.
6073 * @param callback A callback with an integer containing the
6074 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6075 */
6076 @Override
6077 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6078 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006079 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6080 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6081 "IMS not available on device.");
6082 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006083 final long token = Binder.clearCallingIdentity();
6084 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006085 int slotId = getSlotIndex(subId);
6086 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6087 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6088 + subId + "'");
6089 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6090 }
6091 verifyImsMmTelConfiguredOrThrow(slotId);
6092 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6093 try {
6094 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6095 } catch (RemoteException e) {
6096 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6097 + "Ignore");
6098 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006099 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006100 } catch (ImsException e) {
6101 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006102 } finally {
6103 Binder.restoreCallingIdentity(token);
6104 }
6105 }
6106
Daniel Brightbb5840b2021-01-12 15:48:18 -08006107 /**
6108 * Sets the ims registration state on all valid {@link Phone}s.
6109 */
6110 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006111 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112
6113 final long identity = Binder.clearCallingIdentity();
6114 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006115 // NOTE: Before S, this method only set the default phone.
6116 for (final Phone phone : PhoneFactory.getPhones()) {
6117 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6118 phone.setImsRegistrationState(registered);
6119 }
6120 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006121 } finally {
6122 Binder.restoreCallingIdentity(identity);
6123 }
Wink Saville36469e72014-06-11 15:17:00 -07006124 }
6125
6126 /**
Stuart Scott54788802015-03-30 13:18:01 -07006127 * Set the network selection mode to automatic.
6128 *
6129 */
6130 @Override
6131 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006132 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6133 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134
6135 final long identity = Binder.clearCallingIdentity();
6136 try {
shilufc958392020-01-20 11:36:01 -08006137 if (!isActiveSubscription(subId)) {
6138 return;
6139 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006140 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006141 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6142 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006143 } finally {
6144 Binder.restoreCallingIdentity(identity);
6145 }
Stuart Scott54788802015-03-30 13:18:01 -07006146 }
6147
Jack Yud10cdd42020-09-28 20:28:01 -07006148 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006149 * Ask the radio to connect to the input network and change selection mode to manual.
6150 *
6151 * @param subId the id of the subscription.
6152 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6153 * the operator to attach to.
6154 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6155 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6156 * normal network selection next time.
6157 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006158 */
6159 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006160 public boolean setNetworkSelectionModeManual(
6161 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6163 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006164
Jack Yu285100e2022-12-02 22:48:35 -08006165 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006166 if (!isActiveSubscription(subId)) {
6167 return false;
6168 }
6169
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006170 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006171 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006172 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006173 if (DBG) {
6174 log("setNetworkSelectionModeManual: subId: " + subId
6175 + " operator: " + operatorInfo);
6176 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006177 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6178 } finally {
6179 Binder.restoreCallingIdentity(identity);
6180 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006181 }
shilu84f6e8b2019-12-19 13:58:01 -08006182 /**
6183 * Get the manual network selection
6184 *
6185 * @param subId the id of the subscription.
6186 *
6187 * @return the previously saved user selected PLMN
6188 */
6189 @Override
6190 public String getManualNetworkSelectionPlmn(int subId) {
6191 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006192 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006193 mApp, subId, "getManualNetworkSelectionPlmn");
6194
6195 final long identity = Binder.clearCallingIdentity();
6196 try {
6197 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006198 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006199 }
6200
6201 final Phone phone = getPhone(subId);
6202 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006203 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006204 }
6205 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6206 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6207 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6208 } finally {
6209 Binder.restoreCallingIdentity(identity);
6210 }
6211 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006212
6213 /**
6214 * Scans for available networks.
6215 */
6216 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006217 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6218 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6220 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006221 LocationAccessPolicy.LocationPermissionResult locationResult =
6222 LocationAccessPolicy.checkLocationPermission(mApp,
6223 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6224 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006225 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006226 .setCallingPid(Binder.getCallingPid())
6227 .setCallingUid(Binder.getCallingUid())
6228 .setMethod("getCellNetworkScanResults")
6229 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006230 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6231 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006232 .build());
6233 switch (locationResult) {
6234 case DENIED_HARD:
6235 throw new SecurityException("Not allowed to access scan results -- location");
6236 case DENIED_SOFT:
6237 return null;
6238 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006239
Pengquan Menga1bb6272018-09-06 09:59:22 -07006240 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006241 try {
6242 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006243 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006244 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006245 } finally {
6246 Binder.restoreCallingIdentity(identity);
6247 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006248 }
6249
6250 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006251 * Get the call forwarding info, given the call forwarding reason.
6252 */
6253 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006254 public void getCallForwarding(int subId, int callForwardingReason,
6255 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006256 enforceReadPrivilegedPermission("getCallForwarding");
6257 long identity = Binder.clearCallingIdentity();
6258 try {
6259 if (DBG) {
6260 log("getCallForwarding: subId " + subId
6261 + " callForwardingReason" + callForwardingReason);
6262 }
Hall Liu27d24262020-09-18 19:04:59 -07006263
6264 Phone phone = getPhone(subId);
6265 if (phone == null) {
6266 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006267 callback.onError(
6268 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006269 } catch (RemoteException e) {
6270 // ignore
6271 }
6272 return;
6273 }
6274
6275 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6276 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6277 @Override
6278 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6279 try {
6280 callback.onCallForwardingInfoAvailable(info);
6281 } catch (RemoteException e) {
6282 // ignore
6283 }
6284 }
6285
6286 @Override
6287 public void onError(int error) {
6288 try {
6289 callback.onError(error);
6290 } catch (RemoteException e) {
6291 // ignore
6292 }
6293 }
6294 });
6295 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006296 } finally {
6297 Binder.restoreCallingIdentity(identity);
6298 }
6299 }
6300
6301 /**
6302 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6303 * reason, the number to forward, and the timeout before the forwarding is attempted.
6304 */
6305 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006306 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6307 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006308 enforceModifyPermission();
6309 long identity = Binder.clearCallingIdentity();
6310 try {
6311 if (DBG) {
6312 log("setCallForwarding: subId " + subId
6313 + " callForwardingInfo" + callForwardingInfo);
6314 }
Hall Liu27d24262020-09-18 19:04:59 -07006315
6316 Phone phone = getPhone(subId);
6317 if (phone == null) {
6318 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006319 callback.accept(
6320 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006321 } catch (RemoteException e) {
6322 // ignore
6323 }
6324 return;
6325 }
6326
6327 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6328 FunctionalUtils.ignoreRemoteException(callback::accept));
6329
6330 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006331 } finally {
6332 Binder.restoreCallingIdentity(identity);
6333 }
6334 }
6335
6336 /**
Hall Liu27d24262020-09-18 19:04:59 -07006337 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006338 */
6339 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006340 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006341 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006342 long identity = Binder.clearCallingIdentity();
6343 try {
Hall Liu27d24262020-09-18 19:04:59 -07006344 Phone phone = getPhone(subId);
6345 if (phone == null) {
6346 try {
6347 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6348 } catch (RemoteException e) {
6349 // ignore
6350 }
6351 return;
6352 }
SongFerngWang0e767992021-03-31 22:08:45 +08006353 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6354 PersistableBundle c = configManager.getConfigForSubId(subId);
6355 boolean requireUssd = c.getBoolean(
6356 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006357
Shuo Qian4a594052020-01-23 11:59:30 -08006358 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006359 if (requireUssd) {
6360 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6361 getSubscriptionCarrierId(subId));
6362 String newUssdCommand = "";
6363 try {
6364 newUssdCommand = carrierXmlParser.getFeature(
6365 CarrierXmlParser.FEATURE_CALL_WAITING)
6366 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6367 } catch (NullPointerException e) {
6368 loge("Failed to generate USSD number" + e);
6369 }
6370 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6371 mMainThreadHandler, callback, carrierXmlParser,
6372 CarrierXmlParser.SsEntry.SSAction.QUERY);
6373 final String ussdCommand = newUssdCommand;
6374 Executors.newSingleThreadExecutor().execute(() -> {
6375 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6376 });
6377 } else {
6378 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6379 callback::accept);
6380 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6381 }
Shuo Qian4a594052020-01-23 11:59:30 -08006382 } finally {
6383 Binder.restoreCallingIdentity(identity);
6384 }
6385 }
6386
6387 /**
Hall Liu27d24262020-09-18 19:04:59 -07006388 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006389 */
6390 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006391 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006392 enforceModifyPermission();
6393 long identity = Binder.clearCallingIdentity();
6394 try {
Hall Liu27d24262020-09-18 19:04:59 -07006395 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6396
6397 Phone phone = getPhone(subId);
6398 if (phone == null) {
6399 try {
6400 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6401 } catch (RemoteException e) {
6402 // ignore
6403 }
6404 return;
6405 }
6406
SongFerngWang0e767992021-03-31 22:08:45 +08006407 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6408 PersistableBundle c = configManager.getConfigForSubId(subId);
6409 boolean requireUssd = c.getBoolean(
6410 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006411
SongFerngWang0e767992021-03-31 22:08:45 +08006412 if (DBG) log("getCallWaitingStatus: subId " + subId);
6413 if (requireUssd) {
6414 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6415 getSubscriptionCarrierId(subId));
6416 CarrierXmlParser.SsEntry.SSAction ssAction =
6417 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6418 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6419 String newUssdCommand = "";
6420 try {
6421 newUssdCommand = carrierXmlParser.getFeature(
6422 CarrierXmlParser.FEATURE_CALL_WAITING)
6423 .makeCommand(ssAction, null);
6424 } catch (NullPointerException e) {
6425 loge("Failed to generate USSD number" + e);
6426 }
6427 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6428 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6429 final String ussdCommand = newUssdCommand;
6430 Executors.newSingleThreadExecutor().execute(() -> {
6431 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6432 });
6433 } else {
6434 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6435 FunctionalUtils.ignoreRemoteException(callback::accept));
6436
6437 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6438 }
Shuo Qian4a594052020-01-23 11:59:30 -08006439 } finally {
6440 Binder.restoreCallingIdentity(identity);
6441 }
6442 }
6443
6444 /**
yinxub1bed742017-04-17 11:45:04 -07006445 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006446 *
yinxub1bed742017-04-17 11:45:04 -07006447 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006448 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6449 * location related information which will be sent if the caller already possess
6450 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006451 * @param request contains the radio access networks with bands/channels to scan
6452 * @param messenger callback messenger for scan results or errors
6453 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006454 * @return the id of the requested scan which can be used to stop the scan.
6455 */
6456 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006457 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6458 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006459 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6461 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006462 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006463 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6464 if (!renounceFineLocationAccess) {
6465 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6466 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6467 .setCallingPackage(callingPackage)
6468 .setCallingFeatureId(callingFeatureId)
6469 .setCallingPid(Binder.getCallingPid())
6470 .setCallingUid(Binder.getCallingUid())
6471 .setMethod("requestNetworkScan")
6472 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6473 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6474 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6475 .build());
6476 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006477 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006478 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6479 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006480 if (e != null) {
6481 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6482 throw e;
6483 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006484 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006485 return TelephonyScanManager.INVALID_SCAN_ID;
6486 }
6487 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006488 }
Hall Liu912dfd32019-04-25 14:02:26 -07006489 int callingUid = Binder.getCallingUid();
6490 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006491 final long identity = Binder.clearCallingIdentity();
6492 try {
6493 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006494 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006495 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006496 } finally {
6497 Binder.restoreCallingIdentity(identity);
6498 }
yinxu504e1392017-04-12 16:03:22 -07006499 }
6500
Hall Liub2ac8ef2019-02-28 15:56:23 -08006501 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006502 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006503 boolean hasCarrierPriv;
6504 final long identity = Binder.clearCallingIdentity();
6505 try {
6506 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6507 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6508 } finally {
6509 Binder.restoreCallingIdentity(identity);
6510 }
Hall Liu558027f2019-05-15 19:14:05 -07006511 boolean hasNetworkScanPermission =
6512 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6513 == PERMISSION_GRANTED;
6514
6515 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6516 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6517 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006518 }
6519
6520 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6521 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006522 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6523 return new SecurityException("Specific channels must not be"
6524 + " scanned without location access.");
6525 }
6526 }
6527 }
6528
Hall Liub2ac8ef2019-02-28 15:56:23 -08006529 return null;
6530 }
6531
yinxu504e1392017-04-12 16:03:22 -07006532 /**
6533 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006534 *
6535 * @param subId id of the subscription
6536 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006537 */
6538 @Override
6539 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6541 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006542
Hall Liu912dfd32019-04-25 14:02:26 -07006543 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006544 final long identity = Binder.clearCallingIdentity();
6545 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006546 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006547 } finally {
6548 Binder.restoreCallingIdentity(identity);
6549 }
yinxu504e1392017-04-12 16:03:22 -07006550 }
6551
6552 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006553 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006554 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006555 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006556 */
6557 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006558 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006559 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006560 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006561 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562
6563 final long identity = Binder.clearCallingIdentity();
6564 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006565 if (DBG) log("getAllowedNetworkTypesBitmask");
6566 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6567 int networkTypesBitmask = (result != null ? result[0] : -1);
6568 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6569 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006570 } finally {
6571 Binder.restoreCallingIdentity(identity);
6572 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006573 }
6574
6575 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006576 * Get the allowed network types for certain reason.
6577 *
6578 * @param subId the id of the subscription.
6579 * @param reason the reason the allowed network type change is taking place
6580 * @return the allowed network types.
6581 */
6582 @Override
6583 public long getAllowedNetworkTypesForReason(int subId,
6584 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006585 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006586 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006587 final long identity = Binder.clearCallingIdentity();
6588 try {
6589 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6590 } finally {
6591 Binder.restoreCallingIdentity(identity);
6592 }
6593 }
6594
6595 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006596 * Enable/Disable E-UTRA-NR Dual Connectivity
6597 * @param subId subscription id of the sim card
6598 * @param nrDualConnectivityState expected NR dual connectivity state
6599 * This can be passed following states
6600 * <ol>
6601 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6602 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6603 * <li>Disable NR dual connectivity and force secondary cell to be released
6604 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6605 * </ol>
6606 * @return operation result.
6607 */
6608 @Override
6609 public int setNrDualConnectivityState(int subId,
6610 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6611 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6612 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006613 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006614 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6615 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6616 }
6617
Sooraj Sasindran37444802020-08-11 10:40:43 -07006618 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6619 final long identity = Binder.clearCallingIdentity();
6620 try {
6621 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6622 nrDualConnectivityState, subId,
6623 workSource);
6624 if (DBG) log("enableNRDualConnectivity result: " + result);
6625 return result;
6626 } finally {
6627 Binder.restoreCallingIdentity(identity);
6628 }
6629 }
6630
6631 /**
6632 * Is E-UTRA-NR Dual Connectivity enabled
6633 * @return true if dual connectivity is enabled else false
6634 */
6635 @Override
6636 public boolean isNrDualConnectivityEnabled(int subId) {
6637 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006638 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006639 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006640 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006641 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6642 return false;
6643 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006644 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6645 final long identity = Binder.clearCallingIdentity();
6646 try {
6647 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6648 null, subId, workSource);
6649 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6650 return isEnabled;
6651 } finally {
6652 Binder.restoreCallingIdentity(identity);
6653 }
6654 }
6655
6656 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006657 * Set the allowed network types of the device and
6658 * provide the reason triggering the allowed network change.
6659 *
6660 * @param subId the id of the subscription.
6661 * @param reason the reason the allowed network type change is taking place
6662 * @param allowedNetworkTypes the allowed network types.
6663 * @return true on success; false on any failure.
6664 */
6665 @Override
6666 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006667 @TelephonyManager.AllowedNetworkTypesReason int reason,
6668 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006669 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6670 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006671 // If the caller only has carrier privileges, then they should not be able to override
6672 // any network types which were set for security reasons.
6673 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6674 != PERMISSION_GRANTED
6675 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6676 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6677 throw new SecurityException(
6678 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6679 + " reason "
6680 + reason);
6681 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006682 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006683 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6684 return false;
6685 }
6686 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6687 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006688 return false;
6689 }
6690
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006691 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6692 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6693
6694
6695 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6696 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6697 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006698 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006699
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006700 final long identity = Binder.clearCallingIdentity();
6701 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006702 Boolean success = (Boolean) sendRequest(
6703 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6704 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6705
6706 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6707 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006708 } finally {
6709 Binder.restoreCallingIdentity(identity);
6710 }
6711 }
6712
6713 /**
Miaoa84611c2019-03-15 09:21:10 +08006714 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006715 *
Miaoa84611c2019-03-15 09:21:10 +08006716 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006717 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006718 * @hide
6719 */
6720 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006721 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006722 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006723 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006724 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006725 try {
Miaoa84611c2019-03-15 09:21:10 +08006726 if (phone != null) {
6727 return phone.hasMatchedTetherApnSetting();
6728 } else {
6729 return false;
6730 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006731 } finally {
6732 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006733 }
Junda Liu475951f2014-11-07 16:45:03 -08006734 }
6735
6736 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006737 * Get the user enabled state of Mobile Data.
6738 *
6739 * TODO: remove and use isUserDataEnabled.
6740 * This can't be removed now because some vendor codes
6741 * calls through ITelephony directly while they should
6742 * use TelephonyManager.
6743 *
6744 * @return true on enabled
6745 */
6746 @Override
6747 public boolean getDataEnabled(int subId) {
6748 return isUserDataEnabled(subId);
6749 }
6750
6751 /**
6752 * Get whether mobile data is enabled per user setting.
6753 *
6754 * There are other factors deciding whether mobile data is actually enabled, but they are
6755 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006756 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006757 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6758 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006759 *
6760 * @return {@code true} if data is enabled else {@code false}
6761 */
6762 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006763 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006764 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006765 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006766 try {
6767 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6768 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006769 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006770 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6771 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006772 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006774 mApp, subId, functionName);
6775
Robert Greenwalt646120a2014-05-23 11:54:03 -07006776 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006777
6778 final long identity = Binder.clearCallingIdentity();
6779 try {
Jack Yu285100e2022-12-02 22:48:35 -08006780 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006781 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6782 Phone phone = PhoneFactory.getPhone(phoneId);
6783 if (phone != null) {
6784 boolean retVal = phone.isUserDataEnabled();
6785 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6786 return retVal;
6787 } else {
6788 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6789 return false;
6790 }
6791 } finally {
6792 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006793 }
6794 }
6795
6796 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006797 * Checks if the device is capable of mobile data by considering whether whether the
6798 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6799 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006800 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006801 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006802 */
6803 @Override
6804 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006805 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006806 try {
6807 try {
6808 mApp.enforceCallingOrSelfPermission(
6809 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006810 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006811 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006812 try {
6813 mApp.enforceCallingOrSelfPermission(
6814 android.Manifest.permission.READ_PHONE_STATE,
6815 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006816 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006817 mApp.enforceCallingOrSelfPermission(
6818 permission.READ_BASIC_PHONE_STATE, functionName);
6819 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006820 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006821 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006822 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006823 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006824
6825 final long identity = Binder.clearCallingIdentity();
6826 try {
Jack Yu285100e2022-12-02 22:48:35 -08006827 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006828 Phone phone = PhoneFactory.getPhone(phoneId);
6829 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006830 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006831 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006832 return retVal;
6833 } else {
6834 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6835 return false;
6836 }
6837 } finally {
6838 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006839 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006840 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006841
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006842 /**
6843 * Check if data is enabled for a specific reason
6844 * @param subId Subscription index
6845 * @param reason the reason the data enable change is taking place
6846 * @return {@code true} if the overall data is enabled; {@code false} if not.
6847 */
6848 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006849 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006850 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006851 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006852 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006853 try {
6854 mApp.enforceCallingOrSelfPermission(
6855 android.Manifest.permission.ACCESS_NETWORK_STATE,
6856 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006857 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006858 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6859 functionName);
6860 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006861 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006862 try {
6863 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006864 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006865 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006867 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006868 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006869 }
6870
6871
6872 final long identity = Binder.clearCallingIdentity();
6873 try {
Jack Yu285100e2022-12-02 22:48:35 -08006874 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006875 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006876 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006877 + " reason=" + reason);
6878 }
6879 Phone phone = PhoneFactory.getPhone(phoneId);
6880 if (phone != null) {
6881 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006882 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006883 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006884 return retVal;
6885 } else {
6886 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006887 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006888 + subId + " retVal=false");
6889 }
6890 return false;
6891 }
6892 } finally {
6893 Binder.restoreCallingIdentity(identity);
6894 }
6895 }
6896
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006897 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006898 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006899 // No permission needed; this only lets the caller inspect their own status.
6900 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006901 }
Junda Liu29340342014-07-10 15:23:27 -07006902
6903 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006904 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006905 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006906 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6907 }
6908
6909 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6910 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006911 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006912 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006913 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6914 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006915 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6916 if (cpt == null) {
6917 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006918 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6919 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006920 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006921 }
6922
6923 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006924 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006925 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006926 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006927 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006928 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006929 Phone phone = getPhone(subId);
6930 if (phone == null) {
6931 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6932 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6933 }
6934 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6935 if (cpt == null) {
6936 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006937 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6938 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006939 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006940 }
6941
6942 @Override
6943 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006944 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006945 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6946 }
6947
6948 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006949 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006950 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006951 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006952 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006953 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6954 Phone phone = PhoneFactory.getPhone(phoneId);
6955 if (phone == null) {
6956 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006957 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006958 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6959 if (cpt == null) {
6960 continue;
6961 }
6962 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006963 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6964 break;
6965 }
6966 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006967 return result;
Junda Liu29340342014-07-10 15:23:27 -07006968 }
Derek Tan89e89d42014-07-08 17:00:10 -07006969
6970 @Override
Junda Liue64de782015-04-16 17:19:16 -07006971 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006972 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006973 Phone phone = PhoneFactory.getPhone(phoneId);
6974 if (phone == null) {
6975 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006976 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006977 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6978 if (cpt == null) {
6979 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006980 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006981 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006982 }
6983
Amith Yamasani6e118872016-02-19 12:53:51 -08006984 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006985 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006986 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006987 Phone phone = PhoneFactory.getPhone(phoneId);
6988 if (phone == null) {
6989 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006990 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006991 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6992 if (cpt == null) {
6993 return Collections.emptyList();
6994 }
6995 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006996 }
6997
chen xuf7e9fe82019-05-09 19:31:02 -07006998 @Override
6999 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007000 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007001 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007002 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007003 try {
7004 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7005 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7006 }
7007 } finally {
7008 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007009 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007010 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007011 }
7012
Rambo Wang6812ffb2022-03-15 16:54:17 -07007013 @Override
7014 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7015 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7016
7017 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7018 if (phone == null) {
7019 return null;
7020 }
7021 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7022 if (cpt == null) {
7023 return null;
7024 }
7025 return cpt.getCarrierServicePackageName();
7026 }
7027
Wink Savilleb564aae2014-10-23 10:18:09 -07007028 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007029 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007030 UiccPort port = phone == null ? null : phone.getUiccPort();
7031 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007032 return null;
7033 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007034 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007035 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007036 return null;
7037 }
7038 return iccId;
7039 }
7040
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007041 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007042 public void setCallComposerStatus(int subId, int status) {
7043 enforceModifyPermission();
7044
7045 final long identity = Binder.clearCallingIdentity();
7046 try {
7047 Phone phone = getPhone(subId);
7048 if (phone != null) {
7049 Phone defaultPhone = phone.getImsPhone();
7050 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7051 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7052 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007053 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7054 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007055 }
7056 }
Shuo Qian284ae752020-12-22 19:10:14 -08007057 } catch (ImsException e) {
7058 throw new ServiceSpecificException(e.getCode());
7059 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007060 Binder.restoreCallingIdentity(identity);
7061 }
7062 }
7063
7064 @Override
7065 public int getCallComposerStatus(int subId) {
7066 enforceReadPrivilegedPermission("getCallComposerStatus");
7067
7068 final long identity = Binder.clearCallingIdentity();
7069 try {
7070 Phone phone = getPhone(subId);
7071 if (phone != null) {
7072 Phone defaultPhone = phone.getImsPhone();
7073 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7074 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7075 return imsPhone.getCallComposerStatus();
7076 }
7077 }
7078 } finally {
7079 Binder.restoreCallingIdentity(identity);
7080 }
7081 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7082 }
7083
7084 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007085 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7086 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007087 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007088 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007090 final long identity = Binder.clearCallingIdentity();
7091 try {
7092 final String iccId = getIccId(subId);
7093 final Phone phone = getPhone(subId);
7094 if (phone == null) {
7095 return false;
7096 }
7097 final String subscriberId = phone.getSubscriberId();
7098
7099 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007100 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007101 + subscriberId + " to " + number);
7102 }
7103
7104 if (TextUtils.isEmpty(iccId)) {
7105 return false;
7106 }
7107
7108 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7109
7110 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7111 if (alphaTag == null) {
7112 editor.remove(alphaTagPrefKey);
7113 } else {
7114 editor.putString(alphaTagPrefKey, alphaTag);
7115 }
7116
7117 // Record both the line number and IMSI for this ICCID, since we need to
7118 // track all merged IMSIs based on line number
7119 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7120 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7121 if (number == null) {
7122 editor.remove(numberPrefKey);
7123 editor.remove(subscriberPrefKey);
7124 } else {
7125 editor.putString(numberPrefKey, number);
7126 editor.putString(subscriberPrefKey, subscriberId);
7127 }
7128
7129 editor.commit();
7130 return true;
7131 } finally {
7132 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007133 }
Derek Tan7226c842014-07-02 17:42:23 -07007134 }
7135
7136 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007137 public String getLine1NumberForDisplay(int subId, String callingPackage,
7138 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007139 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007140 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007141 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007142 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007143 return null;
7144 }
Derek Tan97ebb422014-09-05 16:55:38 -07007145
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007146 final long identity = Binder.clearCallingIdentity();
7147 try {
7148 String iccId = getIccId(subId);
7149 if (iccId != null) {
7150 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7151 if (DBG_MERGE) {
7152 log("getLine1NumberForDisplay returning "
7153 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7154 }
7155 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007156 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007157 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7158 return null;
7159 } finally {
7160 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007161 }
Derek Tan7226c842014-07-02 17:42:23 -07007162 }
7163
7164 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007165 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7166 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007167 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007168 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007169 return null;
7170 }
Derek Tan97ebb422014-09-05 16:55:38 -07007171
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007172 final long identity = Binder.clearCallingIdentity();
7173 try {
7174 String iccId = getIccId(subId);
7175 if (iccId != null) {
7176 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7177 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7178 }
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 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007184
7185 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007186 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7187 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007188 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7189 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007190 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007191 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007192 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007193 return null;
7194 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007195
Jordan Liub49b04b2019-05-06 14:45:15 -07007196 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7197 // the process, where TelephonyManager was instantiated.
7198 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007199 final long identity = Binder.clearCallingIdentity();
7200 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007201 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007202 final TelephonyManager tele = TelephonyManager.from(context);
7203 final SubscriptionManager sub = SubscriptionManager.from(context);
7204
7205 // Figure out what subscribers are currently active
7206 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007207
Jordan Liub49b04b2019-05-06 14:45:15 -07007208 // Only consider subs which match the current subId
7209 // This logic can be simplified. See b/131189269 for progress.
7210 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007211 activeSubscriberIds.add(tele.getSubscriberId(subId));
7212 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007213
7214 // First pass, find a number override for an active subscriber
7215 String mergeNumber = null;
7216 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7217 for (String key : prefs.keySet()) {
7218 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7219 final String subscriberId = (String) prefs.get(key);
7220 if (activeSubscriberIds.contains(subscriberId)) {
7221 final String iccId = key.substring(
7222 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7223 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7224 mergeNumber = (String) prefs.get(numberKey);
7225 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007226 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007227 + " for active subscriber " + subscriberId);
7228 }
7229 if (!TextUtils.isEmpty(mergeNumber)) {
7230 break;
7231 }
7232 }
7233 }
7234 }
7235
7236 // Shortcut when no active merged subscribers
7237 if (TextUtils.isEmpty(mergeNumber)) {
7238 return null;
7239 }
7240
7241 // Second pass, find all subscribers under that line override
7242 final ArraySet<String> result = new ArraySet<>();
7243 for (String key : prefs.keySet()) {
7244 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7245 final String number = (String) prefs.get(key);
7246 if (mergeNumber.equals(number)) {
7247 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7248 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7249 final String subscriberId = (String) prefs.get(subscriberKey);
7250 if (!TextUtils.isEmpty(subscriberId)) {
7251 result.add(subscriberId);
7252 }
7253 }
7254 }
7255 }
7256
7257 final String[] resultArray = result.toArray(new String[result.size()]);
7258 Arrays.sort(resultArray);
7259 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007260 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007261 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7262 }
7263 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007264 } finally {
7265 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007266 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007267 }
7268
7269 @Override
zoey chen38003472019-12-13 17:16:31 +08007270 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7271 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007272
7273 final long identity = Binder.clearCallingIdentity();
7274 try {
7275 final TelephonyManager telephonyManager = mApp.getSystemService(
7276 TelephonyManager.class);
7277 String subscriberId = telephonyManager.getSubscriberId(subId);
7278 if (subscriberId == null) {
7279 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007280 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007281 + subId);
7282 }
7283 return null;
7284 }
7285
Jack Yu285100e2022-12-02 22:48:35 -08007286 ParcelUuid groupUuid;
7287 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7288 final SubscriptionInfo info = SubscriptionManagerService.getInstance()
7289 .getSubscriptionInfo(subId);
7290 groupUuid = info.getGroupUuid();
7291 } else {
7292 final SubscriptionInfo info = mSubscriptionController
7293 .getSubscriptionInfo(subId);
7294 groupUuid = info.getGroupUuid();
7295 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007296 // If it doesn't belong to any group, return just subscriberId of itself.
7297 if (groupUuid == null) {
7298 return new String[]{subscriberId};
7299 }
7300
7301 // Get all subscriberIds from the group.
7302 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007303 List<SubscriptionInfo> groupInfos;
7304 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7305 groupInfos = SubscriptionManagerService.getInstance()
7306 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7307 mApp.getAttributionTag());
7308 } else {
7309 groupInfos = mSubscriptionController
7310 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7311 mApp.getAttributionTag());
7312 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007313 for (SubscriptionInfo subInfo : groupInfos) {
7314 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7315 if (subscriberId != null) {
7316 mergedSubscriberIds.add(subscriberId);
7317 }
7318 }
7319
7320 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7321 } finally {
7322 Binder.restoreCallingIdentity(identity);
7323
7324 }
7325 }
7326
7327 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007328 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007329 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007330 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007331
7332 final long identity = Binder.clearCallingIdentity();
7333 try {
7334 final Phone phone = getPhone(subId);
7335 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7336 } finally {
7337 Binder.restoreCallingIdentity(identity);
7338 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007339 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007340
7341 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007342 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007343 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7344 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007345 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7346 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007347
7348 final long identity = Binder.clearCallingIdentity();
7349 try {
7350 final Phone phone = getPhone(subId);
7351 if (phone == null) {
7352 return false;
7353 }
7354 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7355 cdmaNonRoamingList);
7356 } finally {
7357 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007358 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007359 }
7360
7361 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007362 @Deprecated
7363 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7364 enforceModifyPermission();
7365
7366 int returnValue = 0;
7367 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007368 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007369 if(result.exception == null) {
7370 if (result.result != null) {
7371 byte[] responseData = (byte[])(result.result);
7372 if(responseData.length > oemResp.length) {
7373 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7374 responseData.length + "bytes. Buffer Size is " +
7375 oemResp.length + "bytes.");
7376 }
7377 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7378 returnValue = responseData.length;
7379 }
7380 } else {
7381 CommandException ex = (CommandException) result.exception;
7382 returnValue = ex.getCommandError().ordinal();
7383 if(returnValue > 0) returnValue *= -1;
7384 }
7385 } catch (RuntimeException e) {
7386 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7387 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7388 if(returnValue > 0) returnValue *= -1;
7389 }
7390
7391 return returnValue;
7392 }
7393
7394 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007395 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007396 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007397 try {
7398 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007399 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007400 mApp, phone.getSubId(), "getRadioAccessFamily");
7401 } catch (SecurityException e) {
7402 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7403 throw e;
7404 }
chen xub97461a2018-10-26 14:17:57 -07007405 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007406 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007407 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007408 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007409 final long identity = Binder.clearCallingIdentity();
7410 try {
chen xub97461a2018-10-26 14:17:57 -07007411 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007412 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007413 mApp, phone.getSubId(), "getRadioAccessFamily");
7414 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007415 } finally {
7416 Binder.restoreCallingIdentity(identity);
7417 }
chen xub97461a2018-10-26 14:17:57 -07007418 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007419 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007420
7421 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007422 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007423 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007424 try {
7425 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7426 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007427 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007428 }
7429 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007430 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007431 }
7432 RoleManager rm = mApp.getSystemService(RoleManager.class);
7433 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7434 if (!dialerRoleHolders.contains(callingPackage)) {
7435 throw new SecurityException("App must be the dialer role holder to"
7436 + " upload a call composer pic");
7437 }
7438
7439 Executors.newSingleThreadExecutor().execute(() -> {
7440 ByteArrayOutputStream output = new ByteArrayOutputStream(
7441 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7442 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7443 boolean readUntilEnd = false;
7444 int totalBytesRead = 0;
7445 byte[] buffer = new byte[16 * 1024];
7446 while (true) {
7447 int numRead;
7448 try {
7449 numRead = input.read(buffer);
7450 } catch (IOException e) {
7451 try {
7452 fd.checkError();
7453 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7454 null);
7455 } catch (IOException e1) {
7456 // This means that the other side closed explicitly with an error. If this
7457 // happens, log and ignore.
7458 loge("Remote end of call composer picture pipe closed: " + e1);
7459 }
7460 break;
7461 }
7462 if (numRead == -1) {
7463 readUntilEnd = true;
7464 break;
7465 }
7466 totalBytesRead += numRead;
7467 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7468 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7469 try {
7470 input.close();
7471 } catch (IOException e) {
7472 // ignore
7473 }
7474 break;
7475 }
7476 output.write(buffer, 0, numRead);
7477 }
7478 // Generally, the remote end will close the file descriptors. The only case where we
7479 // close is above, where the picture size is too big.
7480
7481 try {
7482 fd.checkError();
7483 } catch (IOException e) {
7484 loge("Remote end for call composer closed with an error: " + e);
7485 return;
7486 }
7487
Hall Liuaa4211e2021-01-20 15:43:39 -08007488 if (!readUntilEnd) {
7489 loge("Did not finish reading entire image; aborting");
7490 return;
7491 }
Hall Liu82694d52020-12-11 18:22:04 -08007492
Hall Liuaa4211e2021-01-20 15:43:39 -08007493 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7494 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7495 new CallComposerPictureTransfer.Factory() {},
7496 imageData,
7497 (result) -> {
7498 if (result.first != null) {
7499 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7500 Bundle outputResult = new Bundle();
7501 outputResult.putParcelable(
7502 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7503 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7504 outputResult);
7505 } else {
7506 callback.send(result.second, null);
7507 }
7508 }
7509 );
Hall Liu82694d52020-12-11 18:22:04 -08007510 });
7511 }
7512
7513 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007514 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007515 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007516 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007517
7518 final long identity = Binder.clearCallingIdentity();
7519 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007520 ImsManager.getInstance(defaultPhone.getContext(),
7521 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522 } finally {
7523 Binder.restoreCallingIdentity(identity);
7524 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007525 }
7526
7527 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007528 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007529 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007530 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7531 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007532 return false;
7533 }
Svet Ganovb320e182015-04-16 12:30:10 -07007534
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007535 final long identity = Binder.clearCallingIdentity();
7536 try {
7537 // Check the user preference and the system-level IMS setting. Even if the user has
7538 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7539 // In the long run, we may instead need to check if there exists a connection service
7540 // which can support video calling.
7541 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007542 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007543 return imsManager.isVtEnabledByPlatform()
7544 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7545 && imsManager.isVtEnabledByUser();
7546 } finally {
7547 Binder.restoreCallingIdentity(identity);
7548 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007549 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007550
Andrew Leea1239f22015-03-02 17:44:07 -08007551 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007552 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7553 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007554 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007555 mApp, subId, callingPackage, callingFeatureId,
7556 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007557 return false;
7558 }
7559
7560 final long identity = Binder.clearCallingIdentity();
7561 try {
7562 CarrierConfigManager configManager =
7563 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007564 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007565 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7566 } finally {
7567 Binder.restoreCallingIdentity(identity);
7568 }
Andrew Leea1239f22015-03-02 17:44:07 -08007569 }
7570
7571 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007572 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007573 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007574 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007575 return false;
7576 }
7577
7578 final long identity = Binder.clearCallingIdentity();
7579 try {
7580 CarrierConfigManager configManager =
7581 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007582 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007583 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7584 } finally {
7585 Binder.restoreCallingIdentity(identity);
7586 }
Andrew Leea1239f22015-03-02 17:44:07 -08007587 }
7588
Andrew Lee9431b832015-03-09 18:46:45 -07007589 @Override
7590 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007591 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007592 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007593 }
7594
7595 @Override
7596 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007597 final long identity = Binder.clearCallingIdentity();
7598 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007599 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007600 } finally {
7601 Binder.restoreCallingIdentity(identity);
7602 }
Andrew Lee9431b832015-03-09 18:46:45 -07007603 }
7604
Hall Liuf6668912018-10-31 17:05:23 -07007605 /**
7606 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7607 * support for the feature and device firmware support.
7608 *
7609 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7610 */
7611 @Override
7612 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007613 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007614 final Phone phone = getPhone(subscriptionId);
7615 if (phone == null) {
7616 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7617 return false;
7618 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007619 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007620 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007621 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7622 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007623 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007624 return isCarrierSupported && isDeviceSupported;
7625 } finally {
7626 Binder.restoreCallingIdentity(identity);
7627 }
Hall Liu98187582018-01-22 19:15:32 -08007628 }
7629
Hall Liuf6668912018-10-31 17:05:23 -07007630 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007631 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7632 * RTT setting, will return true if the device and carrier both support RTT.
7633 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007634 */
7635 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007636 final long identity = Binder.clearCallingIdentity();
7637 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007638 boolean isRttSupported = isRttSupported(subscriptionId);
7639 boolean isUserRttSettingOn = Settings.Secure.getInt(
7640 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7641 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7642 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7643 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007644 } finally {
7645 Binder.restoreCallingIdentity(identity);
7646 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007647 }
7648
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007649 @Deprecated
7650 @Override
7651 public String getDeviceId(String callingPackage) {
7652 return getDeviceIdWithFeature(callingPackage, null);
7653 }
7654
Sanket Padawe7310cc72015-01-14 09:53:20 -08007655 /**
7656 * Returns the unique device ID of phone, for example, the IMEI for
7657 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7658 *
7659 * <p>Requires Permission:
7660 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7661 */
7662 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007663 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007664 try {
7665 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7666 } catch (SecurityException se) {
7667 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7668 throw new SecurityException("Package " + callingPackage + " does not belong to "
7669 + Binder.getCallingUid());
7670 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007671 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007672 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007673 return null;
7674 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007675 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007676 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007677 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007678 return null;
7679 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007680
7681 final long identity = Binder.clearCallingIdentity();
7682 try {
7683 return phone.getDeviceId();
7684 } finally {
7685 Binder.restoreCallingIdentity(identity);
7686 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007687 }
7688
Ping Sunc67b7c22016-03-02 19:16:45 +08007689 /**
7690 * {@hide}
7691 * Returns the IMS Registration Status on a particular subid
7692 *
7693 * @param subId
7694 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007695 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007696 Phone phone = getPhone(subId);
7697 if (phone != null) {
7698 return phone.isImsRegistered();
7699 } else {
7700 return false;
7701 }
7702 }
7703
Santos Cordon7a1885b2015-02-03 11:15:19 -08007704 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007705 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007706 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007707 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007708 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007709 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7710 }
7711 final long identity = Binder.clearCallingIdentity();
7712 try {
7713 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7714 } finally {
7715 Binder.restoreCallingIdentity(identity);
7716 }
7717 }
7718
7719 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007720 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007721 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007722 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007723 mApp,
7724 subscriptionId,
7725 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007726 final long identity = Binder.clearCallingIdentity();
7727 try {
7728 Phone phone = getPhone(subscriptionId);
7729 if (phone == null) {
7730 return null;
7731 }
7732 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7733 } finally {
7734 Binder.restoreCallingIdentity(identity);
7735 }
7736 }
7737
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007738 /**
7739 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007740 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007741 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007742 final long identity = Binder.clearCallingIdentity();
7743 try {
7744 Phone phone = getPhone(subId);
7745 if (phone != null) {
7746 return phone.isWifiCallingEnabled();
7747 } else {
7748 return false;
7749 }
7750 } finally {
7751 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007752 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007753 }
7754
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007755 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007756 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007757 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007758 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007759 final long identity = Binder.clearCallingIdentity();
7760 try {
7761 Phone phone = getPhone(subId);
7762 if (phone != null) {
7763 return phone.isVideoEnabled();
7764 } else {
7765 return false;
7766 }
7767 } finally {
7768 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007769 }
7770 }
7771
7772 /**
7773 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7774 * defined in {@link ImsRegistrationImplBase}.
7775 */
7776 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007777 final long identity = Binder.clearCallingIdentity();
7778 try {
7779 Phone phone = getPhone(subId);
7780 if (phone != null) {
7781 return phone.getImsRegistrationTech();
7782 } else {
7783 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7784 }
7785 } finally {
7786 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007787 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007788 }
7789
Stuart Scott8eef64f2015-04-08 15:13:54 -07007790 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007791 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007792 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007793 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7794 return;
7795 }
Kai Shif70f46f2021-03-03 13:59:46 -08007796 Phone defaultPhone = getDefaultPhone();
7797 if (defaultPhone != null) {
7798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7799 mApp, getDefaultPhone().getSubId(), "factoryReset");
7800 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007801 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007802
Svet Ganovcc087f82015-05-12 20:35:54 -07007803 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007804 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7805 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007806 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007807 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007808 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007809 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007810 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007811 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007812 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007813 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007814 // There has been issues when Sms raw table somehow stores orphan
7815 // fragments. They lead to garbled message when new fragments come
7816 // in and combined with those stale ones. In case this happens again,
7817 // user can reset all network settings which will clean up this table.
7818 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007819 // Clean up IMS settings as well here.
7820 int slotId = getSlotIndex(subId);
7821 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7822 ImsManager.getInstance(mApp, slotId).factoryReset();
7823 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007824
Kai Shif70f46f2021-03-03 13:59:46 -08007825 if (defaultPhone == null) {
7826 return;
7827 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007828 // Erase modem config if erase modem on network setting is enabled.
7829 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7830 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7831 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007832 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007833 }
Kai Shif70f46f2021-03-03 13:59:46 -08007834
7835 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007836 } finally {
7837 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007838 }
7839 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007840
SongFerngWangfd89b102021-05-27 22:44:54 +08007841 @VisibleForTesting
7842 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7843 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7844 return;
7845 }
7846 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7847 RILConstants.PREFERRED_NETWORK_MODE);
7848 SubscriptionManager.setSubscriptionProperty(subId,
7849 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7850 "user=" + defaultNetworkType);
7851 phone.loadAllowedNetworksFromSubscriptionDatabase();
7852 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7853 defaultNetworkType, null);
7854 }
7855
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007856 private void cleanUpSmsRawTable(Context context) {
7857 ContentResolver resolver = context.getContentResolver();
7858 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7859 resolver.delete(uri, null, null);
7860 }
7861
Narayan Kamath1c496c22015-04-16 14:40:19 +01007862 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007863 public String getSimLocaleForSubscriber(int subId) {
7864 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7865 final Phone phone = getPhone(subId);
7866 if (phone == null) {
7867 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007868 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007869 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007870 final long identity = Binder.clearCallingIdentity();
7871 try {
Jack Yu285100e2022-12-02 22:48:35 -08007872 SubscriptionInfo info;
7873 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7874 info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId,
7875 phone.getContext().getOpPackageName(),
7876 phone.getContext().getAttributionTag());
7877 if (info == null) {
7878 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7879 return null;
7880 }
7881 } else {
7882 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
7883 phone.getContext().getOpPackageName(),
7884 phone.getContext().getAttributionTag());
7885 if (info == null) {
7886 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7887 return null;
7888 }
chen xu6291c472019-02-04 12:55:53 -08007889 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007890 // Try and fetch the locale from the carrier properties or from the SIM language
7891 // preferences (EF-PL and EF-LI)...
7892 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007893 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007894 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7895 if (localeFromDefaultSim != null) {
7896 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7897 if (DBG) log("Using locale from subId: " + subId + " locale: "
7898 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08007899 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007900 } else {
7901 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007902 }
7903 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007904
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007905 // The SIM language preferences only store a language (e.g. fr = French), not an
7906 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7907 // the SIM and carrier preferences does not include a country we add the country
7908 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007909 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007910 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007911 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08007912 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007913 }
7914
7915 if (DBG) log("No locale found - returning null");
7916 return null;
7917 } finally {
7918 Binder.restoreCallingIdentity(identity);
7919 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007920 }
7921
tom hsu0b59d292022-09-29 23:49:21 +08007922 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08007923 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08007924 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08007925 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08007926 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08007927 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
7928 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08007929 Locale.forLanguageTag(localeTag).getCountry())) {
7930 return localeTag;
7931 }
7932 }
7933 return inputLocale.toLanguageTag();
7934 }
7935
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007936 /**
7937 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7938 */
7939 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08007940 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7941 return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList(
7942 mApp.getOpPackageName(), mApp.getAttributionTag());
7943 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007944 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007945 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007946 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007947
Gary Jian3aa9a762022-01-24 16:41:19 +08007948 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7949 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007950
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007951 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007952 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7953 * representing the state of the modem.
7954 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007955 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7956 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007957 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007958 */
7959 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007960 public void requestModemActivityInfo(ResultReceiver result) {
7961 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007962 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007963
7964 final long identity = Binder.clearCallingIdentity();
7965 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007966 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007967 } finally {
7968 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007969 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007970 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007971
Siddharth Rayb8114062018-06-17 15:02:38 -07007972 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7973 // less than total activity duration.
7974 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7975 if (info == null) {
7976 return false;
7977 }
7978 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007979 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7980 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7981
Siddharth Rayb8114062018-06-17 15:02:38 -07007982 return (info.isValid()
7983 && (info.getSleepTimeMillis() <= activityDurationMs)
7984 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007985 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007986 && (totalTxTimeMs <= activityDurationMs));
7987 }
7988
Gary Jian3aa9a762022-01-24 16:41:19 +08007989 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7990 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7991 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7992 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7993
7994 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7995 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7996 }
7997
7998 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7999 mLastModemActivityInfo.setReceiveTimeMillis(
8000 rat,
8001 freq,
8002 info.getReceiveTimeMillis(rat, freq)
8003 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8004 }
8005
8006 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8007 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8008 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8009 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8010
8011 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8012 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8013 }
8014 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8015 mLastModemActivityInfo.setReceiveTimeMillis(
8016 rat,
8017 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8018 }
8019
8020 /**
8021 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8022 * @param info recent ModemActivityInfo
8023 */
8024 private void mergeModemActivityInfo(ModemActivityInfo info) {
8025 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008026 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008027 boolean matched;
8028 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8029 matched = false;
8030 int rat = info.getSpecificInfoRat(i);
8031 int freq = info.getSpecificInfoFrequencyRange(i);
8032 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8033 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8034 //if it already exists
8035 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8036 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8037 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8038 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8039 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8040 updateLastModemActivityInfo(info, rat, freq);
8041 matched = true;
8042 }
8043 } else {
8044 updateLastModemActivityInfo(info, rat);
8045 matched = true;
8046 }
8047 }
8048 }
8049
8050 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008051 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008052 new ActivityStatsTechSpecificInfo(
8053 rat,
8054 freq,
8055 info.getTransmitTimeMillis(rat, freq),
8056 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008057 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008058 }
8059 }
8060 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8061 mLastModemActivitySpecificInfo =
8062 new ActivityStatsTechSpecificInfo[merged.size()];
8063 merged.toArray(mLastModemActivitySpecificInfo);
8064
8065 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8066 mLastModemActivityInfo.setSleepTimeMillis(
8067 info.getSleepTimeMillis()
8068 + mLastModemActivityInfo.getSleepTimeMillis());
8069 mLastModemActivityInfo.setIdleTimeMillis(
8070 info.getIdleTimeMillis()
8071 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008072
8073 mLastModemActivityInfo =
8074 new ModemActivityInfo(
8075 mLastModemActivityInfo.getTimestampMillis(),
8076 mLastModemActivityInfo.getSleepTimeMillis(),
8077 mLastModemActivityInfo.getIdleTimeMillis(),
8078 mLastModemActivitySpecificInfo);
8079 }
8080
8081 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8082 ActivityStatsTechSpecificInfo[] info) {
8083 int infoSize = info.length;
8084 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8085 for (int i = 0; i < infoSize; i++) {
8086 ret[i] = new ActivityStatsTechSpecificInfo(
8087 info[i].getRat(), info[i].getFrequencyRange(),
8088 info[i].getTransmitTimeMillis(),
8089 (int) info[i].getReceiveTimeMillis());
8090 }
8091 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008092 }
8093
Jack Yu85bd38a2015-11-09 11:34:32 -08008094 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008095 * Returns the service state information on specified subscription.
8096 */
8097 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008098 public ServiceState getServiceStateForSubscriber(int subId,
8099 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8100 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008101 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008102 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008103 return null;
8104 }
8105
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008106 boolean hasFinePermission = false;
8107 boolean hasCoarsePermission = false;
8108 if (!renounceFineLocationAccess) {
8109 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8110 LocationAccessPolicy.checkLocationPermission(mApp,
8111 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8112 .setCallingPackage(callingPackage)
8113 .setCallingFeatureId(callingFeatureId)
8114 .setCallingPid(Binder.getCallingPid())
8115 .setCallingUid(Binder.getCallingUid())
8116 .setMethod("getServiceStateForSubscriber")
8117 .setLogAsInfo(true)
8118 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8119 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8120 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8121 .build());
8122 hasFinePermission =
8123 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8124 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008125
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008126 if (!renounceCoarseLocationAccess) {
8127 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8128 LocationAccessPolicy.checkLocationPermission(mApp,
8129 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8130 .setCallingPackage(callingPackage)
8131 .setCallingFeatureId(callingFeatureId)
8132 .setCallingPid(Binder.getCallingPid())
8133 .setCallingUid(Binder.getCallingUid())
8134 .setMethod("getServiceStateForSubscriber")
8135 .setLogAsInfo(true)
8136 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8137 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8138 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8139 .build());
8140 hasCoarsePermission =
8141 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8142 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008143
Jack Yu479f40e2020-10-27 21:29:25 -07008144 final Phone phone = getPhone(subId);
8145 if (phone == null) {
8146 return null;
8147 }
8148
Jordan Liu0f2bc442020-11-18 16:47:37 -08008149 final long identity = Binder.clearCallingIdentity();
8150
Jack Yu479f40e2020-10-27 21:29:25 -07008151 boolean isCallingPackageDataService = phone.getDataServicePackages()
8152 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008153 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008154 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008155 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8156 SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance()
8157 .getSubscriptionInfoInternal(subId);
8158 if (subInfo == null || !subInfo.isActive()) {
8159 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8160 + "subId=" + subId);
8161 return null;
8162 }
8163 } else {
8164 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8165 callingFeatureId)) {
8166 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8167 + "subId=" + subId);
8168 return null;
8169 }
Jordan Liuc437b192020-08-17 10:59:12 -07008170 }
8171
Hall Liuf19c44f2018-11-27 14:38:17 -08008172 ServiceState ss = phone.getServiceState();
8173
8174 // Scrub out the location info in ServiceState depending on what level of access
8175 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008176 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008177 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8178 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008179 } finally {
8180 Binder.restoreCallingIdentity(identity);
8181 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008182 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008183
8184 /**
8185 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8186 *
8187 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8188 * voicemail ringtone.
8189 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8190 * PhoneAccount.
8191 */
8192 @Override
8193 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008194 final long identity = Binder.clearCallingIdentity();
8195 try {
8196 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8197 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008198 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008199 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008200
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008201 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8202 } finally {
8203 Binder.restoreCallingIdentity(identity);
8204 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008205 }
8206
8207 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008208 * Sets the per-account voicemail ringtone.
8209 *
8210 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8211 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8212 *
8213 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8214 * voicemail ringtone.
8215 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8216 * PhoneAccount.
8217 */
8218 @Override
8219 public void setVoicemailRingtoneUri(String callingPackage,
8220 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008221 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008222 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008223 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8224 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008225 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8226 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8227 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008228 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008229
8230 final long identity = Binder.clearCallingIdentity();
8231 try {
8232 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8233 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008234 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008235 }
8236 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8237 } finally {
8238 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008239 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008240 }
8241
8242 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008243 * Returns whether vibration is set for voicemail notification in Phone settings.
8244 *
8245 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8246 * voicemail vibration setting.
8247 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8248 */
8249 @Override
8250 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008251 final long identity = Binder.clearCallingIdentity();
8252 try {
8253 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8254 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008255 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008256 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008257
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008258 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8259 } finally {
8260 Binder.restoreCallingIdentity(identity);
8261 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008262 }
8263
Youhan Wange64578a2016-05-02 15:32:42 -07008264 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008265 * Sets the per-account voicemail vibration.
8266 *
8267 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8268 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8269 *
8270 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8271 * voicemail vibration setting.
8272 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8273 * specific PhoneAccount.
8274 */
8275 @Override
8276 public void setVoicemailVibrationEnabled(String callingPackage,
8277 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008278 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008279 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008280 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8281 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008282 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8283 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8284 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008285 }
8286
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008287 final long identity = Binder.clearCallingIdentity();
8288 try {
8289 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8290 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008291 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008292 }
8293 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8294 } finally {
8295 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008296 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008297 }
8298
8299 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008300 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8301 *
8302 * @throws SecurityException if the caller does not have the required permission
8303 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008304 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008305 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008306 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008307 }
8308
8309 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008310 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8311 * permission.
8312 *
8313 * @throws SecurityException if the caller does not have the required permission
8314 */
8315 private void enforceSendSmsPermission() {
8316 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8317 }
8318
8319 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008320 * Make sure either called from same process as self (phone) or IPC caller has interact across
8321 * users permission.
8322 *
8323 * @throws SecurityException if the caller does not have the required permission
8324 */
8325 private void enforceInteractAcrossUsersPermission(String message) {
8326 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8327 }
8328
8329 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008330 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008331 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008332 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008333 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008334 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008335 final long identity = Binder.clearCallingIdentity();
8336 try {
8337 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008338 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008339 if (componentName == null) {
8340 throw new SecurityException(
8341 "Caller not current active visual voicemail package[null]");
8342 }
8343 String vvmPackage = componentName.getPackageName();
8344 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008345 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008346 }
8347 } finally {
8348 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008349 }
8350 }
8351
8352 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008353 * Return the application ID for the app type.
8354 *
8355 * @param subId the subscription ID that this request applies to.
8356 * @param appType the uicc app type.
8357 * @return Application ID for specificied app type, or null if no uicc.
8358 */
8359 @Override
8360 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008361 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008362 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008363
8364 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008365 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008366 if (phone == null) {
8367 return null;
8368 }
8369 String aid = null;
8370 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008371 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008372 .getApplicationByType(appType).getAid();
8373 } catch (Exception e) {
8374 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8375 }
8376 return aid;
8377 } finally {
8378 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008379 }
Youhan Wange64578a2016-05-02 15:32:42 -07008380 }
8381
Youhan Wang4001d252016-05-11 10:29:41 -07008382 /**
8383 * Return the Electronic Serial Number.
8384 *
8385 * @param subId the subscription ID that this request applies to.
8386 * @return ESN or null if error.
8387 */
8388 @Override
8389 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008390 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008391 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008392
8393 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008394 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008395 if (phone == null) {
8396 return null;
8397 }
8398 String esn = null;
8399 try {
8400 esn = phone.getEsn();
8401 } catch (Exception e) {
8402 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8403 }
8404 return esn;
8405 } finally {
8406 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008407 }
Youhan Wang4001d252016-05-11 10:29:41 -07008408 }
8409
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008410 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008411 * Return the Preferred Roaming List Version.
8412 *
8413 * @param subId the subscription ID that this request applies to.
8414 * @return PRLVersion or null if error.
8415 */
8416 @Override
8417 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008418 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008419 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008420
8421 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008422 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008423 if (phone == null) {
8424 return null;
8425 }
8426 String cdmaPrlVersion = null;
8427 try {
8428 cdmaPrlVersion = phone.getCdmaPrlVersion();
8429 } catch (Exception e) {
8430 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8431 }
8432 return cdmaPrlVersion;
8433 } finally {
8434 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008435 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008436 }
8437
8438 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008439 * Get snapshot of Telephony histograms
8440 * @return List of Telephony histograms
8441 * @hide
8442 */
8443 @Override
8444 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8446 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008447
8448 final long identity = Binder.clearCallingIdentity();
8449 try {
8450 return RIL.getTelephonyRILTimingHistograms();
8451 } finally {
8452 Binder.restoreCallingIdentity(identity);
8453 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008454 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008455
8456 /**
8457 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008458 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8459 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008460 * Require system privileges. In the future we may add this to carrier APIs.
8461 *
Michele Berionne482f8202018-11-27 18:57:59 -08008462 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008463 */
8464 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008465 @TelephonyManager.SetCarrierRestrictionResult
8466 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008467 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008468 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008469
Michele Berionne482f8202018-11-27 18:57:59 -08008470 if (carrierRestrictionRules == null) {
8471 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008472 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008473
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008474 final long identity = Binder.clearCallingIdentity();
8475 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008476 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008477 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008478 } finally {
8479 Binder.restoreCallingIdentity(identity);
8480 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008481 }
8482
8483 /**
8484 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008485 * Get the allowed carrier list and the excluded carrier list, including the priority between
8486 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008487 * Require system privileges. In the future we may add this to carrier APIs.
8488 *
Michele Berionne482f8202018-11-27 18:57:59 -08008489 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008490 */
8491 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008492 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008493 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008494 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008495
8496 final long identity = Binder.clearCallingIdentity();
8497 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008498 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8499 if (response instanceof CarrierRestrictionRules) {
8500 return (CarrierRestrictionRules) response;
8501 }
8502 // Response is an Exception of some kind,
8503 // which is signalled to the user as a NULL retval
8504 return null;
8505 } catch (Exception e) {
8506 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8507 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008508 } finally {
8509 Binder.restoreCallingIdentity(identity);
8510 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008511 }
8512
fionaxu59545b42016-05-25 15:53:37 -07008513 /**
fionaxu59545b42016-05-25 15:53:37 -07008514 * Action set from carrier signalling broadcast receivers to enable/disable radio
8515 * @param subId the subscription ID that this action applies to.
8516 * @param enabled control enable or disable radio.
8517 * {@hide}
8518 */
8519 @Override
8520 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8521 enforceModifyPermission();
8522 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008523
8524 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008525 if (phone == null) {
8526 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8527 return;
8528 }
8529 try {
8530 phone.carrierActionSetRadioEnabled(enabled);
8531 } catch (Exception e) {
8532 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008533 } finally {
8534 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008535 }
8536 }
8537
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008538 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008539 * Enable or disable Voice over NR (VoNR)
8540 * @param subId the subscription ID that this action applies to.
8541 * @param enabled enable or disable VoNR.
8542 * @return operation result.
8543 */
8544 @Override
8545 public int setVoNrEnabled(int subId, boolean enabled) {
8546 enforceModifyPermission();
8547 final Phone phone = getPhone(subId);
8548
8549 final long identity = Binder.clearCallingIdentity();
8550 if (phone == null) {
8551 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8552 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8553 }
8554
8555 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8556 try {
8557 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8558 workSource);
8559 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008560
8561 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8562 if (DBG) {
8563 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8564 }
8565 SubscriptionManager.setSubscriptionProperty(
8566 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8567 (enabled ? "1" : "0"));
8568 }
8569
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008570 return result;
8571 } finally {
8572 Binder.restoreCallingIdentity(identity);
8573 }
8574 }
8575
8576 /**
8577 * Is voice over NR enabled
8578 * @return true if VoNR is enabled else false
8579 */
8580 @Override
8581 public boolean isVoNrEnabled(int subId) {
8582 enforceReadPrivilegedPermission("isVoNrEnabled");
8583 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8584 final long identity = Binder.clearCallingIdentity();
8585 try {
8586 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8587 null, subId, workSource);
8588 if (DBG) log("isVoNrEnabled: " + isEnabled);
8589 return isEnabled;
8590 } finally {
8591 Binder.restoreCallingIdentity(identity);
8592 }
8593 }
8594
8595 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008596 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8597 * network status based on which carrier apps could apply actions accordingly,
8598 * enable/disable default url handler for example.
8599 *
8600 * @param subId the subscription ID that this action applies to.
8601 * @param report control start/stop reporting the default network status.
8602 * {@hide}
8603 */
8604 @Override
8605 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8606 enforceModifyPermission();
8607 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008608
8609 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008610 if (phone == null) {
8611 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8612 return;
8613 }
8614 try {
8615 phone.carrierActionReportDefaultNetworkStatus(report);
8616 } catch (Exception e) {
8617 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008618 } finally {
8619 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008620 }
8621 }
8622
8623 /**
fionaxud9622282017-07-17 17:51:30 -07008624 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8625 * @param subId the subscription ID that this action applies to.
8626 * {@hide}
8627 */
8628 @Override
8629 public void carrierActionResetAll(int subId) {
8630 enforceModifyPermission();
8631 final Phone phone = getPhone(subId);
8632 if (phone == null) {
8633 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8634 return;
8635 }
8636 try {
8637 phone.carrierActionResetAll();
8638 } catch (Exception e) {
8639 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8640 }
8641 }
8642
8643 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008644 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8645 * bug report is being generated.
8646 */
8647 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008648 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008649 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8650 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008651 writer.println("Permission Denial: can't dump Phone from pid="
8652 + Binder.getCallingPid()
8653 + ", uid=" + Binder.getCallingUid()
8654 + "without permission "
8655 + android.Manifest.permission.DUMP);
8656 return;
8657 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008658 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008659 }
Jack Yueb89b242016-06-22 13:27:47 -07008660
Brad Ebingerdac2f002018-04-03 15:17:52 -07008661 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008662 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8663 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8664 @NonNull String[] args) {
8665 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8666 this, in.getFileDescriptor(), out.getFileDescriptor(),
8667 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008668 }
8669
Jack Yueb89b242016-06-22 13:27:47 -07008670 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008671 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008672 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008673 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008674 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008675 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008676 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008677 */
8678 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008679 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008680 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008681 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8682 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8683 try {
8684 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008685 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008686 } catch (SecurityException se) {
8687 enforceModifyPermission();
8688 }
8689 } else {
8690 enforceModifyPermission();
8691 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008692
8693 final long identity = Binder.clearCallingIdentity();
8694 try {
8695 Phone phone = getPhone(subId);
8696 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008697 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8698 phone.carrierActionSetMeteredApnsEnabled(enabled);
8699 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008700 phone.getDataSettingsManager().setDataEnabled(
8701 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008702 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008703 }
8704 } finally {
8705 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008706 }
8707 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008708
8709 /**
8710 * Get Client request stats
8711 * @return List of Client Request Stats
8712 * @hide
8713 */
8714 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008715 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8716 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008717 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008718 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008719 return null;
8720 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008721 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008722
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008723 final long identity = Binder.clearCallingIdentity();
8724 try {
8725 if (phone != null) {
8726 return phone.getClientRequestStats();
8727 }
8728
8729 return null;
8730 } finally {
8731 Binder.restoreCallingIdentity(identity);
8732 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008733 }
8734
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008735 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008736 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008737 if (uid == Process.ROOT_UID && packageName == null) {
8738 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8739 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8740 // exception. ROOT_UID seems not to have a valid package name returned by
8741 // PackageManager, so just fake it here to avoid issues when running telephony shell
8742 // commands that plumb through the RIL as root, like so:
8743 // $ adb root
8744 // $ adb shell cmd phone ...
8745 packageName = "root";
8746 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008747 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008748 }
Jack Yueb4124c2017-02-16 15:32:43 -08008749
8750 /**
Grace Chen70990072017-03-24 17:21:30 -07008751 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008752 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008753 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008754 * @param state State of SIM (power down, power up, pass through)
8755 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8756 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8757 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008758 *
8759 **/
8760 @Override
Grace Chen70990072017-03-24 17:21:30 -07008761 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008762 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008763 Phone phone = PhoneFactory.getPhone(slotIndex);
8764
vagdeviaf9a5b92018-08-15 16:01:53 -07008765 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8766
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008767 final long identity = Binder.clearCallingIdentity();
8768 try {
8769 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008770 phone.setSimPowerState(state, null, workSource);
8771 }
8772 } finally {
8773 Binder.restoreCallingIdentity(identity);
8774 }
8775 }
8776
8777 /**
8778 * Set SIM card power state.
8779 *
8780 * @param slotIndex SIM slot id.
8781 * @param state State of SIM (power down, power up, pass through)
8782 * @param callback callback to trigger after success or failure
8783 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8784 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8785 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8786 *
8787 **/
8788 @Override
8789 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8790 IIntegerConsumer callback) {
8791 enforceModifyPermission();
8792 Phone phone = PhoneFactory.getPhone(slotIndex);
8793
8794 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8795
8796 final long identity = Binder.clearCallingIdentity();
8797 try {
8798 if (phone != null) {
8799 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8800 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008801 }
8802 } finally {
8803 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008804 }
8805 }
Shuo Qiandd210312017-04-12 22:11:33 +00008806
Tyler Gunn65d45c22017-06-05 11:22:26 -07008807 private boolean isUssdApiAllowed(int subId) {
8808 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008809 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008810 if (configManager == null) {
8811 return false;
8812 }
8813 PersistableBundle pb = configManager.getConfigForSubId(subId);
8814 if (pb == null) {
8815 return false;
8816 }
8817 return pb.getBoolean(
8818 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8819 }
8820
Shuo Qiandd210312017-04-12 22:11:33 +00008821 /**
8822 * Check if phone is in emergency callback mode
8823 * @return true if phone is in emergency callback mode
8824 * @param subId sub id
8825 */
goneil9c5f4872017-12-05 14:07:56 -08008826 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008827 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008828 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008829 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008830
8831 final long identity = Binder.clearCallingIdentity();
8832 try {
8833 if (phone != null) {
8834 return phone.isInEcm();
8835 } else {
8836 return false;
8837 }
8838 } finally {
8839 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008840 }
8841 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008842
8843 /**
8844 * Get the current signal strength information for the given subscription.
8845 * Because this information is not updated when the device is in a low power state
8846 * it should not be relied-upon to be current.
8847 * @param subId Subscription index
8848 * @return the most recent cached signal strength info from the modem
8849 */
8850 @Override
8851 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008852 final long identity = Binder.clearCallingIdentity();
8853 try {
8854 Phone p = getPhone(subId);
8855 if (p == null) {
8856 return null;
8857 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008858
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008859 return p.getSignalStrength();
8860 } finally {
8861 Binder.restoreCallingIdentity(identity);
8862 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008863 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008864
Pengquan Meng77b7f132018-08-22 14:49:57 -07008865 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008866 * Get the current modem radio state for the given slot.
8867 * @param slotIndex slot index.
8868 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008869 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008870 * @return the current radio power state from the modem
8871 */
8872 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008873 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008874 Phone phone = PhoneFactory.getPhone(slotIndex);
8875 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008876 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8877 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008878 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8879 }
8880
8881 final long identity = Binder.clearCallingIdentity();
8882 try {
8883 return phone.getRadioPowerState();
8884 } finally {
8885 Binder.restoreCallingIdentity(identity);
8886 }
8887 }
8888 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8889 }
8890
8891 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008892 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8893 *
8894 * <p>Requires one of the following permissions:
8895 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008896 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008897 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8898 * privileges.
8899 *
8900 * @param subId subscription id
8901 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8902 * {@code false}.
8903 */
8904 @Override
8905 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008906 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008907 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008908 try {
8909 mApp.enforceCallingOrSelfPermission(
8910 android.Manifest.permission.ACCESS_NETWORK_STATE,
8911 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008912 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008913 mApp.enforceCallingOrSelfPermission(
8914 permission.READ_BASIC_PHONE_STATE, functionName);
8915 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008916 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008917 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008918 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008919 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008920
Pengquan Menga1bb6272018-09-06 09:59:22 -07008921 boolean isEnabled = false;
8922 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008923 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008924 Phone phone = getPhone(subId);
8925 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008926 } finally {
8927 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008928 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008929 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008930 }
8931
8932
8933 /**
8934 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8935 *
8936 * <p> Requires permission:
8937 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8938 * privileges.
8939 *
8940 * @param subId subscription id
8941 * @param isEnabled {@code true} means enable, {@code false} means disable.
8942 */
8943 @Override
8944 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008945 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8946 mApp, subId, "setDataRoamingEnabled");
8947
Pengquan Menga1bb6272018-09-06 09:59:22 -07008948 final long identity = Binder.clearCallingIdentity();
8949 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008950 Phone phone = getPhone(subId);
8951 if (phone != null) {
8952 phone.setDataRoamingEnabled(isEnabled);
8953 }
8954 } finally {
8955 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008956 }
8957 }
8958
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008959 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008960 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008961 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008962 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008963 mApp, subId, "isManualNetworkSelectionAllowed");
8964
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008965 boolean isAllowed = true;
8966 final long identity = Binder.clearCallingIdentity();
8967 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008968 Phone phone = getPhone(subId);
8969 if (phone != null) {
8970 isAllowed = phone.isCspPlmnEnabled();
8971 }
8972 } finally {
8973 Binder.restoreCallingIdentity(identity);
8974 }
8975 return isAllowed;
8976 }
8977
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008978 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8979 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008980 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008981 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008982 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008983 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8984 if (phone == null) {
8985 return false;
8986 }
8987 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8988 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8989 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008990 }
8991
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008992 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008993 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008994 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008995 mApp.getSystemService(AppOpsManager.class)
8996 .checkPackage(Binder.getCallingUid(), callingPackage);
8997
Jordan Liu1e142fc2019-04-22 15:10:43 -07008998 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008999 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009000 try {
9001 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009002 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009003 } catch (SecurityException e) {
9004 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9005 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009006 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08009007 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009008 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009009 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009010 }
sandeepjsb6c87872021-09-27 15:34:44 +00009011 // checking compatibility, if calling app's target SDK is T and beyond.
9012 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9013 Binder.getCallingUid())) {
9014 isIccIdAccessRestricted = true;
9015 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009016 final long identity = Binder.clearCallingIdentity();
9017 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009018 UiccController uiccController = UiccController.getInstance();
9019 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009020 if (hasReadPermission) {
9021 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009022 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009023
9024 // Remove private info if the caller doesn't have access
9025 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9026 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009027 //setting the value after compatibility check
9028 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009029 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9030 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009031 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009032 if (card == null) {
9033 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009034 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009035 continue;
9036 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009037 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9038 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009039 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009040 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009041 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009042 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9043 for (UiccPortInfo portInfo : portInfos) {
9044 UiccPort port = uiccController.getUiccPortForSlot(
9045 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9046 if (port == null) {
9047 // assume no access if port is null
9048 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9049 continue;
9050 }
9051 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9052 uiccPortInfos.add(portInfo);
9053 } else {
9054 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9055 }
9056 }
9057 filteredInfos.add(new UiccCardInfo(
9058 cardInfo.isEuicc(),
9059 cardInfo.getCardId(),
9060 null,
9061 cardInfo.getPhysicalSlotIndex(),
9062 cardInfo.isRemovable(),
9063 cardInfo.isMultipleEnabledProfilesSupported(),
9064 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009065 }
9066 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009067 } finally {
9068 Binder.restoreCallingIdentity(identity);
9069 }
9070 }
9071
sandeepjsb6c87872021-09-27 15:34:44 +00009072 /**
9073 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9074 * generally private and require carrier privileges to view.
9075 *
9076 * @hide
9077 */
9078 @NonNull
9079 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9080 List<UiccPortInfo> portinfo = new ArrayList<>();
9081 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9082 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9083 }
9084 return new UiccCardInfo(
9085 cardInfo.isEuicc(),
9086 cardInfo.getCardId(),
9087 null,
9088 cardInfo.getPhysicalSlotIndex(),
9089 cardInfo.isRemovable(),
9090 cardInfo.isMultipleEnabledProfilesSupported(),
9091 portinfo
9092 );
9093 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009094
sandeepjsb6c87872021-09-27 15:34:44 +00009095 /**
9096 * @hide
9097 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9098 * These values are generally private and require carrier privileges to view.
9099 */
9100 @NonNull
9101 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9102 return new UiccPortInfo(
9103 UiccPortInfo.ICCID_REDACTED,
9104 portInfo.getPortIndex(),
9105 portInfo.getLogicalSlotIndex(),
9106 portInfo.isActive()
9107 );
9108 }
9109 @Override
9110 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009111 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009112 mApp.getSystemService(AppOpsManager.class)
9113 .checkPackage(Binder.getCallingUid(), callingPackage);
9114
sandeepjsb6c87872021-09-27 15:34:44 +00009115 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009116
Aman Guptaf3c90b32022-03-17 04:54:16 +00009117 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9118 // we are reading iccId which is PII data.
9119 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009120
9121 // checking compatibility, if calling app's target SDK is T and beyond.
9122 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9123 Binder.getCallingUid())) {
9124 isLogicalSlotAccessRestricted = true;
9125 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009126 final long identity = Binder.clearCallingIdentity();
9127 try {
9128 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009129 if (slots == null || slots.length == 0) {
9130 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009131 return null;
9132 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009133 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9134 for (int i = 0; i < slots.length; i++) {
9135 UiccSlot slot = slots[i];
9136 if (slot == null) {
9137 continue;
9138 }
9139
Jordan Liu7be7e652019-05-06 18:55:02 +00009140 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009141 UiccCard card = slot.getUiccCard();
9142 if (card != null) {
9143 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009144 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009145 cardId = slot.getEid();
9146 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009147 // If cardId is null, use iccId of default port as cardId.
9148 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009149 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009150 }
9151
Jordan Liu857451f2019-05-09 16:35:35 -07009152 if (cardId != null) {
9153 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9154 // if cardId is an EID, it's all digits so this is fine
9155 cardId = IccUtils.stripTrailingFs(cardId);
9156 }
9157
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009158 int cardState = 0;
9159 switch (slot.getCardState()) {
9160 case CARDSTATE_ABSENT:
9161 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9162 break;
9163 case CARDSTATE_PRESENT:
9164 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9165 break;
9166 case CARDSTATE_ERROR:
9167 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9168 break;
9169 case CARDSTATE_RESTRICTED:
9170 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9171 break;
9172 default:
9173 break;
9174
9175 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009176 List<UiccPortInfo> portInfos = new ArrayList<>();
9177 int[] portIndexes = slot.getPortList();
9178 for (int portIdx : portIndexes) {
9179 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009180 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009181 portInfos.add(new UiccPortInfo(iccId, portIdx,
9182 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009183 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009184 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009185 slot.isEuicc(),
9186 cardId,
9187 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009188 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009189 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009190 //setting the value after compatibility check
9191 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009192 }
9193 return infos;
9194 } finally {
9195 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009196 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009197 }
9198
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009199 /* Returns null if doesn't have read permission or carrier privilege access. */
9200 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9201 boolean hasReadPermission) {
9202 String iccId = slot.getIccId(portIndex);
9203 if (hasReadPermission) { // if has read permission
9204 return iccId;
9205 } else {
9206 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9207 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9208 // if no read permission, checking carrier privilege access
9209 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9210 return iccId;
9211 }
9212 }
9213 }
9214 // No read permission or carrier privilege access.
9215 return UiccPortInfo.ICCID_REDACTED;
9216 }
9217
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009218 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009219 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009220 public boolean switchSlots(int[] physicalSlots) {
9221 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009222
9223 final long identity = Binder.clearCallingIdentity();
9224 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009225 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9226 for (int i = 0; i < physicalSlots.length; i++) {
9227 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9228 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9229 physicalSlots[i], i));
9230 }
9231 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009232 } finally {
9233 Binder.restoreCallingIdentity(identity);
9234 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009235 }
Jack Yu4c988042018-02-27 15:30:01 -08009236
9237 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009238 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9239 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9240 enforceModifyPermission();
9241
9242 final long identity = Binder.clearCallingIdentity();
9243 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009244 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009245 } finally {
9246 Binder.restoreCallingIdentity(identity);
9247 }
9248 }
9249
9250 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009251 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009252 final long identity = Binder.clearCallingIdentity();
9253 try {
9254 return UiccController.getInstance().getCardIdForDefaultEuicc();
9255 } finally {
9256 Binder.restoreCallingIdentity(identity);
9257 }
9258 }
9259
Pengquan Meng85728fb2018-03-12 16:31:21 -07009260 /**
goneil47ffb6e2018-04-06 15:40:58 -07009261 * A test API to reload the UICC profile.
9262 *
9263 * <p>Requires that the calling app has permission
9264 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9265 * @hide
9266 */
9267 @Override
9268 public void refreshUiccProfile(int subId) {
9269 enforceModifyPermission();
9270
9271 final long identity = Binder.clearCallingIdentity();
9272 try {
9273 Phone phone = getPhone(subId);
9274 if (phone == null) {
9275 return;
9276 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009277 UiccPort uiccPort = phone.getUiccPort();
9278 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009279 return;
9280 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009281 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009282 if (uiccProfile == null) {
9283 return;
9284 }
9285 uiccProfile.refresh();
9286 } finally {
9287 Binder.restoreCallingIdentity(identity);
9288 }
9289 }
9290
9291 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009292 * Returns false if the mobile data is disabled by default, otherwise return true.
9293 */
9294 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009295 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009296 }
9297
9298 /**
9299 * Returns true if the data roaming is enabled by default, i.e the system property
9300 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9301 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9302 */
9303 private boolean getDefaultDataRoamingEnabled(int subId) {
9304 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009305 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009306 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009307 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9308 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9309 return isDataRoamingEnabled;
9310 }
9311
9312 /**
9313 * Returns the default network type for the given {@code subId}, if the default network type is
9314 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9315 */
9316 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009317 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009318 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009319 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9320 return list.get(phoneId);
9321 }
9322 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009323 }
fionaxua13278b2018-03-21 00:08:13 -07009324
9325 @Override
9326 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009327 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009328 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009329
9330 final long identity = Binder.clearCallingIdentity();
9331 try {
9332 final Phone phone = getPhone(subId);
9333 if (phone == null) {
9334 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9335 return;
9336 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009337 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9338 if (cpt != null) {
9339 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9340 }
9341 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009342 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9343 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009344 if (carrierPrivilegeRules == null) {
9345 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9346 } else {
9347 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9348 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009349 } finally {
9350 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009351 }
fionaxua13278b2018-03-21 00:08:13 -07009352 }
9353
9354 @Override
9355 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009356 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009357
9358 final long identity = Binder.clearCallingIdentity();
9359 try {
9360 final Phone phone = getPhone(subId);
9361 if (phone == null) {
9362 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9363 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9364 }
9365 return phone.getCarrierIdListVersion();
9366 } finally {
9367 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009368 }
fionaxua13278b2018-03-21 00:08:13 -07009369 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009370
9371 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009372 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9373 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009374 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009375 mApp, subId, callingPackage, callingFeatureId,
9376 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009377 return -1;
9378 }
9379
9380 final long identity = Binder.clearCallingIdentity();
9381 try {
9382 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9383 } finally {
9384 Binder.restoreCallingIdentity(identity);
9385 }
9386 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009387
9388 @Override
9389 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009390 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009391 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009392 mApp, subId, "getCdmaRoamingMode");
9393
9394 final long identity = Binder.clearCallingIdentity();
9395 try {
9396 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9397 } finally {
9398 Binder.restoreCallingIdentity(identity);
9399 }
9400 }
9401
9402 @Override
9403 public boolean setCdmaRoamingMode(int subId, int mode) {
9404 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9405 mApp, subId, "setCdmaRoamingMode");
9406
9407 final long identity = Binder.clearCallingIdentity();
9408 try {
9409 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9410 } finally {
9411 Binder.restoreCallingIdentity(identity);
9412 }
9413 }
9414
9415 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009416 public int getCdmaSubscriptionMode(int subId) {
9417 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009418 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009419 mApp, subId, "getCdmaSubscriptionMode");
9420
9421 final long identity = Binder.clearCallingIdentity();
9422 try {
9423 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9424 } finally {
9425 Binder.restoreCallingIdentity(identity);
9426 }
9427 }
9428
9429 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009430 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9431 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9432 mApp, subId, "setCdmaSubscriptionMode");
9433
9434 final long identity = Binder.clearCallingIdentity();
9435 try {
9436 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9437 } finally {
9438 Binder.restoreCallingIdentity(identity);
9439 }
9440 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009441
sqianc5eccab2018-10-19 18:46:41 -07009442 @Override
sqian8c685422019-02-22 15:55:18 -08009443 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009444 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009445 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009446 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9447 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009448 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9449 }
9450 final long identity = Binder.clearCallingIdentity();
9451 try {
sqian854d44b2018-12-12 16:48:18 -08009452 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9453 for (Phone phone: PhoneFactory.getPhones()) {
9454 if (phone.getEmergencyNumberTracker() != null
9455 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9456 emergencyNumberListInternal.put(
9457 phone.getSubId(),
9458 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9459 }
sqian11b7a0e2018-12-05 18:48:28 -08009460 }
sqian854d44b2018-12-12 16:48:18 -08009461 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009462 } finally {
9463 Binder.restoreCallingIdentity(identity);
9464 }
sqianc5eccab2018-10-19 18:46:41 -07009465 }
9466
9467 @Override
sqian8c685422019-02-22 15:55:18 -08009468 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009469 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009470 if (!exactMatch) {
9471 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009472 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009473 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009474 }
9475 final long identity = Binder.clearCallingIdentity();
9476 try {
sqian854d44b2018-12-12 16:48:18 -08009477 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009478 //Note: we ignore passed in param exactMatch. We can remove it once
9479 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009480 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009481 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009482 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009483 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009484 }
sqian11b7a0e2018-12-05 18:48:28 -08009485 }
9486 return false;
9487 } finally {
9488 Binder.restoreCallingIdentity(identity);
9489 }
9490 }
9491
sqianf4ca7ed2019-01-15 18:32:07 -08009492 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009493 * Start emergency callback mode for GsmCdmaPhone for testing.
9494 */
9495 @Override
9496 public void startEmergencyCallbackMode() {
9497 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9498 "startEmergencyCallbackMode");
9499 enforceModifyPermission();
9500 final long identity = Binder.clearCallingIdentity();
9501 try {
9502 for (Phone phone : PhoneFactory.getPhones()) {
9503 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9504 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9505 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9506 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9507 gsmCdmaPhone.obtainMessage(
9508 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9509 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9510 }
9511 }
9512 } finally {
9513 Binder.restoreCallingIdentity(identity);
9514 }
9515 }
9516
9517 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009518 * Update emergency number list for test mode.
9519 */
9520 @Override
9521 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9522 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9523 "updateEmergencyNumberListTestMode");
9524
9525 final long identity = Binder.clearCallingIdentity();
9526 try {
9527 for (Phone phone: PhoneFactory.getPhones()) {
9528 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9529 if (tracker != null) {
9530 tracker.executeEmergencyNumberTestModeCommand(action, num);
9531 }
9532 }
9533 } finally {
9534 Binder.restoreCallingIdentity(identity);
9535 }
9536 }
9537
9538 /**
9539 * Get the full emergency number list for test mode.
9540 */
9541 @Override
9542 public List<String> getEmergencyNumberListTestMode() {
9543 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9544 "getEmergencyNumberListTestMode");
9545
9546 final long identity = Binder.clearCallingIdentity();
9547 try {
9548 Set<String> emergencyNumbers = new HashSet<>();
9549 for (Phone phone: PhoneFactory.getPhones()) {
9550 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9551 if (tracker != null) {
9552 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9553 emergencyNumbers.add(num.getNumber());
9554 }
9555 }
9556 }
9557 return new ArrayList<>(emergencyNumbers);
9558 } finally {
9559 Binder.restoreCallingIdentity(identity);
9560 }
9561 }
9562
chen xud6b45bd2018-10-30 22:27:10 -07009563 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009564 public int getEmergencyNumberDbVersion(int subId) {
9565 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9566
9567 final long identity = Binder.clearCallingIdentity();
9568 try {
9569 final Phone phone = getPhone(subId);
9570 if (phone == null) {
9571 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9572 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9573 }
9574 return phone.getEmergencyNumberDbVersion();
9575 } finally {
9576 Binder.restoreCallingIdentity(identity);
9577 }
9578 }
9579
9580 @Override
9581 public void notifyOtaEmergencyNumberDbInstalled() {
9582 enforceModifyPermission();
9583
9584 final long identity = Binder.clearCallingIdentity();
9585 try {
9586 for (Phone phone: PhoneFactory.getPhones()) {
9587 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9588 if (tracker != null) {
9589 tracker.updateOtaEmergencyNumberDatabase();
9590 }
9591 }
9592 } finally {
9593 Binder.restoreCallingIdentity(identity);
9594 }
9595 }
9596
9597 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009598 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009599 enforceActiveEmergencySessionPermission();
9600
9601 final long identity = Binder.clearCallingIdentity();
9602 try {
9603 for (Phone phone: PhoneFactory.getPhones()) {
9604 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9605 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009606 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9607 }
9608 }
9609 } finally {
9610 Binder.restoreCallingIdentity(identity);
9611 }
9612 }
9613
9614 @Override
9615 public void resetOtaEmergencyNumberDbFilePath() {
9616 enforceActiveEmergencySessionPermission();
9617
9618 final long identity = Binder.clearCallingIdentity();
9619 try {
9620 for (Phone phone: PhoneFactory.getPhones()) {
9621 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9622 if (tracker != null) {
9623 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009624 }
9625 }
9626 } finally {
9627 Binder.restoreCallingIdentity(identity);
9628 }
9629 }
9630
9631 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009632 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9633 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9634 Phone phone = getPhone(subId);
9635 if (phone == null) {
9636 return null;
9637 }
9638 final long identity = Binder.clearCallingIdentity();
9639 try {
9640 UiccProfile profile = UiccController.getInstance()
9641 .getUiccProfileForPhone(phone.getPhoneId());
9642 if (profile != null) {
9643 return profile.getCertsFromCarrierPrivilegeAccessRules();
9644 }
9645 } finally {
9646 Binder.restoreCallingIdentity(identity);
9647 }
9648 return null;
9649 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009650
9651 /**
9652 * Enable or disable a modem stack.
9653 */
9654 @Override
9655 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9656 enforceModifyPermission();
9657
9658 final long identity = Binder.clearCallingIdentity();
9659 try {
9660 Phone phone = PhoneFactory.getPhone(slotIndex);
9661 if (phone == null) {
9662 return false;
9663 } else {
9664 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9665 }
9666 } finally {
9667 Binder.restoreCallingIdentity(identity);
9668 }
9669 }
Michelecea4cf22018-12-21 15:00:11 -08009670
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009671 /**
9672 * Whether a modem stack is enabled or not.
9673 */
9674 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009675 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9676 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009677 Phone phone = PhoneFactory.getPhone(slotIndex);
9678 if (phone == null) return false;
9679
9680 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009681 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9682 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009683 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9684 }
9685
9686 final long identity = Binder.clearCallingIdentity();
9687 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009688 try {
9689 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9690 } catch (NoSuchElementException ex) {
9691 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9692 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009693 } finally {
9694 Binder.restoreCallingIdentity(identity);
9695 }
9696 }
9697
Michelecea4cf22018-12-21 15:00:11 -08009698 @Override
Michele0ea7d782019-03-19 14:58:42 -07009699 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009700 enforceModifyPermission();
9701
9702 final long identity = Binder.clearCallingIdentity();
9703 try {
9704 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009705 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009706 .commit();
9707 } finally {
9708 Binder.restoreCallingIdentity(identity);
9709 }
9710 }
9711
9712 @Override
Michele0ea7d782019-03-19 14:58:42 -07009713 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009714 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009715 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009716 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9717 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009718 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009719 }
Michelecea4cf22018-12-21 15:00:11 -08009720
9721 final long identity = Binder.clearCallingIdentity();
9722 try {
Michele0ea7d782019-03-19 14:58:42 -07009723 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009724 } finally {
9725 Binder.restoreCallingIdentity(identity);
9726 }
9727 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009728
Michele0ea7d782019-03-19 14:58:42 -07009729 @TelephonyManager.IsMultiSimSupportedResult
9730 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009731 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9732 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9733 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009734 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9735 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009736 }
9737 // Check if the hardware supports multisim functionality. If usage of multisim is not
9738 // supported by the modem, indicate that it is restricted.
9739 PhoneCapability staticCapability =
9740 mPhoneConfigurationManager.getStaticPhoneCapability();
9741 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009742 loge("isMultiSimSupportedInternal: no static configuration available");
9743 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009744 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009745 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009746 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9747 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009748 }
9749 // Check if support of multiple SIMs is restricted by carrier
9750 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009751 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009752 }
9753
Michele0ea7d782019-03-19 14:58:42 -07009754 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009755 }
9756
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009757 /**
9758 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009759 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9760 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9761 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009762 * @param numOfSims number of active sims we want to switch to
9763 */
9764 @Override
9765 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009766 if (numOfSims == 1) {
9767 enforceModifyPermission();
9768 } else {
9769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9770 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9771 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009772 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009773
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009774 try {
Michele30b57b22019-03-01 12:01:14 -08009775 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009776 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009777 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9778 return;
9779 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009780 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9781 } finally {
9782 Binder.restoreCallingIdentity(identity);
9783 }
9784 }
9785
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009786 @Override
9787 public boolean isApplicationOnUicc(int subId, int appType) {
9788 enforceReadPrivilegedPermission("isApplicationOnUicc");
9789 Phone phone = getPhone(subId);
9790 if (phone == null) {
9791 return false;
9792 }
9793 final long identity = Binder.clearCallingIdentity();
9794 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009795 UiccPort uiccPort = phone.getUiccPort();
9796 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009797 return false;
9798 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009799 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009800 if (uiccProfile == null) {
9801 return false;
9802 }
9803 if (TelephonyManager.APPTYPE_SIM <= appType
9804 && appType <= TelephonyManager.APPTYPE_ISIM) {
9805 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9806 }
9807 return false;
9808 } finally {
9809 Binder.restoreCallingIdentity(identity);
9810 }
9811 }
9812
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009813 /**
chen xub4baa772019-04-03 10:23:41 -07009814 * Get whether making changes to modem configurations will trigger reboot.
9815 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009816 */
9817 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009818 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9819 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009820 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009821 mApp, subId, callingPackage, callingFeatureId,
9822 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009823 return false;
9824 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009825 final long identity = Binder.clearCallingIdentity();
9826 try {
9827 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9828 } finally {
9829 Binder.restoreCallingIdentity(identity);
9830 }
9831 }
9832
Nathan Harold29f5f052019-02-15 13:41:57 -08009833 private void updateModemStateMetrics() {
9834 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9835 // TODO: check the state for each modem if the api is ready.
9836 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9837 }
9838
Pengquan Meng3889a572019-01-23 11:16:29 -08009839 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009840 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009841 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009842 // Verify that the callingPackage belongs to the calling UID
9843 mApp.getSystemService(AppOpsManager.class)
9844 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009845 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009846 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009847 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009848 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9849 if (slotInfos != null) {
9850 for (int i = 0; i < slotInfos.length; i++) {
9851 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9852 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9853 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9854 portInfo.getLogicalSlotIndex()));
9855 }
9856 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009857 }
9858 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009859 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009860 } finally {
9861 Binder.restoreCallingIdentity(identity);
9862 }
9863 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009864
9865 /**
9866 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +08009867 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -08009868 */
jimsunf9ec1622022-09-13 21:18:43 +08009869 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -08009870 @Override
9871 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +08009872 return getHalVersion(HAL_SERVICE_RADIO);
9873 }
9874
9875 /**
9876 * Get the HAL Version of a specific service
9877 */
9878 @Override
9879 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -08009880 Phone phone = getDefaultPhone();
9881 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +08009882 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -08009883 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9884 return hv.major * 100 + hv.minor;
9885 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009886
9887 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009888 * Get the current calling package name.
9889 * @return the current calling package name
9890 */
9891 @Override
9892 public String getCurrentPackageName() {
9893 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9894 }
9895
9896 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009897 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9898 * corresponding network requests on a subId.
9899 *
9900 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009901 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009902 * 2) APN is un-metered for this subscription, or
9903 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009904 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009905 *
9906 * @return whether data is allowed for a apn type.
9907 *
9908 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009909 */
9910 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009911 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009912 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9913 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009914
9915 // Now that all security checks passes, perform the operation as ourselves.
9916 final long identity = Binder.clearCallingIdentity();
9917 try {
9918 Phone phone = getPhone(subId);
9919 if (phone == null) return false;
9920
Jack Yu27422a52022-03-21 10:38:05 -07009921 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009922 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -07009923 isMetered = phone.getDataNetworkController().getDataConfigManager()
9924 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9925 phone.getServiceState().getDataRoaming());
9926 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009927 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009928 } finally {
9929 Binder.restoreCallingIdentity(identity);
9930 }
9931 }
9932
9933 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009934 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009935 enforceReadPrivilegedPermission("isApnMetered");
9936
9937 // Now that all security checks passes, perform the operation as ourselves.
9938 final long identity = Binder.clearCallingIdentity();
9939 try {
9940 Phone phone = getPhone(subId);
9941 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -07009942 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9943 DataUtils.apnTypeToNetworkCapability(apnType),
9944 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009945 } finally {
9946 Binder.restoreCallingIdentity(identity);
9947 }
9948 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009949
9950 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009951 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9952 int subscriptionId, IBooleanConsumer resultCallback) {
9953 enforceModifyPermission();
9954 long token = Binder.clearCallingIdentity();
9955 try {
9956 Phone phone = getPhone(subscriptionId);
9957 if (phone == null) {
9958 try {
9959 if (resultCallback != null) {
9960 resultCallback.accept(false);
9961 }
9962 } catch (RemoteException e) {
9963 // ignore
9964 }
9965 return;
9966 }
9967 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9968 Pair.create(specifiers, (x) -> {
9969 try {
9970 if (resultCallback != null) {
9971 resultCallback.accept(x);
9972 }
9973 } catch (RemoteException e) {
9974 // ignore
9975 }
9976 });
9977 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9978 } finally {
9979 Binder.restoreCallingIdentity(token);
9980 }
9981 }
9982
9983 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009984 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9985 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009986 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009987 mApp, subId, "getSystemSelectionChannels");
9988 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9989 final long identity = Binder.clearCallingIdentity();
9990 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009991 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9992 if (result instanceof IllegalStateException) {
9993 throw (IllegalStateException) result;
9994 }
9995 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009996 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9997 return specifiers;
9998 } finally {
9999 Binder.restoreCallingIdentity(identity);
10000 }
10001 }
10002
10003 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010004 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010005 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010006 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010007 }
10008
10009 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010010 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10011 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010012 if (callingPackage == null) {
10013 callingPackage = getCurrentPackageName();
10014 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010015 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10016 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010017 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10018 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010019 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10020 }
10021 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10022 Intent intent = new Intent();
10023 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10024 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10025 // Bring up choose default SMS subscription dialog right now
10026 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10027 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10028 mApp.startActivity(intent);
10029 }
chen xud5ca2d52019-05-28 15:20:57 -070010030
10031 @Override
10032 public String getMmsUAProfUrl(int subId) {
10033 //TODO investigate if this API should require proper permission check in R b/133791609
10034 final long identity = Binder.clearCallingIdentity();
10035 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010036 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10037 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10038 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10039 return carrierUAProfUrl;
10040 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010041 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10042 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010043 } finally {
10044 Binder.restoreCallingIdentity(identity);
10045 }
10046 }
10047
10048 @Override
10049 public String getMmsUserAgent(int subId) {
10050 //TODO investigate if this API should require proper permission check in R b/133791609
10051 final long identity = Binder.clearCallingIdentity();
10052 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010053 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10054 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10055 if (!TextUtils.isEmpty(carrierUserAgent)) {
10056 return carrierUserAgent;
10057 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010058 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10059 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010060 } finally {
10061 Binder.restoreCallingIdentity(identity);
10062 }
10063 }
Jack Yub07d4972019-05-28 16:12:25 -070010064
10065 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010066 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10067 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010068
Jack Yub07d4972019-05-28 16:12:25 -070010069 final long identity = Binder.clearCallingIdentity();
10070 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010071 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010072 if (phone == null) return false;
10073
Ling Maf188d502022-09-16 15:22:36 -070010074 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010075 } finally {
10076 Binder.restoreCallingIdentity(identity);
10077 }
10078 }
10079
10080 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010081 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010082 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010083 enforceModifyPermission();
10084
changbettyd5c246e2019-12-24 15:40:37 +080010085 final long identity = Binder.clearCallingIdentity();
10086 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010087 Phone phone = getPhone(subscriptionId);
10088 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010089
Ling Maf188d502022-09-16 15:22:36 -070010090 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010091 } finally {
10092 Binder.restoreCallingIdentity(identity);
10093 }
10094 }
10095
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010096 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010097 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010098 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10099 * otherwise.
10100 */
10101 @Override
10102 public void setCepEnabled(boolean isCepEnabled) {
10103 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10104
10105 final long identity = Binder.clearCallingIdentity();
10106 try {
10107 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10108 for (Phone phone : PhoneFactory.getPhones()) {
10109 Phone defaultPhone = phone.getImsPhone();
10110 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10111 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10112 ImsPhoneCallTracker imsPhoneCallTracker =
10113 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10114 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10115 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10116 + imsPhone.getMsisdn());
10117 }
10118 }
10119 } finally {
10120 Binder.restoreCallingIdentity(identity);
10121 }
10122 }
allenwtsu46dcc572020-01-08 18:24:03 +080010123
10124 /**
10125 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10126 *
10127 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10128 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10129 * before being read.
10130 */
10131 @Override
10132 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10133 isCompressed) {
10134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10135 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010136 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10137 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10138 }
10139 if (!isImsAvailableOnDevice()) {
10140 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10141 "IMS not available on device.");
10142 }
10143
10144 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010145 try {
Hui Wang761a6682020-10-31 05:12:53 +000010146 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10147 } finally {
10148 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010149 }
10150 }
zoey chene02881a2019-12-30 16:11:23 +080010151
10152 @Override
10153 public boolean isIccLockEnabled(int subId) {
10154 enforceReadPrivilegedPermission("isIccLockEnabled");
10155
10156 // Now that all security checks passes, perform the operation as ourselves.
10157 final long identity = Binder.clearCallingIdentity();
10158 try {
10159 Phone phone = getPhone(subId);
10160 if (phone != null && phone.getIccCard() != null) {
10161 return phone.getIccCard().getIccLockEnabled();
10162 } else {
10163 return false;
10164 }
10165 } finally {
10166 Binder.restoreCallingIdentity(identity);
10167 }
10168 }
10169
10170 /**
10171 * Set the ICC pin lock enabled or disabled.
10172 *
10173 * @return an integer representing the status of IccLock enabled or disabled in the following
10174 * three cases:
10175 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10176 * successfully.
10177 * - Positive number and zero for remaining password attempts.
10178 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10179 *
10180 */
10181 @Override
10182 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10183 enforceModifyPermission();
10184
10185 Phone phone = getPhone(subId);
10186 if (phone == null) {
10187 return 0;
10188 }
10189 // Now that all security checks passes, perform the operation as ourselves.
10190 final long identity = Binder.clearCallingIdentity();
10191 try {
10192 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10193 new Pair<Boolean, String>(enabled, password), phone, null);
10194 return attemptsRemaining;
10195
10196 } catch (Exception e) {
10197 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10198 } finally {
10199 Binder.restoreCallingIdentity(identity);
10200 }
10201 return 0;
10202 }
10203
10204 /**
10205 * Change the ICC password used in ICC pin lock.
10206 *
10207 * @return an integer representing the status of IccLock changed in the following three cases:
10208 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10209 * - Positive number and zero for remaining password attempts.
10210 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10211 *
10212 */
10213 @Override
10214 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10215 enforceModifyPermission();
10216
10217 Phone phone = getPhone(subId);
10218 if (phone == null) {
10219 return 0;
10220 }
10221 // Now that all security checks passes, perform the operation as ourselves.
10222 final long identity = Binder.clearCallingIdentity();
10223 try {
10224 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10225 new Pair<String, String>(oldPassword, newPassword), phone, null);
10226 return attemptsRemaining;
10227
10228 } catch (Exception e) {
10229 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10230 } finally {
10231 Binder.restoreCallingIdentity(identity);
10232 }
10233 return 0;
10234 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010235
10236 /**
10237 * Request for receiving user activity notification
10238 */
10239 @Override
10240 public void requestUserActivityNotification() {
10241 if (!mNotifyUserActivity.get()
10242 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10243 mNotifyUserActivity.set(true);
10244 }
10245 }
10246
10247 /**
10248 * Called when userActivity is signalled in the power manager.
10249 * This is safe to call from any thread, with any window manager locks held or not.
10250 */
10251 @Override
10252 public void userActivity() {
10253 // ***************************************
10254 // * Inherited from PhoneWindowManager *
10255 // ***************************************
10256 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10257 // WITH ITS LOCKS HELD.
10258 //
10259 // This code must be VERY careful about the locks
10260 // it acquires.
10261 // In fact, the current code acquires way too many,
10262 // and probably has lurking deadlocks.
10263
10264 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10265 throw new SecurityException("Only the OS may call notifyUserActivity()");
10266 }
10267
10268 if (mNotifyUserActivity.getAndSet(false)) {
10269 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10270 USER_ACTIVITY_NOTIFICATION_DELAY);
10271 }
10272 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010273
10274 @Override
10275 public boolean canConnectTo5GInDsdsMode() {
10276 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10277 }
Jack Yud10cdd42020-09-28 20:28:01 -070010278
10279 @Override
10280 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10281 String callingFeatureId) {
10282 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10283 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10284 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10285 }
10286
10287 Phone phone = getPhone(subId);
10288 if (phone == null) {
10289 throw new RuntimeException("phone is not available");
10290 }
10291 // Now that all security checks passes, perform the operation as ourselves.
10292 final long identity = Binder.clearCallingIdentity();
10293 try {
10294 return phone.getEquivalentHomePlmns();
10295 } finally {
10296 Binder.restoreCallingIdentity(identity);
10297 }
10298 }
Daniel Bright59e67312020-11-13 11:49:37 -080010299
10300 @Override
10301 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010302 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10303 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010304 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010305 if (radioInterfaceCapabilities == null) {
10306 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010307 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010308 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010309 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010310
Hui Wang641e81c2020-10-12 12:14:23 -070010311 @Override
10312 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10313 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010314 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10315 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10316 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10317 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10318 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010319 if (DBG) {
10320 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10321 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10322 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10323 }
10324
10325 if (!SubscriptionManager.isValidSubscriptionId(subId)
10326 || appType < TelephonyManager.APPTYPE_UNKNOWN
10327 || appType > TelephonyManager.APPTYPE_ISIM
10328 || nafUrl == null || securityProtocol == null || callback == null) {
10329 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10330 if (callback != null) {
10331 try {
10332 callback.onAuthenticationFailure(
10333 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10334 } catch (RemoteException exception) {
10335 log("Fail to notify onAuthenticationFailure due to " + exception);
10336 }
10337 return;
10338 }
10339 }
10340
10341 final long token = Binder.clearCallingIdentity();
10342 try {
10343 getGbaManager(subId).bootstrapAuthenticationRequest(
10344 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10345 forceBootStrapping, callback));
10346 } finally {
10347 Binder.restoreCallingIdentity(token);
10348 }
10349 }
10350
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010351 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010352 * Attempts to set the radio power state for all phones for thermal reason.
10353 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010354 * requested radio power state will actually be set. See {@link
10355 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10356 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010357 * @param enable {@code true} if trying to turn radio on.
10358 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10359 * false}.
10360 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010361 private boolean setRadioPowerForThermal(boolean enable) {
10362 boolean isPhoneAvailable = false;
10363 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10364 Phone phone = PhoneFactory.getPhone(i);
10365 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010366 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010367 isPhoneAvailable = true;
10368 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010369 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010370
10371 // return true if successfully informed the phone object about the thermal radio power
10372 // request.
10373 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010374 }
10375
10376 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010377 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010378 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10379 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10380 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10381 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10382 throw new IllegalArgumentException("modem does not support data throttling");
10383 }
10384
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010385 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10386 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010387 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010388 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10389 }
10390
Sarah Chinecc78c42022-03-31 21:16:48 -070010391 setDataEnabledForReason(
10392 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010393
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010394 if (isDataThrottlingSupported) {
10395 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010396 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010397 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10398 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10399 } else if (thermalMitigationResult
10400 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010401 log("Modem likely does not support data throttling on secondary carrier. Data " +
10402 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10403 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010404 }
10405 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010406 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010407
10408 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010409 }
10410
Jack Nudelman644b91a2021-03-12 14:09:48 -080010411 private static List<String> getThermalMitigationAllowlist(Context context) {
10412 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10413 for (String pckg : context.getResources()
10414 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10415 sThermalMitigationAllowlistedPackages.add(pckg);
10416 }
10417 }
10418
10419 return sThermalMitigationAllowlistedPackages;
10420 }
10421
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010422 private boolean isAnyPhoneInEmergencyState() {
10423 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10424 if (tm.isInEmergencyCall()) {
10425 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10426 return true;
10427 }
10428 for (Phone phone : PhoneFactory.getPhones()) {
10429 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10430 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10431 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10432 + phone.isInEcm());
10433 return true;
10434 }
10435 }
10436
10437 return false;
10438 }
10439
Jack Nudelman644b91a2021-03-12 14:09:48 -080010440 /**
10441 * Used by shell commands to add an authorized package name for thermal mitigation.
10442 * @param packageName name of package to be allowlisted
10443 * @param context
10444 */
10445 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10446 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10447 sThermalMitigationAllowlistedPackages.add(packageName);
10448 }
10449
10450 /**
10451 * Used by shell commands to remove an authorized package name for thermal mitigation.
10452 * @param packageName name of package to remove from allowlist
10453 * @param context
10454 */
10455 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10456 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10457 sThermalMitigationAllowlistedPackages.remove(packageName);
10458 }
10459
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010460 /**
10461 * Thermal mitigation request to control functionalities at modem.
10462 *
10463 * @param subId the id of the subscription.
10464 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010465 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010466 *
10467 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10468 */
10469 @Override
10470 @ThermalMitigationResult
10471 public int sendThermalMitigationRequest(
10472 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010473 ThermalMitigationRequest thermalMitigationRequest,
10474 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010475 enforceModifyPermission();
10476
Jack Nudelman644b91a2021-03-12 14:09:48 -080010477 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10478 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10479 .contains(callingPackage)) {
10480 throw new SecurityException("Calling package must be configured in the device config. "
10481 + "calling package: " + callingPackage);
10482 }
10483
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010484 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10485 final long identity = Binder.clearCallingIdentity();
10486
10487 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10488 try {
10489 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10490 switch (thermalMitigationAction) {
10491 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10492 thermalMitigationResult =
10493 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010494 thermalMitigationRequest.getDataThrottlingRequest(),
10495 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010496 break;
10497 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10498 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10499 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10500 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10501 }
10502
10503 // Ensure that radio is on. If not able to power on due to phone being
10504 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010505 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010506 thermalMitigationResult =
10507 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10508 break;
10509 }
10510
10511 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010512 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010513 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10514 break;
10515 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10516 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10517 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10518 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10519 }
10520
10521 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10522 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010523 Phone phone = getPhone(subId);
10524 if (phone == null) {
10525 thermalMitigationResult =
10526 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10527 break;
10528 }
10529
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010530 TelephonyConnectionService service =
10531 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010532 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010533 Log.e(LOG_TAG, "An emergency call is pending");
10534 thermalMitigationResult =
10535 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10536 break;
10537 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010538 thermalMitigationResult =
10539 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10540 break;
10541 }
10542 } else {
10543 thermalMitigationResult =
10544 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10545 break;
10546 }
10547
10548 // Turn radio off. If not able to power off due to phone being unavailable,
10549 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010550 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010551 thermalMitigationResult =
10552 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10553 break;
10554 }
10555 thermalMitigationResult =
10556 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10557 break;
10558 default:
10559 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10560 + "not exist. Requested action: " + thermalMitigationAction);
10561 }
10562 } catch (IllegalArgumentException e) {
10563 throw e;
10564 } catch (Exception e) {
10565 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10566 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10567 } finally {
10568 Binder.restoreCallingIdentity(identity);
10569 }
10570
10571 if (DBG) {
10572 log("thermalMitigationRequest returning with thermalMitigationResult: "
10573 + thermalMitigationResult);
10574 }
10575
10576 return thermalMitigationResult;
10577 }
Hui Wang641e81c2020-10-12 12:14:23 -070010578
10579 /**
10580 * Set the GbaService Package Name that Telephony will bind to.
10581 *
10582 * @param subId The sim that the GbaService is associated with.
10583 * @param packageName The name of the package to be replaced with.
10584 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10585 */
10586 @Override
10587 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10588 enforceModifyPermission();
10589
10590 final long identity = Binder.clearCallingIdentity();
10591 try {
10592 return getGbaManager(subId).overrideServicePackage(packageName);
10593 } finally {
10594 Binder.restoreCallingIdentity(identity);
10595 }
10596 }
10597
10598 /**
10599 * Return the package name of the currently bound GbaService.
10600 *
10601 * @param subId The sim that the GbaService is associated with.
10602 * @return the package name of the GbaService configuration, null if GBA is not supported.
10603 */
10604 @Override
10605 public String getBoundGbaService(int subId) {
10606 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10607
10608 final long identity = Binder.clearCallingIdentity();
10609 try {
10610 return getGbaManager(subId).getServicePackage();
10611 } finally {
10612 Binder.restoreCallingIdentity(identity);
10613 }
10614 }
10615
10616 /**
10617 * Set the release time for telephony to unbind GbaService.
10618 *
10619 * @param subId The sim that the GbaService is associated with.
10620 * @param interval The release time to unbind GbaService by millisecond.
10621 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10622 */
10623 @Override
10624 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10625 enforceModifyPermission();
10626
10627 final long identity = Binder.clearCallingIdentity();
10628 try {
10629 return getGbaManager(subId).overrideReleaseTime(interval);
10630 } finally {
10631 Binder.restoreCallingIdentity(identity);
10632 }
10633 }
10634
10635 /**
10636 * Return the release time for telephony to unbind GbaService.
10637 *
10638 * @param subId The sim that the GbaService is associated with.
10639 * @return The release time to unbind GbaService by millisecond.
10640 */
10641 @Override
10642 public int getGbaReleaseTime(int subId) {
10643 enforceReadPrivilegedPermission("getGbaReleaseTime");
10644
10645 final long identity = Binder.clearCallingIdentity();
10646 try {
10647 return getGbaManager(subId).getReleaseTime();
10648 } finally {
10649 Binder.restoreCallingIdentity(identity);
10650 }
10651 }
10652
10653 private GbaManager getGbaManager(int subId) {
10654 GbaManager instance = GbaManager.getInstance(subId);
10655 if (instance == null) {
10656 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10657 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10658 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10659 }
10660 return instance;
10661 }
Hui Wang761a6682020-10-31 05:12:53 +000010662
10663 /**
10664 * indicate whether the device and the carrier can support
10665 * RCS VoLTE single registration.
10666 */
10667 @Override
10668 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010669 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10670 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10671 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10672 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010673
10674 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10675 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10676 }
10677
10678 final long identity = Binder.clearCallingIdentity();
10679 try {
10680 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10681 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010682 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10683 if (isCapable != null) {
10684 return isCapable;
10685 }
Hui Wang761a6682020-10-31 05:12:53 +000010686 }
Hui Wang67af90e2021-06-04 16:57:15 -070010687 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10688 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010689 } finally {
10690 Binder.restoreCallingIdentity(identity);
10691 }
10692 }
10693
10694 /**
10695 * Register RCS provisioning callback.
10696 */
10697 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010698 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010699 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010700 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010701 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010702 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10703 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010704
10705 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10706 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10707 }
10708 if (!isImsAvailableOnDevice()) {
10709 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10710 "IMS not available on device.");
10711 }
10712
10713 final long identity = Binder.clearCallingIdentity();
10714 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010715 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010716 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010717 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10718 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010719 }
Hui Wang761a6682020-10-31 05:12:53 +000010720 } finally {
10721 Binder.restoreCallingIdentity(identity);
10722 }
10723 }
10724
10725 /**
10726 * Unregister RCS provisioning callback.
10727 */
10728 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010729 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010730 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010731 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010732 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010733 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10734 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010735
10736 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10737 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10738 }
10739 if (!isImsAvailableOnDevice()) {
10740 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10741 "IMS not available on device.");
10742 }
10743
10744 final long identity = Binder.clearCallingIdentity();
10745 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010746 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010747 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010748 } finally {
10749 Binder.restoreCallingIdentity(identity);
10750 }
10751 }
10752
10753 /**
10754 * trigger RCS reconfiguration.
10755 */
10756 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010757 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10758 "triggerRcsReconfiguration",
10759 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010760
10761 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10762 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10763 }
10764 if (!isImsAvailableOnDevice()) {
10765 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10766 "IMS not available on device.");
10767 }
10768
10769 final long identity = Binder.clearCallingIdentity();
10770 try {
10771 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10772 } finally {
10773 Binder.restoreCallingIdentity(identity);
10774 }
10775 }
10776
10777 /**
10778 * Provide the client configuration parameters of the RCS application.
10779 */
10780 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010781 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10782 "setRcsClientConfiguration",
10783 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010784
10785 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10786 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10787 }
10788 if (!isImsAvailableOnDevice()) {
10789 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10790 "IMS not available on device.");
10791 }
10792
10793 final long identity = Binder.clearCallingIdentity();
10794
10795 try {
10796 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10797 if (configBinder == null) {
10798 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010799 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10800 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010801 } else {
10802 configBinder.setRcsClientConfiguration(rcc);
10803 }
joonhunshin3e154242021-09-17 06:33:39 +000010804
10805 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10806 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010807 } catch (RemoteException e) {
10808 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010809 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10810 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010811 } finally {
10812 Binder.restoreCallingIdentity(identity);
10813 }
10814 }
10815
10816 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010817 * Enables or disables the test mode for RCS VoLTE single registration.
10818 */
10819 @Override
10820 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10821 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10822 "setRcsSingleRegistrationTestModeEnabled");
10823
10824 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10825 }
10826
10827 /**
10828 * Gets the test mode for RCS VoLTE single registration.
10829 */
10830 @Override
10831 public boolean getRcsSingleRegistrationTestModeEnabled() {
10832 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10833 "getRcsSingleRegistrationTestModeEnabled");
10834
10835 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10836 }
10837
10838 /**
Hui Wang761a6682020-10-31 05:12:53 +000010839 * Overrides the config of RCS VoLTE single registration enabled for the device.
10840 */
10841 @Override
10842 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10843 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10844 "setDeviceSingleRegistrationEnabledOverride");
10845 enforceModifyPermission();
10846
10847 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10848 : Boolean.parseBoolean(enabledStr);
10849 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010850 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010851 }
10852
10853 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010854 * Sends a device to device communication message. Only usable via shell.
10855 * @param message message to send.
10856 * @param value message value.
10857 */
10858 @Override
10859 public void sendDeviceToDeviceMessage(int message, int value) {
10860 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010861 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010862 enforceModifyPermission();
10863
10864 final long identity = Binder.clearCallingIdentity();
10865 try {
10866 TelephonyConnectionService service =
10867 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10868 if (service == null) {
10869 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10870 return;
10871 }
10872 service.sendTestDeviceToDeviceMessage(message, value);
10873 } finally {
10874 Binder.restoreCallingIdentity(identity);
10875 }
10876 }
10877
Tyler Gunnbabbda02021-02-10 11:05:02 -080010878 /**
10879 * Sets the specified device to device transport active.
10880 * @param transport The transport to set active.
10881 */
10882 @Override
10883 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10884 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10885 "setActiveDeviceToDeviceTransport");
10886 enforceModifyPermission();
10887
10888 final long identity = Binder.clearCallingIdentity();
10889 try {
10890 TelephonyConnectionService service =
10891 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10892 if (service == null) {
10893 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10894 return;
10895 }
10896 service.setActiveDeviceToDeviceTransport(transport);
10897 } finally {
10898 Binder.restoreCallingIdentity(identity);
10899 }
10900 }
Tyler Gunn92479152021-01-20 16:30:10 -080010901
Tyler Gunnd4339262021-05-03 14:46:49 -070010902 @Override
10903 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10904 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10905 "setDeviceToDeviceForceEnabled");
10906
10907 final long identity = Binder.clearCallingIdentity();
10908 try {
10909 Arrays.stream(PhoneFactory.getPhones()).forEach(
10910 p -> {
10911 Phone thePhone = p.getImsPhone();
10912 if (thePhone != null && thePhone instanceof ImsPhone) {
10913 ImsPhone imsPhone = (ImsPhone) thePhone;
10914 CallTracker tracker = imsPhone.getCallTracker();
10915 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10916 ImsPhoneCallTracker imsPhoneCallTracker =
10917 (ImsPhoneCallTracker) tracker;
10918 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10919 }
10920 }
10921 }
10922 );
10923 } finally {
10924 Binder.restoreCallingIdentity(identity);
10925 }
10926 }
10927
Tyler Gunn92479152021-01-20 16:30:10 -080010928 /**
Hui Wang761a6682020-10-31 05:12:53 +000010929 * Gets the config of RCS VoLTE single registration enabled for the device.
10930 */
10931 @Override
10932 public boolean getDeviceSingleRegistrationEnabled() {
10933 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10934 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10935 }
10936
10937 /**
10938 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10939 */
10940 @Override
10941 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10942 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10943 "setCarrierSingleRegistrationEnabledOverride");
10944 enforceModifyPermission();
10945
10946 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10947 : Boolean.parseBoolean(enabledStr);
10948 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10949 subId, enabled);
10950 }
10951
10952 /**
10953 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10954 */
10955 @Override
10956 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10957 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10958 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10959 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010960
10961 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010962 * Overrides the ims feature validation result
10963 */
10964 @Override
10965 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10966 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10967 "setImsFeatureValidationOverride");
10968
10969 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10970 : Boolean.parseBoolean(enabledStr);
10971 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10972 subId, enabled);
10973 }
10974
10975 /**
10976 * Gets the ims feature validation override value
10977 */
10978 @Override
10979 public boolean getImsFeatureValidationOverride(int subId) {
10980 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10981 "getImsFeatureValidationOverride");
10982 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10983 }
10984
10985 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010986 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10987 * their mobile plan.
10988 */
10989 @Override
10990 public String getMobileProvisioningUrl() {
10991 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10992 final long identity = Binder.clearCallingIdentity();
10993 try {
10994 return getDefaultPhone().getMobileProvisioningUrl();
10995 } finally {
10996 Binder.restoreCallingIdentity(identity);
10997 }
10998 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010999
James.cf Linbcdf8b32021-01-14 16:44:13 +080011000 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011001 * Get the EAB contact from the EAB database.
11002 */
11003 @Override
11004 public String getContactFromEab(String contact) {
11005 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11006 enforceModifyPermission();
11007 final long identity = Binder.clearCallingIdentity();
11008 try {
11009 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11010 } finally {
11011 Binder.restoreCallingIdentity(identity);
11012 }
11013 }
11014
11015 /**
Calvin Pana1434322021-07-01 19:27:01 +080011016 * Get the EAB capability from the EAB database.
11017 */
11018 @Override
11019 public String getCapabilityFromEab(String contact) {
11020 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11021 enforceModifyPermission();
11022 final long identity = Binder.clearCallingIdentity();
11023 try {
11024 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11025 } finally {
11026 Binder.restoreCallingIdentity(identity);
11027 }
11028 }
11029
11030 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011031 * Remove the EAB contacts from the EAB database.
11032 */
11033 @Override
11034 public int removeContactFromEab(int subId, String contacts) {
11035 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11036 enforceModifyPermission();
11037 final long identity = Binder.clearCallingIdentity();
11038 try {
11039 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11040 } finally {
11041 Binder.restoreCallingIdentity(identity);
11042 }
11043 }
11044
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011045 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011046 public boolean getDeviceUceEnabled() {
11047 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11048 final long identity = Binder.clearCallingIdentity();
11049 try {
11050 return mApp.getDeviceUceEnabled();
11051 } finally {
11052 Binder.restoreCallingIdentity(identity);
11053 }
11054 }
11055
11056 @Override
11057 public void setDeviceUceEnabled(boolean isEnabled) {
11058 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11059 final long identity = Binder.clearCallingIdentity();
11060 try {
11061 mApp.setDeviceUceEnabled(isEnabled);
11062 } finally {
11063 Binder.restoreCallingIdentity(identity);
11064 }
11065 }
11066
Brad Ebinger14d467f2021-02-12 06:18:28 +000011067 /**
11068 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11069 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11070 */
11071 // Used for SHELL command only right now.
11072 @Override
11073 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11074 List<String> featureTags) {
11075 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11076 "addUceRegistrationOverrideShell");
11077 final long identity = Binder.clearCallingIdentity();
11078 try {
11079 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11080 new ArraySet<>(featureTags));
11081 } catch (ImsException e) {
11082 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11083 } finally {
11084 Binder.restoreCallingIdentity(identity);
11085 }
11086 }
11087
11088 /**
11089 * Remove existing 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 removeUceRegistrationOverrideShell(int subId,
11095 List<String> featureTags) {
11096 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11097 "removeUceRegistrationOverrideShell");
11098 final long identity = Binder.clearCallingIdentity();
11099 try {
11100 return mApp.imsRcsController.removeUceRegistrationOverrideShell(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 * Clear all overrides in 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 clearUceRegistrationOverrideShell(int subId) {
11116 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11117 "clearUceRegistrationOverrideShell");
11118 final long identity = Binder.clearCallingIdentity();
11119 try {
11120 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11121 } catch (ImsException e) {
11122 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11123 } finally {
11124 Binder.restoreCallingIdentity(identity);
11125 }
11126 }
11127
11128 /**
11129 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11130 */
11131 // Used for SHELL command only right now.
11132 @Override
11133 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11134 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11135 "getLatestRcsContactUceCapabilityShell");
11136 final long identity = Binder.clearCallingIdentity();
11137 try {
11138 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11139 } catch (ImsException e) {
11140 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11141 } finally {
11142 Binder.restoreCallingIdentity(identity);
11143 }
11144 }
11145
11146 /**
11147 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11148 * device does not have an active PUBLISH.
11149 */
11150 // Used for SHELL command only right now.
11151 @Override
11152 public String getLastUcePidfXmlShell(int subId) {
11153 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11154 final long identity = Binder.clearCallingIdentity();
11155 try {
11156 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11157 } catch (ImsException e) {
11158 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11159 } finally {
11160 Binder.restoreCallingIdentity(identity);
11161 }
11162 }
11163
James.cf Line8713a42021-04-29 16:04:26 +080011164 /**
11165 * Remove UCE requests cannot be sent to the network status.
11166 */
11167 // Used for SHELL command only right now.
11168 @Override
11169 public boolean removeUceRequestDisallowedStatus(int subId) {
11170 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11171 final long identity = Binder.clearCallingIdentity();
11172 try {
11173 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11174 } catch (ImsException e) {
11175 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11176 } finally {
11177 Binder.restoreCallingIdentity(identity);
11178 }
11179 }
11180
James.cf Lin18bb9002021-05-25 01:37:38 +080011181 /**
11182 * Remove UCE requests cannot be sent to the network status.
11183 */
11184 // Used for SHELL command only.
11185 @Override
11186 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11187 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11188 final long identity = Binder.clearCallingIdentity();
11189 try {
11190 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11191 } catch (ImsException e) {
11192 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11193 } finally {
11194 Binder.restoreCallingIdentity(identity);
11195 }
11196 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011197
James.cf Lin4b784aa2021-01-31 03:25:15 +080011198 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011199 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11200 String callingPackage) {
11201 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11202 mApp, subId, "setSignalStrengthUpdateRequest");
11203
11204 final int callingUid = Binder.getCallingUid();
11205 // Verify that tha callingPackage belongs to the calling UID
11206 mApp.getSystemService(AppOpsManager.class)
11207 .checkPackage(callingUid, callingPackage);
11208
Rambo Wang3607f502021-02-01 21:51:40 -080011209 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011210
11211 final long identity = Binder.clearCallingIdentity();
11212 try {
11213 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11214 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11215
11216 if (result instanceof IllegalStateException) {
11217 throw (IllegalStateException) result;
11218 }
11219 } finally {
11220 Binder.restoreCallingIdentity(identity);
11221 }
11222 }
11223
11224 @Override
11225 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11226 String callingPackage) {
11227 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11228 mApp, subId, "clearSignalStrengthUpdateRequest");
11229
11230 final int callingUid = Binder.getCallingUid();
11231 // Verify that tha callingPackage belongs to the calling UID
11232 mApp.getSystemService(AppOpsManager.class)
11233 .checkPackage(callingUid, callingPackage);
11234
11235 final long identity = Binder.clearCallingIdentity();
11236 try {
11237 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11238 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11239
11240 if (result instanceof IllegalStateException) {
11241 throw (IllegalStateException) result;
11242 }
11243 } finally {
11244 Binder.restoreCallingIdentity(identity);
11245 }
11246 }
11247
Rambo Wang3607f502021-02-01 21:51:40 -080011248 private static void validateSignalStrengthUpdateRequest(Context context,
11249 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011250 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11251 // phone/system process do not have further restriction on request
11252 return;
11253 }
11254
11255 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011256 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011257 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011258 context.enforceCallingOrSelfPermission(
11259 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11260 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011261 }
11262
11263 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11264 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11265 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11266 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11267 || info.isEnabled()) {
11268 throw new IllegalArgumentException(
11269 "Only system can set hide fields in SignalThresholdInfo");
11270 }
11271
11272 // Thresholds length for each RAN need in range. This has been validated in
11273 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11274 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11275 final int[] thresholds = info.getThresholds();
11276 Objects.requireNonNull(thresholds);
11277 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11278 || thresholds.length
11279 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11280 throw new IllegalArgumentException(
11281 "thresholds length is out of range: " + thresholds.length);
11282 }
11283 }
11284 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011285
11286 /**
11287 * Gets the current phone capability.
11288 *
11289 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11290 * @return the PhoneCapability which describes the data connection capability of modem.
11291 * It's used to evaluate possible phone config change, for example from single
11292 * SIM device to multi-SIM device.
11293 */
11294 @Override
11295 public PhoneCapability getPhoneCapability() {
11296 enforceReadPrivilegedPermission("getPhoneCapability");
11297 final long identity = Binder.clearCallingIdentity();
11298 try {
11299 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11300 } finally {
11301 Binder.restoreCallingIdentity(identity);
11302 }
11303 }
Michele Berionne5e411512020-11-13 02:36:59 +000011304
11305 /**
11306 * Prepare TelephonyManager for an unattended reboot. The reboot is
11307 * required to be done shortly after the API is invoked.
11308 */
11309 @Override
11310 @TelephonyManager.PrepareUnattendedRebootResult
11311 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011312 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011313 enforceRebootPermission();
11314
11315 final long identity = Binder.clearCallingIdentity();
11316 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011317 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011318 } finally {
11319 Binder.restoreCallingIdentity(identity);
11320 }
11321 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011322
11323 /**
11324 * Request to get the current slicing configuration including URSP rules and
11325 * NSSAIs (configured, allowed and rejected).
11326 *
11327 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11328 */
11329 @Override
11330 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011331 TelephonyPermissions
11332 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11333 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011334
11335 final long identity = Binder.clearCallingIdentity();
11336 try {
11337 Phone phone = getDefaultPhone();
11338 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11339 } finally {
11340 Binder.restoreCallingIdentity(identity);
11341 }
11342 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011343
11344 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011345 * Check whether the given premium capability is available for purchase from the carrier.
11346 *
11347 * @param capability The premium capability to check.
11348 * @param subId The subId to check the premium capability for.
11349 *
11350 * @return Whether the given premium capability is available to purchase.
11351 */
11352 @Override
11353 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11354 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11355 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11356 log("Premium capability "
11357 + TelephonyManager.convertPremiumCapabilityToString(capability)
11358 + " is not available for purchase due to missing permissions.");
11359 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11360 + "permission READ_BASIC_PHONE_STATE.");
11361 }
11362
11363 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011364 if (phone == null) {
11365 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11366 return false;
11367 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011368 final long identity = Binder.clearCallingIdentity();
11369 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011370 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011371 .isPremiumCapabilityAvailableForPurchase(capability);
11372 } finally {
11373 Binder.restoreCallingIdentity(identity);
11374 }
11375 }
11376
11377 /**
11378 * Purchase the given premium capability from the carrier.
11379 *
11380 * @param capability The premium capability to purchase.
11381 * @param callback The result of the purchase request.
11382 * @param subId The subId to purchase the premium capability for.
11383 */
11384 @Override
11385 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11386 log("purchasePremiumCapability: capability="
11387 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11388 + getCurrentPackageName());
11389
11390 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11391 mApp, "purchasePremiumCapability")) {
11392 log("purchasePremiumCapability "
11393 + TelephonyManager.convertPremiumCapabilityToString(capability)
11394 + " failed due to missing permissions.");
11395 throw new SecurityException("purchasePremiumCapability requires permission "
11396 + "READ_BASIC_PHONE_STATE.");
11397 }
11398
11399 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011400 if (phone == null) {
11401 try {
11402 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11403 callback.accept(result);
11404 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11405 } catch (RemoteException e) {
11406 String logStr = "Purchase premium capability "
11407 + TelephonyManager.convertPremiumCapabilityToString(capability)
11408 + " failed due to RemoteException handling null phone: " + e;
11409 if (DBG) log(logStr);
11410 AnomalyReporter.reportAnomaly(
11411 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11412 }
11413 return;
11414 }
Sarah Chin71b3a852022-09-28 15:54:19 -070011415 String appName;
11416 try {
11417 appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager()
11418 .getApplicationInfo(getCurrentPackageName(), 0)).toString();
11419 } catch (PackageManager.NameNotFoundException e) {
11420 appName = "An application";
11421 }
11422 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
11423 new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011424 }
11425
11426 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011427 * Register an IMS connection state callback
11428 */
11429 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011430 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11431 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011432 if (feature == ImsFeature.FEATURE_MMTEL) {
11433 // ImsMmTelManager
11434 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11435 TelephonyPermissions
11436 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11437 mApp, subId, "registerImsStateCallback");
11438 } else if (feature == ImsFeature.FEATURE_RCS) {
11439 // ImsRcsManager or SipDelegateManager
11440 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11441 Binder.getCallingUid(), "registerImsStateCallback",
11442 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11443 Manifest.permission.READ_PRECISE_PHONE_STATE,
11444 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11445 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11446 }
11447
11448 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11449 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11450 "IMS not available on device.");
11451 }
11452
11453 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11454 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11455 }
11456
11457 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11458 if (controller == null) {
11459 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11460 "IMS not available on device.");
11461 }
11462
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011463 if (callingPackage == null) {
11464 callingPackage = getCurrentPackageName();
11465 }
11466
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011467 final long token = Binder.clearCallingIdentity();
11468 try {
11469 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011470 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011471 } catch (ImsException e) {
11472 throw new ServiceSpecificException(e.getCode());
11473 } finally {
11474 Binder.restoreCallingIdentity(token);
11475 }
11476 }
11477
11478 /**
11479 * Unregister an IMS connection state callback
11480 */
11481 @Override
11482 public void unregisterImsStateCallback(IImsStateCallback cb) {
11483 final long token = Binder.clearCallingIdentity();
11484 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11485 if (controller == null) {
11486 return;
11487 }
11488 try {
11489 controller.unregisterImsStateCallback(cb);
11490 } finally {
11491 Binder.restoreCallingIdentity(token);
11492 }
11493 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011494
11495 /**
11496 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11497 *
11498 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11499 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11500 * SecurityException.
11501 * If there is current registered network this value will be same as the registered cell
11502 * identity. If the device goes out of service the previous cell identity is cached and
11503 * will be returned. If the cache age of the Cell identity is more than 24 hours
11504 * it will be cleared and null will be returned.
11505 *
11506 */
11507 @Override
11508 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11509 String callingFeatureId) {
11510 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11511 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11512 LocationAccessPolicy.checkLocationPermission(mApp,
11513 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11514 .setCallingPackage(callingPackage)
11515 .setCallingFeatureId(callingFeatureId)
11516 .setCallingPid(Binder.getCallingPid())
11517 .setCallingUid(Binder.getCallingUid())
11518 .setMethod("getLastKnownCellIdentity")
11519 .setLogAsInfo(true)
11520 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11521 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11522 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11523 .build());
11524
11525 boolean hasFinePermission =
11526 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11527 if (!hasFinePermission
11528 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11529 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011530 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011531 }
11532
11533 final long identity = Binder.clearCallingIdentity();
11534 try {
11535 Phone phone = getPhone(subId);
11536 if (phone == null) return null;
11537 ServiceStateTracker sst = phone.getServiceStateTracker();
11538 if (sst == null) return null;
11539 return sst.getLastKnownCellIdentity();
11540 } finally {
11541 Binder.restoreCallingIdentity(identity);
11542 }
11543 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011544
jimsun3b9ccac2021-10-26 15:01:23 +080011545 /**
11546 * Sets the modem service class Name that Telephony will bind to.
11547 *
11548 * @param serviceName The class name of the modem service.
11549 * @return true if the operation is succeed, otherwise false.
11550 */
11551 public boolean setModemService(String serviceName) {
11552 Log.d(LOG_TAG, "setModemService - " + serviceName);
11553 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11555 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11556 "setModemService");
11557 return mPhoneConfigurationManager.setModemService(serviceName);
11558 }
11559
11560 /**
11561 * Return the class name of the currently bounded modem service.
11562 *
11563 * @return the class name of the modem service.
11564 */
11565 public String getModemService() {
11566 String result;
11567 Log.d(LOG_TAG, "getModemService");
11568 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11569 TelephonyPermissions
11570 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11571 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11572 "getModemService");
11573 result = mPhoneConfigurationManager.getModemService();
11574 Log.d(LOG_TAG, "result = " + result);
11575 return result;
11576 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011577
11578 @Override
11579 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11580 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11581 mApp.enforceCallingOrSelfPermission(
11582 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11583 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11584
11585 final long identity = Binder.clearCallingIdentity();
11586 try {
11587 Phone phone = getPhone(subId);
11588 if (phone == null) return;
11589 phone.setVoiceServiceStateOverride(hasService);
11590 } finally {
11591 Binder.restoreCallingIdentity(identity);
11592 }
11593 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011594
11595 /**
11596 * set removable eSIM as default eUICC.
11597 *
11598 * @hide
11599 */
11600 @Override
11601 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11602 enforceModifyPermission();
11603 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11604
11605 final long identity = Binder.clearCallingIdentity();
11606 try {
11607 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11608 } finally {
11609 Binder.restoreCallingIdentity(identity);
11610 }
11611 }
11612
11613 /**
11614 * Returns whether the removable eSIM is default eUICC or not.
11615 *
11616 * @hide
11617 */
11618 @Override
11619 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11620 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11621 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11622
11623 final long identity = Binder.clearCallingIdentity();
11624 try {
11625 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11626 } finally {
11627 Binder.restoreCallingIdentity(identity);
11628 }
11629 }
11630
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011631 /**
11632 * Get the component name of the default app to direct respond-via-message intent for the
11633 * user associated with this subscription, update the cache if there is no respond-via-message
11634 * application currently configured for this user.
11635 * @return component name of the app and class to direct Respond Via Message intent to, or
11636 * {@code null} if the functionality is not supported.
11637 * @hide
11638 */
11639 @Override
11640 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11641 boolean updateIfNeeded) {
11642 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011643
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011644 Context context = getPhone(subId).getContext();
11645 UserHandle userHandle = null;
11646 final long identity = Binder.clearCallingIdentity();
11647 try {
11648 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11649 } finally {
11650 Binder.restoreCallingIdentity(identity);
11651 }
11652 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11653 updateIfNeeded, userHandle);
11654 }
Jack Yuf5badd92022-12-08 00:50:53 -080011655
11656 /**
11657 * Get the SIM state for the slot index.
11658 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11659 *
11660 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11661 */
11662 @Override
11663 @SimState
11664 public int getSimStateForSlotIndex(int slotIndex) {
11665 IccCardConstants.State simState;
11666 if (slotIndex < 0) {
11667 simState = IccCardConstants.State.UNKNOWN;
11668 } else {
11669 Phone phone = null;
11670 try {
11671 phone = PhoneFactory.getPhone(slotIndex);
11672 } catch (IllegalStateException e) {
11673 // ignore
11674 }
11675 if (phone == null) {
11676 simState = IccCardConstants.State.UNKNOWN;
11677 } else {
11678 IccCard icc = phone.getIccCard();
11679 if (icc == null) {
11680 simState = IccCardConstants.State.UNKNOWN;
11681 } else {
11682 simState = icc.getState();
11683 }
11684 }
11685 }
11686 return simState.ordinal();
11687 }
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011688}