blob: 11f9c30cdb7fc8583fc979343105e2e493c78462 [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;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800114import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800115import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800116import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000117import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000118import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000119import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700120import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700121import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800122import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800123import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700124import android.telephony.gba.GbaAuthRequest;
125import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700126import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800127import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000128import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000129import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700130import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000131import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700132import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800133import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700134import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800135import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700136import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000137import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700138import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800139import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800140import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800142import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700143import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800145import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800146
Andrew Lee312e8172014-10-23 17:01:36 -0700147import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800148import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800149import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800150import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800151import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700152import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700153import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700154import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800155import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800156import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700157import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700158import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800159import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700160import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800161import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800162import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800163import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700164import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000165import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700166import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800167import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700168import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800169import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800170import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700171import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700172import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700173import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700175import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800176import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700177import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700178import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700179import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700180import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800181import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800182import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700183import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000184import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700185import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700186import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800187import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800188import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800189import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700190import com.android.internal.telephony.data.DataUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800191import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700192import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800193import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700194import com.android.internal.telephony.imsphone.ImsPhone;
195import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000196import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800197import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700198import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700199import com.android.internal.telephony.uicc.IccIoResult;
200import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800201import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700202import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800203import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700204import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000205import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800206import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000207import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800208import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000209import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700210import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700211import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800212import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800213import com.android.phone.callcomposer.CallComposerPictureManager;
214import com.android.phone.callcomposer.CallComposerPictureTransfer;
215import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700216import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700217import com.android.phone.slice.SlicePurchaseController;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700218import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800219import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700220import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700221import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800222import com.android.services.telephony.TelecomAccountRegistry;
223import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800224import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800225
Hall Liu82694d52020-12-11 18:22:04 -0800226import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700227import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800228import java.io.IOException;
229import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700230import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700231import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800232import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000233import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800234import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800235import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800236import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800237import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100238import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800239import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700240import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800241import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800242import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700243import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800244import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800245import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800246import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700247
248/**
249 * Implementation of the ITelephony interface.
250 */
Santos Cordon117fee72014-05-16 17:56:12 -0700251public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700252 private static final String LOG_TAG = "PhoneInterfaceManager";
253 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
254 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800255 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700256
257 // Message codes used with mMainThreadHandler
258 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700259 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
260 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700261 private static final int CMD_OPEN_CHANNEL = 9;
262 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
263 private static final int CMD_CLOSE_CHANNEL = 11;
264 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800265 private static final int CMD_NV_READ_ITEM = 13;
266 private static final int EVENT_NV_READ_ITEM_DONE = 14;
267 private static final int CMD_NV_WRITE_ITEM = 15;
268 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
269 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
270 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700271 private static final int CMD_RESET_MODEM_CONFIG = 19;
272 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800273 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
274 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800275 private static final int CMD_SEND_ENVELOPE = 25;
276 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000277 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
278 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700279 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
280 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
281 private static final int CMD_EXCHANGE_SIM_IO = 31;
282 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800283 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
284 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700285 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
286 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700287 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
288 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700289 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
290 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
291 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
292 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700293 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
294 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
295 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
296 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700297 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800298 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
299 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000300 private static final int CMD_SWITCH_SLOTS = 50;
301 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700302 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
303 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
304 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
305 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
306 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
307 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
308 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
309 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700310 private static final int CMD_GET_ALL_CELL_INFO = 60;
311 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
312 private static final int CMD_GET_CELL_LOCATION = 62;
313 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700314 private static final int CMD_MODEM_REBOOT = 64;
315 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700316 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
317 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800318 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
319 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700320 private static final int CMD_GET_MODEM_STATUS = 70;
321 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700322 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
323 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700324 private static final int CMD_ERASE_MODEM_CONFIG = 74;
325 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800326 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
327 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
328 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
329 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800330 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
331 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800332 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800333 private static final int CMD_GET_CALL_FORWARDING = 83;
334 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
335 private static final int CMD_SET_CALL_FORWARDING = 85;
336 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
337 private static final int CMD_GET_CALL_WAITING = 87;
338 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
339 private static final int CMD_SET_CALL_WAITING = 89;
340 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700341 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
342 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
343 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
344 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700345 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
346 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800347 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
348 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800349 private static final int CMD_SET_DATA_THROTTLING = 99;
350 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800351 private static final int CMD_SET_SIM_POWER = 101;
352 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800353 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
354 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
355 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
356 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800357 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
358 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000359 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800360 private static final int CMD_GET_SLICING_CONFIG = 110;
361 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800362 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700363 private static final int CMD_ENABLE_VONR = 113;
364 private static final int EVENT_ENABLE_VONR_DONE = 114;
365 private static final int CMD_IS_VONR_ENABLED = 115;
366 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700367 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
368 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800370 // Parameters of select command.
371 private static final int SELECT_COMMAND = 0xA4;
372 private static final int SELECT_P1 = 0x04;
373 private static final int SELECT_P2 = 0;
374 private static final int SELECT_P3 = 0x10;
375
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376 /** The singleton instance. */
377 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800378 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379
Wink Saville3ab207e2014-11-20 13:07:20 -0800380 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800381 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800382 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700383 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800384 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700385 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800386 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800387 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800388 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700389 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800390 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Gil Cukierman6dac5eb2022-09-19 16:09:04 +0000391 private final Telephony2gUpdater mTelephony2gUpdater;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700392
Peter Wangdafb9ac2020-01-15 14:13:38 -0800393 /** User Activity */
394 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800395 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
396
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700397 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
398
Derek Tan97ebb422014-09-05 16:55:38 -0700399 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
400 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800401 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800402 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700403
Michelecea4cf22018-12-21 15:00:11 -0800404 // String to store multi SIM allowed
405 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
406
Derek Tan740e1672017-06-27 14:56:27 -0700407 // The AID of ISD-R.
408 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
409
yinxub1bed742017-04-17 11:45:04 -0700410 private NetworkScanRequestTracker mNetworkScanRequestTracker;
411
David Kelly5e06a7f2018-03-12 14:10:59 +0000412 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
413 private static final int MANUFACTURER_CODE_LENGTH = 8;
414
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800415 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800416 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800417
Sarah Chin2ec39f62022-08-31 17:03:26 -0700418 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
419 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
420
Derek Tan89e89d42014-07-08 17:00:10 -0700421 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700422 * Experiment flag to enable erase modem config on reset network, default value is false
423 */
424 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
425 "reset_network_erase_modem_config_enabled";
426
Rambo Wang0f050d82021-02-12 11:43:36 -0800427 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800428
sandeepjsb6c87872021-09-27 15:34:44 +0000429 /**
430 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
431 * one ICCID active at the same time.
432 * Apps should use below API signatures if targeting SDK is T and beyond.
433 *
434 * @hide
435 */
436 @ChangeId
437 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
438 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800439
Naina Nallurid63128d2019-09-17 14:10:30 -0700440 /**
Chen Xu540470b2021-12-14 17:15:47 -0800441 * Apps targeting on Android T and beyond will get exception whenever icc close channel
442 * operation fails.
443 */
444 @ChangeId
445 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
446 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
447
448 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700449 * A request object to use for transmitting data to an ICC.
450 */
451 private static final class IccAPDUArgument {
452 public int channel, cla, command, p1, p2, p3;
453 public String data;
454
455 public IccAPDUArgument(int channel, int cla, int command,
456 int p1, int p2, int p3, String data) {
457 this.channel = channel;
458 this.cla = cla;
459 this.command = command;
460 this.p1 = p1;
461 this.p2 = p2;
462 this.p3 = p3;
463 this.data = data;
464 }
465 }
466
467 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700468 * A request object to use for transmitting data to an ICC.
469 */
470 private static final class ManualNetworkSelectionArgument {
471 public OperatorInfo operatorInfo;
472 public boolean persistSelection;
473
474 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
475 this.operatorInfo = operatorInfo;
476 this.persistSelection = persistSelection;
477 }
478 }
479
Sarah Chin71b3a852022-09-28 15:54:19 -0700480 private static final class PurchasePremiumCapabilityArgument {
481 public @TelephonyManager.PremiumCapability int capability;
482 public @NonNull String appName;
483 public @NonNull IIntegerConsumer callback;
484
485 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
486 @NonNull String appName, @NonNull IIntegerConsumer callback) {
487 this.capability = capability;
488 this.appName = appName;
489 this.callback = callback;
490 }
491 }
492
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700493 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700494 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
495 * request after sending. The main thread will notify the request when it is complete.
496 */
497 private static final class MainThreadRequest {
498 /** The argument to use for the request */
499 public Object argument;
500 /** The result of the request that is run on the main thread */
501 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800502 // The subscriber id that this request applies to. Defaults to
503 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
504 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700505
Nathan Harold92bed182018-10-12 18:16:49 -0700506 // In cases where subId is unavailable, the caller needs to specify the phone.
507 public Phone phone;
508
vagdeviaf9a5b92018-08-15 16:01:53 -0700509 public WorkSource workSource;
510
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700511 public MainThreadRequest(Object argument) {
512 this.argument = argument;
513 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800514
Nathan Harold92bed182018-10-12 18:16:49 -0700515 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
516 this.argument = argument;
517 if (phone != null) {
518 this.phone = phone;
519 }
520 this.workSource = workSource;
521 }
522
vagdeviaf9a5b92018-08-15 16:01:53 -0700523 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800524 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800525 if (subId != null) {
526 this.subId = subId;
527 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700528 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800529 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700530 }
531
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800532 private static final class IncomingThirdPartyCallArgs {
533 public final ComponentName component;
534 public final String callId;
535 public final String callerDisplayName;
536
537 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
538 String callerDisplayName) {
539 this.component = component;
540 this.callId = callId;
541 this.callerDisplayName = callerDisplayName;
542 }
543 }
544
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545 /**
546 * A handler that processes messages on the main thread in the phone process. Since many
547 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
548 * inbound binder threads to the main thread in the phone process. The Binder thread
549 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
550 * on, which will be notified when the operation completes and will contain the result of the
551 * request.
552 *
553 * <p>If a MainThreadRequest object is provided in the msg.obj field,
554 * note that request.result must be set to something non-null for the calling thread to
555 * unblock.
556 */
557 private final class MainThreadHandler extends Handler {
558 @Override
559 public void handleMessage(Message msg) {
560 MainThreadRequest request;
561 Message onCompleted;
562 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000563 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800565 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700566
567 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700568 case CMD_HANDLE_USSD_REQUEST: {
569 request = (MainThreadRequest) msg.obj;
570 final Phone phone = getPhoneFromRequest(request);
571 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800572 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700573 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700574
Pengquan Menga1bb6272018-09-06 09:59:22 -0700575 if (!isUssdApiAllowed(request.subId)) {
576 // Carrier does not support use of this API, return failure.
577 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
578 UssdResponse response = new UssdResponse(ussdRequest, null);
579 Bundle returnData = new Bundle();
580 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
581 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700582
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 request.result = true;
584 notifyRequester(request);
585 return;
586 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700587
Pengquan Menga1bb6272018-09-06 09:59:22 -0700588 try {
589 request.result = phone != null
590 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
591 } catch (CallStateException cse) {
592 request.result = false;
593 }
594 // Wake up the requesting thread
595 notifyRequester(request);
596 break;
pkanwar32d516d2016-10-14 19:37:38 -0700597 }
598
Yorke Lee716f67e2015-06-17 15:39:16 -0700599 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700600 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700601 final Phone phone = getPhoneFromRequest(request);
602 request.result = phone != null ?
603 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
604 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700605 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700606 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700607 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700608 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700609
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000613 uiccPort = getUiccPortFromRequest(request);
614 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700615 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800616 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700618 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700619 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800620 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000621 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800622 iccArgument.channel, iccArgument.cla, iccArgument.command,
623 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
624 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700625 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 break;
627
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700628 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 ar = (AsyncResult) msg.obj;
630 request = (MainThreadRequest) ar.userObj;
631 if (ar.exception == null && ar.result != null) {
632 request.result = ar.result;
633 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800634 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 if (ar.result == null) {
636 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800637 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800639 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 } else {
641 loge("iccTransmitApduLogicalChannel: Unknown exception");
642 }
643 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700644 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 break;
646
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700647 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
648 request = (MainThreadRequest) msg.obj;
649 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000650 uiccPort = getUiccPortFromRequest(request);
651 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700652 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800653 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700655 } else {
656 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800657 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000658 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800659 iccArgument.cla, iccArgument.command, iccArgument.p1,
660 iccArgument.p2,
661 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700662 }
663 break;
664
665 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
666 ar = (AsyncResult) msg.obj;
667 request = (MainThreadRequest) ar.userObj;
668 if (ar.exception == null && ar.result != null) {
669 request.result = ar.result;
670 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800671 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700672 if (ar.result == null) {
673 loge("iccTransmitApduBasicChannel: Empty response");
674 } else if (ar.exception instanceof CommandException) {
675 loge("iccTransmitApduBasicChannel: CommandException: " +
676 ar.exception);
677 } else {
678 loge("iccTransmitApduBasicChannel: Unknown exception");
679 }
680 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700681 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700682 break;
683
684 case CMD_EXCHANGE_SIM_IO:
685 request = (MainThreadRequest) msg.obj;
686 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000687 uiccPort = getUiccPortFromRequest(request);
688 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700689 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800690 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700691 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700692 } else {
693 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
694 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000695 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700696 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
697 iccArgument.data, onCompleted);
698 }
699 break;
700
701 case EVENT_EXCHANGE_SIM_IO_DONE:
702 ar = (AsyncResult) msg.obj;
703 request = (MainThreadRequest) ar.userObj;
704 if (ar.exception == null && ar.result != null) {
705 request.result = ar.result;
706 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800707 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700709 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700710 break;
711
Derek Tan4d5e5c12014-02-04 11:54:58 -0800712 case CMD_SEND_ENVELOPE:
713 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000714 uiccPort = getUiccPortFromRequest(request);
715 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700716 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800717 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700718 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700719 } else {
720 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800721 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700722 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800723 break;
724
725 case EVENT_SEND_ENVELOPE_DONE:
726 ar = (AsyncResult) msg.obj;
727 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700728 if (ar.exception == null && ar.result != null) {
729 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800730 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800731 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700732 if (ar.result == null) {
733 loge("sendEnvelopeWithStatus: Empty response");
734 } else if (ar.exception instanceof CommandException) {
735 loge("sendEnvelopeWithStatus: CommandException: " +
736 ar.exception);
737 } else {
738 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
739 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800740 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700741 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800742 break;
743
Shishir Agrawal566b7612013-10-28 14:41:00 -0700744 case CMD_OPEN_CHANNEL:
745 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000746 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800747 IccLogicalChannelRequest openChannelRequest =
748 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000749 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700750 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800751 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800752 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700753 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700754 } else {
755 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800756 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
757 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700758 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700759 break;
760
761 case EVENT_OPEN_CHANNEL_DONE:
762 ar = (AsyncResult) msg.obj;
763 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700764 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700765 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700766 int[] result = (int[]) ar.result;
767 int channelId = result[0];
768 byte[] selectResponse = null;
769 if (result.length > 1) {
770 selectResponse = new byte[result.length - 1];
771 for (int i = 1; i < result.length; ++i) {
772 selectResponse[i - 1] = (byte) result[i];
773 }
774 }
775 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800776 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800777
778 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700779 if (uiccPort == null) {
780 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
781 } else {
782 IccLogicalChannelRequest channelRequest =
783 (IccLogicalChannelRequest) request.argument;
784 channelRequest.channel = channelId;
785 uiccPort.onLogicalChannelOpened(channelRequest);
786 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700787 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700788 if (ar.result == null) {
789 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700790 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700791 if (ar.exception != null) {
792 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
793 }
794
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700795 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700796 if (ar.exception instanceof CommandException) {
797 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800798 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700799 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700800 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700801 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700802 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700803 }
804 }
805 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800806 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700807 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700808 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700809 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700810 break;
811
812 case CMD_CLOSE_CHANNEL:
813 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000814 uiccPort = getUiccPortFromRequest(request);
815 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700816 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800817 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800818 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800819 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700820 } else {
821 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000822 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700823 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700824 break;
825
826 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800827 ar = (AsyncResult) msg.obj;
828 request = (MainThreadRequest) ar.userObj;
829 if (ar.exception == null) {
830 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800831 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700832 if (uiccPort == null) {
833 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
834 } else {
835 final int channelId = (Integer) request.argument;
836 uiccPort.onLogicalChannelClosed(channelId);
837 }
Chen Xu540470b2021-12-14 17:15:47 -0800838 } else {
839 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800840 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800841 if (ar.exception instanceof CommandException) {
842 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
843 CommandException.Error error =
844 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800845 if (error == CommandException.Error.INVALID_ARGUMENTS) {
846 // should only throw exceptions from the binder threads.
847 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800848 "iccCloseLogicalChannel: invalid argument ");
849 }
850 } else {
851 loge("iccCloseLogicalChannel: Unknown exception");
852 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800853 request.result = (exception != null) ? exception :
854 new IllegalStateException(
855 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800856 }
857 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800858 break;
859
860 case CMD_NV_READ_ITEM:
861 request = (MainThreadRequest) msg.obj;
862 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800863 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
864 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800865 break;
866
867 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700868 ar = (AsyncResult) msg.obj;
869 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800870 if (ar.exception == null && ar.result != null) {
871 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700872 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800873 request.result = "";
874 if (ar.result == null) {
875 loge("nvReadItem: Empty response");
876 } else if (ar.exception instanceof CommandException) {
877 loge("nvReadItem: CommandException: " +
878 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700879 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800880 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700881 }
882 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700883 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700884 break;
885
Jake Hambye994d462014-02-03 13:10:13 -0800886 case CMD_NV_WRITE_ITEM:
887 request = (MainThreadRequest) msg.obj;
888 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
889 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800890 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700891 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800892 break;
893
894 case EVENT_NV_WRITE_ITEM_DONE:
895 handleNullReturnEvent(msg, "nvWriteItem");
896 break;
897
898 case CMD_NV_WRITE_CDMA_PRL:
899 request = (MainThreadRequest) msg.obj;
900 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800901 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800902 break;
903
904 case EVENT_NV_WRITE_CDMA_PRL_DONE:
905 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
906 break;
907
chen xu6dac5ab2018-10-26 17:39:23 -0700908 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800909 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700910 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800911 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800912 break;
913
chen xu6dac5ab2018-10-26 17:39:23 -0700914 case EVENT_RESET_MODEM_CONFIG_DONE:
915 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800916 break;
917
Sooraj Sasindran37444802020-08-11 10:40:43 -0700918 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
919 request = (MainThreadRequest) msg.obj;
920 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
921 request);
922 Phone phone = getPhoneFromRequest(request);
923 if (phone != null) {
924 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
925 } else {
926 loge("isNRDualConnectivityEnabled: No phone object");
927 request.result = false;
928 notifyRequester(request);
929 }
930 break;
931 }
932
933 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
934 ar = (AsyncResult) msg.obj;
935 request = (MainThreadRequest) ar.userObj;
936 if (ar.exception == null && ar.result != null) {
937 request.result = ar.result;
938 } else {
939 // request.result must be set to something non-null
940 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700941 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700942 request.result = ar.result;
943 } else {
944 request.result = false;
945 }
946 if (ar.result == null) {
947 loge("isNRDualConnectivityEnabled: Empty response");
948 } else if (ar.exception instanceof CommandException) {
949 loge("isNRDualConnectivityEnabled: CommandException: "
950 + ar.exception);
951 } else {
952 loge("isNRDualConnectivityEnabled: Unknown exception");
953 }
954 }
955 notifyRequester(request);
956 break;
957
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700958 case CMD_IS_VONR_ENABLED: {
959 request = (MainThreadRequest) msg.obj;
960 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
961 request);
962 Phone phone = getPhoneFromRequest(request);
963 if (phone != null) {
964 phone.isVoNrEnabled(onCompleted, request.workSource);
965 } else {
966 loge("isVoNrEnabled: No phone object");
967 request.result = false;
968 notifyRequester(request);
969 }
970 break;
971 }
972
973 case EVENT_IS_VONR_ENABLED_DONE:
974 ar = (AsyncResult) msg.obj;
975 request = (MainThreadRequest) ar.userObj;
976 if (ar.exception == null && ar.result != null) {
977 request.result = ar.result;
978 } else {
979 // request.result must be set to something non-null
980 // for the calling thread to unblock
981 if (ar.result != null) {
982 request.result = ar.result;
983 } else {
984 request.result = false;
985 }
986 if (ar.result == null) {
987 loge("isVoNrEnabled: Empty response");
988 } else if (ar.exception instanceof CommandException) {
989 loge("isVoNrEnabled: CommandException: "
990 + ar.exception);
991 } else {
992 loge("isVoNrEnabled: Unknown exception");
993 }
994 }
995 notifyRequester(request);
996 break;
997
Sooraj Sasindran37444802020-08-11 10:40:43 -0700998 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
999 request = (MainThreadRequest) msg.obj;
1000 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1001 Phone phone = getPhoneFromRequest(request);
1002 if (phone != null) {
1003 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1004 request.workSource);
1005 } else {
1006 loge("enableNrDualConnectivity: No phone object");
1007 request.result =
1008 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1009 notifyRequester(request);
1010 }
1011 break;
1012 }
1013
1014 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1015 ar = (AsyncResult) msg.obj;
1016 request = (MainThreadRequest) ar.userObj;
1017 if (ar.exception == null) {
1018 request.result =
1019 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1020 } else {
1021 request.result =
1022 TelephonyManager
1023 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1024 if (ar.exception instanceof CommandException) {
1025 CommandException.Error error =
1026 ((CommandException) (ar.exception)).getCommandError();
1027 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1028 request.result =
1029 TelephonyManager
1030 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001031 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1032 request.result =
1033 TelephonyManager
1034 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001035 }
1036 loge("enableNrDualConnectivity" + ": CommandException: "
1037 + ar.exception);
1038 } else {
1039 loge("enableNrDualConnectivity" + ": Unknown exception");
1040 }
1041 }
1042 notifyRequester(request);
1043 break;
1044 }
1045
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001046 case CMD_ENABLE_VONR: {
1047 request = (MainThreadRequest) msg.obj;
1048 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1049 Phone phone = getPhoneFromRequest(request);
1050 if (phone != null) {
1051 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1052 request.workSource);
1053 } else {
1054 loge("setVoNrEnabled: No phone object");
1055 request.result =
1056 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1057 notifyRequester(request);
1058 }
1059 break;
1060 }
1061
1062 case EVENT_ENABLE_VONR_DONE: {
1063 ar = (AsyncResult) msg.obj;
1064 request = (MainThreadRequest) ar.userObj;
1065 if (ar.exception == null) {
1066 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1067 } else {
1068 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1069 if (ar.exception instanceof CommandException) {
1070 CommandException.Error error =
1071 ((CommandException) (ar.exception)).getCommandError();
1072 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1073 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1074 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1075 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1076 } else {
1077 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1078 }
1079 loge("setVoNrEnabled" + ": CommandException: "
1080 + ar.exception);
1081 } else {
1082 loge("setVoNrEnabled" + ": Unknown exception");
1083 }
1084 }
1085 notifyRequester(request);
1086 break;
1087 }
1088
SongFerngWang3ef3e072020-12-21 16:41:52 +08001089 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001090 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001091 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1092 request);
1093 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001094 break;
1095
SongFerngWang3ef3e072020-12-21 16:41:52 +08001096 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001097 ar = (AsyncResult) msg.obj;
1098 request = (MainThreadRequest) ar.userObj;
1099 if (ar.exception == null && ar.result != null) {
1100 request.result = ar.result; // Integer
1101 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301102 // request.result must be set to something non-null
1103 // for the calling thread to unblock
1104 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001105 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001106 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001107 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001108 loge("getAllowedNetworkTypesBitmask: CommandException: "
1109 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001110 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001111 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001112 }
1113 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001114 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001115 break;
1116
SongFerngWang3ef3e072020-12-21 16:41:52 +08001117 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001118 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001119 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1120 request);
1121 Pair<Integer, Long> reasonWithNetworkTypes =
1122 (Pair<Integer, Long>) request.argument;
1123 getPhoneFromRequest(request).setAllowedNetworkTypes(
1124 reasonWithNetworkTypes.first,
1125 reasonWithNetworkTypes.second,
1126 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001127 break;
1128
SongFerngWang3ef3e072020-12-21 16:41:52 +08001129 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1130 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001131 break;
1132
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001133 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1134 request = (MainThreadRequest)msg.obj;
1135 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001136 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001137 break;
1138
1139 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1140 ar = (AsyncResult)msg.obj;
1141 request = (MainThreadRequest)ar.userObj;
1142 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001143 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001144 break;
1145
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001146 case CMD_SET_VOICEMAIL_NUMBER:
1147 request = (MainThreadRequest) msg.obj;
1148 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1149 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001150 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1151 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001152 break;
1153
1154 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1155 handleNullReturnEvent(msg, "setVoicemailNumber");
1156 break;
1157
Stuart Scott54788802015-03-30 13:18:01 -07001158 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1159 request = (MainThreadRequest) msg.obj;
1160 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1161 request);
1162 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1163 break;
1164
1165 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1166 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1167 break;
1168
Shishir Agrawal302c8692015-06-19 13:49:39 -07001169 case CMD_PERFORM_NETWORK_SCAN:
1170 request = (MainThreadRequest) msg.obj;
1171 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1172 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1173 break;
1174
Hall Liu27d24262020-09-18 19:04:59 -07001175 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001176 request = (MainThreadRequest) msg.obj;
1177 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001178 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1179 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1180 request.argument;
1181 int callForwardingReason = args.first;
1182 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001183 break;
Hall Liu27d24262020-09-18 19:04:59 -07001184 }
1185 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001186 ar = (AsyncResult) msg.obj;
1187 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001188 TelephonyManager.CallForwardingInfoCallback callback =
1189 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1190 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001191 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001192 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001193 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1194 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1195 // Service Class is a bit mask per 3gpp 27.007. Search for
1196 // any service for voice call.
1197 if ((callForwardInfo.serviceClass
1198 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001199 callForwardingInfo = new CallForwardingInfo(
1200 callForwardInfo.status
1201 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001202 callForwardInfo.reason,
1203 callForwardInfo.number,
1204 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001205 break;
1206 }
1207 }
1208 // Didn't find a call forward info for voice call.
1209 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001210 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1211 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001212 }
Hall Liu27d24262020-09-18 19:04:59 -07001213 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001214 } else {
1215 if (ar.result == null) {
1216 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1217 }
1218 if (ar.exception != null) {
1219 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1220 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001221 int errorCode = TelephonyManager
1222 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001223 if (ar.exception instanceof CommandException) {
1224 CommandException.Error error =
1225 ((CommandException) (ar.exception)).getCommandError();
1226 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001227 errorCode = TelephonyManager
1228 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001229 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001230 errorCode = TelephonyManager
1231 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001232 }
1233 }
Hall Liu27d24262020-09-18 19:04:59 -07001234 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001235 }
Shuo Qian4a594052020-01-23 11:59:30 -08001236 break;
Hall Liu27d24262020-09-18 19:04:59 -07001237 }
Shuo Qian4a594052020-01-23 11:59:30 -08001238
Hall Liu27d24262020-09-18 19:04:59 -07001239 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001240 request = (MainThreadRequest) msg.obj;
1241 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001242 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001243 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001244 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1245 request.argument).first;
1246 request.phone.setCallForwardingOption(
1247 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001248 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001249 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001250 callForwardingInfoToSet.getReason(),
1251 callForwardingInfoToSet.getNumber(),
1252 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1253 break;
Hall Liu27d24262020-09-18 19:04:59 -07001254 }
Shuo Qian4a594052020-01-23 11:59:30 -08001255
Hall Liu27d24262020-09-18 19:04:59 -07001256 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001257 ar = (AsyncResult) msg.obj;
1258 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001259 Consumer<Integer> callback =
1260 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1261 request.argument).second;
1262 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001263 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001264 int errorCode = TelephonyManager.CallForwardingInfoCallback
1265 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001266 if (ar.exception instanceof CommandException) {
1267 CommandException.Error error =
1268 ((CommandException) (ar.exception)).getCommandError();
1269 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001270 errorCode = TelephonyManager.CallForwardingInfoCallback
1271 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001272 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001273 errorCode = TelephonyManager.CallForwardingInfoCallback
1274 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001275 }
1276 }
1277 callback.accept(errorCode);
1278 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001279 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001280 }
Shuo Qian4a594052020-01-23 11:59:30 -08001281 break;
Hall Liu27d24262020-09-18 19:04:59 -07001282 }
Shuo Qian4a594052020-01-23 11:59:30 -08001283
Hall Liu27d24262020-09-18 19:04:59 -07001284 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001285 request = (MainThreadRequest) msg.obj;
1286 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1287 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1288 break;
Hall Liu27d24262020-09-18 19:04:59 -07001289 }
Shuo Qian4a594052020-01-23 11:59:30 -08001290
Hall Liu27d24262020-09-18 19:04:59 -07001291 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001292 ar = (AsyncResult) msg.obj;
1293 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001294 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001295 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001296 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001297 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001298 // Service Class is a bit mask per 3gpp 27.007.
1299 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001300 if (callForwardResults.length > 1
1301 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001302 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001303 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001304 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1305 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001306 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001307 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001308 }
1309 } else {
1310 if (ar.result == null) {
1311 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1312 }
1313 if (ar.exception != null) {
1314 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1315 }
1316 if (ar.exception instanceof CommandException) {
1317 CommandException.Error error =
1318 ((CommandException) (ar.exception)).getCommandError();
1319 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001320 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001321 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001322 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1323 callWaitingStatus =
1324 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001325 }
1326 }
1327 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001328 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001329 break;
Hall Liu27d24262020-09-18 19:04:59 -07001330 }
Shuo Qian4a594052020-01-23 11:59:30 -08001331
Hall Liu27d24262020-09-18 19:04:59 -07001332 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001333 request = (MainThreadRequest) msg.obj;
1334 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001335 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1336 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001337 break;
Hall Liu27d24262020-09-18 19:04:59 -07001338 }
Shuo Qian4a594052020-01-23 11:59:30 -08001339
Hall Liu27d24262020-09-18 19:04:59 -07001340 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001341 ar = (AsyncResult) msg.obj;
1342 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001343 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1344 Consumer<Integer> callback =
1345 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1346 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001347 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001348 if (ar.exception instanceof CommandException) {
1349 CommandException.Error error =
1350 ((CommandException) (ar.exception)).getCommandError();
1351 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1352 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001353 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1354 callback.accept(
1355 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001356 } else {
1357 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1358 }
1359 } else {
1360 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1361 }
1362 } else {
1363 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1364 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001365 }
Shuo Qian4a594052020-01-23 11:59:30 -08001366 break;
Hall Liu27d24262020-09-18 19:04:59 -07001367 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001368 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1369 ar = (AsyncResult) msg.obj;
1370 request = (MainThreadRequest) ar.userObj;
1371 CellNetworkScanResult cellScanResult;
1372 if (ar.exception == null && ar.result != null) {
1373 cellScanResult = new CellNetworkScanResult(
1374 CellNetworkScanResult.STATUS_SUCCESS,
1375 (List<OperatorInfo>) ar.result);
1376 } else {
1377 if (ar.result == null) {
1378 loge("getCellNetworkScanResults: Empty response");
1379 }
1380 if (ar.exception != null) {
1381 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1382 }
1383 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1384 if (ar.exception instanceof CommandException) {
1385 CommandException.Error error =
1386 ((CommandException) (ar.exception)).getCommandError();
1387 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1388 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1389 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1390 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1391 }
1392 }
1393 cellScanResult = new CellNetworkScanResult(errorCode, null);
1394 }
1395 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001396 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001397 break;
1398
1399 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1400 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001401 ManualNetworkSelectionArgument selArg =
1402 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001403 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1404 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001405 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1406 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001407 break;
1408
1409 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001410 ar = (AsyncResult) msg.obj;
1411 request = (MainThreadRequest) ar.userObj;
1412 if (ar.exception == null) {
1413 request.result = true;
1414 } else {
1415 request.result = false;
1416 loge("setNetworkSelectionModeManual " + ar.exception);
1417 }
1418 notifyRequester(request);
1419 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001420 break;
1421
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001422 case CMD_GET_MODEM_ACTIVITY_INFO:
1423 request = (MainThreadRequest) msg.obj;
1424 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001425 if (defaultPhone != null) {
1426 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001427 } else {
1428 ResultReceiver result = (ResultReceiver) request.argument;
1429 Bundle bundle = new Bundle();
1430 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001431 new ModemActivityInfo(0, 0, 0,
1432 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001433 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001434 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001435 break;
1436
Hall Liud0f208c2020-10-14 16:54:44 -07001437 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001438 ar = (AsyncResult) msg.obj;
1439 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001440 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001441 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001442 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001443 if (mLastModemActivityInfo == null) {
1444 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1445 mLastModemActivitySpecificInfo[0] =
1446 new ActivityStatsTechSpecificInfo(
1447 0,
1448 0,
1449 new int[ModemActivityInfo.getNumTxPowerLevels()],
1450 0);
1451 mLastModemActivityInfo =
1452 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1453 }
1454
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001455 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001456 // Update the last modem activity info and the result of the request.
1457 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1458 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001459 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001460 }
Kai Shi917fdc62022-11-28 14:01:02 -08001461 // This is needed to decouple ret from mLastModemActivityInfo
1462 // We don't want to return mLastModemActivityInfo which is updated
1463 // inside mergeModemActivityInfo()
1464 ret = new ModemActivityInfo(
1465 mLastModemActivityInfo.getTimestampMillis(),
1466 mLastModemActivityInfo.getSleepTimeMillis(),
1467 mLastModemActivityInfo.getIdleTimeMillis(),
1468 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001469
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001470 } else {
1471 if (ar.result == null) {
1472 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001473 error = TelephonyManager.ModemActivityInfoException
1474 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001475 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001476 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001477 error = TelephonyManager.ModemActivityInfoException
1478 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001479 } else {
1480 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001481 error = TelephonyManager.ModemActivityInfoException
1482 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001483 }
1484 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001485 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001486 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001487 bundle.putParcelable(
1488 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001489 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001490 } else {
1491 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1492 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001493 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001494 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001495 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001496 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001497
Meng Wang1a7c35a2016-05-05 20:56:15 -07001498 case CMD_SET_ALLOWED_CARRIERS:
1499 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001500 CarrierRestrictionRules argument =
1501 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001502 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001503 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001504 break;
1505
1506 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1507 ar = (AsyncResult) msg.obj;
1508 request = (MainThreadRequest) ar.userObj;
1509 if (ar.exception == null && ar.result != null) {
1510 request.result = ar.result;
1511 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001512 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1513 if (ar.exception instanceof CommandException) {
1514 loge("setAllowedCarriers: CommandException: " + ar.exception);
1515 CommandException.Error error =
1516 ((CommandException) (ar.exception)).getCommandError();
1517 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1518 request.result =
1519 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1520 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001521 } else {
1522 loge("setAllowedCarriers: Unknown exception");
1523 }
1524 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001525 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001526 break;
1527
1528 case CMD_GET_ALLOWED_CARRIERS:
1529 request = (MainThreadRequest) msg.obj;
1530 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001531 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001532 break;
1533
1534 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1535 ar = (AsyncResult) msg.obj;
1536 request = (MainThreadRequest) ar.userObj;
1537 if (ar.exception == null && ar.result != null) {
1538 request.result = ar.result;
1539 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001540 request.result = new IllegalStateException(
1541 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001542 if (ar.result == null) {
1543 loge("getAllowedCarriers: Empty response");
1544 } else if (ar.exception instanceof CommandException) {
1545 loge("getAllowedCarriers: CommandException: " +
1546 ar.exception);
1547 } else {
1548 loge("getAllowedCarriers: Unknown exception");
1549 }
1550 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001551 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001552 break;
1553
Nathan Haroldb3014052017-01-25 15:57:32 -08001554 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1555 ar = (AsyncResult) msg.obj;
1556 request = (MainThreadRequest) ar.userObj;
1557 if (ar.exception == null && ar.result != null) {
1558 request.result = ar.result;
1559 } else {
1560 request.result = new IllegalArgumentException(
1561 "Failed to retrieve Forbidden Plmns");
1562 if (ar.result == null) {
1563 loge("getForbiddenPlmns: Empty response");
1564 } else {
1565 loge("getForbiddenPlmns: Unknown exception");
1566 }
1567 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001568 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001569 break;
1570
1571 case CMD_GET_FORBIDDEN_PLMNS:
1572 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001573 uiccPort = getUiccPortFromRequest(request);
1574 if (uiccPort == null) {
1575 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001576 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001577 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001578 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001579 break;
1580 }
1581 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001582 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001583 if (uiccApp == null) {
1584 loge("getForbiddenPlmns() no app with specified type -- "
1585 + appType);
1586 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001587 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001588 break;
1589 } else {
1590 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1591 + " specified type -- " + appType);
1592 }
1593 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1594 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1595 onCompleted);
1596 break;
1597
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001598 case CMD_SWITCH_SLOTS:
1599 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001600 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001601 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001602 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001603 break;
1604
1605 case EVENT_SWITCH_SLOTS_DONE:
1606 ar = (AsyncResult) msg.obj;
1607 request = (MainThreadRequest) ar.userObj;
1608 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001609 notifyRequester(request);
1610 break;
1611 case CMD_GET_NETWORK_SELECTION_MODE:
1612 request = (MainThreadRequest) msg.obj;
1613 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1614 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1615 break;
1616
1617 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1618 ar = (AsyncResult) msg.obj;
1619 request = (MainThreadRequest) ar.userObj;
1620 if (ar.exception != null) {
1621 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1622 } else {
1623 int mode = ((int[]) ar.result)[0];
1624 if (mode == 0) {
1625 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1626 } else {
1627 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1628 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001629 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001630 notifyRequester(request);
1631 break;
1632 case CMD_GET_CDMA_ROAMING_MODE:
1633 request = (MainThreadRequest) msg.obj;
1634 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1635 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1636 break;
1637 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1638 ar = (AsyncResult) msg.obj;
1639 request = (MainThreadRequest) ar.userObj;
1640 if (ar.exception != null) {
1641 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1642 } else {
1643 request.result = ((int[]) ar.result)[0];
1644 }
1645 notifyRequester(request);
1646 break;
1647 case CMD_SET_CDMA_ROAMING_MODE:
1648 request = (MainThreadRequest) msg.obj;
1649 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1650 int mode = (int) request.argument;
1651 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1652 break;
1653 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1654 ar = (AsyncResult) msg.obj;
1655 request = (MainThreadRequest) ar.userObj;
1656 request.result = ar.exception == null;
1657 notifyRequester(request);
1658 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001659 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1660 request = (MainThreadRequest) msg.obj;
1661 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1662 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1663 break;
1664 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1665 ar = (AsyncResult) msg.obj;
1666 request = (MainThreadRequest) ar.userObj;
1667 if (ar.exception != null) {
1668 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1669 } else {
1670 request.result = ((int[]) ar.result)[0];
1671 }
1672 notifyRequester(request);
1673 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001674 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1675 request = (MainThreadRequest) msg.obj;
1676 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1677 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001678 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1679 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001680 break;
1681 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1682 ar = (AsyncResult) msg.obj;
1683 request = (MainThreadRequest) ar.userObj;
1684 request.result = ar.exception == null;
1685 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001686 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001687 case CMD_GET_ALL_CELL_INFO:
1688 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001689 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001690 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001691 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001692 case EVENT_GET_ALL_CELL_INFO_DONE:
1693 ar = (AsyncResult) msg.obj;
1694 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001695 // If a timeout occurs, the response will be null
1696 request.result = (ar.exception == null && ar.result != null)
1697 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001698 synchronized (request) {
1699 request.notifyAll();
1700 }
1701 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001702 case CMD_REQUEST_CELL_INFO_UPDATE:
1703 request = (MainThreadRequest) msg.obj;
1704 request.phone.requestCellInfoUpdate(request.workSource,
1705 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1706 break;
1707 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1708 ar = (AsyncResult) msg.obj;
1709 request = (MainThreadRequest) ar.userObj;
1710 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1711 try {
1712 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001713 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001714 cb.onError(
1715 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1716 ar.exception.getClass().getName(),
1717 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001718 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001719 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001720 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001721 } else {
1722 // use the result as returned
1723 cb.onCellInfo((List<CellInfo>) ar.result);
1724 }
1725 } catch (RemoteException re) {
1726 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1727 }
1728 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001729 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001730 request = (MainThreadRequest) msg.obj;
1731 WorkSource ws = (WorkSource) request.argument;
1732 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001733 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001734 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001735 }
1736 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001737 ar = (AsyncResult) msg.obj;
1738 request = (MainThreadRequest) ar.userObj;
1739 if (ar.exception == null) {
1740 request.result = ar.result;
1741 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001742 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001743 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001744 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001745 }
1746
1747 synchronized (request) {
1748 request.notifyAll();
1749 }
1750 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001751 }
chen xu6dac5ab2018-10-26 17:39:23 -07001752 case CMD_MODEM_REBOOT:
1753 request = (MainThreadRequest) msg.obj;
1754 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001755 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001756 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001757 case EVENT_CMD_MODEM_REBOOT_DONE:
1758 handleNullReturnEvent(msg, "rebootModem");
1759 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001760 case CMD_REQUEST_ENABLE_MODEM:
1761 request = (MainThreadRequest) msg.obj;
1762 boolean enable = (boolean) request.argument;
1763 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001764 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001765 PhoneConfigurationManager.getInstance()
1766 .enablePhone(request.phone, enable, onCompleted);
1767 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001768 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001769 ar = (AsyncResult) msg.obj;
1770 request = (MainThreadRequest) ar.userObj;
1771 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001772 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001773 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001774 if ((boolean) request.result) {
1775 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1776 updateModemStateMetrics();
1777 } else {
1778 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1779 + ar.exception);
1780 }
1781 notifyRequester(request);
1782 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001783 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001784 case CMD_GET_MODEM_STATUS:
1785 request = (MainThreadRequest) msg.obj;
1786 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1787 PhoneConfigurationManager.getInstance()
1788 .getPhoneStatusFromModem(request.phone, onCompleted);
1789 break;
1790 case EVENT_GET_MODEM_STATUS_DONE:
1791 ar = (AsyncResult) msg.obj;
1792 request = (MainThreadRequest) ar.userObj;
1793 int id = request.phone.getPhoneId();
1794 if (ar.exception == null && ar.result != null) {
1795 request.result = ar.result;
1796 //update the cache as modem status has changed
1797 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1798 (boolean) request.result);
1799 } else {
1800 // Return true if modem status cannot be retrieved. For most cases,
1801 // modem status is on. And for older version modems, GET_MODEM_STATUS
1802 // and disable modem are not supported. Modem is always on.
1803 // TODO: this should be fixed in R to support a third
1804 // status UNKNOWN b/131631629
1805 request.result = true;
1806 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1807 + ar.exception);
1808 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001809 notifyRequester(request);
1810 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001811 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1812 request = (MainThreadRequest) msg.obj;
1813 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1814 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1815 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1816 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1817 break;
1818 }
1819 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1820 ar = (AsyncResult) msg.obj;
1821 request = (MainThreadRequest) ar.userObj;
1822 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1823 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1824 args.second.accept(ar.exception == null);
1825 notifyRequester(request);
1826 break;
1827 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001828 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1829 request = (MainThreadRequest) msg.obj;
1830 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1831 Phone phone = getPhoneFromRequest(request);
1832 if (phone != null) {
1833 phone.getSystemSelectionChannels(onCompleted);
1834 } else {
1835 loge("getSystemSelectionChannels: No phone object");
1836 request.result = new ArrayList<RadioAccessSpecifier>();
1837 notifyRequester(request);
1838 }
1839 break;
1840 }
1841 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1842 ar = (AsyncResult) msg.obj;
1843 request = (MainThreadRequest) ar.userObj;
1844 if (ar.exception == null && ar.result != null) {
1845 request.result = ar.result;
1846 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001847 request.result = new IllegalStateException(
1848 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001849 if (ar.result == null) {
1850 loge("getSystemSelectionChannels: Empty response");
1851 } else {
1852 loge("getSystemSelectionChannels: Unknown exception");
1853 }
1854 }
1855 notifyRequester(request);
1856 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001857 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1858 ar = (AsyncResult) msg.obj;
1859 request = (MainThreadRequest) ar.userObj;
1860 if (ar.exception == null && ar.result != null) {
1861 request.result = ar.result;
1862 } else {
1863 request.result = -1;
1864 loge("Failed to set Forbidden Plmns");
1865 if (ar.result == null) {
1866 loge("setForbidenPlmns: Empty response");
1867 } else if (ar.exception != null) {
1868 loge("setForbiddenPlmns: Exception: " + ar.exception);
1869 request.result = -1;
1870 } else {
1871 loge("setForbiddenPlmns: Unknown exception");
1872 }
1873 }
1874 notifyRequester(request);
1875 break;
1876 case CMD_SET_FORBIDDEN_PLMNS:
1877 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001878 uiccPort = getUiccPortFromRequest(request);
1879 if (uiccPort == null) {
1880 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001881 request.result = -1;
1882 notifyRequester(request);
1883 break;
1884 }
1885 Pair<Integer, List<String>> setFplmnsArgs =
1886 (Pair<Integer, List<String>>) request.argument;
1887 appType = setFplmnsArgs.first;
1888 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001889 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001890 if (uiccApp == null) {
1891 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1892 request.result = -1;
1893 loge("Failed to get UICC App");
1894 notifyRequester(request);
1895 } else {
1896 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1897 ((SIMRecords) uiccApp.getIccRecords())
1898 .setForbiddenPlmns(onCompleted, fplmns);
1899 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001900 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001901 case CMD_ERASE_MODEM_CONFIG:
1902 request = (MainThreadRequest) msg.obj;
1903 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1904 defaultPhone.eraseModemConfig(onCompleted);
1905 break;
1906 case EVENT_ERASE_MODEM_CONFIG_DONE:
1907 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001908 break;
zoey chene02881a2019-12-30 16:11:23 +08001909
Kai Shif70f46f2021-03-03 13:59:46 -08001910 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1911 request = (MainThreadRequest) msg.obj;
1912 request.result = defaultPhone.eraseDataInSharedPreferences();
1913 notifyRequester(request);
1914 break;
1915
zoey chene02881a2019-12-30 16:11:23 +08001916 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1917 request = (MainThreadRequest) msg.obj;
1918 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1919 Pair<String, String> changed = (Pair<String, String>) request.argument;
1920 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1921 changed.first, changed.second, onCompleted);
1922 break;
1923 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1924 ar = (AsyncResult) msg.obj;
1925 request = (MainThreadRequest) ar.userObj;
1926 if (ar.exception == null) {
1927 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001928 // If the operation is successful, update the PIN storage
1929 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1930 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001931 UiccController.getInstance().getPinStorage()
1932 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001933 } else {
1934 request.result = msg.arg1;
1935 }
1936 notifyRequester(request);
1937 break;
1938
Michele Berionne5e411512020-11-13 02:36:59 +00001939 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001940 request = (MainThreadRequest) msg.obj;
1941 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1942 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1943 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1944 enabled.first, enabled.second, onCompleted);
1945 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001946 }
zoey chene02881a2019-12-30 16:11:23 +08001947 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1948 ar = (AsyncResult) msg.obj;
1949 request = (MainThreadRequest) ar.userObj;
1950 if (ar.exception == null) {
1951 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001952 // If the operation is successful, update the PIN storage
1953 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1954 int phoneId = getPhoneFromRequest(request).getPhoneId();
1955 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001956 UiccController.getInstance().getPinStorage()
1957 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001958 } else {
1959 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1960 }
zoey chene02881a2019-12-30 16:11:23 +08001961 } else {
1962 request.result = msg.arg1;
1963 }
Michele Berionne5e411512020-11-13 02:36:59 +00001964
1965
zoey chene02881a2019-12-30 16:11:23 +08001966 notifyRequester(request);
1967 break;
1968
Peter Wangdafb9ac2020-01-15 14:13:38 -08001969 case MSG_NOTIFY_USER_ACTIVITY:
1970 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001971 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001972 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1973 getDefaultPhone().getContext().sendBroadcastAsUser(
1974 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1975 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001976
1977 case CMD_SET_DATA_THROTTLING: {
1978 request = (MainThreadRequest) msg.obj;
1979 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1980 DataThrottlingRequest dataThrottlingRequest =
1981 (DataThrottlingRequest) request.argument;
1982 Phone phone = getPhoneFromRequest(request);
1983 if (phone != null) {
1984 phone.setDataThrottling(onCompleted,
1985 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1986 dataThrottlingRequest.getCompletionDurationMillis());
1987 } else {
1988 loge("setDataThrottling: No phone object");
1989 request.result =
1990 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1991 notifyRequester(request);
1992 }
1993
1994 break;
1995 }
1996 case EVENT_SET_DATA_THROTTLING_DONE:
1997 ar = (AsyncResult) msg.obj;
1998 request = (MainThreadRequest) ar.userObj;
1999
2000 if (ar.exception == null) {
2001 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2002 } else if (ar.exception instanceof CommandException) {
2003 loge("setDataThrottling: CommandException: " + ar.exception);
2004 CommandException.Error error =
2005 ((CommandException) (ar.exception)).getCommandError();
2006
2007 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2008 request.result = TelephonyManager
2009 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2010 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2011 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002012 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2013 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002014 } else {
2015 request.result =
2016 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2017 }
2018 } else {
2019 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2020 }
2021 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2022 notifyRequester(request);
2023 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002024
2025 case CMD_SET_SIM_POWER: {
2026 request = (MainThreadRequest) msg.obj;
2027 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2028 request = (MainThreadRequest) msg.obj;
2029 int stateToSet =
2030 ((Pair<Integer, IIntegerConsumer>)
2031 request.argument).first;
2032 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2033 break;
2034 }
2035 case EVENT_SET_SIM_POWER_DONE: {
2036 ar = (AsyncResult) msg.obj;
2037 request = (MainThreadRequest) ar.userObj;
2038 IIntegerConsumer callback =
2039 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2040 if (ar.exception != null) {
2041 loge("setSimPower exception: " + ar.exception);
2042 int errorCode = TelephonyManager.CallForwardingInfoCallback
2043 .RESULT_ERROR_UNKNOWN;
2044 if (ar.exception instanceof CommandException) {
2045 CommandException.Error error =
2046 ((CommandException) (ar.exception)).getCommandError();
2047 if (error == CommandException.Error.SIM_ERR) {
2048 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2049 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2050 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2051 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2052 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2053 } else {
2054 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2055 }
2056 }
2057 try {
2058 callback.accept(errorCode);
2059 } catch (RemoteException e) {
2060 // Ignore if the remote process is no longer available to call back.
2061 Log.w(LOG_TAG, "setSimPower: callback not available.");
2062 }
2063 } else {
2064 try {
2065 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2066 } catch (RemoteException e) {
2067 // Ignore if the remote process is no longer available to call back.
2068 Log.w(LOG_TAG, "setSimPower: callback not available.");
2069 }
2070 }
2071 break;
2072 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002073 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2074 request = (MainThreadRequest) msg.obj;
2075
2076 final Phone phone = getPhoneFromRequest(request);
2077 if (phone == null || phone.getServiceStateTracker() == null) {
2078 request.result = new IllegalStateException("Phone or SST is null");
2079 notifyRequester(request);
2080 break;
2081 }
2082
2083 Pair<Integer, SignalStrengthUpdateRequest> pair =
2084 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2085 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2086 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002087 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002088 request.subId, pair.first /*callingUid*/,
2089 pair.second /*request*/, onCompleted);
2090 break;
2091 }
2092 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2093 ar = (AsyncResult) msg.obj;
2094 request = (MainThreadRequest) ar.userObj;
2095 // request.result will be the exception of ar if present, true otherwise.
2096 // Be cautious not to leave result null which will wait() forever
2097 request.result = ar.exception != null ? ar.exception : true;
2098 notifyRequester(request);
2099 break;
2100 }
2101 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2102 request = (MainThreadRequest) msg.obj;
2103
2104 Phone phone = getPhoneFromRequest(request);
2105 if (phone == null || phone.getServiceStateTracker() == null) {
2106 request.result = new IllegalStateException("Phone or SST is null");
2107 notifyRequester(request);
2108 break;
2109 }
2110
2111 Pair<Integer, SignalStrengthUpdateRequest> pair =
2112 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2113 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2114 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002115 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002116 request.subId, pair.first /*callingUid*/,
2117 pair.second /*request*/, onCompleted);
2118 break;
2119 }
2120 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2121 ar = (AsyncResult) msg.obj;
2122 request = (MainThreadRequest) ar.userObj;
2123 request.result = ar.exception != null ? ar.exception : true;
2124 notifyRequester(request);
2125 break;
2126 }
Jordan Liu109698e2020-11-24 14:50:34 -08002127
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002128 case CMD_GET_SLICING_CONFIG: {
2129 request = (MainThreadRequest) msg.obj;
2130 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2131 request.phone.getSlicingConfig(onCompleted);
2132 break;
2133 }
2134 case EVENT_GET_SLICING_CONFIG_DONE: {
2135 ar = (AsyncResult) msg.obj;
2136 request = (MainThreadRequest) ar.userObj;
2137 ResultReceiver result = (ResultReceiver) request.argument;
2138
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002139 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002140 Bundle bundle = new Bundle();
2141 int resultCode = 0;
2142 if (ar.exception != null) {
2143 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2144 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002145 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002146 } else if (ar.result == null) {
2147 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002148 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002149 } else {
2150 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002151 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2152 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002153 }
2154
2155 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002156 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002157 }
2158 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2159 result.send(resultCode, bundle);
2160 notifyRequester(request);
2161 break;
2162 }
2163
Sarah Chin71b3a852022-09-28 15:54:19 -07002164 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002165 request = (MainThreadRequest) msg.obj;
2166 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002167 PurchasePremiumCapabilityArgument arg =
2168 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002169 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chin71b3a852022-09-28 15:54:19 -07002170 arg.capability, arg.appName, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002171 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002172 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002173
Sarah Chin71b3a852022-09-28 15:54:19 -07002174 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002175 ar = (AsyncResult) msg.obj;
2176 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002177 PurchasePremiumCapabilityArgument arg =
2178 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002179 try {
2180 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002181 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002182 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002183 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002184 + ", result= "
2185 + TelephonyManager.convertPurchaseResultToString(result));
2186 } catch (RemoteException e) {
2187 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002188 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002189 + " failed: " + e;
2190 if (DBG) log(logStr);
2191 AnomalyReporter.reportAnomaly(
2192 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2193 }
2194 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002195 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002196
Michele Berionne5e411512020-11-13 02:36:59 +00002197 case CMD_PREPARE_UNATTENDED_REBOOT:
2198 request = (MainThreadRequest) msg.obj;
2199 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002200 UiccController.getInstance().getPinStorage()
2201 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002202 notifyRequester(request);
2203 break;
2204
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002205 default:
2206 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2207 break;
2208 }
2209 }
Jake Hambye994d462014-02-03 13:10:13 -08002210
Pengquan Menga1bb6272018-09-06 09:59:22 -07002211 private void notifyRequester(MainThreadRequest request) {
2212 synchronized (request) {
2213 request.notifyAll();
2214 }
2215 }
2216
Jake Hambye994d462014-02-03 13:10:13 -08002217 private void handleNullReturnEvent(Message msg, String command) {
2218 AsyncResult ar = (AsyncResult) msg.obj;
2219 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2220 if (ar.exception == null) {
2221 request.result = true;
2222 } else {
2223 request.result = false;
2224 if (ar.exception instanceof CommandException) {
2225 loge(command + ": CommandException: " + ar.exception);
2226 } else {
2227 loge(command + ": Unknown exception");
2228 }
2229 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002230 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002231 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002232 }
2233
2234 /**
2235 * Posts the specified command to be executed on the main thread,
2236 * waits for the request to complete, and returns the result.
2237 * @see #sendRequestAsync
2238 */
2239 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002240 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2241 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002242 }
2243
2244 /**
2245 * Posts the specified command to be executed on the main thread,
2246 * waits for the request to complete, and returns the result.
2247 * @see #sendRequestAsync
2248 */
2249 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2250 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002251 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002252 }
2253
2254 /**
2255 * Posts the specified command to be executed on the main thread,
2256 * waits for the request to complete, and returns the result.
2257 * @see #sendRequestAsync
2258 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002259 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002260 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2261 }
2262
2263 /**
2264 * Posts the specified command to be executed on the main thread,
2265 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2266 * if not timeout or null otherwise.
2267 * @see #sendRequestAsync
2268 */
2269 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2270 long timeoutInMs) {
2271 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002272 }
2273
2274 /**
2275 * Posts the specified command to be executed on the main thread,
2276 * waits for the request to complete, and returns the result.
2277 * @see #sendRequestAsync
2278 */
Nathan Harold92bed182018-10-12 18:16:49 -07002279 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002280 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002281 }
2282
2283 /**
2284 * Posts the specified command to be executed on the main thread,
2285 * waits for the request to complete, and returns the result.
2286 * @see #sendRequestAsync
2287 */
2288 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002289 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2290 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002291 }
2292
2293 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002294 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2295 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2296 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002297 * @see #sendRequestAsync
2298 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002299 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2300 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2302 throw new RuntimeException("This method will deadlock if called from the main thread.");
2303 }
2304
Nathan Harold92bed182018-10-12 18:16:49 -07002305 MainThreadRequest request = null;
2306 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2307 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2308 } else if (phone != null) {
2309 request = new MainThreadRequest(argument, phone, workSource);
2310 } else {
2311 request = new MainThreadRequest(argument, subId, workSource);
2312 }
2313
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 Message msg = mMainThreadHandler.obtainMessage(command, request);
2315 msg.sendToTarget();
2316
Rambo Wang0f050d82021-02-12 11:43:36 -08002317
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002319 if (timeoutInMs >= 0) {
2320 // Wait for at least timeoutInMs before returning null request result
2321 long now = SystemClock.elapsedRealtime();
2322 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002323 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002324 try {
2325 request.wait(deadline - now);
2326 } catch (InterruptedException e) {
2327 // Do nothing, go back and check if request is completed or timeout
2328 } finally {
2329 now = SystemClock.elapsedRealtime();
2330 }
2331 }
2332 } else {
2333 // Wait for the request to complete
2334 while (request.result == null) {
2335 try {
2336 request.wait();
2337 } catch (InterruptedException e) {
2338 // Do nothing, go back and wait until the request is complete
2339 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 }
2341 }
2342 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002343 if (request.result == null) {
2344 Log.wtf(LOG_TAG,
2345 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2346 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002347 return request.result;
2348 }
2349
2350 /**
2351 * Asynchronous ("fire and forget") version of sendRequest():
2352 * Posts the specified command to be executed on the main thread, and
2353 * returns immediately.
2354 * @see #sendRequest
2355 */
2356 private void sendRequestAsync(int command) {
2357 mMainThreadHandler.sendEmptyMessage(command);
2358 }
2359
2360 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002361 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002362 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002363 */
2364 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002365 sendRequestAsync(command, argument, null, null);
2366 }
2367
2368 /**
2369 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2370 * @see {@link #sendRequest(int,Object)}
2371 */
2372 private void sendRequestAsync(
2373 int command, Object argument, Phone phone, WorkSource workSource) {
2374 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002375 Message msg = mMainThreadHandler.obtainMessage(command, request);
2376 msg.sendToTarget();
2377 }
2378
2379 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002380 * Initialize the singleton PhoneInterfaceManager instance.
2381 * This is only done once, at startup, from PhoneApp.onCreate().
2382 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002383 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002384 synchronized (PhoneInterfaceManager.class) {
2385 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002386 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 } else {
2388 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2389 }
2390 return sInstance;
2391 }
2392 }
2393
2394 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002395 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002397 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002398 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002399 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002400 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002401 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002402 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002403 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002404 mTelephonySharedPreferences =
2405 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002406 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002407 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002408 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002409 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002410 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002411 mTelephony2gUpdater = new Telephony2gUpdater(
2412 Executors.newSingleThreadExecutor(), mApp);
2413 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002414 publish();
2415 }
2416
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002417 private Phone getDefaultPhone() {
2418 Phone thePhone = getPhone(getDefaultSubscription());
2419 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2420 }
2421
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422 private void publish() {
2423 if (DBG) log("publish: " + this);
2424
Peter Wangc035ce42020-01-08 21:00:22 -08002425 TelephonyFrameworkInitializer
2426 .getTelephonyServiceManager()
2427 .getTelephonyServiceRegisterer()
2428 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 }
2430
Stuart Scott584921c2015-01-15 17:10:34 -08002431 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002432 if (request.phone != null) {
2433 return request.phone;
2434 } else {
2435 return getPhoneFromSubId(request.subId);
2436 }
2437 }
2438
2439 private Phone getPhoneFromSubId(int subId) {
2440 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2441 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002442 }
2443
Rambo Wange53e07d2022-05-10 13:01:13 -07002444 @Nullable
2445 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002446 Phone phone = getPhoneFromRequest(request);
2447 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002448 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002449 }
2450
Wink Saville36469e72014-06-11 15:17:00 -07002451 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002452 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002453 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002454 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455
Kai Shif70f46f2021-03-03 13:59:46 -08002456 private void sendEraseModemConfig(@NonNull Phone phone) {
2457 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2458 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2459 }
2460
2461 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2462 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2463 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002464 }
2465
Peter Wang44b186e2020-01-13 23:33:09 -08002466 private boolean isImsAvailableOnDevice() {
2467 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2468 if (pm == null) {
2469 // For some reason package manger is not available.. This will fail internally anyway,
2470 // so do not throw error and allow.
2471 return true;
2472 }
2473 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2474 }
2475
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002477 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002478 }
2479
Wink Savilleb564aae2014-10-23 10:18:09 -07002480 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481 if (DBG) log("dial: " + number);
2482 // No permission check needed here: This is just a wrapper around the
2483 // ACTION_DIAL intent, which is available to any app since it puts up
2484 // the UI before it does anything.
2485
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002486 final long identity = Binder.clearCallingIdentity();
2487 try {
2488 String url = createTelUrl(number);
2489 if (url == null) {
2490 return;
2491 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002492
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002493 // PENDING: should we just silently fail if phone is offhook or ringing?
2494 PhoneConstants.State state = mCM.getState(subId);
2495 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2496 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2497 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2498 mApp.startActivity(intent);
2499 }
2500 } finally {
2501 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002502 }
2503 }
2504
2505 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002506 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002507 }
2508
Wink Savilleb564aae2014-10-23 10:18:09 -07002509 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002510 if (DBG) log("call: " + number);
2511
2512 // This is just a wrapper around the ACTION_CALL intent, but we still
2513 // need to do a permission check since we're calling startActivity()
2514 // from the context of the phone app.
2515 enforceCallPermission();
2516
Jordan Liu1617b712019-07-10 15:06:26 -07002517 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002518 != AppOpsManager.MODE_ALLOWED) {
2519 return;
2520 }
2521
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002522 final long identity = Binder.clearCallingIdentity();
2523 try {
2524 String url = createTelUrl(number);
2525 if (url == null) {
2526 return;
2527 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002528
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002529 boolean isValid = false;
2530 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2531 if (slist != null) {
2532 for (SubscriptionInfo subInfoRecord : slist) {
2533 if (subInfoRecord.getSubscriptionId() == subId) {
2534 isValid = true;
2535 break;
2536 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002537 }
Wink Saville08874612014-08-31 19:19:58 -07002538 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002539 if (!isValid) {
2540 return;
2541 }
Wink Saville08874612014-08-31 19:19:58 -07002542
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002543 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2544 intent.putExtra(SUBSCRIPTION_KEY, subId);
2545 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2546 mApp.startActivity(intent);
2547 } finally {
2548 Binder.restoreCallingIdentity(identity);
2549 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002550 }
2551
Wink Savilleb564aae2014-10-23 10:18:09 -07002552 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002553 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002554 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2555 }
2556
Wink Savilleb564aae2014-10-23 10:18:09 -07002557 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002558 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002559 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2560 }
2561
Wink Savilleb564aae2014-10-23 10:18:09 -07002562 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002563 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002564
2565 final long identity = Binder.clearCallingIdentity();
2566 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002567 Phone phone = getPhone(subId);
2568 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002569 checkSimPin.start();
2570 return checkSimPin.unlockSim(null, pin);
2571 } finally {
2572 Binder.restoreCallingIdentity(identity);
2573 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002574 }
2575
Wink Savilleb564aae2014-10-23 10:18:09 -07002576 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002577 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002578
2579 final long identity = Binder.clearCallingIdentity();
2580 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002581 Phone phone = getPhone(subId);
2582 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002583 checkSimPuk.start();
2584 return checkSimPuk.unlockSim(puk, pin);
2585 } finally {
2586 Binder.restoreCallingIdentity(identity);
2587 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002588 }
2589
2590 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002591 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002592 * a synchronous one.
2593 */
2594 private static class UnlockSim extends Thread {
2595
2596 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002597 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002598
2599 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002600 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2601 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002602
2603 // For replies from SimCard interface
2604 private Handler mHandler;
2605
2606 // For async handler to identify request type
2607 private static final int SUPPLY_PIN_COMPLETE = 100;
2608
Michele Berionne5e411512020-11-13 02:36:59 +00002609 UnlockSim(int phoneId, IccCard simCard) {
2610 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002611 mSimCard = simCard;
2612 }
2613
2614 @Override
2615 public void run() {
2616 Looper.prepare();
2617 synchronized (UnlockSim.this) {
2618 mHandler = new Handler() {
2619 @Override
2620 public void handleMessage(Message msg) {
2621 AsyncResult ar = (AsyncResult) msg.obj;
2622 switch (msg.what) {
2623 case SUPPLY_PIN_COMPLETE:
2624 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2625 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002626 mRetryCount = msg.arg1;
2627 if (ar.exception != null) {
2628 if (ar.exception instanceof CommandException &&
2629 ((CommandException)(ar.exception)).getCommandError()
2630 == CommandException.Error.PASSWORD_INCORRECT) {
2631 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002632 } //When UiccCardApp dispose,handle message and return exception
2633 else if (ar.exception instanceof CommandException &&
2634 ((CommandException) (ar.exception)).getCommandError()
2635 == CommandException.Error.ABORTED) {
2636 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002637 } else {
2638 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2639 }
2640 } else {
2641 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2642 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002643 mDone = true;
2644 UnlockSim.this.notifyAll();
2645 }
2646 break;
2647 }
2648 }
2649 };
2650 UnlockSim.this.notifyAll();
2651 }
2652 Looper.loop();
2653 }
2654
2655 /*
2656 * Use PIN or PUK to unlock SIM card
2657 *
2658 * If PUK is null, unlock SIM card with PIN
2659 *
2660 * If PUK is not null, unlock SIM card with PUK and set PIN code
2661 */
Wink Saville9de0f752013-10-22 19:04:03 -07002662 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002663
2664 while (mHandler == null) {
2665 try {
2666 wait();
2667 } catch (InterruptedException e) {
2668 Thread.currentThread().interrupt();
2669 }
2670 }
2671 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2672
2673 if (puk == null) {
2674 mSimCard.supplyPin(pin, callback);
2675 } else {
2676 mSimCard.supplyPuk(puk, pin, callback);
2677 }
2678
2679 while (!mDone) {
2680 try {
2681 Log.d(LOG_TAG, "wait for done");
2682 wait();
2683 } catch (InterruptedException e) {
2684 // Restore the interrupted status
2685 Thread.currentThread().interrupt();
2686 }
2687 }
2688 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002689 int[] resultArray = new int[2];
2690 resultArray[0] = mResult;
2691 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002692
2693 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002694 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002695 }
2696
Wink Saville9de0f752013-10-22 19:04:03 -07002697 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002698 }
2699 }
2700
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002701 /**
2702 * This method has been removed due to privacy and stability concerns.
2703 */
2704 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002705 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002706 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2707 return;
Wink Saville36469e72014-06-11 15:17:00 -07002708 }
2709
Nathan Harold1f889d82020-06-04 17:05:26 -07002710 @Override
2711 public void updateServiceLocationWithPackageName(String callingPackage) {
2712 mApp.getSystemService(AppOpsManager.class)
2713 .checkPackage(Binder.getCallingUid(), callingPackage);
2714
Nathan Haroldf096d982020-11-18 17:18:06 -08002715 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002716 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2717 // Callers targeting S have no business invoking this method.
2718 return;
2719 }
2720
2721 LocationAccessPolicy.LocationPermissionResult locationResult =
2722 LocationAccessPolicy.checkLocationPermission(mApp,
2723 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2724 .setCallingPackage(callingPackage)
2725 .setCallingFeatureId(null)
2726 .setCallingPid(Binder.getCallingPid())
2727 .setCallingUid(Binder.getCallingUid())
2728 .setMethod("updateServiceLocation")
2729 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2730 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2731 .build());
2732 // Apps that lack location permission have no business calling this method;
2733 // however, because no permission was declared in the public API, denials must
2734 // all be "soft".
2735 switch (locationResult) {
2736 case DENIED_HARD: /* fall through */
2737 case DENIED_SOFT:
2738 return;
2739 }
2740
2741 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002742 final long identity = Binder.clearCallingIdentity();
2743 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002744 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002745 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002746 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002747 }
2748 } finally {
2749 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002750 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002751 }
2752
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002753 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002754 @Override
2755 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002756 return isRadioOnWithFeature(callingPackage, null);
2757 }
2758
2759
2760 @Override
2761 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2762 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2763 callingFeatureId);
2764 }
2765
2766 @Deprecated
2767 @Override
2768 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2769 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002770 }
2771
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002772 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002773 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2774 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002775 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002776 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002777 return false;
2778 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002779
2780 final long identity = Binder.clearCallingIdentity();
2781 try {
2782 return isRadioOnForSubscriber(subId);
2783 } finally {
2784 Binder.restoreCallingIdentity(identity);
2785 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002786 }
2787
2788 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002789 final long identity = Binder.clearCallingIdentity();
2790 try {
2791 final Phone phone = getPhone(subId);
2792 if (phone != null) {
2793 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2794 } else {
2795 return false;
2796 }
2797 } finally {
2798 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002799 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002800 }
2801
2802 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002803 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002804 }
Wink Saville36469e72014-06-11 15:17:00 -07002805
Wink Savilleb564aae2014-10-23 10:18:09 -07002806 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002807 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002808
2809 final long identity = Binder.clearCallingIdentity();
2810 try {
2811 final Phone phone = getPhone(subId);
2812 if (phone != null) {
2813 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2814 }
2815 } finally {
2816 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002817 }
Wink Saville36469e72014-06-11 15:17:00 -07002818 }
2819
2820 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002821 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002822 }
2823
Wink Savilleb564aae2014-10-23 10:18:09 -07002824 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002825 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826
2827 final long identity = Binder.clearCallingIdentity();
2828 try {
2829 final Phone phone = getPhone(subId);
2830 if (phone == null) {
2831 return false;
2832 }
2833 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2834 toggleRadioOnOffForSubscriber(subId);
2835 }
2836 return true;
2837 } finally {
2838 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002839 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002840 }
Wink Saville36469e72014-06-11 15:17:00 -07002841
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002842 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002843 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002844 /*
2845 * If any of the Radios are available, it will need to be
2846 * shutdown. So return true if any Radio is available.
2847 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848 final long identity = Binder.clearCallingIdentity();
2849 try {
2850 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2851 Phone phone = PhoneFactory.getPhone(i);
2852 if (phone != null && phone.isRadioAvailable()) return true;
2853 }
2854 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2855 return false;
2856 } finally {
2857 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002858 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002859 }
2860
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002861 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002862 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002863 enforceModifyPermission();
2864
2865 final long identity = Binder.clearCallingIdentity();
2866 try {
2867 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2868 logv("Shutting down Phone " + i);
2869 shutdownRadioUsingPhoneId(i);
2870 }
2871 } finally {
2872 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002873 }
2874 }
2875
2876 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002877 Phone phone = PhoneFactory.getPhone(phoneId);
2878 if (phone != null && phone.isRadioAvailable()) {
2879 phone.shutdownRadio();
2880 }
2881 }
2882
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002883 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002884 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885
2886 final long identity = Binder.clearCallingIdentity();
2887 try {
2888 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2889 if (defaultPhone != null) {
2890 defaultPhone.setRadioPower(turnOn);
2891 return true;
2892 } else {
2893 loge("There's no default phone.");
2894 return false;
2895 }
2896 } finally {
2897 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002898 }
Wink Saville36469e72014-06-11 15:17:00 -07002899 }
2900
Wink Savilleb564aae2014-10-23 10:18:09 -07002901 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002902 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002903
2904 final long identity = Binder.clearCallingIdentity();
2905 try {
2906 final Phone phone = getPhone(subId);
2907 if (phone != null) {
2908 phone.setRadioPower(turnOn);
2909 return true;
2910 } else {
2911 return false;
2912 }
2913 } finally {
2914 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002915 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002916 }
2917
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002918 /**
2919 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2920 * no reason to power it off. When any of the voters want to power it off, it will be turned
2921 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2922 * powering it off, and these radio off votes will be cleared.
2923 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
2924 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
2925 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
2926 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
2927 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
2928 * check its vote.
2929 *
2930 * @param subId The subscription ID.
2931 * @param reason The reason for powering off radio.
2932 * @return true on success and false on failure.
2933 */
2934 public boolean requestRadioPowerOffForReason(int subId,
2935 @TelephonyManager.RadioPowerReason int reason) {
2936 enforceModifyPermission();
2937
2938 final long identity = Binder.clearCallingIdentity();
2939 try {
2940 final Phone phone = getPhone(subId);
2941 if (phone != null) {
2942 phone.setRadioPowerForReason(false, reason);
2943 return true;
2944 } else {
2945 return false;
2946 }
2947 } finally {
2948 Binder.restoreCallingIdentity(identity);
2949 }
2950 }
2951
2952 /**
2953 * Remove the vote on powering off the radio for a reason, as requested by
2954 * {@link requestRadioPowerOffForReason}.
2955 *
2956 * @param subId The subscription ID.
2957 * @param reason The reason for powering off radio.
2958 * @return true on success and false on failure.
2959 */
2960 public boolean clearRadioPowerOffForReason(int subId,
2961 @TelephonyManager.RadioPowerReason int reason) {
2962 enforceModifyPermission();
2963
2964 final long identity = Binder.clearCallingIdentity();
2965 try {
2966 final Phone phone = getPhone(subId);
2967 if (phone != null) {
2968 phone.setRadioPowerForReason(true, reason);
2969 return true;
2970 } else {
2971 return false;
2972 }
2973 } finally {
2974 Binder.restoreCallingIdentity(identity);
2975 }
2976 }
2977
2978 /**
2979 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
2980 *
2981 * @param subId The subscription ID.
2982 * @param callingPackage The package making the call.
2983 * @param callingFeatureId The feature in the package.
2984 * @return List of reasons for powering off radio.
2985 */
2986 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
2987 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
2988
2989 final long identity = Binder.clearCallingIdentity();
2990 List result = new ArrayList();
2991 try {
2992 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
2993 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
2994 return result;
2995 }
2996
2997 final Phone phone = getPhone(subId);
2998 if (phone != null) {
2999 result.addAll(phone.getRadioPowerOffReasons());
3000 }
3001 } finally {
3002 Binder.restoreCallingIdentity(identity);
3003 }
3004 return result;
3005 }
3006
Wink Saville36469e72014-06-11 15:17:00 -07003007 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003008 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003009 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003010 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003011
3012 final long identity = Binder.clearCallingIdentity();
3013 try {
3014 int subId = mSubscriptionController.getDefaultDataSubId();
3015 final Phone phone = getPhone(subId);
3016 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003017 phone.getDataSettingsManager().setDataEnabled(
3018 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019 return true;
3020 } else {
3021 return false;
3022 }
3023 } finally {
3024 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003025 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003026 }
3027
Wink Saville36469e72014-06-11 15:17:00 -07003028 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003029 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003030 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003031 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003032
3033 final long identity = Binder.clearCallingIdentity();
3034 try {
3035 int subId = mSubscriptionController.getDefaultDataSubId();
3036 final Phone phone = getPhone(subId);
3037 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003038 phone.getDataSettingsManager().setDataEnabled(
3039 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003040 return true;
3041 } else {
3042 return false;
3043 }
3044 } finally {
3045 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003046 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003047 }
3048
Sanket Padawe356d7632015-06-22 14:03:32 -07003049 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003050 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003051 final long identity = Binder.clearCallingIdentity();
3052 try {
3053 final Phone phone = getPhone(subId);
3054 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003055 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003056 } else {
3057 return false;
3058 }
3059 } finally {
3060 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003061 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003062 }
3063
3064 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003065 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003066 }
3067
pkanwarae03a6b2016-11-06 20:37:09 -08003068 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003069 enforceCallPermission();
3070
3071 final long identity = Binder.clearCallingIdentity();
3072 try {
3073 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3074 return;
3075 }
3076 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3077 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3078 } finally {
3079 Binder.restoreCallingIdentity(identity);
3080 }
pkanwar32d516d2016-10-14 19:37:38 -07003081 };
3082
Wink Savilleb564aae2014-10-23 10:18:09 -07003083 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003084 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003085
3086 final long identity = Binder.clearCallingIdentity();
3087 try {
3088 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3089 return false;
3090 }
3091 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3092 } finally {
3093 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003094 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003095 }
3096
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003097 /**
3098 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3099 * tag on getCallState Binder call.
3100 */
3101 @Deprecated
3102 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003103 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003104 if (CompatChanges.isChangeEnabled(
3105 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3106 Binder.getCallingUid())) {
3107 // Do not allow this API to be called on API version 31+, it should only be
3108 // called on old apps using this Binder call directly.
3109 throw new SecurityException("This method can only be used for applications "
3110 + "targeting API version 30 or less.");
3111 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003112 final long identity = Binder.clearCallingIdentity();
3113 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003114 Phone phone = getPhone(getDefaultSubscription());
3115 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3116 PhoneConstantConversions.convertCallState(phone.getState());
3117 } finally {
3118 Binder.restoreCallingIdentity(identity);
3119 }
3120 }
3121
3122 @Override
3123 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3124 if (CompatChanges.isChangeEnabled(
3125 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3126 Binder.getCallingUid())) {
3127 // Check READ_PHONE_STATE for API version 31+
3128 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3129 featureId, "getCallStateForSubscription")) {
3130 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3131 + "targeting API level 31+.");
3132 }
3133 }
3134 final long identity = Binder.clearCallingIdentity();
3135 try {
3136 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003137 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3138 PhoneConstantConversions.convertCallState(phone.getState());
3139 } finally {
3140 Binder.restoreCallingIdentity(identity);
3141 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003142 }
3143
Sanket Padawe356d7632015-06-22 14:03:32 -07003144 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003145 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003146 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
3147 }
3148
3149 @Override
3150 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003151 final long identity = Binder.clearCallingIdentity();
3152 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003153 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003154 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003155 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003156 } else {
3157 return PhoneConstantConversions.convertDataState(
3158 PhoneConstants.DataState.DISCONNECTED);
3159 }
3160 } finally {
3161 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003162 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003163 }
3164
Sanket Padawe356d7632015-06-22 14:03:32 -07003165 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003166 public @DataActivityType int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003167 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3168 }
3169
3170 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003171 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003172 final long identity = Binder.clearCallingIdentity();
3173 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003174 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003175 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003176 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003177 } else {
3178 return TelephonyManager.DATA_ACTIVITY_NONE;
3179 }
3180 } finally {
3181 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003182 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003183 }
3184
3185 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003186 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003187 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003188 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003189
3190 LocationAccessPolicy.LocationPermissionResult locationResult =
3191 LocationAccessPolicy.checkLocationPermission(mApp,
3192 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3193 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003194 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003195 .setCallingPid(Binder.getCallingPid())
3196 .setCallingUid(Binder.getCallingUid())
3197 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003198 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003199 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3200 .build());
3201 switch (locationResult) {
3202 case DENIED_HARD:
3203 throw new SecurityException("Not allowed to access cell location");
3204 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003205 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3206 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003207 }
3208
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003209 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003210 final long identity = Binder.clearCallingIdentity();
3211 try {
3212 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003213 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003214 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003215 } finally {
3216 Binder.restoreCallingIdentity(identity);
3217 }
Svetoslav64fad262015-04-14 14:35:21 -07003218 }
3219
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003220 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003221 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003222 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3223 // registered cell info, so return a NULL country instead.
3224 final long identity = Binder.clearCallingIdentity();
3225 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003226 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3227 // Get default phone in this case.
3228 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3229 }
Jack Yue84aa0e2022-11-17 22:47:32 -08003230 final int subId = mSubscriptionController.getSubId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003231 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003232 if (phone == null) return "";
3233 ServiceStateTracker sst = phone.getServiceStateTracker();
3234 if (sst == null) return "";
3235 LocaleTracker lt = sst.getLocaleTracker();
3236 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003237 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003238 } finally {
3239 Binder.restoreCallingIdentity(identity);
3240 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003241 }
3242
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003243 /**
3244 * This method was removed due to potential issues caused by performing partial
3245 * updates of service state, and lack of a credible use case.
3246 *
3247 * This has the ability to break the telephony implementation by disabling notification of
3248 * changes in device connectivity. DO NOT USE THIS!
3249 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003250 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003251 public void enableLocationUpdates() {
3252 mApp.enforceCallingOrSelfPermission(
3253 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003254 }
3255
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003256 /**
3257 * This method was removed due to potential issues caused by performing partial
3258 * updates of service state, and lack of a credible use case.
3259 *
3260 * This has the ability to break the telephony implementation by disabling notification of
3261 * changes in device connectivity. DO NOT USE THIS!
3262 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003263 @Override
3264 public void disableLocationUpdates() {
3265 mApp.enforceCallingOrSelfPermission(
3266 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003267 }
3268
3269 @Override
3270 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003271 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3272 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003273 try {
3274 mApp.getSystemService(AppOpsManager.class)
3275 .checkPackage(Binder.getCallingUid(), callingPackage);
3276 } catch (SecurityException e) {
3277 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3278 throw e;
3279 }
3280
Nathan Haroldf096d982020-11-18 17:18:06 -08003281 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003282 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3283 throw new SecurityException(
3284 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3285 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003286
Jordan Liu1617b712019-07-10 15:06:26 -07003287 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003288 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3289 return null;
3290 }
Svetoslav64fad262015-04-14 14:35:21 -07003291
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003292 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003293
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003294 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003295 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003296
Nathan Haroldf180aac2018-06-01 18:43:55 -07003297 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3298 for (CellInfo ci : info) {
3299 if (ci instanceof CellInfoGsm) {
3300 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3301 } else if (ci instanceof CellInfoWcdma) {
3302 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3303 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003304 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003305 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003306 }
3307
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003308 private List<CellInfo> getCachedCellInfo() {
3309 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3310 for (Phone phone : PhoneFactory.getPhones()) {
3311 List<CellInfo> info = phone.getAllCellInfo();
3312 if (info != null) cellInfos.addAll(info);
3313 }
3314 return cellInfos;
3315 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003316
3317 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003318 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003319 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003320 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003321
3322 LocationAccessPolicy.LocationPermissionResult locationResult =
3323 LocationAccessPolicy.checkLocationPermission(mApp,
3324 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3325 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003326 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003327 .setCallingPid(Binder.getCallingPid())
3328 .setCallingUid(Binder.getCallingUid())
3329 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003330 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003331 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3332 .build());
3333 switch (locationResult) {
3334 case DENIED_HARD:
3335 throw new SecurityException("Not allowed to access cell info");
3336 case DENIED_SOFT:
3337 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003338 }
3339
Nathan Haroldf096d982020-11-18 17:18:06 -08003340 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003341 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3342 return getCachedCellInfo();
3343 }
3344
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003345 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003346 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003347 final long identity = Binder.clearCallingIdentity();
3348 try {
3349 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3350 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003351 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003352 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003353 if (info != null) cellInfos.addAll(info);
3354 }
3355 return cellInfos;
3356 } finally {
3357 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003358 }
3359 }
3360
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003361 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003362 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3363 String callingFeatureId) {
3364 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3365 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003366 }
3367
3368 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003369 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3370 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003371 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003372 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003373 }
3374
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003375 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3376 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003377 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003378 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003379
3380 LocationAccessPolicy.LocationPermissionResult locationResult =
3381 LocationAccessPolicy.checkLocationPermission(mApp,
3382 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3383 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003384 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003385 .setCallingPid(Binder.getCallingPid())
3386 .setCallingUid(Binder.getCallingUid())
3387 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003388 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3389 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003390 .build());
3391 switch (locationResult) {
3392 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003393 if (TelephonyPermissions
3394 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003395 // Safetynet logging for b/154934934
3396 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3397 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003398 throw new SecurityException("Not allowed to access cell info");
3399 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003400 if (TelephonyPermissions
3401 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003402 // Safetynet logging for b/154934934
3403 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3404 }
Nathan Harold5320c422019-05-09 10:26:08 -07003405 try {
3406 cb.onCellInfo(new ArrayList<CellInfo>());
3407 } catch (RemoteException re) {
3408 // Drop without consequences
3409 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003410 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003411 }
3412
Nathan Harolda939a962019-05-09 10:13:47 -07003413
3414 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003415 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3416
3417 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3418 }
3419
3420 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003421 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003422 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003423 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003424
3425 final long identity = Binder.clearCallingIdentity();
3426 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003427 Phone phone = getPhone(subId);
3428 if (phone == null) {
3429 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3430 } else {
3431 phone.setCellInfoListRate(rateInMillis, workSource);
3432 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003433 } finally {
3434 Binder.restoreCallingIdentity(identity);
3435 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003436 }
3437
Shishir Agrawala9f32182016-04-12 12:00:16 -07003438 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003439 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003440 Phone phone = PhoneFactory.getPhone(slotIndex);
3441 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003442 return null;
3443 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003444 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003445 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003446 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003447 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003448 return null;
3449 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003450
3451 final long identity = Binder.clearCallingIdentity();
3452 try {
3453 return phone.getImei();
3454 } finally {
3455 Binder.restoreCallingIdentity(identity);
3456 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003457 }
3458
3459 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003460 public String getTypeAllocationCodeForSlot(int slotIndex) {
3461 Phone phone = PhoneFactory.getPhone(slotIndex);
3462 String tac = null;
3463 if (phone != null) {
3464 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003465 try {
3466 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3467 } catch (IndexOutOfBoundsException e) {
3468 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3469 return null;
3470 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003471 }
3472 return tac;
3473 }
3474
3475 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003476 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003477 try {
3478 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3479 } catch (SecurityException se) {
3480 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3481 throw new SecurityException("Package " + callingPackage + " does not belong to "
3482 + Binder.getCallingUid());
3483 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003484 Phone phone = PhoneFactory.getPhone(slotIndex);
3485 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003486 return null;
3487 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003488
Jeff Davidson913390f2018-02-23 17:11:49 -08003489 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003490 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003491 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003492 return null;
3493 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003494
3495 final long identity = Binder.clearCallingIdentity();
3496 try {
3497 return phone.getMeid();
3498 } finally {
3499 Binder.restoreCallingIdentity(identity);
3500 }
Jack Yu2af8d712017-03-15 17:14:14 -07003501 }
3502
3503 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003504 public String getManufacturerCodeForSlot(int slotIndex) {
3505 Phone phone = PhoneFactory.getPhone(slotIndex);
3506 String manufacturerCode = null;
3507 if (phone != null) {
3508 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003509 try {
3510 manufacturerCode =
3511 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3512 } catch (IndexOutOfBoundsException e) {
3513 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3514 return null;
3515 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003516 }
3517 return manufacturerCode;
3518 }
3519
3520 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003521 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3522 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003523 Phone phone = PhoneFactory.getPhone(slotIndex);
3524 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003525 return null;
3526 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003527 int subId = phone.getSubId();
3528 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003529 mApp, subId, callingPackage, callingFeatureId,
3530 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003531 return null;
3532 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003533
3534 final long identity = Binder.clearCallingIdentity();
3535 try {
3536 return phone.getDeviceSvn();
3537 } finally {
3538 Binder.restoreCallingIdentity(identity);
3539 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003540 }
3541
fionaxu43304da2017-11-27 22:51:16 -08003542 @Override
3543 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003544 final long identity = Binder.clearCallingIdentity();
3545 try {
3546 final Phone phone = getPhone(subId);
3547 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3548 } finally {
3549 Binder.restoreCallingIdentity(identity);
3550 }
fionaxu43304da2017-11-27 22:51:16 -08003551 }
3552
3553 @Override
3554 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003555 final long identity = Binder.clearCallingIdentity();
3556 try {
3557 final Phone phone = getPhone(subId);
3558 return phone == null ? null : phone.getCarrierName();
3559 } finally {
3560 Binder.restoreCallingIdentity(identity);
3561 }
fionaxu43304da2017-11-27 22:51:16 -08003562 }
3563
calvinpanffe225e2018-11-01 19:43:06 +08003564 @Override
chen xu0026ca62019-03-06 15:28:50 -08003565 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003566 final long identity = Binder.clearCallingIdentity();
3567 try {
3568 final Phone phone = getPhone(subId);
3569 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003570 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003571 } finally {
3572 Binder.restoreCallingIdentity(identity);
3573 }
3574 }
3575
3576 @Override
chen xu0026ca62019-03-06 15:28:50 -08003577 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003578 final long identity = Binder.clearCallingIdentity();
3579 try {
3580 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003581 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003582 } finally {
3583 Binder.restoreCallingIdentity(identity);
3584 }
3585 }
3586
chen xu651eec72018-11-11 19:03:44 -08003587 @Override
chen xu864e11c2018-12-06 22:10:03 -08003588 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3589 if (!isSubscriptionMccMnc) {
3590 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3591 }
chen xu651eec72018-11-11 19:03:44 -08003592 final Phone phone = PhoneFactory.getPhone(slotIndex);
3593 if (phone == null) {
3594 return TelephonyManager.UNKNOWN_CARRIER_ID;
3595 }
3596 final long identity = Binder.clearCallingIdentity();
3597 try {
3598 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3599 } finally {
3600 Binder.restoreCallingIdentity(identity);
3601 }
3602 }
3603
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003604 //
3605 // Internal helper methods.
3606 //
3607
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003608 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003609 * Make sure the caller is the calling package itself
3610 *
3611 * @throws SecurityException if the caller is not the calling package
3612 */
3613 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3614 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003615 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3616 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003617 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003618 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003619 } catch (PackageManager.NameNotFoundException e) {
3620 // packageUid is -1
3621 }
3622 if (packageUid != callingUid) {
3623 throw new SecurityException(message + ": Package " + callingPackage
3624 + " does not belong to " + callingUid);
3625 }
3626 }
3627
3628 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003629 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3630 *
3631 * @throws SecurityException if the caller does not have the required permission
3632 */
3633 private void enforceModifyPermission() {
3634 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3635 }
3636
Shuo Qian3b6ee772019-11-13 17:43:31 -08003637 private void enforceActiveEmergencySessionPermission() {
3638 mApp.enforceCallingOrSelfPermission(
3639 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3640 }
3641
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003642 /**
3643 * Make sure the caller has the CALL_PHONE permission.
3644 *
3645 * @throws SecurityException if the caller does not have the required permission
3646 */
3647 private void enforceCallPermission() {
3648 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3649 }
3650
paulhu5a773602019-08-23 19:17:33 +08003651 private void enforceSettingsPermission() {
3652 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003653 }
3654
Michele Berionne5e411512020-11-13 02:36:59 +00003655 private void enforceRebootPermission() {
3656 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3657 }
3658
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003659 private String createTelUrl(String number) {
3660 if (TextUtils.isEmpty(number)) {
3661 return null;
3662 }
3663
Jake Hambye994d462014-02-03 13:10:13 -08003664 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003665 }
3666
Ihab Awadf9e92732013-12-05 18:02:52 -08003667 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003668 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3669 }
3670
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003671 private static void logv(String msg) {
3672 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3673 }
3674
Ihab Awadf9e92732013-12-05 18:02:52 -08003675 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003676 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3677 }
3678
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003679 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003680 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003681 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003682 }
3683
Sanket Padawe356d7632015-06-22 14:03:32 -07003684 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003685 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003686 final long identity = Binder.clearCallingIdentity();
3687 try {
3688 final Phone phone = PhoneFactory.getPhone(slotIndex);
3689 if (phone == null) {
3690 return PhoneConstants.PHONE_TYPE_NONE;
3691 } else {
3692 return phone.getPhoneType();
3693 }
3694 } finally {
3695 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003697 }
3698
3699 /**
3700 * Returns the CDMA ERI icon index to display
3701 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003702 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003703 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3704 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3705 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003706 }
3707
Sanket Padawe356d7632015-06-22 14:03:32 -07003708 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003709 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3710 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003711 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003712 mApp, subId, callingPackage, callingFeatureId,
3713 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003714 return -1;
3715 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003716
3717 final long identity = Binder.clearCallingIdentity();
3718 try {
3719 final Phone phone = getPhone(subId);
3720 if (phone != null) {
3721 return phone.getCdmaEriIconIndex();
3722 } else {
3723 return -1;
3724 }
3725 } finally {
3726 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003727 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003728 }
3729
3730 /**
3731 * Returns the CDMA ERI icon mode,
3732 * 0 - ON
3733 * 1 - FLASHING
3734 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003735 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003736 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3737 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3738 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003739 }
3740
Sanket Padawe356d7632015-06-22 14:03:32 -07003741 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003742 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3743 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003744 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003745 mApp, subId, callingPackage, callingFeatureId,
3746 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003747 return -1;
3748 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003749
3750 final long identity = Binder.clearCallingIdentity();
3751 try {
3752 final Phone phone = getPhone(subId);
3753 if (phone != null) {
3754 return phone.getCdmaEriIconMode();
3755 } else {
3756 return -1;
3757 }
3758 } finally {
3759 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003760 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003761 }
3762
3763 /**
3764 * Returns the CDMA ERI text,
3765 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003766 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003767 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3768 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3769 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003770 }
3771
Sanket Padawe356d7632015-06-22 14:03:32 -07003772 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003773 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3774 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003775 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003776 mApp, subId, callingPackage, callingFeatureId,
3777 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003778 return null;
3779 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003780
3781 final long identity = Binder.clearCallingIdentity();
3782 try {
3783 final Phone phone = getPhone(subId);
3784 if (phone != null) {
3785 return phone.getCdmaEriText();
3786 } else {
3787 return null;
3788 }
3789 } finally {
3790 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003791 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003792 }
3793
3794 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003795 * Returns the CDMA MDN.
3796 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003797 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003798 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3800 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003801
3802 final long identity = Binder.clearCallingIdentity();
3803 try {
3804 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003805 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003806 return phone.getLine1Number();
3807 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003808 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003809 return null;
3810 }
3811 } finally {
3812 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003813 }
3814 }
3815
3816 /**
3817 * Returns the CDMA MIN.
3818 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003819 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003820 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003821 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3822 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003823
3824 final long identity = Binder.clearCallingIdentity();
3825 try {
3826 final Phone phone = getPhone(subId);
3827 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3828 return phone.getCdmaMin();
3829 } else {
3830 return null;
3831 }
3832 } finally {
3833 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003834 }
3835 }
3836
Hall Liud892bec2018-11-30 14:51:45 -08003837 @Override
3838 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3839 INumberVerificationCallback callback, String callingPackage) {
3840 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3841 != PERMISSION_GRANTED) {
3842 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3843 }
3844 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3845
3846 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3847 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003848 throw new SecurityException("Calling package must be configured in the device config: "
3849 + "calling package: " + callingPackage
3850 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003851 }
3852
3853 if (range == null) {
3854 throw new NullPointerException("Range must be non-null");
3855 }
3856
3857 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003858 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003859
3860 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3861 }
3862
Junda Liuca05d5d2014-08-14 22:36:34 -07003863 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003864 * Returns true if CDMA provisioning needs to run.
3865 */
3866 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003867 final long identity = Binder.clearCallingIdentity();
3868 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003869 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003870 } finally {
3871 Binder.restoreCallingIdentity(identity);
3872 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003873 }
3874
3875 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003876 * Sets the voice mail number of a given subId.
3877 */
3878 @Override
3879 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003880 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3881 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003882
3883 final long identity = Binder.clearCallingIdentity();
3884 try {
3885 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3886 new Pair<String, String>(alphaTag, number), new Integer(subId));
3887 return success;
3888 } finally {
3889 Binder.restoreCallingIdentity(identity);
3890 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003891 }
3892
Ta-wei Yen87c49842016-05-13 21:19:52 -07003893 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003894 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3895 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003896 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3897 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003898 if (!TextUtils.equals(callingPackage, systemDialer)) {
3899 throw new SecurityException("caller must be system dialer");
3900 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003901
3902 final long identity = Binder.clearCallingIdentity();
3903 try {
3904 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3905 if (phoneAccountHandle == null) {
3906 return null;
3907 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003908 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003909 } finally {
3910 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003911 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003912 }
3913
3914 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003915 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3916 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003917 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003918 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003919 mApp, subId, callingPackage, callingFeatureId,
3920 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003921 return null;
3922 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003923
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003924 final long identity = Binder.clearCallingIdentity();
3925 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003926 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003927 } finally {
3928 Binder.restoreCallingIdentity(identity);
3929 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003930 }
3931
3932 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003933 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3934 VisualVoicemailSmsFilterSettings settings) {
3935 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003936
3937 final long identity = Binder.clearCallingIdentity();
3938 try {
3939 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003940 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003941 } finally {
3942 Binder.restoreCallingIdentity(identity);
3943 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003944 }
3945
3946 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003947 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3948 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003949
3950 final long identity = Binder.clearCallingIdentity();
3951 try {
3952 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003953 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003954 } finally {
3955 Binder.restoreCallingIdentity(identity);
3956 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003957 }
3958
3959 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003960 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3961 String callingPackage, int subId) {
3962 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003963
3964 final long identity = Binder.clearCallingIdentity();
3965 try {
3966 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003967 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003968 } finally {
3969 Binder.restoreCallingIdentity(identity);
3970 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003971 }
3972
3973 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003974 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003975 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003976
3977 final long identity = Binder.clearCallingIdentity();
3978 try {
3979 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003980 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003981 } finally {
3982 Binder.restoreCallingIdentity(identity);
3983 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003984 }
3985
3986 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003987 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3988 String callingAttributionTag, int subId, String number, int port, String text,
3989 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003990 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003991 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003992 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003993 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003994 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3995 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003996 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003997
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003998 /**
fionaxu0152e512016-11-14 13:36:14 -08003999 * Sets the voice activation state of a given subId.
4000 */
4001 @Override
4002 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4004 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004005
4006 final long identity = Binder.clearCallingIdentity();
4007 try {
4008 final Phone phone = getPhone(subId);
4009 if (phone != null) {
4010 phone.setVoiceActivationState(activationState);
4011 } else {
4012 loge("setVoiceActivationState fails with invalid subId: " + subId);
4013 }
4014 } finally {
4015 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004016 }
4017 }
4018
4019 /**
4020 * Sets the data activation state of a given subId.
4021 */
4022 @Override
4023 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4025 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004026
4027 final long identity = Binder.clearCallingIdentity();
4028 try {
4029 final Phone phone = getPhone(subId);
4030 if (phone != null) {
4031 phone.setDataActivationState(activationState);
4032 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004033 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004034 }
4035 } finally {
4036 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004037 }
4038 }
4039
4040 /**
4041 * Returns the voice activation state of a given subId.
4042 */
4043 @Override
4044 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004045 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004046
fionaxu0152e512016-11-14 13:36:14 -08004047 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004048 final long identity = Binder.clearCallingIdentity();
4049 try {
4050 if (phone != null) {
4051 return phone.getVoiceActivationState();
4052 } else {
4053 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4054 }
4055 } finally {
4056 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004057 }
4058 }
4059
4060 /**
4061 * Returns the data activation state of a given subId.
4062 */
4063 @Override
4064 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004065 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004066
fionaxu0152e512016-11-14 13:36:14 -08004067 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004068 final long identity = Binder.clearCallingIdentity();
4069 try {
4070 if (phone != null) {
4071 return phone.getDataActivationState();
4072 } else {
4073 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4074 }
4075 } finally {
4076 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004077 }
4078 }
4079
4080 /**
Wink Saville36469e72014-06-11 15:17:00 -07004081 * Returns the unread count of voicemails for a subId
4082 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004083 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004084 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4085 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004086 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004087 mApp, subId, callingPackage, callingFeatureId,
4088 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004089 return 0;
4090 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004091 final long identity = Binder.clearCallingIdentity();
4092 try {
4093 final Phone phone = getPhone(subId);
4094 if (phone != null) {
4095 return phone.getVoiceMessageCount();
4096 } else {
4097 return 0;
4098 }
4099 } finally {
4100 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004101 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004102 }
4103
4104 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004105 * returns true, if the device is in a state where both voice and data
4106 * are supported simultaneously. This can change based on location or network condition.
4107 */
4108 @Override
4109 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004110 final long identity = Binder.clearCallingIdentity();
4111 try {
4112 final Phone phone = getPhone(subId);
4113 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4114 } finally {
4115 Binder.restoreCallingIdentity(identity);
4116 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004117 }
4118
4119 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004120 * Send the dialer code if called from the current default dialer or the caller has
4121 * carrier privilege.
4122 * @param inputCode The dialer code to send
4123 */
4124 @Override
4125 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004126 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004127 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004128 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4129 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004130 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004131 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004132 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004133 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004134
4135 final long identity = Binder.clearCallingIdentity();
4136 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004137 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004138 } finally {
4139 Binder.restoreCallingIdentity(identity);
4140 }
fionaxu235cc5e2017-03-06 22:25:57 -08004141 }
4142
Pengquan Menga1bb6272018-09-06 09:59:22 -07004143 @Override
4144 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004145 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004146 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004147 mApp, subId, "getNetworkSelectionMode");
4148 final long identity = Binder.clearCallingIdentity();
4149 try {
4150 if (!isActiveSubscription(subId)) {
4151 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4152 }
4153 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4154 } finally {
4155 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004156 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004157 }
4158
Brad Ebinger35c841c2018-10-01 10:40:55 -07004159 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004160 public boolean isInEmergencySmsMode() {
4161 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4162 final long identity = Binder.clearCallingIdentity();
4163 try {
4164 for (Phone phone : PhoneFactory.getPhones()) {
4165 if (phone.isInEmergencySmsMode()) {
4166 return true;
4167 }
4168 }
4169 } finally {
4170 Binder.restoreCallingIdentity(identity);
4171 }
4172 return false;
4173 }
4174
shilu366312e2019-12-17 09:28:10 -08004175 /**
4176 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4177 * @param subId The subscription to use to check the configuration.
4178 * @param c The callback that will be used to send the result.
4179 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004180 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004181 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4182 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004183 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004184 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004185
4186 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4187 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4188 "IMS not available on device.");
4189 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004190 final long token = Binder.clearCallingIdentity();
4191 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004192 int slotId = getSlotIndexOrException(subId);
4193 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004194
4195 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4196 if (controller != null) {
4197 ImsManager imsManager = controller.getImsManager(subId);
4198 if (imsManager != null) {
4199 imsManager.addRegistrationCallbackForSubscription(c, subId);
4200 } else {
4201 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4202 }
4203 } else {
4204 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4205 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004206 } catch (ImsException e) {
4207 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004208 } finally {
4209 Binder.restoreCallingIdentity(token);
4210 }
4211 }
4212
shilu366312e2019-12-17 09:28:10 -08004213 /**
4214 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4215 * @param subId The subscription to use to check the configuration.
4216 * @param c The callback that will be used to send the result.
4217 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004218 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004219 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004220 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004221 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004222 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4223 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4224 }
Meng Wangafbc5852019-09-19 17:37:13 -07004225 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004226
Meng Wangafbc5852019-09-19 17:37:13 -07004227 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004228 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4229 if (controller != null) {
4230 ImsManager imsManager = controller.getImsManager(subId);
4231 if (imsManager != null) {
4232 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4233 } else {
4234 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4235 + "is inactive, ignoring unregister.");
4236 // If the ImsManager is not valid, just return, since the callback
4237 // will already have been removed internally.
4238 }
4239 }
Meng Wangafbc5852019-09-19 17:37:13 -07004240 } finally {
4241 Binder.restoreCallingIdentity(token);
4242 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004243 }
4244
Brad Ebingera34a6c22019-10-22 17:36:18 -07004245 /**
4246 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4247 */
4248 @Override
4249 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4250 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4251 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4252 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4253 "IMS not available on device.");
4254 }
4255 final long token = Binder.clearCallingIdentity();
4256 try {
4257 Phone phone = getPhone(subId);
4258 if (phone == null) {
4259 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4260 + subId + "'");
4261 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4262 }
4263 phone.getImsRegistrationState(regState -> {
4264 try {
4265 consumer.accept((regState == null)
4266 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4267 } catch (RemoteException e) {
4268 // Ignore if the remote process is no longer available to call back.
4269 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4270 }
4271 });
4272 } finally {
4273 Binder.restoreCallingIdentity(token);
4274 }
4275 }
4276
4277 /**
4278 * Get the transport type for the IMS service registration state.
4279 */
4280 @Override
4281 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004282 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004283 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004284 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4285 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4286 "IMS not available on device.");
4287 }
4288 final long token = Binder.clearCallingIdentity();
4289 try {
4290 Phone phone = getPhone(subId);
4291 if (phone == null) {
4292 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4293 + subId + "'");
4294 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4295 }
4296 phone.getImsRegistrationTech(regTech -> {
4297 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4298 int regTechConverted = (regTech == null)
4299 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4300 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4301 regTechConverted);
4302 try {
4303 consumer.accept(regTechConverted);
4304 } catch (RemoteException e) {
4305 // Ignore if the remote process is no longer available to call back.
4306 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4307 }
4308 });
4309 } finally {
4310 Binder.restoreCallingIdentity(token);
4311 }
4312 }
4313
shilu366312e2019-12-17 09:28:10 -08004314 /**
4315 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4316 * @param subId The subscription to use to check the configuration.
4317 * @param c The callback that will be used to send the result.
4318 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004319 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004320 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4321 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004322 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004323 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004324 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4325 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4326 "IMS not available on device.");
4327 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004328 final long token = Binder.clearCallingIdentity();
4329 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004330 int slotId = getSlotIndexOrException(subId);
4331 verifyImsMmTelConfiguredOrThrow(slotId);
4332 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004333 } catch (ImsException e) {
4334 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004335 } finally {
4336 Binder.restoreCallingIdentity(token);
4337 }
4338 }
4339
shilu366312e2019-12-17 09:28:10 -08004340 /**
4341 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4342 * @param subId The subscription to use to check the configuration.
4343 * @param c The callback that will be used to send the result.
4344 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004345 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004346 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004347 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004348 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004349 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4350 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4351 }
Meng Wangafbc5852019-09-19 17:37:13 -07004352
4353 final long token = Binder.clearCallingIdentity();
4354 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004355 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004356 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004357 } catch (ImsException e) {
4358 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4359 + "is inactive, ignoring unregister.");
4360 // If the subscription is no longer active, just return, since the callback
4361 // will already have been removed internally.
4362 } finally {
4363 Binder.restoreCallingIdentity(token);
4364 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004365 }
4366
4367 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004368 public boolean isCapable(int subId, int capability, int regTech) {
4369 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004370 final long token = Binder.clearCallingIdentity();
4371 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004372 int slotId = getSlotIndexOrException(subId);
4373 verifyImsMmTelConfiguredOrThrow(slotId);
4374 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4375 } catch (com.android.ims.ImsException e) {
4376 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4377 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004378 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004379 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4380 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004381 } finally {
4382 Binder.restoreCallingIdentity(token);
4383 }
4384 }
4385
4386 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004387 public boolean isAvailable(int subId, int capability, int regTech) {
4388 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004389 final long token = Binder.clearCallingIdentity();
4390 try {
4391 Phone phone = getPhone(subId);
4392 if (phone == null) return false;
4393 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004394 } catch (com.android.ims.ImsException e) {
4395 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4396 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004397 } finally {
4398 Binder.restoreCallingIdentity(token);
4399 }
4400 }
4401
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004402 /**
4403 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4404 * subscription.
4405 * @param subId The subscription to use to check the configuration.
4406 * @param callback The callback that will be used to send the result.
4407 * @param capability The MmTelFeature capability that will be used to send the result.
4408 * @param transportType The transport type of the MmTelFeature capability.
4409 */
4410 @Override
4411 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4412 int transportType) {
4413 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004414 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4415 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4416 "IMS not available on device.");
4417 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004418 final long token = Binder.clearCallingIdentity();
4419 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004420 int slotId = getSlotIndex(subId);
4421 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4422 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4423 + subId + "'");
4424 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4425 }
4426 verifyImsMmTelConfiguredOrThrow(slotId);
4427 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4428 transportType, aBoolean -> {
4429 try {
4430 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4431 } catch (RemoteException e) {
4432 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4433 + "running. Ignore");
4434 }
4435 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004436 } catch (ImsException e) {
4437 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004438 } finally {
4439 Binder.restoreCallingIdentity(token);
4440 }
4441 }
4442
shilu366312e2019-12-17 09:28:10 -08004443 /**
4444 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4445 * @param subId The subscription to use to check the configuration.
4446 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004447 @Override
4448 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004449 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004450 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004451
Brad Ebinger35c841c2018-10-01 10:40:55 -07004452 final long token = Binder.clearCallingIdentity();
4453 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004454 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004455 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004456 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004457 } catch (ImsException e) {
4458 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004459 } finally {
4460 Binder.restoreCallingIdentity(token);
4461 }
4462 }
4463
4464 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004465 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004467 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004468 final long identity = Binder.clearCallingIdentity();
4469 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004470 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004471 // This setting doesn't require an active ImsService connection, so do not verify. The
4472 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004473 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004474 } catch (ImsException e) {
4475 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004476 } finally {
4477 Binder.restoreCallingIdentity(identity);
4478 }
4479 }
4480
shilu366312e2019-12-17 09:28:10 -08004481 /**
4482 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4483 * @param subId The subscription to use to check the configuration.
4484 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004485 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004486 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004487 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004488 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004489 final long identity = Binder.clearCallingIdentity();
4490 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004491 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004492 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004493 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004494 } catch (ImsException e) {
4495 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004496 } finally {
4497 Binder.restoreCallingIdentity(identity);
4498 }
4499 }
4500
4501 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004502 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004504 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004505 final long identity = Binder.clearCallingIdentity();
4506 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004507 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004508 // This setting doesn't require an active ImsService connection, so do not verify. The
4509 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004510 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004511 } catch (ImsException e) {
4512 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004513 } finally {
4514 Binder.restoreCallingIdentity(identity);
4515 }
4516 }
4517
shilu366312e2019-12-17 09:28:10 -08004518 /**
4519 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4520 * @param subId The subscription to use to check the configuration.
4521 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004522 @Override
4523 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004524 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004525 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004526 final long identity = Binder.clearCallingIdentity();
4527 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004528 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004529 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004530 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004531 } catch (ImsException e) {
4532 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004533 } finally {
4534 Binder.restoreCallingIdentity(identity);
4535 }
4536 }
4537
4538 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004539 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004541 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004542 final long identity = Binder.clearCallingIdentity();
4543 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004544 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004545 // This setting doesn't require an active ImsService connection, so do not verify. The
4546 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004547 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004548 } catch (ImsException e) {
4549 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004550 } finally {
4551 Binder.restoreCallingIdentity(identity);
4552 }
4553 }
4554
shilu366312e2019-12-17 09:28:10 -08004555 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004556 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4557 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4558 * @param subId The subscription to use to check the configuration.
4559 */
4560 @Override
4561 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004562 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004563 mApp, subId, "isCrossSimCallingEnabledByUser");
4564 final long identity = Binder.clearCallingIdentity();
4565 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004566 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004567 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004568 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004569 } catch (ImsException e) {
4570 throw new ServiceSpecificException(e.getCode());
4571 } finally {
4572 Binder.restoreCallingIdentity(identity);
4573 }
4574 }
4575
4576 /**
4577 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4578 * Requires MODIFY_PHONE_STATE permission.
4579 * @param subId The subscription to use to check the configuration.
4580 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4581 * false otherwise
4582 */
4583 @Override
4584 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4586 "setCrossSimCallingEnabled");
4587 final long identity = Binder.clearCallingIdentity();
4588 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004589 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004590 // This setting doesn't require an active ImsService connection, so do not verify. The
4591 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004592 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004593 } catch (ImsException e) {
4594 throw new ServiceSpecificException(e.getCode());
4595 } finally {
4596 Binder.restoreCallingIdentity(identity);
4597 }
4598 }
4599
4600 /**
shilu366312e2019-12-17 09:28:10 -08004601 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4602 * @param subId The subscription to use to check the configuration.
4603 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004604 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004605
Brad Ebinger35c841c2018-10-01 10:40:55 -07004606 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004607 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004608 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004609 final long identity = Binder.clearCallingIdentity();
4610 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004611 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004612 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004613 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004614 } catch (ImsException e) {
4615 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004616 } finally {
4617 Binder.restoreCallingIdentity(identity);
4618 }
4619 }
4620
4621 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004622 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004623 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004624 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004625 final long identity = Binder.clearCallingIdentity();
4626 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004627 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004628 // This setting doesn't require an active ImsService connection, so do not verify. The
4629 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004630 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004631 } catch (ImsException e) {
4632 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004633 } finally {
4634 Binder.restoreCallingIdentity(identity);
4635 }
4636 }
4637
4638 @Override
4639 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4641 "setVoWiFiNonPersistent");
4642 final long identity = Binder.clearCallingIdentity();
4643 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004644 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004645 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004646 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004647 } catch (ImsException e) {
4648 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004649 } finally {
4650 Binder.restoreCallingIdentity(identity);
4651 }
4652 }
4653
shilu366312e2019-12-17 09:28:10 -08004654 /**
4655 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4656 * @param subId The subscription to use to check the configuration.
4657 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004658 @Override
4659 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004660 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004661 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004662 final long identity = Binder.clearCallingIdentity();
4663 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004664 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004665 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004666 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004667 } catch (ImsException e) {
4668 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004669 } finally {
4670 Binder.restoreCallingIdentity(identity);
4671 }
4672 }
4673
4674 @Override
4675 public void setVoWiFiModeSetting(int subId, int mode) {
4676 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4677 "setVoWiFiModeSetting");
4678 final long identity = Binder.clearCallingIdentity();
4679 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004680 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004681 // This setting doesn't require an active ImsService connection, so do not verify. The
4682 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004683 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004684 } catch (ImsException e) {
4685 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004686 } finally {
4687 Binder.restoreCallingIdentity(identity);
4688 }
4689 }
4690
4691 @Override
4692 public int getVoWiFiRoamingModeSetting(int subId) {
4693 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4694 final long identity = Binder.clearCallingIdentity();
4695 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004696 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004697 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004698 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004699 } catch (ImsException e) {
4700 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004701 } finally {
4702 Binder.restoreCallingIdentity(identity);
4703 }
4704 }
4705
4706 @Override
4707 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4708 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4709 "setVoWiFiRoamingModeSetting");
4710 final long identity = Binder.clearCallingIdentity();
4711 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004712 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004713 // This setting doesn't require an active ImsService connection, so do not verify. The
4714 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004715 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004716 } catch (ImsException e) {
4717 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004718 } finally {
4719 Binder.restoreCallingIdentity(identity);
4720 }
4721 }
4722
4723 @Override
4724 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4725 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4726 "setRttCapabilityEnabled");
4727 final long identity = Binder.clearCallingIdentity();
4728 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004729 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004730 // This setting doesn't require an active ImsService connection, so do not verify. The
4731 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004732 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004733 } catch (ImsException e) {
4734 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004735 } finally {
4736 Binder.restoreCallingIdentity(identity);
4737 }
4738 }
4739
shilu366312e2019-12-17 09:28:10 -08004740 /**
4741 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4742 * @param subId The subscription to use to check the configuration.
4743 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004744 @Override
4745 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004746 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004747 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004748 final long identity = Binder.clearCallingIdentity();
4749 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004750 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004751 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004752 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004753 } catch (ImsException e) {
4754 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004755 } finally {
4756 Binder.restoreCallingIdentity(identity);
4757 }
4758 }
4759
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004760 @Override
4761 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4762 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004763
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004764 final long identity = Binder.clearCallingIdentity();
4765 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004766 if (!isImsAvailableOnDevice()) {
4767 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4768 "IMS not available on device.");
4769 }
4770 int slotId = getSlotIndexOrException(subId);
4771 verifyImsMmTelConfiguredOrThrow(slotId);
4772 ImsManager.getInstance(mApp, slotId)
4773 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004774 } catch (ImsException e) {
4775 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004776 } finally {
4777 Binder.restoreCallingIdentity(identity);
4778 }
4779 }
4780
4781 @Override
4782 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4783 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004784
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004785 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004786 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4787 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4788 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004789 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004790 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004791 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004792 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004793 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4794 + "is inactive, ignoring unregister.");
4795 // If the subscription is no longer active, just return, since the callback will already
4796 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004797 } finally {
4798 Binder.restoreCallingIdentity(identity);
4799 }
4800 }
4801
joonhunshincffb7fc2021-11-28 07:32:01 +00004802 @Override
4803 public void registerFeatureProvisioningChangedCallback(int subId,
4804 IFeatureProvisioningCallback callback) {
4805 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4806 mApp, subId, "registerFeatureProvisioningChangedCallback");
4807
4808 final long identity = Binder.clearCallingIdentity();
4809 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4810 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4811 }
4812
joonhunshin91bc1952022-04-29 08:47:15 +00004813 try {
4814 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4815 if (controller == null) {
4816 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4817 "Device does not support IMS");
4818 }
4819 controller.addFeatureProvisioningChangedCallback(subId, callback);
4820 } finally {
4821 Binder.restoreCallingIdentity(identity);
4822 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004823 }
4824
4825 @Override
4826 public void unregisterFeatureProvisioningChangedCallback(int subId,
4827 IFeatureProvisioningCallback callback) {
4828 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4829 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4830
4831 final long identity = Binder.clearCallingIdentity();
4832 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4833 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4834 }
4835
joonhunshin91bc1952022-04-29 08:47:15 +00004836 try {
4837 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4838 if (controller == null) {
4839 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4840 return;
4841 }
4842 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4843 } finally {
4844 Binder.restoreCallingIdentity(identity);
4845 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004846 }
allenwtsu99c623b2020-01-03 18:24:23 +08004847
4848 private void checkModifyPhoneStatePermission(int subId, String message) {
4849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4850 message);
4851 }
4852
allenwtsu99c623b2020-01-03 18:24:23 +08004853 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004854 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004855 boolean isProvisioned) {
4856 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4857
4858 final long identity = Binder.clearCallingIdentity();
4859 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004860 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4861 if (controller == null) {
4862 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4863 return;
4864 }
4865 controller.setRcsProvisioningStatusForCapability(
4866 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004867 } finally {
4868 Binder.restoreCallingIdentity(identity);
4869 }
allenwtsu99c623b2020-01-03 18:24:23 +08004870 }
4871
4872
4873 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004874 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4875 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4876 mApp, subId, "getRcsProvisioningStatusForCapability");
4877
allenwtsu99c623b2020-01-03 18:24:23 +08004878 final long identity = Binder.clearCallingIdentity();
4879 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004880 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4881 if (controller == null) {
4882 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4883
4884 // device does not support IMS, this method will return true always.
4885 return true;
4886 }
4887 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004888 } finally {
4889 Binder.restoreCallingIdentity(identity);
4890 }
4891 }
4892
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004893 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004894 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4895 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004896 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004897
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004898 final long identity = Binder.clearCallingIdentity();
4899 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004900 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4901 if (controller == null) {
4902 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4903 return;
4904 }
4905 controller.setImsProvisioningStatusForCapability(
4906 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004907 } finally {
4908 Binder.restoreCallingIdentity(identity);
4909 }
4910 }
4911
4912 @Override
4913 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004914 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4915 mApp, subId, "getProvisioningStatusForCapability");
4916
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004917 final long identity = Binder.clearCallingIdentity();
4918 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004919 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4920 if (controller == null) {
4921 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004922
joonhunshin91bc1952022-04-29 08:47:15 +00004923 // device does not support IMS, this method will return true always.
4924 return true;
4925 }
4926 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004927 } finally {
4928 Binder.restoreCallingIdentity(identity);
4929 }
4930 }
4931
4932 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004933 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4934 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4935 mApp, subId, "isProvisioningRequiredForCapability");
4936
4937 final long identity = Binder.clearCallingIdentity();
4938 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004939 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4940 if (controller == null) {
4941 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4942
4943 // device does not support IMS, this method will return false
4944 return false;
4945 }
4946 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004947 } finally {
4948 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004949 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004950 }
4951
4952 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004953 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4954 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4955 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004956
joonhunshincffb7fc2021-11-28 07:32:01 +00004957 final long identity = Binder.clearCallingIdentity();
4958 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004959 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4960 if (controller == null) {
4961 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4962
4963 // device does not support IMS, this method will return false
4964 return false;
4965 }
4966 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004967 } finally {
4968 Binder.restoreCallingIdentity(identity);
4969 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004970 }
4971
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004972 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004973 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004974 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4975 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4976 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004977 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4978 mApp, subId, "getImsProvisioningInt");
4979
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004980 final long identity = Binder.clearCallingIdentity();
4981 try {
4982 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004983 int slotId = getSlotIndex(subId);
4984 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4985 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4986 + subId + "' for key:" + key);
4987 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4988 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004989
joonhunshin91bc1952022-04-29 08:47:15 +00004990 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4991 if (controller == null) {
4992 loge("getImsProvisioningInt: Device does not support IMS");
4993
4994 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4995 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4996 }
4997 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004998 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4999 return retVal;
5000 }
5001
calvinpanb5a34062021-02-08 19:59:36 +08005002 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005003 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005004 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5005 + subId + "' for key:" + key);
5006 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005007 } finally {
5008 Binder.restoreCallingIdentity(identity);
5009 }
5010 }
5011
5012 @Override
5013 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005014 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5015 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5016 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005017 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5018 mApp, subId, "getImsProvisioningString");
5019
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005020 final long identity = Binder.clearCallingIdentity();
5021 try {
5022 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005023 int slotId = getSlotIndex(subId);
5024 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5025 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5026 + subId + "' for key:" + key);
5027 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5028 }
calvinpanb5a34062021-02-08 19:59:36 +08005029 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005030 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005031 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5032 + subId + "' for key:" + key);
5033 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005034 } finally {
5035 Binder.restoreCallingIdentity(identity);
5036 }
5037 }
5038
5039 @Override
5040 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005041 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5042 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5043 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5045 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005046
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005047 final long identity = Binder.clearCallingIdentity();
5048 try {
5049 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005050 int slotId = getSlotIndex(subId);
5051 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5052 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5053 + subId + "' for key:" + key);
5054 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5055 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005056
joonhunshin91bc1952022-04-29 08:47:15 +00005057 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5058 if (controller == null) {
5059 loge("setImsProvisioningInt: Device does not support IMS");
5060
5061 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5062 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5063 }
5064 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005065 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5066 return retVal;
5067 }
5068
calvinpanb5a34062021-02-08 19:59:36 +08005069 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5070 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005071 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005072 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005073 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005074 } finally {
5075 Binder.restoreCallingIdentity(identity);
5076 }
5077 }
5078
5079 @Override
5080 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005081 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5082 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5083 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5085 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005086 final long identity = Binder.clearCallingIdentity();
5087 try {
5088 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005089 int slotId = getSlotIndex(subId);
5090 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5091 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5092 + subId + "' for key:" + key);
5093 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5094 }
calvinpanb5a34062021-02-08 19:59:36 +08005095 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5096 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005097 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005098 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005099 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005100 } finally {
5101 Binder.restoreCallingIdentity(identity);
5102 }
5103 }
5104
Brad Ebinger919631e2021-06-02 17:46:35 -07005105 /**
5106 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5107 * for the given slot ID or no ImsResolver instance has been created.
5108 * @param slotId The slot ID that the IMS service is created for.
5109 * @throws ImsException If there is no ImsService configured for this slot.
5110 */
5111 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5112 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5113 ImsFeature.FEATURE_MMTEL)) {
5114 throw new ImsException("This subscription does not support MMTEL over IMS",
5115 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5116 }
5117 }
5118
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005119 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005120 int slotId = SubscriptionManager.getSlotIndex(subId);
5121 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005122 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5123 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005124 }
5125 return slotId;
5126 }
5127
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005128 private int getSlotIndex(int subId) {
5129 int slotId = SubscriptionManager.getSlotIndex(subId);
5130 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5131 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5132 }
5133 return slotId;
5134 }
5135
Wink Saville36469e72014-06-11 15:17:00 -07005136 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005137 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005138 */
5139 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005140 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5141 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005142 try {
5143 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5144 } catch (SecurityException se) {
5145 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5146 throw new SecurityException("Package " + callingPackage + " does not belong to "
5147 + Binder.getCallingUid());
5148 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005149 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005150 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005151 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005152 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005153 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005154 mApp, subId, callingPackage, callingFeatureId,
5155 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005156 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5157 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005158
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005159 final long identity = Binder.clearCallingIdentity();
5160 try {
5161 final Phone phone = getPhone(subId);
5162 if (phone != null) {
5163 return phone.getServiceState().getDataNetworkType();
5164 } else {
5165 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5166 }
5167 } finally {
5168 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005170 }
5171
5172 /**
5173 * Returns the data network type
5174 */
5175 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005176 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005177 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5178 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005179 }
5180
5181 /**
5182 * Returns the data network type for a subId
5183 */
5184 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005185 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5186 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005187 String functionName = "getDataNetworkTypeForSubscriber";
5188 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5189 mApp, functionName)) {
5190 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5191 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5192 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5193 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005194 }
5195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005196 final long identity = Binder.clearCallingIdentity();
5197 try {
5198 final Phone phone = getPhone(subId);
5199 if (phone != null) {
5200 return phone.getServiceState().getDataNetworkType();
5201 } else {
5202 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5203 }
5204 } finally {
5205 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005206 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005207 }
5208
5209 /**
Wink Saville36469e72014-06-11 15:17:00 -07005210 * Returns the Voice network type for a subId
5211 */
5212 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005213 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5214 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005215 String functionName = "getVoiceNetworkTypeForSubscriber";
5216 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5217 mApp, functionName)) {
5218 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5219 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5220 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5221 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005222 }
5223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005224 final long identity = Binder.clearCallingIdentity();
5225 try {
5226 final Phone phone = getPhone(subId);
5227 if (phone != null) {
5228 return phone.getServiceState().getVoiceNetworkType();
5229 } else {
5230 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5231 }
5232 } finally {
5233 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005234 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005235 }
5236
5237 /**
5238 * @return true if a ICC card is present
5239 */
5240 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005241 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005242 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5243 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005244 }
5245
5246 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005247 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005248 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005249 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005250 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005251 final long identity = Binder.clearCallingIdentity();
5252 try {
5253 final Phone phone = PhoneFactory.getPhone(slotIndex);
5254 if (phone != null) {
5255 return phone.getIccCard().hasIccCard();
5256 } else {
5257 return false;
5258 }
5259 } finally {
5260 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005261 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005262 }
5263
5264 /**
5265 * Return if the current radio is LTE on CDMA. This
5266 * is a tri-state return value as for a period of time
5267 * the mode may be unknown.
5268 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005269 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005270 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005271 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005272 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005273 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005274 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5275 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5276 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005277 }
5278
Sanket Padawe356d7632015-06-22 14:03:32 -07005279 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005280 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5281 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005282 try {
5283 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5284 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005285 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5286 }
5287
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005288 final long identity = Binder.clearCallingIdentity();
5289 try {
5290 final Phone phone = getPhone(subId);
5291 if (phone == null) {
5292 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5293 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005294 return TelephonyProperties.lte_on_cdma_device()
5295 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005296 }
5297 } finally {
5298 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005299 }
Wink Saville36469e72014-06-11 15:17:00 -07005300 }
5301
Wink Saville36469e72014-06-11 15:17:00 -07005302 /**
5303 * {@hide}
5304 * Returns Default subId, 0 in the case of single standby.
5305 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005306 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005307 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005308 }
5309
Shishir Agrawala9f32182016-04-12 12:00:16 -07005310 private int getSlotForDefaultSubscription() {
5311 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5312 }
5313
Wink Savilleb564aae2014-10-23 10:18:09 -07005314 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005315 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005316 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005317
Pengquan Menge92a50d2018-09-21 15:54:48 -07005318 private boolean isActiveSubscription(int subId) {
5319 return mSubscriptionController.isActiveSubId(subId);
5320 }
5321
Ihab Awadf2177b72013-11-25 13:33:23 -08005322 /**
5323 * @see android.telephony.TelephonyManager.WifiCallingChoices
5324 */
5325 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326 final long identity = Binder.clearCallingIdentity();
5327 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005328 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005329 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5330 getWhenToMakeWifiCallsDefaultPreference());
5331 } finally {
5332 Binder.restoreCallingIdentity(identity);
5333 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005334 }
5335
5336 /**
5337 * @see android.telephony.TelephonyManager.WifiCallingChoices
5338 */
5339 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005340 final long identity = Binder.clearCallingIdentity();
5341 try {
5342 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005343 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005344 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5345 } finally {
5346 Binder.restoreCallingIdentity(identity);
5347 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005348 }
5349
Sailesh Nepald1e68152013-12-12 19:08:02 -08005350 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005351 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005352 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005353 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005354
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005355 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5356 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5357 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005358 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005359 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5360 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005361 }
5362 return PhoneFactory.getPhone(phoneId);
5363 }
5364
Shishir Agrawal566b7612013-10-28 14:41:00 -07005365 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005366 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005367 @NonNull IccLogicalChannelRequest request) {
5368 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5369 /*message=*/ "iccOpenLogicalChannel");
5370
5371 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5372 // Verify that the callingPackage in the request belongs to the calling UID
5373 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5374
5375 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005376 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005377
Rambo Wanga1782702021-11-10 20:15:19 -08005378 private Phone getPhoneFromValidIccLogicalChannelRequest(
5379 @NonNull IccLogicalChannelRequest request, String message) {
5380 Phone phone;
5381 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5383 mApp, request.subId, message);
5384 phone = getPhoneFromSubId(request.subId);
5385 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5386 enforceModifyPermission();
5387 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5388 } else {
5389 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005390 }
Rambo Wanga1782702021-11-10 20:15:19 -08005391 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005392 }
5393
5394 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005395 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396 final long identity = Binder.clearCallingIdentity();
5397 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005398 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005400 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5401 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005402 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5403 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005404 loge("The calling package is not allowed to access ISD-R.");
5405 throw new SecurityException(
5406 "The calling package is not allowed to access ISD-R.");
5407 }
Derek Tan740e1672017-06-27 14:56:27 -07005408 }
Derek Tan740e1672017-06-27 14:56:27 -07005409
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005411 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5412 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005413 return response;
5414 } finally {
5415 Binder.restoreCallingIdentity(identity);
5416 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005417 }
5418
5419 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005420 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5421 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5422 /*message=*/"iccCloseLogicalChannel");
5423
5424 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5425
5426 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005427 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005428
Rambo Wanga1782702021-11-10 20:15:19 -08005429 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5430 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005431 // before this feature is enabled, this API should only return false if
5432 // the operation fails instead of throwing runtime exception for
5433 // backward-compatibility.
5434 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5435 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005436 final long identity = Binder.clearCallingIdentity();
5437 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005438 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005439 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005440 }
Chen Xue9d737e2022-01-01 23:41:31 -08005441 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005442 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005443 Boolean success = false;
5444 if (result instanceof RuntimeException) {
5445 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005446 if (shouldThrowExceptionOnFailure) {
5447 throw (RuntimeException) result;
5448 } else {
5449 return false;
5450 }
Chen Xue9d737e2022-01-01 23:41:31 -08005451 } else if (result instanceof Boolean) {
5452 success = (Boolean) result;
5453 } else {
5454 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5455 }
Rambo Wanga1782702021-11-10 20:15:19 -08005456 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457 return success;
5458 } finally {
5459 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005460 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005461 }
5462
5463 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005464 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005465 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5467 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005468 if (DBG) {
5469 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5470 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5471 + p3 + " data=" + data);
5472 }
5473 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5474 command, p1, p2, p3, data);
5475 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005476
Jordan Liu4c733742019-02-28 12:03:40 -08005477 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005478 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5479 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005480 enforceModifyPermission();
5481 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005482 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5483 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5484 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005485 }
5486 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005487 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5488 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005489 }
5490
5491 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5492 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005493 final long identity = Binder.clearCallingIdentity();
5494 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005495 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005496 return "";
5497 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005498
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005499 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005500 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5501 null /* workSource */);
5502 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005503
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005504 // Append the returned status code to the end of the response payload.
5505 String s = Integer.toHexString(
5506 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5507 if (response.payload != null) {
5508 s = IccUtils.bytesToHexString(response.payload) + s;
5509 }
5510 return s;
5511 } finally {
5512 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005513 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005514 }
Jake Hambye994d462014-02-03 13:10:13 -08005515
Evan Charltonc66da362014-05-16 14:06:40 -07005516 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005517 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5518 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005519 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5520 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005522 if (DBG) {
5523 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5524 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5525 }
5526 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5527 cla, command, p1, p2, p3, data);
5528 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005529
Jordan Liu4c733742019-02-28 12:03:40 -08005530 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005531 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5532 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005533 enforceModifyPermission();
5534 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5535 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005536 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5537 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5538 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005539 }
5540
5541 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005542 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5543 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005544 }
5545
5546 // open APDU basic channel assuming the caller has sufficient permissions
5547 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5548 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005549 final long identity = Binder.clearCallingIdentity();
5550 try {
5551 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5552 && TextUtils.equals(ISDR_AID, data)) {
5553 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005554 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5555 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005556 if (bestComponent == null
5557 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5558 loge("The calling package is not allowed to select ISD-R.");
5559 throw new SecurityException(
5560 "The calling package is not allowed to select ISD-R.");
5561 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005562 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005563
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005565 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5566 null /* workSource */);
5567 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005568
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005569 // Append the returned status code to the end of the response payload.
5570 String s = Integer.toHexString(
5571 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5572 if (response.payload != null) {
5573 s = IccUtils.bytesToHexString(response.payload) + s;
5574 }
5575 return s;
5576 } finally {
5577 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005578 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005579 }
5580
5581 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005582 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005583 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5585 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005586
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587 final long identity = Binder.clearCallingIdentity();
5588 try {
5589 if (DBG) {
5590 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5591 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5592 }
5593
5594 IccIoResult response =
5595 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5596 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5597 subId);
5598
5599 if (DBG) {
5600 log("Exchange SIM_IO [R]" + response);
5601 }
5602
5603 byte[] result = null;
5604 int length = 2;
5605 if (response.payload != null) {
5606 length = 2 + response.payload.length;
5607 result = new byte[length];
5608 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5609 } else {
5610 result = new byte[length];
5611 }
5612
5613 result[length - 1] = (byte) response.sw2;
5614 result[length - 2] = (byte) response.sw1;
5615 return result;
5616 } finally {
5617 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005618 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005619 }
5620
Nathan Haroldb3014052017-01-25 15:57:32 -08005621 /**
5622 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5623 * on a particular subscription
5624 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005625 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5626 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005627 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005628 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005629 return null;
5630 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005631
5632 final long identity = Binder.clearCallingIdentity();
5633 try {
5634 if (appType != TelephonyManager.APPTYPE_USIM
5635 && appType != TelephonyManager.APPTYPE_SIM) {
5636 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5637 return null;
5638 }
5639 Object response = sendRequest(
5640 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5641 if (response instanceof String[]) {
5642 return (String[]) response;
5643 }
yincheng zhao2737e882019-09-06 17:06:54 -07005644 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005645 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005646 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005647 } finally {
5648 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005649 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005650 }
5651
yincheng zhao2737e882019-09-06 17:06:54 -07005652 /**
5653 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5654 * subscription.
5655 *
5656 * @param subId the id of the subscription.
5657 * @param appType the uicc app type, must be USIM or SIM.
5658 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5659 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005660 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005661 * @return number of fplmns that is successfully written to the SIM.
5662 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005663 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5664 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5666 mApp, subId, "setForbiddenPlmns");
5667
yincheng zhao2737e882019-09-06 17:06:54 -07005668 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5669 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5670 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5671 }
5672 if (fplmns == null) {
5673 throw new IllegalArgumentException("Fplmn List provided is null");
5674 }
5675 for (String fplmn : fplmns) {
5676 if (!CellIdentity.isValidPlmn(fplmn)) {
5677 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5678 }
5679 }
5680 final long identity = Binder.clearCallingIdentity();
5681 try {
5682 Object response = sendRequest(
5683 CMD_SET_FORBIDDEN_PLMNS,
5684 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5685 subId);
5686 return (int) response;
5687 } finally {
5688 Binder.restoreCallingIdentity(identity);
5689 }
5690 }
5691
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005692 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005693 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5695 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005696
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005697 final long identity = Binder.clearCallingIdentity();
5698 try {
5699 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5700 if (response.payload == null) {
5701 return "";
5702 }
Evan Charltonc66da362014-05-16 14:06:40 -07005703
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005704 // Append the returned status code to the end of the response payload.
5705 String s = Integer.toHexString(
5706 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5707 s = IccUtils.bytesToHexString(response.payload) + s;
5708 return s;
5709 } finally {
5710 Binder.restoreCallingIdentity(identity);
5711 }
Evan Charltonc66da362014-05-16 14:06:40 -07005712 }
5713
Jake Hambye994d462014-02-03 13:10:13 -08005714 /**
5715 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5716 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5717 *
5718 * @param itemID the ID of the item to read
5719 * @return the NV item as a String, or null on error.
5720 */
5721 @Override
5722 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005723 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5725 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005726
5727 final long identity = Binder.clearCallingIdentity();
5728 try {
5729 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005730 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005731 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5732 return value;
5733 } finally {
5734 Binder.restoreCallingIdentity(identity);
5735 }
Jake Hambye994d462014-02-03 13:10:13 -08005736 }
5737
5738 /**
5739 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5740 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5741 *
5742 * @param itemID the ID of the item to read
5743 * @param itemValue the value to write, as a String
5744 * @return true on success; false on any failure
5745 */
5746 @Override
5747 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005748 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5750 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005751
5752 final long identity = Binder.clearCallingIdentity();
5753 try {
5754 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5755 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005756 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005757 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5758 return success;
5759 } finally {
5760 Binder.restoreCallingIdentity(identity);
5761 }
Jake Hambye994d462014-02-03 13:10:13 -08005762 }
5763
5764 /**
5765 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5766 * Used for device configuration by some CDMA operators.
5767 *
5768 * @param preferredRoamingList byte array containing the new PRL
5769 * @return true on success; false on any failure
5770 */
5771 @Override
5772 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5774 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005775
5776 final long identity = Binder.clearCallingIdentity();
5777 try {
5778 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5779 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5780 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5781 return success;
5782 } finally {
5783 Binder.restoreCallingIdentity(identity);
5784 }
Jake Hambye994d462014-02-03 13:10:13 -08005785 }
5786
5787 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005788 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005789 * Used for device configuration by some CDMA operators.
5790 *
chen xu6dac5ab2018-10-26 17:39:23 -07005791 * @param slotIndex - device slot.
5792 *
Jake Hambye994d462014-02-03 13:10:13 -08005793 * @return true on success; false on any failure
5794 */
5795 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005796 public boolean resetModemConfig(int slotIndex) {
5797 Phone phone = PhoneFactory.getPhone(slotIndex);
5798 if (phone != null) {
5799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5800 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005801
chen xu6dac5ab2018-10-26 17:39:23 -07005802 final long identity = Binder.clearCallingIdentity();
5803 try {
5804 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5805 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5806 return success;
5807 } finally {
5808 Binder.restoreCallingIdentity(identity);
5809 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005810 }
chen xu6dac5ab2018-10-26 17:39:23 -07005811 return false;
5812 }
5813
5814 /**
5815 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5816 *
5817 * @param slotIndex - device slot.
5818 *
5819 * @return true on success; false on any failure
5820 */
5821 @Override
5822 public boolean rebootModem(int slotIndex) {
5823 Phone phone = PhoneFactory.getPhone(slotIndex);
5824 if (phone != null) {
5825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5826 mApp, phone.getSubId(), "rebootModem");
5827
5828 final long identity = Binder.clearCallingIdentity();
5829 try {
5830 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5831 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5832 return success;
5833 } finally {
5834 Binder.restoreCallingIdentity(identity);
5835 }
5836 }
5837 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005838 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005839
Brad Ebinger51f743a2017-01-23 13:50:20 -08005840 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005841 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5842 * {@link #disableIms(int)}.
5843 * @param slotIndex device slot.
5844 */
5845 public void resetIms(int slotIndex) {
5846 enforceModifyPermission();
5847
5848 final long identity = Binder.clearCallingIdentity();
5849 try {
5850 if (mImsResolver == null) {
5851 // may happen if the does not support IMS.
5852 return;
5853 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00005854 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005855 } finally {
5856 Binder.restoreCallingIdentity(identity);
5857 }
5858 }
5859
5860 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005861 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5862 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005863 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005864 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005865 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005866
5867 final long identity = Binder.clearCallingIdentity();
5868 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005869 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005870 // may happen if the device does not support IMS.
5871 return;
5872 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005873 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005874 } finally {
5875 Binder.restoreCallingIdentity(identity);
5876 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005877 }
5878
5879 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005880 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5881 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005882 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005883 public void disableIms(int slotId) {
5884 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005885
5886 final long identity = Binder.clearCallingIdentity();
5887 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005888 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005889 // may happen if the device does not support IMS.
5890 return;
5891 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005892 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005893 } finally {
5894 Binder.restoreCallingIdentity(identity);
5895 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005896 }
5897
5898 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005899 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5900 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005901 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005902 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005903 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005904 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005905
5906 final long identity = Binder.clearCallingIdentity();
5907 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005908 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005909 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5910 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005911 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005912 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005913 } finally {
5914 Binder.restoreCallingIdentity(identity);
5915 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005916 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005917 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005918 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5919 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005920 @Override
5921 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005922 enforceModifyPermission();
5923
5924 final long identity = Binder.clearCallingIdentity();
5925 try {
5926 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005927 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005928 } finally {
5929 Binder.restoreCallingIdentity(identity);
5930 }
5931 }
5932
5933 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005934 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005935 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005936 */
5937 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5938 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005939
5940 final long identity = Binder.clearCallingIdentity();
5941 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005942 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005943 // may happen if the device does not support IMS.
5944 return null;
5945 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005946 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005947 } finally {
5948 Binder.restoreCallingIdentity(identity);
5949 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005950 }
5951
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005952 /**
5953 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005954 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005955 */
5956 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5957 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005958
5959 final long identity = Binder.clearCallingIdentity();
5960 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005961 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005962 // may happen if the device does not support IMS.
5963 return null;
5964 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005965 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005966 } finally {
5967 Binder.restoreCallingIdentity(identity);
5968 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005969 }
5970
Brad Ebinger884c07b2018-02-15 16:17:40 -08005971 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005972 * Sets the ImsService Package Name that Telephony will bind to.
5973 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005974 * @param slotIndex the slot ID that the ImsService should bind for.
5975 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005976 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005977 * @param featureTypes An integer array of feature types associated with a packageName.
5978 * @param packageName The name of the package that the current configuration will be replaced
5979 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005980 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005981 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005982 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5983 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08005984 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005985 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08005986 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005987
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988 final long identity = Binder.clearCallingIdentity();
5989 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005990 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005991 // may happen if the device does not support IMS.
5992 return false;
5993 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005994 Map<Integer, String> featureConfig = new HashMap<>();
5995 for (int featureType : featureTypes) {
5996 featureConfig.put(featureType, packageName);
5997 }
5998 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5999 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006000 } finally {
6001 Binder.restoreCallingIdentity(identity);
6002 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006003 }
6004
6005 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006006 * Clears any carrier ImsService overrides for the slot index specified that were previously
6007 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6008 *
6009 * This should only be used for testing.
6010 *
6011 * @param slotIndex the slot ID that the ImsService should bind for.
6012 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6013 */
6014 @Override
6015 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006016 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6017 "clearCarrierImsServiceOverride");
6018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006019 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006020
6021 final long identity = Binder.clearCallingIdentity();
6022 try {
6023 if (mImsResolver == null) {
6024 // may happen if the device does not support IMS.
6025 return false;
6026 }
6027 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6028 } finally {
6029 Binder.restoreCallingIdentity(identity);
6030 }
6031 }
6032
6033 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006034 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006035 *
6036 * @param slotId The slot that the ImsService is associated with.
6037 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6038 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006039 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006040 * @return the package name of the ImsService configuration.
6041 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006042 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6043 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006044 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006045 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6046 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048 final long identity = Binder.clearCallingIdentity();
6049 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006050 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006051 // may happen if the device does not support IMS.
6052 return "";
6053 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006054 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006055 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6056 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006057 } finally {
6058 Binder.restoreCallingIdentity(identity);
6059 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006060 }
6061
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006062 /**
6063 * Get the MmTelFeature state associated with the requested subscription id.
6064 * @param subId The subscription that the MmTelFeature is associated with.
6065 * @param callback A callback with an integer containing the
6066 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6067 */
6068 @Override
6069 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6070 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006071 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6072 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6073 "IMS not available on device.");
6074 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006075 final long token = Binder.clearCallingIdentity();
6076 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006077 int slotId = getSlotIndex(subId);
6078 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6079 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6080 + subId + "'");
6081 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6082 }
6083 verifyImsMmTelConfiguredOrThrow(slotId);
6084 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6085 try {
6086 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6087 } catch (RemoteException e) {
6088 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6089 + "Ignore");
6090 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006091 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006092 } catch (ImsException e) {
6093 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006094 } finally {
6095 Binder.restoreCallingIdentity(token);
6096 }
6097 }
6098
Daniel Brightbb5840b2021-01-12 15:48:18 -08006099 /**
6100 * Sets the ims registration state on all valid {@link Phone}s.
6101 */
6102 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006103 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006104
6105 final long identity = Binder.clearCallingIdentity();
6106 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006107 // NOTE: Before S, this method only set the default phone.
6108 for (final Phone phone : PhoneFactory.getPhones()) {
6109 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6110 phone.setImsRegistrationState(registered);
6111 }
6112 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006113 } finally {
6114 Binder.restoreCallingIdentity(identity);
6115 }
Wink Saville36469e72014-06-11 15:17:00 -07006116 }
6117
6118 /**
Stuart Scott54788802015-03-30 13:18:01 -07006119 * Set the network selection mode to automatic.
6120 *
6121 */
6122 @Override
6123 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6125 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006126
6127 final long identity = Binder.clearCallingIdentity();
6128 try {
shilufc958392020-01-20 11:36:01 -08006129 if (!isActiveSubscription(subId)) {
6130 return;
6131 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006133 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6134 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135 } finally {
6136 Binder.restoreCallingIdentity(identity);
6137 }
Stuart Scott54788802015-03-30 13:18:01 -07006138 }
6139
Jack Yud10cdd42020-09-28 20:28:01 -07006140 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006141 * Ask the radio to connect to the input network and change selection mode to manual.
6142 *
6143 * @param subId the id of the subscription.
6144 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6145 * the operator to attach to.
6146 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6147 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6148 * normal network selection next time.
6149 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006150 */
6151 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006152 public boolean setNetworkSelectionModeManual(
6153 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6155 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006156
6157 if (!isActiveSubscription(subId)) {
6158 return false;
6159 }
6160
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006161 final long identity = Binder.clearCallingIdentity();
6162 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006163 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006165 if (DBG) {
6166 log("setNetworkSelectionModeManual: subId: " + subId
6167 + " operator: " + operatorInfo);
6168 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006169 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6170 } finally {
6171 Binder.restoreCallingIdentity(identity);
6172 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006173 }
shilu84f6e8b2019-12-19 13:58:01 -08006174 /**
6175 * Get the manual network selection
6176 *
6177 * @param subId the id of the subscription.
6178 *
6179 * @return the previously saved user selected PLMN
6180 */
6181 @Override
6182 public String getManualNetworkSelectionPlmn(int subId) {
6183 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006184 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006185 mApp, subId, "getManualNetworkSelectionPlmn");
6186
6187 final long identity = Binder.clearCallingIdentity();
6188 try {
6189 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006190 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006191 }
6192
6193 final Phone phone = getPhone(subId);
6194 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006195 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006196 }
6197 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6198 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6199 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6200 } finally {
6201 Binder.restoreCallingIdentity(identity);
6202 }
6203 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006204
6205 /**
6206 * Scans for available networks.
6207 */
6208 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006209 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6210 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006211 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6212 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006213 LocationAccessPolicy.LocationPermissionResult locationResult =
6214 LocationAccessPolicy.checkLocationPermission(mApp,
6215 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6216 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006217 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006218 .setCallingPid(Binder.getCallingPid())
6219 .setCallingUid(Binder.getCallingUid())
6220 .setMethod("getCellNetworkScanResults")
6221 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006222 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6223 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006224 .build());
6225 switch (locationResult) {
6226 case DENIED_HARD:
6227 throw new SecurityException("Not allowed to access scan results -- location");
6228 case DENIED_SOFT:
6229 return null;
6230 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006231
Pengquan Menga1bb6272018-09-06 09:59:22 -07006232 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006233 try {
6234 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006235 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006236 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006237 } finally {
6238 Binder.restoreCallingIdentity(identity);
6239 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006240 }
6241
6242 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006243 * Get the call forwarding info, given the call forwarding reason.
6244 */
6245 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006246 public void getCallForwarding(int subId, int callForwardingReason,
6247 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006248 enforceReadPrivilegedPermission("getCallForwarding");
6249 long identity = Binder.clearCallingIdentity();
6250 try {
6251 if (DBG) {
6252 log("getCallForwarding: subId " + subId
6253 + " callForwardingReason" + callForwardingReason);
6254 }
Hall Liu27d24262020-09-18 19:04:59 -07006255
6256 Phone phone = getPhone(subId);
6257 if (phone == null) {
6258 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006259 callback.onError(
6260 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006261 } catch (RemoteException e) {
6262 // ignore
6263 }
6264 return;
6265 }
6266
6267 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6268 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6269 @Override
6270 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6271 try {
6272 callback.onCallForwardingInfoAvailable(info);
6273 } catch (RemoteException e) {
6274 // ignore
6275 }
6276 }
6277
6278 @Override
6279 public void onError(int error) {
6280 try {
6281 callback.onError(error);
6282 } catch (RemoteException e) {
6283 // ignore
6284 }
6285 }
6286 });
6287 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006288 } finally {
6289 Binder.restoreCallingIdentity(identity);
6290 }
6291 }
6292
6293 /**
6294 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6295 * reason, the number to forward, and the timeout before the forwarding is attempted.
6296 */
6297 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006298 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6299 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006300 enforceModifyPermission();
6301 long identity = Binder.clearCallingIdentity();
6302 try {
6303 if (DBG) {
6304 log("setCallForwarding: subId " + subId
6305 + " callForwardingInfo" + callForwardingInfo);
6306 }
Hall Liu27d24262020-09-18 19:04:59 -07006307
6308 Phone phone = getPhone(subId);
6309 if (phone == null) {
6310 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006311 callback.accept(
6312 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006313 } catch (RemoteException e) {
6314 // ignore
6315 }
6316 return;
6317 }
6318
6319 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6320 FunctionalUtils.ignoreRemoteException(callback::accept));
6321
6322 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006323 } finally {
6324 Binder.restoreCallingIdentity(identity);
6325 }
6326 }
6327
6328 /**
Hall Liu27d24262020-09-18 19:04:59 -07006329 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006330 */
6331 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006332 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006333 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006334 long identity = Binder.clearCallingIdentity();
6335 try {
Hall Liu27d24262020-09-18 19:04:59 -07006336 Phone phone = getPhone(subId);
6337 if (phone == null) {
6338 try {
6339 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6340 } catch (RemoteException e) {
6341 // ignore
6342 }
6343 return;
6344 }
SongFerngWang0e767992021-03-31 22:08:45 +08006345 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6346 PersistableBundle c = configManager.getConfigForSubId(subId);
6347 boolean requireUssd = c.getBoolean(
6348 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006349
Shuo Qian4a594052020-01-23 11:59:30 -08006350 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006351 if (requireUssd) {
6352 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6353 getSubscriptionCarrierId(subId));
6354 String newUssdCommand = "";
6355 try {
6356 newUssdCommand = carrierXmlParser.getFeature(
6357 CarrierXmlParser.FEATURE_CALL_WAITING)
6358 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6359 } catch (NullPointerException e) {
6360 loge("Failed to generate USSD number" + e);
6361 }
6362 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6363 mMainThreadHandler, callback, carrierXmlParser,
6364 CarrierXmlParser.SsEntry.SSAction.QUERY);
6365 final String ussdCommand = newUssdCommand;
6366 Executors.newSingleThreadExecutor().execute(() -> {
6367 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6368 });
6369 } else {
6370 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6371 callback::accept);
6372 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6373 }
Shuo Qian4a594052020-01-23 11:59:30 -08006374 } finally {
6375 Binder.restoreCallingIdentity(identity);
6376 }
6377 }
6378
6379 /**
Hall Liu27d24262020-09-18 19:04:59 -07006380 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006381 */
6382 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006383 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006384 enforceModifyPermission();
6385 long identity = Binder.clearCallingIdentity();
6386 try {
Hall Liu27d24262020-09-18 19:04:59 -07006387 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6388
6389 Phone phone = getPhone(subId);
6390 if (phone == null) {
6391 try {
6392 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6393 } catch (RemoteException e) {
6394 // ignore
6395 }
6396 return;
6397 }
6398
SongFerngWang0e767992021-03-31 22:08:45 +08006399 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6400 PersistableBundle c = configManager.getConfigForSubId(subId);
6401 boolean requireUssd = c.getBoolean(
6402 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006403
SongFerngWang0e767992021-03-31 22:08:45 +08006404 if (DBG) log("getCallWaitingStatus: subId " + subId);
6405 if (requireUssd) {
6406 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6407 getSubscriptionCarrierId(subId));
6408 CarrierXmlParser.SsEntry.SSAction ssAction =
6409 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6410 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6411 String newUssdCommand = "";
6412 try {
6413 newUssdCommand = carrierXmlParser.getFeature(
6414 CarrierXmlParser.FEATURE_CALL_WAITING)
6415 .makeCommand(ssAction, null);
6416 } catch (NullPointerException e) {
6417 loge("Failed to generate USSD number" + e);
6418 }
6419 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6420 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6421 final String ussdCommand = newUssdCommand;
6422 Executors.newSingleThreadExecutor().execute(() -> {
6423 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6424 });
6425 } else {
6426 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6427 FunctionalUtils.ignoreRemoteException(callback::accept));
6428
6429 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6430 }
Shuo Qian4a594052020-01-23 11:59:30 -08006431 } finally {
6432 Binder.restoreCallingIdentity(identity);
6433 }
6434 }
6435
6436 /**
yinxub1bed742017-04-17 11:45:04 -07006437 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006438 *
yinxub1bed742017-04-17 11:45:04 -07006439 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006440 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6441 * location related information which will be sent if the caller already possess
6442 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006443 * @param request contains the radio access networks with bands/channels to scan
6444 * @param messenger callback messenger for scan results or errors
6445 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006446 * @return the id of the requested scan which can be used to stop the scan.
6447 */
6448 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006449 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6450 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006451 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6453 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006454 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006455 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6456 if (!renounceFineLocationAccess) {
6457 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6458 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6459 .setCallingPackage(callingPackage)
6460 .setCallingFeatureId(callingFeatureId)
6461 .setCallingPid(Binder.getCallingPid())
6462 .setCallingUid(Binder.getCallingUid())
6463 .setMethod("requestNetworkScan")
6464 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6465 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6466 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6467 .build());
6468 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006469 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006470 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6471 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006472 if (e != null) {
6473 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6474 throw e;
6475 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006476 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006477 return TelephonyScanManager.INVALID_SCAN_ID;
6478 }
6479 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006480 }
Hall Liu912dfd32019-04-25 14:02:26 -07006481 int callingUid = Binder.getCallingUid();
6482 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006483 final long identity = Binder.clearCallingIdentity();
6484 try {
6485 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006486 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006487 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006488 } finally {
6489 Binder.restoreCallingIdentity(identity);
6490 }
yinxu504e1392017-04-12 16:03:22 -07006491 }
6492
Hall Liub2ac8ef2019-02-28 15:56:23 -08006493 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006494 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006495 boolean hasCarrierPriv;
6496 final long identity = Binder.clearCallingIdentity();
6497 try {
6498 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6499 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6500 } finally {
6501 Binder.restoreCallingIdentity(identity);
6502 }
Hall Liu558027f2019-05-15 19:14:05 -07006503 boolean hasNetworkScanPermission =
6504 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6505 == PERMISSION_GRANTED;
6506
6507 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6508 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6509 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006510 }
6511
6512 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6513 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006514 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6515 return new SecurityException("Specific channels must not be"
6516 + " scanned without location access.");
6517 }
6518 }
6519 }
6520
Hall Liub2ac8ef2019-02-28 15:56:23 -08006521 return null;
6522 }
6523
yinxu504e1392017-04-12 16:03:22 -07006524 /**
6525 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006526 *
6527 * @param subId id of the subscription
6528 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006529 */
6530 @Override
6531 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006532 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6533 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006534
Hall Liu912dfd32019-04-25 14:02:26 -07006535 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006536 final long identity = Binder.clearCallingIdentity();
6537 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006538 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006539 } finally {
6540 Binder.restoreCallingIdentity(identity);
6541 }
yinxu504e1392017-04-12 16:03:22 -07006542 }
6543
6544 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006545 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006546 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006547 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006548 */
6549 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006550 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006551 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006552 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006553 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006554
6555 final long identity = Binder.clearCallingIdentity();
6556 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006557 if (DBG) log("getAllowedNetworkTypesBitmask");
6558 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6559 int networkTypesBitmask = (result != null ? result[0] : -1);
6560 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6561 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562 } finally {
6563 Binder.restoreCallingIdentity(identity);
6564 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006565 }
6566
6567 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006568 * Get the allowed network types for certain reason.
6569 *
6570 * @param subId the id of the subscription.
6571 * @param reason the reason the allowed network type change is taking place
6572 * @return the allowed network types.
6573 */
6574 @Override
6575 public long getAllowedNetworkTypesForReason(int subId,
6576 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006577 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006578 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006579 final long identity = Binder.clearCallingIdentity();
6580 try {
6581 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6582 } finally {
6583 Binder.restoreCallingIdentity(identity);
6584 }
6585 }
6586
6587 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006588 * Enable/Disable E-UTRA-NR Dual Connectivity
6589 * @param subId subscription id of the sim card
6590 * @param nrDualConnectivityState expected NR dual connectivity state
6591 * This can be passed following states
6592 * <ol>
6593 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6594 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6595 * <li>Disable NR dual connectivity and force secondary cell to be released
6596 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6597 * </ol>
6598 * @return operation result.
6599 */
6600 @Override
6601 public int setNrDualConnectivityState(int subId,
6602 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6603 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6604 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006605 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006606 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6607 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6608 }
6609
Sooraj Sasindran37444802020-08-11 10:40:43 -07006610 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6611 final long identity = Binder.clearCallingIdentity();
6612 try {
6613 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6614 nrDualConnectivityState, subId,
6615 workSource);
6616 if (DBG) log("enableNRDualConnectivity result: " + result);
6617 return result;
6618 } finally {
6619 Binder.restoreCallingIdentity(identity);
6620 }
6621 }
6622
6623 /**
6624 * Is E-UTRA-NR Dual Connectivity enabled
6625 * @return true if dual connectivity is enabled else false
6626 */
6627 @Override
6628 public boolean isNrDualConnectivityEnabled(int subId) {
6629 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006630 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006631 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006632 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006633 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6634 return false;
6635 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006636 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6637 final long identity = Binder.clearCallingIdentity();
6638 try {
6639 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6640 null, subId, workSource);
6641 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6642 return isEnabled;
6643 } finally {
6644 Binder.restoreCallingIdentity(identity);
6645 }
6646 }
6647
6648 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006649 * Set the allowed network types of the device and
6650 * provide the reason triggering the allowed network change.
6651 *
6652 * @param subId the id of the subscription.
6653 * @param reason the reason the allowed network type change is taking place
6654 * @param allowedNetworkTypes the allowed network types.
6655 * @return true on success; false on any failure.
6656 */
6657 @Override
6658 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006659 @TelephonyManager.AllowedNetworkTypesReason int reason,
6660 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006661 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6662 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006663 // If the caller only has carrier privileges, then they should not be able to override
6664 // any network types which were set for security reasons.
6665 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6666 != PERMISSION_GRANTED
6667 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6668 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6669 throw new SecurityException(
6670 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6671 + " reason "
6672 + reason);
6673 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006674 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006675 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6676 return false;
6677 }
6678 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6679 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006680 return false;
6681 }
6682
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006683 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6684 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6685
6686
6687 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6688 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6689 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006690 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006691
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006692 final long identity = Binder.clearCallingIdentity();
6693 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006694 Boolean success = (Boolean) sendRequest(
6695 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6696 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6697
6698 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6699 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006700 } finally {
6701 Binder.restoreCallingIdentity(identity);
6702 }
6703 }
6704
6705 /**
Miaoa84611c2019-03-15 09:21:10 +08006706 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006707 *
Miaoa84611c2019-03-15 09:21:10 +08006708 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006709 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006710 * @hide
6711 */
6712 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006713 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006714 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006715 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006716 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006717 try {
Miaoa84611c2019-03-15 09:21:10 +08006718 if (phone != null) {
6719 return phone.hasMatchedTetherApnSetting();
6720 } else {
6721 return false;
6722 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006723 } finally {
6724 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006725 }
Junda Liu475951f2014-11-07 16:45:03 -08006726 }
6727
6728 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006729 * Get the user enabled state of Mobile Data.
6730 *
6731 * TODO: remove and use isUserDataEnabled.
6732 * This can't be removed now because some vendor codes
6733 * calls through ITelephony directly while they should
6734 * use TelephonyManager.
6735 *
6736 * @return true on enabled
6737 */
6738 @Override
6739 public boolean getDataEnabled(int subId) {
6740 return isUserDataEnabled(subId);
6741 }
6742
6743 /**
6744 * Get whether mobile data is enabled per user setting.
6745 *
6746 * There are other factors deciding whether mobile data is actually enabled, but they are
6747 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006748 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006749 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6750 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006751 *
6752 * @return {@code true} if data is enabled else {@code false}
6753 */
6754 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006755 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006756 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006757 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006758 try {
6759 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6760 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006761 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006762 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6763 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006764 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006766 mApp, subId, functionName);
6767
Robert Greenwalt646120a2014-05-23 11:54:03 -07006768 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006769
6770 final long identity = Binder.clearCallingIdentity();
6771 try {
6772 int phoneId = mSubscriptionController.getPhoneId(subId);
6773 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6774 Phone phone = PhoneFactory.getPhone(phoneId);
6775 if (phone != null) {
6776 boolean retVal = phone.isUserDataEnabled();
6777 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6778 return retVal;
6779 } else {
6780 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6781 return false;
6782 }
6783 } finally {
6784 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006785 }
6786 }
6787
6788 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006789 * Checks if the device is capable of mobile data by considering whether whether the
6790 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6791 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006792 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006793 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006794 */
6795 @Override
6796 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006797 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006798 try {
6799 try {
6800 mApp.enforceCallingOrSelfPermission(
6801 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006802 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006803 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006804 try {
6805 mApp.enforceCallingOrSelfPermission(
6806 android.Manifest.permission.READ_PHONE_STATE,
6807 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006808 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006809 mApp.enforceCallingOrSelfPermission(
6810 permission.READ_BASIC_PHONE_STATE, functionName);
6811 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006812 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006813 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006814 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006815 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006816
6817 final long identity = Binder.clearCallingIdentity();
6818 try {
6819 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006820 Phone phone = PhoneFactory.getPhone(phoneId);
6821 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006822 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006823 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006824 return retVal;
6825 } else {
6826 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6827 return false;
6828 }
6829 } finally {
6830 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006831 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006832 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006833
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006834 /**
6835 * Check if data is enabled for a specific reason
6836 * @param subId Subscription index
6837 * @param reason the reason the data enable change is taking place
6838 * @return {@code true} if the overall data is enabled; {@code false} if not.
6839 */
6840 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006841 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006842 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006843 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006844 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006845 try {
6846 mApp.enforceCallingOrSelfPermission(
6847 android.Manifest.permission.ACCESS_NETWORK_STATE,
6848 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006849 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006850 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6851 functionName);
6852 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006853 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006854 try {
6855 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006856 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006857 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006859 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006860 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006861 }
6862
6863
6864 final long identity = Binder.clearCallingIdentity();
6865 try {
6866 int phoneId = mSubscriptionController.getPhoneId(subId);
6867 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006868 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006869 + " reason=" + reason);
6870 }
6871 Phone phone = PhoneFactory.getPhone(phoneId);
6872 if (phone != null) {
6873 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006874 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006875 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006876 return retVal;
6877 } else {
6878 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006879 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006880 + subId + " retVal=false");
6881 }
6882 return false;
6883 }
6884 } finally {
6885 Binder.restoreCallingIdentity(identity);
6886 }
6887 }
6888
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006889 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006890 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006891 // No permission needed; this only lets the caller inspect their own status.
6892 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006893 }
Junda Liu29340342014-07-10 15:23:27 -07006894
6895 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006896 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006897 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006898 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6899 }
6900
6901 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6902 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006903 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006904 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006905 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6906 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006907 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6908 if (cpt == null) {
6909 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006910 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6911 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006912 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006913 }
6914
6915 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006916 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006917 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006918 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006919 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006920 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006921 Phone phone = getPhone(subId);
6922 if (phone == null) {
6923 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6924 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6925 }
6926 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6927 if (cpt == null) {
6928 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006929 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6930 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006931 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006932 }
6933
6934 @Override
6935 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006936 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006937 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6938 }
6939
6940 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006941 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006942 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006943 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006944 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006945 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6946 Phone phone = PhoneFactory.getPhone(phoneId);
6947 if (phone == null) {
6948 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006949 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006950 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6951 if (cpt == null) {
6952 continue;
6953 }
6954 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006955 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6956 break;
6957 }
6958 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006959 return result;
Junda Liu29340342014-07-10 15:23:27 -07006960 }
Derek Tan89e89d42014-07-08 17:00:10 -07006961
6962 @Override
Junda Liue64de782015-04-16 17:19:16 -07006963 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006964 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006965 Phone phone = PhoneFactory.getPhone(phoneId);
6966 if (phone == null) {
6967 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006968 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006969 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6970 if (cpt == null) {
6971 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006972 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006973 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006974 }
6975
Amith Yamasani6e118872016-02-19 12:53:51 -08006976 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006977 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006978 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006979 Phone phone = PhoneFactory.getPhone(phoneId);
6980 if (phone == null) {
6981 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006982 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006983 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6984 if (cpt == null) {
6985 return Collections.emptyList();
6986 }
6987 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006988 }
6989
chen xuf7e9fe82019-05-09 19:31:02 -07006990 @Override
6991 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006992 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006993 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006994 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006995 try {
6996 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6997 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6998 }
6999 } finally {
7000 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007001 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007002 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007003 }
7004
Rambo Wang6812ffb2022-03-15 16:54:17 -07007005 @Override
7006 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7007 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7008
7009 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7010 if (phone == null) {
7011 return null;
7012 }
7013 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7014 if (cpt == null) {
7015 return null;
7016 }
7017 return cpt.getCarrierServicePackageName();
7018 }
7019
Wink Savilleb564aae2014-10-23 10:18:09 -07007020 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007021 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007022 UiccPort port = phone == null ? null : phone.getUiccPort();
7023 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007024 return null;
7025 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007026 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007027 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007028 return null;
7029 }
7030 return iccId;
7031 }
7032
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007033 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007034 public void setCallComposerStatus(int subId, int status) {
7035 enforceModifyPermission();
7036
7037 final long identity = Binder.clearCallingIdentity();
7038 try {
7039 Phone phone = getPhone(subId);
7040 if (phone != null) {
7041 Phone defaultPhone = phone.getImsPhone();
7042 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7043 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7044 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007045 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7046 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007047 }
7048 }
Shuo Qian284ae752020-12-22 19:10:14 -08007049 } catch (ImsException e) {
7050 throw new ServiceSpecificException(e.getCode());
7051 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007052 Binder.restoreCallingIdentity(identity);
7053 }
7054 }
7055
7056 @Override
7057 public int getCallComposerStatus(int subId) {
7058 enforceReadPrivilegedPermission("getCallComposerStatus");
7059
7060 final long identity = Binder.clearCallingIdentity();
7061 try {
7062 Phone phone = getPhone(subId);
7063 if (phone != null) {
7064 Phone defaultPhone = phone.getImsPhone();
7065 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7066 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7067 return imsPhone.getCallComposerStatus();
7068 }
7069 }
7070 } finally {
7071 Binder.restoreCallingIdentity(identity);
7072 }
7073 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7074 }
7075
7076 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007077 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7078 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007079 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007080 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007081
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007082 final long identity = Binder.clearCallingIdentity();
7083 try {
7084 final String iccId = getIccId(subId);
7085 final Phone phone = getPhone(subId);
7086 if (phone == null) {
7087 return false;
7088 }
7089 final String subscriberId = phone.getSubscriberId();
7090
7091 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007092 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007093 + subscriberId + " to " + number);
7094 }
7095
7096 if (TextUtils.isEmpty(iccId)) {
7097 return false;
7098 }
7099
7100 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7101
7102 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7103 if (alphaTag == null) {
7104 editor.remove(alphaTagPrefKey);
7105 } else {
7106 editor.putString(alphaTagPrefKey, alphaTag);
7107 }
7108
7109 // Record both the line number and IMSI for this ICCID, since we need to
7110 // track all merged IMSIs based on line number
7111 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7112 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7113 if (number == null) {
7114 editor.remove(numberPrefKey);
7115 editor.remove(subscriberPrefKey);
7116 } else {
7117 editor.putString(numberPrefKey, number);
7118 editor.putString(subscriberPrefKey, subscriberId);
7119 }
7120
7121 editor.commit();
7122 return true;
7123 } finally {
7124 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007125 }
Derek Tan7226c842014-07-02 17:42:23 -07007126 }
7127
7128 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007129 public String getLine1NumberForDisplay(int subId, String callingPackage,
7130 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007131 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007132 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007133 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007134 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007135 return null;
7136 }
Derek Tan97ebb422014-09-05 16:55:38 -07007137
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007138 final long identity = Binder.clearCallingIdentity();
7139 try {
7140 String iccId = getIccId(subId);
7141 if (iccId != null) {
7142 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7143 if (DBG_MERGE) {
7144 log("getLine1NumberForDisplay returning "
7145 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7146 }
7147 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007148 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007149 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7150 return null;
7151 } finally {
7152 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007153 }
Derek Tan7226c842014-07-02 17:42:23 -07007154 }
7155
7156 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007157 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7158 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007159 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007160 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007161 return null;
7162 }
Derek Tan97ebb422014-09-05 16:55:38 -07007163
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007164 final long identity = Binder.clearCallingIdentity();
7165 try {
7166 String iccId = getIccId(subId);
7167 if (iccId != null) {
7168 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7169 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7170 }
7171 return null;
7172 } finally {
7173 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007174 }
Derek Tan7226c842014-07-02 17:42:23 -07007175 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007176
7177 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007178 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7179 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007180 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7181 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007182 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007183 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007184 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007185 return null;
7186 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007187
Jordan Liub49b04b2019-05-06 14:45:15 -07007188 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7189 // the process, where TelephonyManager was instantiated.
7190 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007191 final long identity = Binder.clearCallingIdentity();
7192 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007193 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007194 final TelephonyManager tele = TelephonyManager.from(context);
7195 final SubscriptionManager sub = SubscriptionManager.from(context);
7196
7197 // Figure out what subscribers are currently active
7198 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007199
Jordan Liub49b04b2019-05-06 14:45:15 -07007200 // Only consider subs which match the current subId
7201 // This logic can be simplified. See b/131189269 for progress.
7202 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007203 activeSubscriberIds.add(tele.getSubscriberId(subId));
7204 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007205
7206 // First pass, find a number override for an active subscriber
7207 String mergeNumber = null;
7208 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7209 for (String key : prefs.keySet()) {
7210 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7211 final String subscriberId = (String) prefs.get(key);
7212 if (activeSubscriberIds.contains(subscriberId)) {
7213 final String iccId = key.substring(
7214 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7215 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7216 mergeNumber = (String) prefs.get(numberKey);
7217 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007218 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007219 + " for active subscriber " + subscriberId);
7220 }
7221 if (!TextUtils.isEmpty(mergeNumber)) {
7222 break;
7223 }
7224 }
7225 }
7226 }
7227
7228 // Shortcut when no active merged subscribers
7229 if (TextUtils.isEmpty(mergeNumber)) {
7230 return null;
7231 }
7232
7233 // Second pass, find all subscribers under that line override
7234 final ArraySet<String> result = new ArraySet<>();
7235 for (String key : prefs.keySet()) {
7236 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7237 final String number = (String) prefs.get(key);
7238 if (mergeNumber.equals(number)) {
7239 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7240 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7241 final String subscriberId = (String) prefs.get(subscriberKey);
7242 if (!TextUtils.isEmpty(subscriberId)) {
7243 result.add(subscriberId);
7244 }
7245 }
7246 }
7247 }
7248
7249 final String[] resultArray = result.toArray(new String[result.size()]);
7250 Arrays.sort(resultArray);
7251 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007252 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007253 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7254 }
7255 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007256 } finally {
7257 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007258 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007259 }
7260
7261 @Override
zoey chen38003472019-12-13 17:16:31 +08007262 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7263 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007264
7265 final long identity = Binder.clearCallingIdentity();
7266 try {
7267 final TelephonyManager telephonyManager = mApp.getSystemService(
7268 TelephonyManager.class);
7269 String subscriberId = telephonyManager.getSubscriberId(subId);
7270 if (subscriberId == null) {
7271 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007272 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007273 + subId);
7274 }
7275 return null;
7276 }
7277
7278 final SubscriptionInfo info = SubscriptionController.getInstance()
7279 .getSubscriptionInfo(subId);
7280 final ParcelUuid groupUuid = info.getGroupUuid();
7281 // If it doesn't belong to any group, return just subscriberId of itself.
7282 if (groupUuid == null) {
7283 return new String[]{subscriberId};
7284 }
7285
7286 // Get all subscriberIds from the group.
7287 final List<String> mergedSubscriberIds = new ArrayList<>();
7288 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007289 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007290 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007291 for (SubscriptionInfo subInfo : groupInfos) {
7292 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7293 if (subscriberId != null) {
7294 mergedSubscriberIds.add(subscriberId);
7295 }
7296 }
7297
7298 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7299 } finally {
7300 Binder.restoreCallingIdentity(identity);
7301
7302 }
7303 }
7304
7305 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007306 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007307 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007308 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007309
7310 final long identity = Binder.clearCallingIdentity();
7311 try {
7312 final Phone phone = getPhone(subId);
7313 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7314 } finally {
7315 Binder.restoreCallingIdentity(identity);
7316 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007317 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007318
7319 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007320 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007321 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7322 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007323 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7324 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007325
7326 final long identity = Binder.clearCallingIdentity();
7327 try {
7328 final Phone phone = getPhone(subId);
7329 if (phone == null) {
7330 return false;
7331 }
7332 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7333 cdmaNonRoamingList);
7334 } finally {
7335 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007336 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007337 }
7338
7339 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007340 @Deprecated
7341 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7342 enforceModifyPermission();
7343
7344 int returnValue = 0;
7345 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007346 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007347 if(result.exception == null) {
7348 if (result.result != null) {
7349 byte[] responseData = (byte[])(result.result);
7350 if(responseData.length > oemResp.length) {
7351 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7352 responseData.length + "bytes. Buffer Size is " +
7353 oemResp.length + "bytes.");
7354 }
7355 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7356 returnValue = responseData.length;
7357 }
7358 } else {
7359 CommandException ex = (CommandException) result.exception;
7360 returnValue = ex.getCommandError().ordinal();
7361 if(returnValue > 0) returnValue *= -1;
7362 }
7363 } catch (RuntimeException e) {
7364 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7365 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7366 if(returnValue > 0) returnValue *= -1;
7367 }
7368
7369 return returnValue;
7370 }
7371
7372 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007373 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007374 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007375 try {
7376 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007377 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007378 mApp, phone.getSubId(), "getRadioAccessFamily");
7379 } catch (SecurityException e) {
7380 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7381 throw e;
7382 }
chen xub97461a2018-10-26 14:17:57 -07007383 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007384 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007385 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007386 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007387 final long identity = Binder.clearCallingIdentity();
7388 try {
chen xub97461a2018-10-26 14:17:57 -07007389 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007390 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007391 mApp, phone.getSubId(), "getRadioAccessFamily");
7392 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007393 } finally {
7394 Binder.restoreCallingIdentity(identity);
7395 }
chen xub97461a2018-10-26 14:17:57 -07007396 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007397 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007398
7399 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007400 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007401 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007402 try {
7403 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7404 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007405 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007406 }
7407 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007408 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007409 }
7410 RoleManager rm = mApp.getSystemService(RoleManager.class);
7411 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7412 if (!dialerRoleHolders.contains(callingPackage)) {
7413 throw new SecurityException("App must be the dialer role holder to"
7414 + " upload a call composer pic");
7415 }
7416
7417 Executors.newSingleThreadExecutor().execute(() -> {
7418 ByteArrayOutputStream output = new ByteArrayOutputStream(
7419 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7420 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7421 boolean readUntilEnd = false;
7422 int totalBytesRead = 0;
7423 byte[] buffer = new byte[16 * 1024];
7424 while (true) {
7425 int numRead;
7426 try {
7427 numRead = input.read(buffer);
7428 } catch (IOException e) {
7429 try {
7430 fd.checkError();
7431 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7432 null);
7433 } catch (IOException e1) {
7434 // This means that the other side closed explicitly with an error. If this
7435 // happens, log and ignore.
7436 loge("Remote end of call composer picture pipe closed: " + e1);
7437 }
7438 break;
7439 }
7440 if (numRead == -1) {
7441 readUntilEnd = true;
7442 break;
7443 }
7444 totalBytesRead += numRead;
7445 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7446 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7447 try {
7448 input.close();
7449 } catch (IOException e) {
7450 // ignore
7451 }
7452 break;
7453 }
7454 output.write(buffer, 0, numRead);
7455 }
7456 // Generally, the remote end will close the file descriptors. The only case where we
7457 // close is above, where the picture size is too big.
7458
7459 try {
7460 fd.checkError();
7461 } catch (IOException e) {
7462 loge("Remote end for call composer closed with an error: " + e);
7463 return;
7464 }
7465
Hall Liuaa4211e2021-01-20 15:43:39 -08007466 if (!readUntilEnd) {
7467 loge("Did not finish reading entire image; aborting");
7468 return;
7469 }
Hall Liu82694d52020-12-11 18:22:04 -08007470
Hall Liuaa4211e2021-01-20 15:43:39 -08007471 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7472 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7473 new CallComposerPictureTransfer.Factory() {},
7474 imageData,
7475 (result) -> {
7476 if (result.first != null) {
7477 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7478 Bundle outputResult = new Bundle();
7479 outputResult.putParcelable(
7480 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7481 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7482 outputResult);
7483 } else {
7484 callback.send(result.second, null);
7485 }
7486 }
7487 );
Hall Liu82694d52020-12-11 18:22:04 -08007488 });
7489 }
7490
7491 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007492 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007493 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007494 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007495
7496 final long identity = Binder.clearCallingIdentity();
7497 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007498 ImsManager.getInstance(defaultPhone.getContext(),
7499 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500 } finally {
7501 Binder.restoreCallingIdentity(identity);
7502 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007503 }
7504
7505 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007506 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007507 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007508 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7509 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007510 return false;
7511 }
Svet Ganovb320e182015-04-16 12:30:10 -07007512
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007513 final long identity = Binder.clearCallingIdentity();
7514 try {
7515 // Check the user preference and the system-level IMS setting. Even if the user has
7516 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7517 // In the long run, we may instead need to check if there exists a connection service
7518 // which can support video calling.
7519 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007520 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007521 return imsManager.isVtEnabledByPlatform()
7522 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7523 && imsManager.isVtEnabledByUser();
7524 } finally {
7525 Binder.restoreCallingIdentity(identity);
7526 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007527 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007528
Andrew Leea1239f22015-03-02 17:44:07 -08007529 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007530 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7531 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007533 mApp, subId, callingPackage, callingFeatureId,
7534 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007535 return false;
7536 }
7537
7538 final long identity = Binder.clearCallingIdentity();
7539 try {
7540 CarrierConfigManager configManager =
7541 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007542 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007543 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7544 } finally {
7545 Binder.restoreCallingIdentity(identity);
7546 }
Andrew Leea1239f22015-03-02 17:44:07 -08007547 }
7548
7549 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007550 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007551 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007552 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007553 return false;
7554 }
7555
7556 final long identity = Binder.clearCallingIdentity();
7557 try {
7558 CarrierConfigManager configManager =
7559 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007560 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007561 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7562 } finally {
7563 Binder.restoreCallingIdentity(identity);
7564 }
Andrew Leea1239f22015-03-02 17:44:07 -08007565 }
7566
Andrew Lee9431b832015-03-09 18:46:45 -07007567 @Override
7568 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007569 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007570 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007571 }
7572
7573 @Override
7574 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007575 final long identity = Binder.clearCallingIdentity();
7576 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007577 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007578 } finally {
7579 Binder.restoreCallingIdentity(identity);
7580 }
Andrew Lee9431b832015-03-09 18:46:45 -07007581 }
7582
Hall Liuf6668912018-10-31 17:05:23 -07007583 /**
7584 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7585 * support for the feature and device firmware support.
7586 *
7587 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7588 */
7589 @Override
7590 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007591 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007592 final Phone phone = getPhone(subscriptionId);
7593 if (phone == null) {
7594 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7595 return false;
7596 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007597 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007598 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007599 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7600 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007601 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007602 return isCarrierSupported && isDeviceSupported;
7603 } finally {
7604 Binder.restoreCallingIdentity(identity);
7605 }
Hall Liu98187582018-01-22 19:15:32 -08007606 }
7607
Hall Liuf6668912018-10-31 17:05:23 -07007608 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007609 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7610 * RTT setting, will return true if the device and carrier both support RTT.
7611 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007612 */
7613 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007614 final long identity = Binder.clearCallingIdentity();
7615 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007616 boolean isRttSupported = isRttSupported(subscriptionId);
7617 boolean isUserRttSettingOn = Settings.Secure.getInt(
7618 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7619 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7620 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7621 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007622 } finally {
7623 Binder.restoreCallingIdentity(identity);
7624 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007625 }
7626
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007627 @Deprecated
7628 @Override
7629 public String getDeviceId(String callingPackage) {
7630 return getDeviceIdWithFeature(callingPackage, null);
7631 }
7632
Sanket Padawe7310cc72015-01-14 09:53:20 -08007633 /**
7634 * Returns the unique device ID of phone, for example, the IMEI for
7635 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7636 *
7637 * <p>Requires Permission:
7638 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7639 */
7640 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007641 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007642 try {
7643 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7644 } catch (SecurityException se) {
7645 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7646 throw new SecurityException("Package " + callingPackage + " does not belong to "
7647 + Binder.getCallingUid());
7648 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007649 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007650 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007651 return null;
7652 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007653 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007654 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007655 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007656 return null;
7657 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007658
7659 final long identity = Binder.clearCallingIdentity();
7660 try {
7661 return phone.getDeviceId();
7662 } finally {
7663 Binder.restoreCallingIdentity(identity);
7664 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007665 }
7666
Ping Sunc67b7c22016-03-02 19:16:45 +08007667 /**
7668 * {@hide}
7669 * Returns the IMS Registration Status on a particular subid
7670 *
7671 * @param subId
7672 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007673 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007674 Phone phone = getPhone(subId);
7675 if (phone != null) {
7676 return phone.isImsRegistered();
7677 } else {
7678 return false;
7679 }
7680 }
7681
Santos Cordon7a1885b2015-02-03 11:15:19 -08007682 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007683 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007684 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007685 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007686 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007687 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7688 }
7689 final long identity = Binder.clearCallingIdentity();
7690 try {
7691 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7692 } finally {
7693 Binder.restoreCallingIdentity(identity);
7694 }
7695 }
7696
7697 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007698 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007699 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007700 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007701 mApp,
7702 subscriptionId,
7703 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007704 final long identity = Binder.clearCallingIdentity();
7705 try {
7706 Phone phone = getPhone(subscriptionId);
7707 if (phone == null) {
7708 return null;
7709 }
7710 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7711 } finally {
7712 Binder.restoreCallingIdentity(identity);
7713 }
7714 }
7715
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007716 /**
7717 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007718 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007719 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007720 final long identity = Binder.clearCallingIdentity();
7721 try {
7722 Phone phone = getPhone(subId);
7723 if (phone != null) {
7724 return phone.isWifiCallingEnabled();
7725 } else {
7726 return false;
7727 }
7728 } finally {
7729 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007730 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007731 }
7732
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007733 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007734 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007735 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007736 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007737 final long identity = Binder.clearCallingIdentity();
7738 try {
7739 Phone phone = getPhone(subId);
7740 if (phone != null) {
7741 return phone.isVideoEnabled();
7742 } else {
7743 return false;
7744 }
7745 } finally {
7746 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007747 }
7748 }
7749
7750 /**
7751 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7752 * defined in {@link ImsRegistrationImplBase}.
7753 */
7754 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007755 final long identity = Binder.clearCallingIdentity();
7756 try {
7757 Phone phone = getPhone(subId);
7758 if (phone != null) {
7759 return phone.getImsRegistrationTech();
7760 } else {
7761 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7762 }
7763 } finally {
7764 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007765 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007766 }
7767
Stuart Scott8eef64f2015-04-08 15:13:54 -07007768 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007769 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007770 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007771 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7772 return;
7773 }
Kai Shif70f46f2021-03-03 13:59:46 -08007774 Phone defaultPhone = getDefaultPhone();
7775 if (defaultPhone != null) {
7776 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7777 mApp, getDefaultPhone().getSubId(), "factoryReset");
7778 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007779 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007780
Svet Ganovcc087f82015-05-12 20:35:54 -07007781 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007782 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7783 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007784 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007785 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007786 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007787 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007788 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007789 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007790 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007791 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007792 // There has been issues when Sms raw table somehow stores orphan
7793 // fragments. They lead to garbled message when new fragments come
7794 // in and combined with those stale ones. In case this happens again,
7795 // user can reset all network settings which will clean up this table.
7796 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007797 // Clean up IMS settings as well here.
7798 int slotId = getSlotIndex(subId);
7799 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7800 ImsManager.getInstance(mApp, slotId).factoryReset();
7801 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007802
Kai Shif70f46f2021-03-03 13:59:46 -08007803 if (defaultPhone == null) {
7804 return;
7805 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007806 // Erase modem config if erase modem on network setting is enabled.
7807 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7808 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7809 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007810 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007811 }
Kai Shif70f46f2021-03-03 13:59:46 -08007812
7813 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007814 } finally {
7815 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007816 }
7817 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007818
SongFerngWangfd89b102021-05-27 22:44:54 +08007819 @VisibleForTesting
7820 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7821 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7822 return;
7823 }
7824 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7825 RILConstants.PREFERRED_NETWORK_MODE);
7826 SubscriptionManager.setSubscriptionProperty(subId,
7827 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7828 "user=" + defaultNetworkType);
7829 phone.loadAllowedNetworksFromSubscriptionDatabase();
7830 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7831 defaultNetworkType, null);
7832 }
7833
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007834 private void cleanUpSmsRawTable(Context context) {
7835 ContentResolver resolver = context.getContentResolver();
7836 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7837 resolver.delete(uri, null, null);
7838 }
7839
Narayan Kamath1c496c22015-04-16 14:40:19 +01007840 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007841 public String getSimLocaleForSubscriber(int subId) {
7842 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7843 final Phone phone = getPhone(subId);
7844 if (phone == null) {
7845 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007846 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007847 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007848 final long identity = Binder.clearCallingIdentity();
7849 try {
chen xu5d3637b2019-01-21 23:31:38 -08007850 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007851 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007852 if (info == null) {
7853 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7854 return null;
7855 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007856 // Try and fetch the locale from the carrier properties or from the SIM language
7857 // preferences (EF-PL and EF-LI)...
7858 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007859 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007860 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7861 if (localeFromDefaultSim != null) {
7862 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7863 if (DBG) log("Using locale from subId: " + subId + " locale: "
7864 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08007865 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007866 } else {
7867 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007868 }
7869 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007870
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007871 // The SIM language preferences only store a language (e.g. fr = French), not an
7872 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7873 // the SIM and carrier preferences does not include a country we add the country
7874 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007875 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007876 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007877 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08007878 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007879 }
7880
7881 if (DBG) log("No locale found - returning null");
7882 return null;
7883 } finally {
7884 Binder.restoreCallingIdentity(identity);
7885 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007886 }
7887
tom hsu0b59d292022-09-29 23:49:21 +08007888 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08007889 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08007890 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08007891 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08007892 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08007893 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
7894 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08007895 Locale.forLanguageTag(localeTag).getCountry())) {
7896 return localeTag;
7897 }
7898 }
7899 return inputLocale.toLanguageTag();
7900 }
7901
Narayan Kamath1c496c22015-04-16 14:40:19 +01007902 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007903 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007904 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007905 }
7906
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007907 /**
7908 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7909 */
7910 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007911 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007912 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007913 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007914
Gary Jian3aa9a762022-01-24 16:41:19 +08007915 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7916 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007917
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007918 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007919 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7920 * representing the state of the modem.
7921 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007922 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7923 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007924 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007925 */
7926 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007927 public void requestModemActivityInfo(ResultReceiver result) {
7928 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007929 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007930
7931 final long identity = Binder.clearCallingIdentity();
7932 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007933 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007934 } finally {
7935 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007936 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007937 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007938
Siddharth Rayb8114062018-06-17 15:02:38 -07007939 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7940 // less than total activity duration.
7941 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7942 if (info == null) {
7943 return false;
7944 }
7945 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007946 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7947 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7948
Siddharth Rayb8114062018-06-17 15:02:38 -07007949 return (info.isValid()
7950 && (info.getSleepTimeMillis() <= activityDurationMs)
7951 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007952 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007953 && (totalTxTimeMs <= activityDurationMs));
7954 }
7955
Gary Jian3aa9a762022-01-24 16:41:19 +08007956 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7957 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7958 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7959 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7960
7961 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7962 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7963 }
7964
7965 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7966 mLastModemActivityInfo.setReceiveTimeMillis(
7967 rat,
7968 freq,
7969 info.getReceiveTimeMillis(rat, freq)
7970 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7971 }
7972
7973 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7974 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7975 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7976 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7977
7978 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7979 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7980 }
7981 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7982 mLastModemActivityInfo.setReceiveTimeMillis(
7983 rat,
7984 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7985 }
7986
7987 /**
7988 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7989 * @param info recent ModemActivityInfo
7990 */
7991 private void mergeModemActivityInfo(ModemActivityInfo info) {
7992 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08007993 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08007994 boolean matched;
7995 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7996 matched = false;
7997 int rat = info.getSpecificInfoRat(i);
7998 int freq = info.getSpecificInfoFrequencyRange(i);
7999 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8000 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8001 //if it already exists
8002 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8003 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8004 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8005 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8006 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8007 updateLastModemActivityInfo(info, rat, freq);
8008 matched = true;
8009 }
8010 } else {
8011 updateLastModemActivityInfo(info, rat);
8012 matched = true;
8013 }
8014 }
8015 }
8016
8017 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008018 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008019 new ActivityStatsTechSpecificInfo(
8020 rat,
8021 freq,
8022 info.getTransmitTimeMillis(rat, freq),
8023 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008024 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008025 }
8026 }
8027 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8028 mLastModemActivitySpecificInfo =
8029 new ActivityStatsTechSpecificInfo[merged.size()];
8030 merged.toArray(mLastModemActivitySpecificInfo);
8031
8032 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8033 mLastModemActivityInfo.setSleepTimeMillis(
8034 info.getSleepTimeMillis()
8035 + mLastModemActivityInfo.getSleepTimeMillis());
8036 mLastModemActivityInfo.setIdleTimeMillis(
8037 info.getIdleTimeMillis()
8038 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008039
8040 mLastModemActivityInfo =
8041 new ModemActivityInfo(
8042 mLastModemActivityInfo.getTimestampMillis(),
8043 mLastModemActivityInfo.getSleepTimeMillis(),
8044 mLastModemActivityInfo.getIdleTimeMillis(),
8045 mLastModemActivitySpecificInfo);
8046 }
8047
8048 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8049 ActivityStatsTechSpecificInfo[] info) {
8050 int infoSize = info.length;
8051 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8052 for (int i = 0; i < infoSize; i++) {
8053 ret[i] = new ActivityStatsTechSpecificInfo(
8054 info[i].getRat(), info[i].getFrequencyRange(),
8055 info[i].getTransmitTimeMillis(),
8056 (int) info[i].getReceiveTimeMillis());
8057 }
8058 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008059 }
8060
Jack Yu85bd38a2015-11-09 11:34:32 -08008061 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008062 * Returns the service state information on specified subscription.
8063 */
8064 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008065 public ServiceState getServiceStateForSubscriber(int subId,
8066 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8067 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008068 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008069 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008070 return null;
8071 }
8072
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008073 boolean hasFinePermission = false;
8074 boolean hasCoarsePermission = false;
8075 if (!renounceFineLocationAccess) {
8076 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8077 LocationAccessPolicy.checkLocationPermission(mApp,
8078 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8079 .setCallingPackage(callingPackage)
8080 .setCallingFeatureId(callingFeatureId)
8081 .setCallingPid(Binder.getCallingPid())
8082 .setCallingUid(Binder.getCallingUid())
8083 .setMethod("getServiceStateForSubscriber")
8084 .setLogAsInfo(true)
8085 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8086 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8087 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8088 .build());
8089 hasFinePermission =
8090 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8091 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008092
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008093 if (!renounceCoarseLocationAccess) {
8094 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8095 LocationAccessPolicy.checkLocationPermission(mApp,
8096 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8097 .setCallingPackage(callingPackage)
8098 .setCallingFeatureId(callingFeatureId)
8099 .setCallingPid(Binder.getCallingPid())
8100 .setCallingUid(Binder.getCallingUid())
8101 .setMethod("getServiceStateForSubscriber")
8102 .setLogAsInfo(true)
8103 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8104 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8105 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8106 .build());
8107 hasCoarsePermission =
8108 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8109 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008110
Jack Yu479f40e2020-10-27 21:29:25 -07008111 final Phone phone = getPhone(subId);
8112 if (phone == null) {
8113 return null;
8114 }
8115
Jordan Liu0f2bc442020-11-18 16:47:37 -08008116 final long identity = Binder.clearCallingIdentity();
8117
Jack Yu479f40e2020-10-27 21:29:25 -07008118 boolean isCallingPackageDataService = phone.getDataServicePackages()
8119 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008120 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008121 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
8122 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
8123 Rlog.d(LOG_TAG,
8124 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
8125 return null;
8126 }
8127
Hall Liuf19c44f2018-11-27 14:38:17 -08008128 ServiceState ss = phone.getServiceState();
8129
8130 // Scrub out the location info in ServiceState depending on what level of access
8131 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008132 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008133 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8134 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008135 } finally {
8136 Binder.restoreCallingIdentity(identity);
8137 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008138 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008139
8140 /**
8141 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8142 *
8143 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8144 * voicemail ringtone.
8145 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8146 * PhoneAccount.
8147 */
8148 @Override
8149 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008150 final long identity = Binder.clearCallingIdentity();
8151 try {
8152 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8153 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008154 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008155 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008156
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008157 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8158 } finally {
8159 Binder.restoreCallingIdentity(identity);
8160 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008161 }
8162
8163 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008164 * Sets the per-account voicemail ringtone.
8165 *
8166 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8167 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8168 *
8169 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8170 * voicemail ringtone.
8171 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8172 * PhoneAccount.
8173 */
8174 @Override
8175 public void setVoicemailRingtoneUri(String callingPackage,
8176 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008177 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008178 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008179 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8180 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008181 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8182 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8183 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008184 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008185
8186 final long identity = Binder.clearCallingIdentity();
8187 try {
8188 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8189 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008190 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008191 }
8192 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8193 } finally {
8194 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008195 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008196 }
8197
8198 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008199 * Returns whether vibration is set for voicemail notification in Phone settings.
8200 *
8201 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8202 * voicemail vibration setting.
8203 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8204 */
8205 @Override
8206 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008207 final long identity = Binder.clearCallingIdentity();
8208 try {
8209 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8210 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008211 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008212 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008214 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8215 } finally {
8216 Binder.restoreCallingIdentity(identity);
8217 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008218 }
8219
Youhan Wange64578a2016-05-02 15:32:42 -07008220 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008221 * Sets the per-account voicemail vibration.
8222 *
8223 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8224 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8225 *
8226 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8227 * voicemail vibration setting.
8228 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8229 * specific PhoneAccount.
8230 */
8231 @Override
8232 public void setVoicemailVibrationEnabled(String callingPackage,
8233 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008234 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008235 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008236 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8237 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008238 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8239 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8240 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008241 }
8242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008243 final long identity = Binder.clearCallingIdentity();
8244 try {
8245 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8246 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008247 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008248 }
8249 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8250 } finally {
8251 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008252 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008253 }
8254
8255 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008256 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8257 *
8258 * @throws SecurityException if the caller does not have the required permission
8259 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008260 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008261 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008262 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008263 }
8264
8265 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008266 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8267 * permission.
8268 *
8269 * @throws SecurityException if the caller does not have the required permission
8270 */
8271 private void enforceSendSmsPermission() {
8272 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8273 }
8274
8275 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008276 * Make sure either called from same process as self (phone) or IPC caller has interact across
8277 * users permission.
8278 *
8279 * @throws SecurityException if the caller does not have the required permission
8280 */
8281 private void enforceInteractAcrossUsersPermission(String message) {
8282 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8283 }
8284
8285 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008286 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008287 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008288 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008289 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008290 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008291 final long identity = Binder.clearCallingIdentity();
8292 try {
8293 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008294 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008295 if (componentName == null) {
8296 throw new SecurityException(
8297 "Caller not current active visual voicemail package[null]");
8298 }
8299 String vvmPackage = componentName.getPackageName();
8300 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008301 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008302 }
8303 } finally {
8304 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008305 }
8306 }
8307
8308 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008309 * Return the application ID for the app type.
8310 *
8311 * @param subId the subscription ID that this request applies to.
8312 * @param appType the uicc app type.
8313 * @return Application ID for specificied app type, or null if no uicc.
8314 */
8315 @Override
8316 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008317 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008318 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008319
8320 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008321 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008322 if (phone == null) {
8323 return null;
8324 }
8325 String aid = null;
8326 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008327 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008328 .getApplicationByType(appType).getAid();
8329 } catch (Exception e) {
8330 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8331 }
8332 return aid;
8333 } finally {
8334 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008335 }
Youhan Wange64578a2016-05-02 15:32:42 -07008336 }
8337
Youhan Wang4001d252016-05-11 10:29:41 -07008338 /**
8339 * Return the Electronic Serial Number.
8340 *
8341 * @param subId the subscription ID that this request applies to.
8342 * @return ESN or null if error.
8343 */
8344 @Override
8345 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008346 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008347 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008348
8349 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008350 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008351 if (phone == null) {
8352 return null;
8353 }
8354 String esn = null;
8355 try {
8356 esn = phone.getEsn();
8357 } catch (Exception e) {
8358 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8359 }
8360 return esn;
8361 } finally {
8362 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008363 }
Youhan Wang4001d252016-05-11 10:29:41 -07008364 }
8365
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008366 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008367 * Return the Preferred Roaming List Version.
8368 *
8369 * @param subId the subscription ID that this request applies to.
8370 * @return PRLVersion or null if error.
8371 */
8372 @Override
8373 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008374 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008375 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008376
8377 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008378 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008379 if (phone == null) {
8380 return null;
8381 }
8382 String cdmaPrlVersion = null;
8383 try {
8384 cdmaPrlVersion = phone.getCdmaPrlVersion();
8385 } catch (Exception e) {
8386 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8387 }
8388 return cdmaPrlVersion;
8389 } finally {
8390 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008391 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008392 }
8393
8394 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008395 * Get snapshot of Telephony histograms
8396 * @return List of Telephony histograms
8397 * @hide
8398 */
8399 @Override
8400 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008401 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8402 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008403
8404 final long identity = Binder.clearCallingIdentity();
8405 try {
8406 return RIL.getTelephonyRILTimingHistograms();
8407 } finally {
8408 Binder.restoreCallingIdentity(identity);
8409 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008410 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008411
8412 /**
8413 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008414 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8415 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008416 * Require system privileges. In the future we may add this to carrier APIs.
8417 *
Michele Berionne482f8202018-11-27 18:57:59 -08008418 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008419 */
8420 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008421 @TelephonyManager.SetCarrierRestrictionResult
8422 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008423 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008424 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008425
Michele Berionne482f8202018-11-27 18:57:59 -08008426 if (carrierRestrictionRules == null) {
8427 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008428 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008429
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008430 final long identity = Binder.clearCallingIdentity();
8431 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008432 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008433 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008434 } finally {
8435 Binder.restoreCallingIdentity(identity);
8436 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008437 }
8438
8439 /**
8440 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008441 * Get the allowed carrier list and the excluded carrier list, including the priority between
8442 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008443 * Require system privileges. In the future we may add this to carrier APIs.
8444 *
Michele Berionne482f8202018-11-27 18:57:59 -08008445 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008446 */
8447 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008448 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008449 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008450 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008451
8452 final long identity = Binder.clearCallingIdentity();
8453 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008454 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8455 if (response instanceof CarrierRestrictionRules) {
8456 return (CarrierRestrictionRules) response;
8457 }
8458 // Response is an Exception of some kind,
8459 // which is signalled to the user as a NULL retval
8460 return null;
8461 } catch (Exception e) {
8462 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8463 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008464 } finally {
8465 Binder.restoreCallingIdentity(identity);
8466 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008467 }
8468
fionaxu59545b42016-05-25 15:53:37 -07008469 /**
fionaxu59545b42016-05-25 15:53:37 -07008470 * Action set from carrier signalling broadcast receivers to enable/disable radio
8471 * @param subId the subscription ID that this action applies to.
8472 * @param enabled control enable or disable radio.
8473 * {@hide}
8474 */
8475 @Override
8476 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8477 enforceModifyPermission();
8478 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008479
8480 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008481 if (phone == null) {
8482 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8483 return;
8484 }
8485 try {
8486 phone.carrierActionSetRadioEnabled(enabled);
8487 } catch (Exception e) {
8488 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008489 } finally {
8490 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008491 }
8492 }
8493
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008494 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008495 * Enable or disable Voice over NR (VoNR)
8496 * @param subId the subscription ID that this action applies to.
8497 * @param enabled enable or disable VoNR.
8498 * @return operation result.
8499 */
8500 @Override
8501 public int setVoNrEnabled(int subId, boolean enabled) {
8502 enforceModifyPermission();
8503 final Phone phone = getPhone(subId);
8504
8505 final long identity = Binder.clearCallingIdentity();
8506 if (phone == null) {
8507 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8508 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8509 }
8510
8511 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8512 try {
8513 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8514 workSource);
8515 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008516
8517 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8518 if (DBG) {
8519 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8520 }
8521 SubscriptionManager.setSubscriptionProperty(
8522 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8523 (enabled ? "1" : "0"));
8524 }
8525
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008526 return result;
8527 } finally {
8528 Binder.restoreCallingIdentity(identity);
8529 }
8530 }
8531
8532 /**
8533 * Is voice over NR enabled
8534 * @return true if VoNR is enabled else false
8535 */
8536 @Override
8537 public boolean isVoNrEnabled(int subId) {
8538 enforceReadPrivilegedPermission("isVoNrEnabled");
8539 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8540 final long identity = Binder.clearCallingIdentity();
8541 try {
8542 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8543 null, subId, workSource);
8544 if (DBG) log("isVoNrEnabled: " + isEnabled);
8545 return isEnabled;
8546 } finally {
8547 Binder.restoreCallingIdentity(identity);
8548 }
8549 }
8550
8551 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008552 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8553 * network status based on which carrier apps could apply actions accordingly,
8554 * enable/disable default url handler for example.
8555 *
8556 * @param subId the subscription ID that this action applies to.
8557 * @param report control start/stop reporting the default network status.
8558 * {@hide}
8559 */
8560 @Override
8561 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8562 enforceModifyPermission();
8563 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008564
8565 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008566 if (phone == null) {
8567 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8568 return;
8569 }
8570 try {
8571 phone.carrierActionReportDefaultNetworkStatus(report);
8572 } catch (Exception e) {
8573 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008574 } finally {
8575 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008576 }
8577 }
8578
8579 /**
fionaxud9622282017-07-17 17:51:30 -07008580 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8581 * @param subId the subscription ID that this action applies to.
8582 * {@hide}
8583 */
8584 @Override
8585 public void carrierActionResetAll(int subId) {
8586 enforceModifyPermission();
8587 final Phone phone = getPhone(subId);
8588 if (phone == null) {
8589 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8590 return;
8591 }
8592 try {
8593 phone.carrierActionResetAll();
8594 } catch (Exception e) {
8595 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8596 }
8597 }
8598
8599 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008600 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8601 * bug report is being generated.
8602 */
8603 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008604 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008605 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8606 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008607 writer.println("Permission Denial: can't dump Phone from pid="
8608 + Binder.getCallingPid()
8609 + ", uid=" + Binder.getCallingUid()
8610 + "without permission "
8611 + android.Manifest.permission.DUMP);
8612 return;
8613 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008614 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008615 }
Jack Yueb89b242016-06-22 13:27:47 -07008616
Brad Ebingerdac2f002018-04-03 15:17:52 -07008617 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008618 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8619 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8620 @NonNull String[] args) {
8621 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8622 this, in.getFileDescriptor(), out.getFileDescriptor(),
8623 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008624 }
8625
Jack Yueb89b242016-06-22 13:27:47 -07008626 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008627 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008628 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008629 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008630 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008631 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008632 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008633 */
8634 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008635 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008636 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008637 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8638 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8639 try {
8640 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008641 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008642 } catch (SecurityException se) {
8643 enforceModifyPermission();
8644 }
8645 } else {
8646 enforceModifyPermission();
8647 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008648
8649 final long identity = Binder.clearCallingIdentity();
8650 try {
8651 Phone phone = getPhone(subId);
8652 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008653 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8654 phone.carrierActionSetMeteredApnsEnabled(enabled);
8655 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008656 phone.getDataSettingsManager().setDataEnabled(
8657 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008658 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008659 }
8660 } finally {
8661 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008662 }
8663 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008664
8665 /**
8666 * Get Client request stats
8667 * @return List of Client Request Stats
8668 * @hide
8669 */
8670 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008671 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8672 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008673 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008674 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008675 return null;
8676 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008677 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008678
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008679 final long identity = Binder.clearCallingIdentity();
8680 try {
8681 if (phone != null) {
8682 return phone.getClientRequestStats();
8683 }
8684
8685 return null;
8686 } finally {
8687 Binder.restoreCallingIdentity(identity);
8688 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008689 }
8690
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008691 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008692 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008693 if (uid == Process.ROOT_UID && packageName == null) {
8694 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8695 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8696 // exception. ROOT_UID seems not to have a valid package name returned by
8697 // PackageManager, so just fake it here to avoid issues when running telephony shell
8698 // commands that plumb through the RIL as root, like so:
8699 // $ adb root
8700 // $ adb shell cmd phone ...
8701 packageName = "root";
8702 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008703 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008704 }
Jack Yueb4124c2017-02-16 15:32:43 -08008705
8706 /**
Grace Chen70990072017-03-24 17:21:30 -07008707 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008708 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008709 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008710 * @param state State of SIM (power down, power up, pass through)
8711 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8712 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8713 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008714 *
8715 **/
8716 @Override
Grace Chen70990072017-03-24 17:21:30 -07008717 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008718 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008719 Phone phone = PhoneFactory.getPhone(slotIndex);
8720
vagdeviaf9a5b92018-08-15 16:01:53 -07008721 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8722
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008723 final long identity = Binder.clearCallingIdentity();
8724 try {
8725 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008726 phone.setSimPowerState(state, null, workSource);
8727 }
8728 } finally {
8729 Binder.restoreCallingIdentity(identity);
8730 }
8731 }
8732
8733 /**
8734 * Set SIM card power state.
8735 *
8736 * @param slotIndex SIM slot id.
8737 * @param state State of SIM (power down, power up, pass through)
8738 * @param callback callback to trigger after success or failure
8739 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8740 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8741 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8742 *
8743 **/
8744 @Override
8745 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8746 IIntegerConsumer callback) {
8747 enforceModifyPermission();
8748 Phone phone = PhoneFactory.getPhone(slotIndex);
8749
8750 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8751
8752 final long identity = Binder.clearCallingIdentity();
8753 try {
8754 if (phone != null) {
8755 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8756 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008757 }
8758 } finally {
8759 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008760 }
8761 }
Shuo Qiandd210312017-04-12 22:11:33 +00008762
Tyler Gunn65d45c22017-06-05 11:22:26 -07008763 private boolean isUssdApiAllowed(int subId) {
8764 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008765 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008766 if (configManager == null) {
8767 return false;
8768 }
8769 PersistableBundle pb = configManager.getConfigForSubId(subId);
8770 if (pb == null) {
8771 return false;
8772 }
8773 return pb.getBoolean(
8774 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8775 }
8776
Shuo Qiandd210312017-04-12 22:11:33 +00008777 /**
8778 * Check if phone is in emergency callback mode
8779 * @return true if phone is in emergency callback mode
8780 * @param subId sub id
8781 */
goneil9c5f4872017-12-05 14:07:56 -08008782 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008783 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008784 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008785 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008786
8787 final long identity = Binder.clearCallingIdentity();
8788 try {
8789 if (phone != null) {
8790 return phone.isInEcm();
8791 } else {
8792 return false;
8793 }
8794 } finally {
8795 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008796 }
8797 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008798
8799 /**
8800 * Get the current signal strength information for the given subscription.
8801 * Because this information is not updated when the device is in a low power state
8802 * it should not be relied-upon to be current.
8803 * @param subId Subscription index
8804 * @return the most recent cached signal strength info from the modem
8805 */
8806 @Override
8807 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008808 final long identity = Binder.clearCallingIdentity();
8809 try {
8810 Phone p = getPhone(subId);
8811 if (p == null) {
8812 return null;
8813 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008814
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008815 return p.getSignalStrength();
8816 } finally {
8817 Binder.restoreCallingIdentity(identity);
8818 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008819 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008820
Pengquan Meng77b7f132018-08-22 14:49:57 -07008821 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008822 * Get the current modem radio state for the given slot.
8823 * @param slotIndex slot index.
8824 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008825 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008826 * @return the current radio power state from the modem
8827 */
8828 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008829 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008830 Phone phone = PhoneFactory.getPhone(slotIndex);
8831 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008832 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8833 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008834 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8835 }
8836
8837 final long identity = Binder.clearCallingIdentity();
8838 try {
8839 return phone.getRadioPowerState();
8840 } finally {
8841 Binder.restoreCallingIdentity(identity);
8842 }
8843 }
8844 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8845 }
8846
8847 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008848 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8849 *
8850 * <p>Requires one of the following permissions:
8851 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008852 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008853 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8854 * privileges.
8855 *
8856 * @param subId subscription id
8857 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8858 * {@code false}.
8859 */
8860 @Override
8861 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008862 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008863 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008864 try {
8865 mApp.enforceCallingOrSelfPermission(
8866 android.Manifest.permission.ACCESS_NETWORK_STATE,
8867 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008868 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008869 mApp.enforceCallingOrSelfPermission(
8870 permission.READ_BASIC_PHONE_STATE, functionName);
8871 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008872 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008873 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008874 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008875 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008876
Pengquan Menga1bb6272018-09-06 09:59:22 -07008877 boolean isEnabled = false;
8878 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008879 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008880 Phone phone = getPhone(subId);
8881 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008882 } finally {
8883 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008884 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008885 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008886 }
8887
8888
8889 /**
8890 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8891 *
8892 * <p> Requires permission:
8893 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8894 * privileges.
8895 *
8896 * @param subId subscription id
8897 * @param isEnabled {@code true} means enable, {@code false} means disable.
8898 */
8899 @Override
8900 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8902 mApp, subId, "setDataRoamingEnabled");
8903
Pengquan Menga1bb6272018-09-06 09:59:22 -07008904 final long identity = Binder.clearCallingIdentity();
8905 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008906 Phone phone = getPhone(subId);
8907 if (phone != null) {
8908 phone.setDataRoamingEnabled(isEnabled);
8909 }
8910 } finally {
8911 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008912 }
8913 }
8914
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008915 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008916 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008917 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008918 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008919 mApp, subId, "isManualNetworkSelectionAllowed");
8920
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008921 boolean isAllowed = true;
8922 final long identity = Binder.clearCallingIdentity();
8923 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008924 Phone phone = getPhone(subId);
8925 if (phone != null) {
8926 isAllowed = phone.isCspPlmnEnabled();
8927 }
8928 } finally {
8929 Binder.restoreCallingIdentity(identity);
8930 }
8931 return isAllowed;
8932 }
8933
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008934 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8935 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008936 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008937 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008938 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008939 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8940 if (phone == null) {
8941 return false;
8942 }
8943 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8944 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8945 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008946 }
8947
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008948 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008949 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008950 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008951 mApp.getSystemService(AppOpsManager.class)
8952 .checkPackage(Binder.getCallingUid(), callingPackage);
8953
Jordan Liu1e142fc2019-04-22 15:10:43 -07008954 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008955 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008956 try {
8957 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008958 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008959 } catch (SecurityException e) {
8960 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8961 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008962 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008963 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008964 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008965 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008966 }
sandeepjsb6c87872021-09-27 15:34:44 +00008967 // checking compatibility, if calling app's target SDK is T and beyond.
8968 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8969 Binder.getCallingUid())) {
8970 isIccIdAccessRestricted = true;
8971 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008972 final long identity = Binder.clearCallingIdentity();
8973 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008974 UiccController uiccController = UiccController.getInstance();
8975 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008976 if (hasReadPermission) {
8977 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008978 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008979
8980 // Remove private info if the caller doesn't have access
8981 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8982 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008983 //setting the value after compatibility check
8984 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008985 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8986 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008987 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008988 if (card == null) {
8989 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008990 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008991 continue;
8992 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008993 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8994 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008995 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008996 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008997 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008998 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8999 for (UiccPortInfo portInfo : portInfos) {
9000 UiccPort port = uiccController.getUiccPortForSlot(
9001 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9002 if (port == null) {
9003 // assume no access if port is null
9004 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9005 continue;
9006 }
9007 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9008 uiccPortInfos.add(portInfo);
9009 } else {
9010 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9011 }
9012 }
9013 filteredInfos.add(new UiccCardInfo(
9014 cardInfo.isEuicc(),
9015 cardInfo.getCardId(),
9016 null,
9017 cardInfo.getPhysicalSlotIndex(),
9018 cardInfo.isRemovable(),
9019 cardInfo.isMultipleEnabledProfilesSupported(),
9020 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009021 }
9022 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009023 } finally {
9024 Binder.restoreCallingIdentity(identity);
9025 }
9026 }
9027
sandeepjsb6c87872021-09-27 15:34:44 +00009028 /**
9029 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9030 * generally private and require carrier privileges to view.
9031 *
9032 * @hide
9033 */
9034 @NonNull
9035 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9036 List<UiccPortInfo> portinfo = new ArrayList<>();
9037 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9038 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9039 }
9040 return new UiccCardInfo(
9041 cardInfo.isEuicc(),
9042 cardInfo.getCardId(),
9043 null,
9044 cardInfo.getPhysicalSlotIndex(),
9045 cardInfo.isRemovable(),
9046 cardInfo.isMultipleEnabledProfilesSupported(),
9047 portinfo
9048 );
9049 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009050
sandeepjsb6c87872021-09-27 15:34:44 +00009051 /**
9052 * @hide
9053 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9054 * These values are generally private and require carrier privileges to view.
9055 */
9056 @NonNull
9057 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9058 return new UiccPortInfo(
9059 UiccPortInfo.ICCID_REDACTED,
9060 portInfo.getPortIndex(),
9061 portInfo.getLogicalSlotIndex(),
9062 portInfo.isActive()
9063 );
9064 }
9065 @Override
9066 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009067 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009068 mApp.getSystemService(AppOpsManager.class)
9069 .checkPackage(Binder.getCallingUid(), callingPackage);
9070
sandeepjsb6c87872021-09-27 15:34:44 +00009071 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009072
Aman Guptaf3c90b32022-03-17 04:54:16 +00009073 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9074 // we are reading iccId which is PII data.
9075 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009076
9077 // checking compatibility, if calling app's target SDK is T and beyond.
9078 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9079 Binder.getCallingUid())) {
9080 isLogicalSlotAccessRestricted = true;
9081 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009082 final long identity = Binder.clearCallingIdentity();
9083 try {
9084 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009085 if (slots == null || slots.length == 0) {
9086 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009087 return null;
9088 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009089 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9090 for (int i = 0; i < slots.length; i++) {
9091 UiccSlot slot = slots[i];
9092 if (slot == null) {
9093 continue;
9094 }
9095
Jordan Liu7be7e652019-05-06 18:55:02 +00009096 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009097 UiccCard card = slot.getUiccCard();
9098 if (card != null) {
9099 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009100 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009101 cardId = slot.getEid();
9102 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009103 // If cardId is null, use iccId of default port as cardId.
9104 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009105 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009106 }
9107
Jordan Liu857451f2019-05-09 16:35:35 -07009108 if (cardId != null) {
9109 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9110 // if cardId is an EID, it's all digits so this is fine
9111 cardId = IccUtils.stripTrailingFs(cardId);
9112 }
9113
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009114 int cardState = 0;
9115 switch (slot.getCardState()) {
9116 case CARDSTATE_ABSENT:
9117 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9118 break;
9119 case CARDSTATE_PRESENT:
9120 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9121 break;
9122 case CARDSTATE_ERROR:
9123 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9124 break;
9125 case CARDSTATE_RESTRICTED:
9126 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9127 break;
9128 default:
9129 break;
9130
9131 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009132 List<UiccPortInfo> portInfos = new ArrayList<>();
9133 int[] portIndexes = slot.getPortList();
9134 for (int portIdx : portIndexes) {
9135 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009136 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009137 portInfos.add(new UiccPortInfo(iccId, portIdx,
9138 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009139 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009140 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009141 slot.isEuicc(),
9142 cardId,
9143 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009144 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009145 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009146 //setting the value after compatibility check
9147 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009148 }
9149 return infos;
9150 } finally {
9151 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009152 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009153 }
9154
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009155 /* Returns null if doesn't have read permission or carrier privilege access. */
9156 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9157 boolean hasReadPermission) {
9158 String iccId = slot.getIccId(portIndex);
9159 if (hasReadPermission) { // if has read permission
9160 return iccId;
9161 } else {
9162 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9163 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9164 // if no read permission, checking carrier privilege access
9165 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9166 return iccId;
9167 }
9168 }
9169 }
9170 // No read permission or carrier privilege access.
9171 return UiccPortInfo.ICCID_REDACTED;
9172 }
9173
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009174 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009175 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009176 public boolean switchSlots(int[] physicalSlots) {
9177 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009178
9179 final long identity = Binder.clearCallingIdentity();
9180 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009181 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9182 for (int i = 0; i < physicalSlots.length; i++) {
9183 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9184 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9185 physicalSlots[i], i));
9186 }
9187 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009188 } finally {
9189 Binder.restoreCallingIdentity(identity);
9190 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009191 }
Jack Yu4c988042018-02-27 15:30:01 -08009192
9193 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009194 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9195 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9196 enforceModifyPermission();
9197
9198 final long identity = Binder.clearCallingIdentity();
9199 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009200 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009201 } finally {
9202 Binder.restoreCallingIdentity(identity);
9203 }
9204 }
9205
9206 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009207 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009208 final long identity = Binder.clearCallingIdentity();
9209 try {
9210 return UiccController.getInstance().getCardIdForDefaultEuicc();
9211 } finally {
9212 Binder.restoreCallingIdentity(identity);
9213 }
9214 }
9215
Pengquan Meng85728fb2018-03-12 16:31:21 -07009216 /**
goneil47ffb6e2018-04-06 15:40:58 -07009217 * A test API to reload the UICC profile.
9218 *
9219 * <p>Requires that the calling app has permission
9220 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9221 * @hide
9222 */
9223 @Override
9224 public void refreshUiccProfile(int subId) {
9225 enforceModifyPermission();
9226
9227 final long identity = Binder.clearCallingIdentity();
9228 try {
9229 Phone phone = getPhone(subId);
9230 if (phone == null) {
9231 return;
9232 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009233 UiccPort uiccPort = phone.getUiccPort();
9234 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009235 return;
9236 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009237 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009238 if (uiccProfile == null) {
9239 return;
9240 }
9241 uiccProfile.refresh();
9242 } finally {
9243 Binder.restoreCallingIdentity(identity);
9244 }
9245 }
9246
9247 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009248 * Returns false if the mobile data is disabled by default, otherwise return true.
9249 */
9250 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009251 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009252 }
9253
9254 /**
9255 * Returns true if the data roaming is enabled by default, i.e the system property
9256 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9257 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9258 */
9259 private boolean getDefaultDataRoamingEnabled(int subId) {
9260 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009261 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009262 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009263 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9264 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9265 return isDataRoamingEnabled;
9266 }
9267
9268 /**
9269 * Returns the default network type for the given {@code subId}, if the default network type is
9270 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9271 */
9272 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009273 List<Integer> list = TelephonyProperties.default_network();
9274 int phoneId = mSubscriptionController.getPhoneId(subId);
9275 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9276 return list.get(phoneId);
9277 }
9278 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009279 }
fionaxua13278b2018-03-21 00:08:13 -07009280
9281 @Override
9282 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009283 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009284 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009285
9286 final long identity = Binder.clearCallingIdentity();
9287 try {
9288 final Phone phone = getPhone(subId);
9289 if (phone == null) {
9290 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9291 return;
9292 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009293 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9294 if (cpt != null) {
9295 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9296 }
9297 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009298 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9299 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009300 if (carrierPrivilegeRules == null) {
9301 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9302 } else {
9303 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009305 } finally {
9306 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009307 }
fionaxua13278b2018-03-21 00:08:13 -07009308 }
9309
9310 @Override
9311 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009312 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009313
9314 final long identity = Binder.clearCallingIdentity();
9315 try {
9316 final Phone phone = getPhone(subId);
9317 if (phone == null) {
9318 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9319 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9320 }
9321 return phone.getCarrierIdListVersion();
9322 } finally {
9323 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009324 }
fionaxua13278b2018-03-21 00:08:13 -07009325 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009326
9327 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009328 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9329 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009330 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009331 mApp, subId, callingPackage, callingFeatureId,
9332 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009333 return -1;
9334 }
9335
9336 final long identity = Binder.clearCallingIdentity();
9337 try {
9338 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9339 } finally {
9340 Binder.restoreCallingIdentity(identity);
9341 }
9342 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009343
9344 @Override
9345 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009346 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009347 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009348 mApp, subId, "getCdmaRoamingMode");
9349
9350 final long identity = Binder.clearCallingIdentity();
9351 try {
9352 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9353 } finally {
9354 Binder.restoreCallingIdentity(identity);
9355 }
9356 }
9357
9358 @Override
9359 public boolean setCdmaRoamingMode(int subId, int mode) {
9360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9361 mApp, subId, "setCdmaRoamingMode");
9362
9363 final long identity = Binder.clearCallingIdentity();
9364 try {
9365 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9366 } finally {
9367 Binder.restoreCallingIdentity(identity);
9368 }
9369 }
9370
9371 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009372 public int getCdmaSubscriptionMode(int subId) {
9373 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009374 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009375 mApp, subId, "getCdmaSubscriptionMode");
9376
9377 final long identity = Binder.clearCallingIdentity();
9378 try {
9379 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9380 } finally {
9381 Binder.restoreCallingIdentity(identity);
9382 }
9383 }
9384
9385 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009386 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9387 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9388 mApp, subId, "setCdmaSubscriptionMode");
9389
9390 final long identity = Binder.clearCallingIdentity();
9391 try {
9392 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9393 } finally {
9394 Binder.restoreCallingIdentity(identity);
9395 }
9396 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009397
sqianc5eccab2018-10-19 18:46:41 -07009398 @Override
sqian8c685422019-02-22 15:55:18 -08009399 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009400 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009401 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009402 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9403 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009404 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9405 }
9406 final long identity = Binder.clearCallingIdentity();
9407 try {
sqian854d44b2018-12-12 16:48:18 -08009408 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9409 for (Phone phone: PhoneFactory.getPhones()) {
9410 if (phone.getEmergencyNumberTracker() != null
9411 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9412 emergencyNumberListInternal.put(
9413 phone.getSubId(),
9414 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9415 }
sqian11b7a0e2018-12-05 18:48:28 -08009416 }
sqian854d44b2018-12-12 16:48:18 -08009417 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009418 } finally {
9419 Binder.restoreCallingIdentity(identity);
9420 }
sqianc5eccab2018-10-19 18:46:41 -07009421 }
9422
9423 @Override
sqian8c685422019-02-22 15:55:18 -08009424 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009425 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009426 if (!exactMatch) {
9427 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009428 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009429 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009430 }
9431 final long identity = Binder.clearCallingIdentity();
9432 try {
sqian854d44b2018-12-12 16:48:18 -08009433 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009434 //Note: we ignore passed in param exactMatch. We can remove it once
9435 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009436 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009437 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009438 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009439 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009440 }
sqian11b7a0e2018-12-05 18:48:28 -08009441 }
9442 return false;
9443 } finally {
9444 Binder.restoreCallingIdentity(identity);
9445 }
9446 }
9447
sqianf4ca7ed2019-01-15 18:32:07 -08009448 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009449 * Start emergency callback mode for GsmCdmaPhone for testing.
9450 */
9451 @Override
9452 public void startEmergencyCallbackMode() {
9453 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9454 "startEmergencyCallbackMode");
9455 enforceModifyPermission();
9456 final long identity = Binder.clearCallingIdentity();
9457 try {
9458 for (Phone phone : PhoneFactory.getPhones()) {
9459 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9460 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9461 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9462 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9463 gsmCdmaPhone.obtainMessage(
9464 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9465 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9466 }
9467 }
9468 } finally {
9469 Binder.restoreCallingIdentity(identity);
9470 }
9471 }
9472
9473 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009474 * Update emergency number list for test mode.
9475 */
9476 @Override
9477 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9478 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9479 "updateEmergencyNumberListTestMode");
9480
9481 final long identity = Binder.clearCallingIdentity();
9482 try {
9483 for (Phone phone: PhoneFactory.getPhones()) {
9484 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9485 if (tracker != null) {
9486 tracker.executeEmergencyNumberTestModeCommand(action, num);
9487 }
9488 }
9489 } finally {
9490 Binder.restoreCallingIdentity(identity);
9491 }
9492 }
9493
9494 /**
9495 * Get the full emergency number list for test mode.
9496 */
9497 @Override
9498 public List<String> getEmergencyNumberListTestMode() {
9499 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9500 "getEmergencyNumberListTestMode");
9501
9502 final long identity = Binder.clearCallingIdentity();
9503 try {
9504 Set<String> emergencyNumbers = new HashSet<>();
9505 for (Phone phone: PhoneFactory.getPhones()) {
9506 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9507 if (tracker != null) {
9508 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9509 emergencyNumbers.add(num.getNumber());
9510 }
9511 }
9512 }
9513 return new ArrayList<>(emergencyNumbers);
9514 } finally {
9515 Binder.restoreCallingIdentity(identity);
9516 }
9517 }
9518
chen xud6b45bd2018-10-30 22:27:10 -07009519 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009520 public int getEmergencyNumberDbVersion(int subId) {
9521 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9522
9523 final long identity = Binder.clearCallingIdentity();
9524 try {
9525 final Phone phone = getPhone(subId);
9526 if (phone == null) {
9527 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9528 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9529 }
9530 return phone.getEmergencyNumberDbVersion();
9531 } finally {
9532 Binder.restoreCallingIdentity(identity);
9533 }
9534 }
9535
9536 @Override
9537 public void notifyOtaEmergencyNumberDbInstalled() {
9538 enforceModifyPermission();
9539
9540 final long identity = Binder.clearCallingIdentity();
9541 try {
9542 for (Phone phone: PhoneFactory.getPhones()) {
9543 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9544 if (tracker != null) {
9545 tracker.updateOtaEmergencyNumberDatabase();
9546 }
9547 }
9548 } finally {
9549 Binder.restoreCallingIdentity(identity);
9550 }
9551 }
9552
9553 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009554 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009555 enforceActiveEmergencySessionPermission();
9556
9557 final long identity = Binder.clearCallingIdentity();
9558 try {
9559 for (Phone phone: PhoneFactory.getPhones()) {
9560 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9561 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009562 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9563 }
9564 }
9565 } finally {
9566 Binder.restoreCallingIdentity(identity);
9567 }
9568 }
9569
9570 @Override
9571 public void resetOtaEmergencyNumberDbFilePath() {
9572 enforceActiveEmergencySessionPermission();
9573
9574 final long identity = Binder.clearCallingIdentity();
9575 try {
9576 for (Phone phone: PhoneFactory.getPhones()) {
9577 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9578 if (tracker != null) {
9579 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009580 }
9581 }
9582 } finally {
9583 Binder.restoreCallingIdentity(identity);
9584 }
9585 }
9586
9587 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009588 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9589 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9590 Phone phone = getPhone(subId);
9591 if (phone == null) {
9592 return null;
9593 }
9594 final long identity = Binder.clearCallingIdentity();
9595 try {
9596 UiccProfile profile = UiccController.getInstance()
9597 .getUiccProfileForPhone(phone.getPhoneId());
9598 if (profile != null) {
9599 return profile.getCertsFromCarrierPrivilegeAccessRules();
9600 }
9601 } finally {
9602 Binder.restoreCallingIdentity(identity);
9603 }
9604 return null;
9605 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009606
9607 /**
9608 * Enable or disable a modem stack.
9609 */
9610 @Override
9611 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9612 enforceModifyPermission();
9613
9614 final long identity = Binder.clearCallingIdentity();
9615 try {
9616 Phone phone = PhoneFactory.getPhone(slotIndex);
9617 if (phone == null) {
9618 return false;
9619 } else {
9620 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9621 }
9622 } finally {
9623 Binder.restoreCallingIdentity(identity);
9624 }
9625 }
Michelecea4cf22018-12-21 15:00:11 -08009626
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009627 /**
9628 * Whether a modem stack is enabled or not.
9629 */
9630 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009631 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9632 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009633 Phone phone = PhoneFactory.getPhone(slotIndex);
9634 if (phone == null) return false;
9635
9636 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009637 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9638 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009639 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9640 }
9641
9642 final long identity = Binder.clearCallingIdentity();
9643 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009644 try {
9645 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9646 } catch (NoSuchElementException ex) {
9647 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9648 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009649 } finally {
9650 Binder.restoreCallingIdentity(identity);
9651 }
9652 }
9653
Michelecea4cf22018-12-21 15:00:11 -08009654 @Override
Michele0ea7d782019-03-19 14:58:42 -07009655 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009656 enforceModifyPermission();
9657
9658 final long identity = Binder.clearCallingIdentity();
9659 try {
9660 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009661 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009662 .commit();
9663 } finally {
9664 Binder.restoreCallingIdentity(identity);
9665 }
9666 }
9667
9668 @Override
Michele0ea7d782019-03-19 14:58:42 -07009669 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009670 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009671 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009672 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9673 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009674 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009675 }
Michelecea4cf22018-12-21 15:00:11 -08009676
9677 final long identity = Binder.clearCallingIdentity();
9678 try {
Michele0ea7d782019-03-19 14:58:42 -07009679 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009680 } finally {
9681 Binder.restoreCallingIdentity(identity);
9682 }
9683 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009684
Michele0ea7d782019-03-19 14:58:42 -07009685 @TelephonyManager.IsMultiSimSupportedResult
9686 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009687 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9688 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9689 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009690 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9691 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009692 }
9693 // Check if the hardware supports multisim functionality. If usage of multisim is not
9694 // supported by the modem, indicate that it is restricted.
9695 PhoneCapability staticCapability =
9696 mPhoneConfigurationManager.getStaticPhoneCapability();
9697 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009698 loge("isMultiSimSupportedInternal: no static configuration available");
9699 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009700 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009701 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009702 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9703 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009704 }
9705 // Check if support of multiple SIMs is restricted by carrier
9706 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009707 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009708 }
9709
Michele0ea7d782019-03-19 14:58:42 -07009710 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009711 }
9712
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009713 /**
9714 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009715 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9716 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9717 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009718 * @param numOfSims number of active sims we want to switch to
9719 */
9720 @Override
9721 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009722 if (numOfSims == 1) {
9723 enforceModifyPermission();
9724 } else {
9725 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9726 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9727 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009728 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009729
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009730 try {
Michele30b57b22019-03-01 12:01:14 -08009731 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009732 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009733 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9734 return;
9735 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009736 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9737 } finally {
9738 Binder.restoreCallingIdentity(identity);
9739 }
9740 }
9741
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009742 @Override
9743 public boolean isApplicationOnUicc(int subId, int appType) {
9744 enforceReadPrivilegedPermission("isApplicationOnUicc");
9745 Phone phone = getPhone(subId);
9746 if (phone == null) {
9747 return false;
9748 }
9749 final long identity = Binder.clearCallingIdentity();
9750 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009751 UiccPort uiccPort = phone.getUiccPort();
9752 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009753 return false;
9754 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009755 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009756 if (uiccProfile == null) {
9757 return false;
9758 }
9759 if (TelephonyManager.APPTYPE_SIM <= appType
9760 && appType <= TelephonyManager.APPTYPE_ISIM) {
9761 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9762 }
9763 return false;
9764 } finally {
9765 Binder.restoreCallingIdentity(identity);
9766 }
9767 }
9768
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009769 /**
chen xub4baa772019-04-03 10:23:41 -07009770 * Get whether making changes to modem configurations will trigger reboot.
9771 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009772 */
9773 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009774 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9775 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009776 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009777 mApp, subId, callingPackage, callingFeatureId,
9778 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009779 return false;
9780 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009781 final long identity = Binder.clearCallingIdentity();
9782 try {
9783 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9784 } finally {
9785 Binder.restoreCallingIdentity(identity);
9786 }
9787 }
9788
Nathan Harold29f5f052019-02-15 13:41:57 -08009789 private void updateModemStateMetrics() {
9790 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9791 // TODO: check the state for each modem if the api is ready.
9792 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9793 }
9794
Pengquan Meng3889a572019-01-23 11:16:29 -08009795 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009796 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009797 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009798 // Verify that the callingPackage belongs to the calling UID
9799 mApp.getSystemService(AppOpsManager.class)
9800 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009801 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009802 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009803 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009804 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9805 if (slotInfos != null) {
9806 for (int i = 0; i < slotInfos.length; i++) {
9807 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9808 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9809 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9810 portInfo.getLogicalSlotIndex()));
9811 }
9812 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009813 }
9814 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009815 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009816 } finally {
9817 Binder.restoreCallingIdentity(identity);
9818 }
9819 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009820
9821 /**
9822 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +08009823 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -08009824 */
jimsunf9ec1622022-09-13 21:18:43 +08009825 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -08009826 @Override
9827 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +08009828 return getHalVersion(HAL_SERVICE_RADIO);
9829 }
9830
9831 /**
9832 * Get the HAL Version of a specific service
9833 */
9834 @Override
9835 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -08009836 Phone phone = getDefaultPhone();
9837 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +08009838 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -08009839 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9840 return hv.major * 100 + hv.minor;
9841 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009842
9843 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009844 * Get the current calling package name.
9845 * @return the current calling package name
9846 */
9847 @Override
9848 public String getCurrentPackageName() {
9849 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9850 }
9851
9852 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009853 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9854 * corresponding network requests on a subId.
9855 *
9856 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009857 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009858 * 2) APN is un-metered for this subscription, or
9859 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009860 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009861 *
9862 * @return whether data is allowed for a apn type.
9863 *
9864 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009865 */
9866 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009867 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009868 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9869 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009870
9871 // Now that all security checks passes, perform the operation as ourselves.
9872 final long identity = Binder.clearCallingIdentity();
9873 try {
9874 Phone phone = getPhone(subId);
9875 if (phone == null) return false;
9876
Jack Yu27422a52022-03-21 10:38:05 -07009877 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009878 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -07009879 isMetered = phone.getDataNetworkController().getDataConfigManager()
9880 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9881 phone.getServiceState().getDataRoaming());
9882 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009883 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009884 } finally {
9885 Binder.restoreCallingIdentity(identity);
9886 }
9887 }
9888
9889 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009890 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009891 enforceReadPrivilegedPermission("isApnMetered");
9892
9893 // Now that all security checks passes, perform the operation as ourselves.
9894 final long identity = Binder.clearCallingIdentity();
9895 try {
9896 Phone phone = getPhone(subId);
9897 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -07009898 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9899 DataUtils.apnTypeToNetworkCapability(apnType),
9900 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009901 } finally {
9902 Binder.restoreCallingIdentity(identity);
9903 }
9904 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009905
9906 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009907 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9908 int subscriptionId, IBooleanConsumer resultCallback) {
9909 enforceModifyPermission();
9910 long token = Binder.clearCallingIdentity();
9911 try {
9912 Phone phone = getPhone(subscriptionId);
9913 if (phone == null) {
9914 try {
9915 if (resultCallback != null) {
9916 resultCallback.accept(false);
9917 }
9918 } catch (RemoteException e) {
9919 // ignore
9920 }
9921 return;
9922 }
9923 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9924 Pair.create(specifiers, (x) -> {
9925 try {
9926 if (resultCallback != null) {
9927 resultCallback.accept(x);
9928 }
9929 } catch (RemoteException e) {
9930 // ignore
9931 }
9932 });
9933 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9934 } finally {
9935 Binder.restoreCallingIdentity(token);
9936 }
9937 }
9938
9939 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009940 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9941 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009942 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009943 mApp, subId, "getSystemSelectionChannels");
9944 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9945 final long identity = Binder.clearCallingIdentity();
9946 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009947 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9948 if (result instanceof IllegalStateException) {
9949 throw (IllegalStateException) result;
9950 }
9951 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009952 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9953 return specifiers;
9954 } finally {
9955 Binder.restoreCallingIdentity(identity);
9956 }
9957 }
9958
9959 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009960 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009961 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009962 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009963 }
9964
9965 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009966 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9967 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009968 if (callingPackage == null) {
9969 callingPackage = getCurrentPackageName();
9970 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009971 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9972 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009973 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9974 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009975 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9976 }
9977 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9978 Intent intent = new Intent();
9979 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9980 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9981 // Bring up choose default SMS subscription dialog right now
9982 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9983 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9984 mApp.startActivity(intent);
9985 }
chen xud5ca2d52019-05-28 15:20:57 -07009986
9987 @Override
9988 public String getMmsUAProfUrl(int subId) {
9989 //TODO investigate if this API should require proper permission check in R b/133791609
9990 final long identity = Binder.clearCallingIdentity();
9991 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009992 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9993 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9994 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9995 return carrierUAProfUrl;
9996 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009997 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9998 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009999 } finally {
10000 Binder.restoreCallingIdentity(identity);
10001 }
10002 }
10003
10004 @Override
10005 public String getMmsUserAgent(int subId) {
10006 //TODO investigate if this API should require proper permission check in R b/133791609
10007 final long identity = Binder.clearCallingIdentity();
10008 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010009 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10010 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10011 if (!TextUtils.isEmpty(carrierUserAgent)) {
10012 return carrierUserAgent;
10013 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010014 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10015 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010016 } finally {
10017 Binder.restoreCallingIdentity(identity);
10018 }
10019 }
Jack Yub07d4972019-05-28 16:12:25 -070010020
10021 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010022 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10023 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010024
Jack Yub07d4972019-05-28 16:12:25 -070010025 final long identity = Binder.clearCallingIdentity();
10026 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010027 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010028 if (phone == null) return false;
10029
Ling Maf188d502022-09-16 15:22:36 -070010030 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010031 } finally {
10032 Binder.restoreCallingIdentity(identity);
10033 }
10034 }
10035
10036 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010037 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010038 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010039 enforceModifyPermission();
10040
changbettyd5c246e2019-12-24 15:40:37 +080010041 final long identity = Binder.clearCallingIdentity();
10042 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010043 Phone phone = getPhone(subscriptionId);
10044 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010045
Ling Maf188d502022-09-16 15:22:36 -070010046 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010047 } finally {
10048 Binder.restoreCallingIdentity(identity);
10049 }
10050 }
10051
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010052 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010053 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010054 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10055 * otherwise.
10056 */
10057 @Override
10058 public void setCepEnabled(boolean isCepEnabled) {
10059 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10060
10061 final long identity = Binder.clearCallingIdentity();
10062 try {
10063 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10064 for (Phone phone : PhoneFactory.getPhones()) {
10065 Phone defaultPhone = phone.getImsPhone();
10066 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10067 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10068 ImsPhoneCallTracker imsPhoneCallTracker =
10069 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10070 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10071 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10072 + imsPhone.getMsisdn());
10073 }
10074 }
10075 } finally {
10076 Binder.restoreCallingIdentity(identity);
10077 }
10078 }
allenwtsu46dcc572020-01-08 18:24:03 +080010079
10080 /**
10081 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10082 *
10083 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10084 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10085 * before being read.
10086 */
10087 @Override
10088 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10089 isCompressed) {
10090 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10091 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010092 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10093 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10094 }
10095 if (!isImsAvailableOnDevice()) {
10096 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10097 "IMS not available on device.");
10098 }
10099
10100 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010101 try {
Hui Wang761a6682020-10-31 05:12:53 +000010102 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10103 } finally {
10104 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010105 }
10106 }
zoey chene02881a2019-12-30 16:11:23 +080010107
10108 @Override
10109 public boolean isIccLockEnabled(int subId) {
10110 enforceReadPrivilegedPermission("isIccLockEnabled");
10111
10112 // Now that all security checks passes, perform the operation as ourselves.
10113 final long identity = Binder.clearCallingIdentity();
10114 try {
10115 Phone phone = getPhone(subId);
10116 if (phone != null && phone.getIccCard() != null) {
10117 return phone.getIccCard().getIccLockEnabled();
10118 } else {
10119 return false;
10120 }
10121 } finally {
10122 Binder.restoreCallingIdentity(identity);
10123 }
10124 }
10125
10126 /**
10127 * Set the ICC pin lock enabled or disabled.
10128 *
10129 * @return an integer representing the status of IccLock enabled or disabled in the following
10130 * three cases:
10131 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10132 * successfully.
10133 * - Positive number and zero for remaining password attempts.
10134 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10135 *
10136 */
10137 @Override
10138 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10139 enforceModifyPermission();
10140
10141 Phone phone = getPhone(subId);
10142 if (phone == null) {
10143 return 0;
10144 }
10145 // Now that all security checks passes, perform the operation as ourselves.
10146 final long identity = Binder.clearCallingIdentity();
10147 try {
10148 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10149 new Pair<Boolean, String>(enabled, password), phone, null);
10150 return attemptsRemaining;
10151
10152 } catch (Exception e) {
10153 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10154 } finally {
10155 Binder.restoreCallingIdentity(identity);
10156 }
10157 return 0;
10158 }
10159
10160 /**
10161 * Change the ICC password used in ICC pin lock.
10162 *
10163 * @return an integer representing the status of IccLock changed in the following three cases:
10164 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10165 * - Positive number and zero for remaining password attempts.
10166 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10167 *
10168 */
10169 @Override
10170 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10171 enforceModifyPermission();
10172
10173 Phone phone = getPhone(subId);
10174 if (phone == null) {
10175 return 0;
10176 }
10177 // Now that all security checks passes, perform the operation as ourselves.
10178 final long identity = Binder.clearCallingIdentity();
10179 try {
10180 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10181 new Pair<String, String>(oldPassword, newPassword), phone, null);
10182 return attemptsRemaining;
10183
10184 } catch (Exception e) {
10185 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10186 } finally {
10187 Binder.restoreCallingIdentity(identity);
10188 }
10189 return 0;
10190 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010191
10192 /**
10193 * Request for receiving user activity notification
10194 */
10195 @Override
10196 public void requestUserActivityNotification() {
10197 if (!mNotifyUserActivity.get()
10198 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10199 mNotifyUserActivity.set(true);
10200 }
10201 }
10202
10203 /**
10204 * Called when userActivity is signalled in the power manager.
10205 * This is safe to call from any thread, with any window manager locks held or not.
10206 */
10207 @Override
10208 public void userActivity() {
10209 // ***************************************
10210 // * Inherited from PhoneWindowManager *
10211 // ***************************************
10212 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10213 // WITH ITS LOCKS HELD.
10214 //
10215 // This code must be VERY careful about the locks
10216 // it acquires.
10217 // In fact, the current code acquires way too many,
10218 // and probably has lurking deadlocks.
10219
10220 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10221 throw new SecurityException("Only the OS may call notifyUserActivity()");
10222 }
10223
10224 if (mNotifyUserActivity.getAndSet(false)) {
10225 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10226 USER_ACTIVITY_NOTIFICATION_DELAY);
10227 }
10228 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010229
10230 @Override
10231 public boolean canConnectTo5GInDsdsMode() {
10232 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10233 }
Jack Yud10cdd42020-09-28 20:28:01 -070010234
10235 @Override
10236 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10237 String callingFeatureId) {
10238 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10239 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10240 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10241 }
10242
10243 Phone phone = getPhone(subId);
10244 if (phone == null) {
10245 throw new RuntimeException("phone is not available");
10246 }
10247 // Now that all security checks passes, perform the operation as ourselves.
10248 final long identity = Binder.clearCallingIdentity();
10249 try {
10250 return phone.getEquivalentHomePlmns();
10251 } finally {
10252 Binder.restoreCallingIdentity(identity);
10253 }
10254 }
Daniel Bright59e67312020-11-13 11:49:37 -080010255
10256 @Override
10257 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010258 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10259 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010260 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010261 if (radioInterfaceCapabilities == null) {
10262 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010263 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010264 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010265 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010266
Hui Wang641e81c2020-10-12 12:14:23 -070010267 @Override
10268 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10269 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010270 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10271 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10272 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10273 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10274 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010275 if (DBG) {
10276 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10277 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10278 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10279 }
10280
10281 if (!SubscriptionManager.isValidSubscriptionId(subId)
10282 || appType < TelephonyManager.APPTYPE_UNKNOWN
10283 || appType > TelephonyManager.APPTYPE_ISIM
10284 || nafUrl == null || securityProtocol == null || callback == null) {
10285 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10286 if (callback != null) {
10287 try {
10288 callback.onAuthenticationFailure(
10289 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10290 } catch (RemoteException exception) {
10291 log("Fail to notify onAuthenticationFailure due to " + exception);
10292 }
10293 return;
10294 }
10295 }
10296
10297 final long token = Binder.clearCallingIdentity();
10298 try {
10299 getGbaManager(subId).bootstrapAuthenticationRequest(
10300 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10301 forceBootStrapping, callback));
10302 } finally {
10303 Binder.restoreCallingIdentity(token);
10304 }
10305 }
10306
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010307 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010308 * Attempts to set the radio power state for all phones for thermal reason.
10309 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010310 * requested radio power state will actually be set. See {@link
10311 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10312 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010313 * @param enable {@code true} if trying to turn radio on.
10314 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10315 * false}.
10316 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010317 private boolean setRadioPowerForThermal(boolean enable) {
10318 boolean isPhoneAvailable = false;
10319 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10320 Phone phone = PhoneFactory.getPhone(i);
10321 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010322 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010323 isPhoneAvailable = true;
10324 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010325 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010326
10327 // return true if successfully informed the phone object about the thermal radio power
10328 // request.
10329 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010330 }
10331
10332 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010333 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010334 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10335 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10336 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10337 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10338 throw new IllegalArgumentException("modem does not support data throttling");
10339 }
10340
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010341 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10342 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010343 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010344 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10345 }
10346
Sarah Chinecc78c42022-03-31 21:16:48 -070010347 setDataEnabledForReason(
10348 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010349
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010350 if (isDataThrottlingSupported) {
10351 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010352 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010353 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10354 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10355 } else if (thermalMitigationResult
10356 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010357 log("Modem likely does not support data throttling on secondary carrier. Data " +
10358 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10359 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010360 }
10361 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010362 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010363
10364 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010365 }
10366
Jack Nudelman644b91a2021-03-12 14:09:48 -080010367 private static List<String> getThermalMitigationAllowlist(Context context) {
10368 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10369 for (String pckg : context.getResources()
10370 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10371 sThermalMitigationAllowlistedPackages.add(pckg);
10372 }
10373 }
10374
10375 return sThermalMitigationAllowlistedPackages;
10376 }
10377
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010378 private boolean isAnyPhoneInEmergencyState() {
10379 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10380 if (tm.isInEmergencyCall()) {
10381 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10382 return true;
10383 }
10384 for (Phone phone : PhoneFactory.getPhones()) {
10385 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10386 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10387 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10388 + phone.isInEcm());
10389 return true;
10390 }
10391 }
10392
10393 return false;
10394 }
10395
Jack Nudelman644b91a2021-03-12 14:09:48 -080010396 /**
10397 * Used by shell commands to add an authorized package name for thermal mitigation.
10398 * @param packageName name of package to be allowlisted
10399 * @param context
10400 */
10401 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10402 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10403 sThermalMitigationAllowlistedPackages.add(packageName);
10404 }
10405
10406 /**
10407 * Used by shell commands to remove an authorized package name for thermal mitigation.
10408 * @param packageName name of package to remove from allowlist
10409 * @param context
10410 */
10411 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10412 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10413 sThermalMitigationAllowlistedPackages.remove(packageName);
10414 }
10415
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010416 /**
10417 * Thermal mitigation request to control functionalities at modem.
10418 *
10419 * @param subId the id of the subscription.
10420 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010421 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010422 *
10423 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10424 */
10425 @Override
10426 @ThermalMitigationResult
10427 public int sendThermalMitigationRequest(
10428 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010429 ThermalMitigationRequest thermalMitigationRequest,
10430 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010431 enforceModifyPermission();
10432
Jack Nudelman644b91a2021-03-12 14:09:48 -080010433 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10434 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10435 .contains(callingPackage)) {
10436 throw new SecurityException("Calling package must be configured in the device config. "
10437 + "calling package: " + callingPackage);
10438 }
10439
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010440 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10441 final long identity = Binder.clearCallingIdentity();
10442
10443 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10444 try {
10445 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10446 switch (thermalMitigationAction) {
10447 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10448 thermalMitigationResult =
10449 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010450 thermalMitigationRequest.getDataThrottlingRequest(),
10451 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010452 break;
10453 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10454 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10455 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10456 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10457 }
10458
10459 // Ensure that radio is on. If not able to power on due to phone being
10460 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010461 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010462 thermalMitigationResult =
10463 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10464 break;
10465 }
10466
10467 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010468 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010469 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10470 break;
10471 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10472 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10473 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10474 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10475 }
10476
10477 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10478 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010479 Phone phone = getPhone(subId);
10480 if (phone == null) {
10481 thermalMitigationResult =
10482 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10483 break;
10484 }
10485
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010486 TelephonyConnectionService service =
10487 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010488 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010489 Log.e(LOG_TAG, "An emergency call is pending");
10490 thermalMitigationResult =
10491 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10492 break;
10493 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010494 thermalMitigationResult =
10495 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10496 break;
10497 }
10498 } else {
10499 thermalMitigationResult =
10500 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10501 break;
10502 }
10503
10504 // Turn radio off. If not able to power off due to phone being unavailable,
10505 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010506 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010507 thermalMitigationResult =
10508 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10509 break;
10510 }
10511 thermalMitigationResult =
10512 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10513 break;
10514 default:
10515 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10516 + "not exist. Requested action: " + thermalMitigationAction);
10517 }
10518 } catch (IllegalArgumentException e) {
10519 throw e;
10520 } catch (Exception e) {
10521 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10522 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10523 } finally {
10524 Binder.restoreCallingIdentity(identity);
10525 }
10526
10527 if (DBG) {
10528 log("thermalMitigationRequest returning with thermalMitigationResult: "
10529 + thermalMitigationResult);
10530 }
10531
10532 return thermalMitigationResult;
10533 }
Hui Wang641e81c2020-10-12 12:14:23 -070010534
10535 /**
10536 * Set the GbaService Package Name that Telephony will bind to.
10537 *
10538 * @param subId The sim that the GbaService is associated with.
10539 * @param packageName The name of the package to be replaced with.
10540 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10541 */
10542 @Override
10543 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10544 enforceModifyPermission();
10545
10546 final long identity = Binder.clearCallingIdentity();
10547 try {
10548 return getGbaManager(subId).overrideServicePackage(packageName);
10549 } finally {
10550 Binder.restoreCallingIdentity(identity);
10551 }
10552 }
10553
10554 /**
10555 * Return the package name of the currently bound GbaService.
10556 *
10557 * @param subId The sim that the GbaService is associated with.
10558 * @return the package name of the GbaService configuration, null if GBA is not supported.
10559 */
10560 @Override
10561 public String getBoundGbaService(int subId) {
10562 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10563
10564 final long identity = Binder.clearCallingIdentity();
10565 try {
10566 return getGbaManager(subId).getServicePackage();
10567 } finally {
10568 Binder.restoreCallingIdentity(identity);
10569 }
10570 }
10571
10572 /**
10573 * Set the release time for telephony to unbind GbaService.
10574 *
10575 * @param subId The sim that the GbaService is associated with.
10576 * @param interval The release time to unbind GbaService by millisecond.
10577 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10578 */
10579 @Override
10580 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10581 enforceModifyPermission();
10582
10583 final long identity = Binder.clearCallingIdentity();
10584 try {
10585 return getGbaManager(subId).overrideReleaseTime(interval);
10586 } finally {
10587 Binder.restoreCallingIdentity(identity);
10588 }
10589 }
10590
10591 /**
10592 * Return the release time for telephony to unbind GbaService.
10593 *
10594 * @param subId The sim that the GbaService is associated with.
10595 * @return The release time to unbind GbaService by millisecond.
10596 */
10597 @Override
10598 public int getGbaReleaseTime(int subId) {
10599 enforceReadPrivilegedPermission("getGbaReleaseTime");
10600
10601 final long identity = Binder.clearCallingIdentity();
10602 try {
10603 return getGbaManager(subId).getReleaseTime();
10604 } finally {
10605 Binder.restoreCallingIdentity(identity);
10606 }
10607 }
10608
10609 private GbaManager getGbaManager(int subId) {
10610 GbaManager instance = GbaManager.getInstance(subId);
10611 if (instance == null) {
10612 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10613 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10614 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10615 }
10616 return instance;
10617 }
Hui Wang761a6682020-10-31 05:12:53 +000010618
10619 /**
10620 * indicate whether the device and the carrier can support
10621 * RCS VoLTE single registration.
10622 */
10623 @Override
10624 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010625 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10626 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10627 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10628 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010629
10630 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10631 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10632 }
10633
10634 final long identity = Binder.clearCallingIdentity();
10635 try {
10636 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10637 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010638 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10639 if (isCapable != null) {
10640 return isCapable;
10641 }
Hui Wang761a6682020-10-31 05:12:53 +000010642 }
Hui Wang67af90e2021-06-04 16:57:15 -070010643 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10644 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010645 } finally {
10646 Binder.restoreCallingIdentity(identity);
10647 }
10648 }
10649
10650 /**
10651 * Register RCS provisioning callback.
10652 */
10653 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010654 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010655 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010656 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010657 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010658 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10659 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010660
10661 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10662 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10663 }
10664 if (!isImsAvailableOnDevice()) {
10665 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10666 "IMS not available on device.");
10667 }
10668
10669 final long identity = Binder.clearCallingIdentity();
10670 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010671 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010672 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010673 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10674 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010675 }
Hui Wang761a6682020-10-31 05:12:53 +000010676 } finally {
10677 Binder.restoreCallingIdentity(identity);
10678 }
10679 }
10680
10681 /**
10682 * Unregister RCS provisioning callback.
10683 */
10684 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010685 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010686 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010687 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010688 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010689 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10690 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010691
10692 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10693 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10694 }
10695 if (!isImsAvailableOnDevice()) {
10696 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10697 "IMS not available on device.");
10698 }
10699
10700 final long identity = Binder.clearCallingIdentity();
10701 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010702 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010703 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010704 } finally {
10705 Binder.restoreCallingIdentity(identity);
10706 }
10707 }
10708
10709 /**
10710 * trigger RCS reconfiguration.
10711 */
10712 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010713 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10714 "triggerRcsReconfiguration",
10715 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010716
10717 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10718 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10719 }
10720 if (!isImsAvailableOnDevice()) {
10721 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10722 "IMS not available on device.");
10723 }
10724
10725 final long identity = Binder.clearCallingIdentity();
10726 try {
10727 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10728 } finally {
10729 Binder.restoreCallingIdentity(identity);
10730 }
10731 }
10732
10733 /**
10734 * Provide the client configuration parameters of the RCS application.
10735 */
10736 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010737 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10738 "setRcsClientConfiguration",
10739 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010740
10741 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10742 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10743 }
10744 if (!isImsAvailableOnDevice()) {
10745 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10746 "IMS not available on device.");
10747 }
10748
10749 final long identity = Binder.clearCallingIdentity();
10750
10751 try {
10752 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10753 if (configBinder == null) {
10754 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010755 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10756 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010757 } else {
10758 configBinder.setRcsClientConfiguration(rcc);
10759 }
joonhunshin3e154242021-09-17 06:33:39 +000010760
10761 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10762 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010763 } catch (RemoteException e) {
10764 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010765 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10766 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010767 } finally {
10768 Binder.restoreCallingIdentity(identity);
10769 }
10770 }
10771
10772 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010773 * Enables or disables the test mode for RCS VoLTE single registration.
10774 */
10775 @Override
10776 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10777 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10778 "setRcsSingleRegistrationTestModeEnabled");
10779
10780 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10781 }
10782
10783 /**
10784 * Gets the test mode for RCS VoLTE single registration.
10785 */
10786 @Override
10787 public boolean getRcsSingleRegistrationTestModeEnabled() {
10788 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10789 "getRcsSingleRegistrationTestModeEnabled");
10790
10791 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10792 }
10793
10794 /**
Hui Wang761a6682020-10-31 05:12:53 +000010795 * Overrides the config of RCS VoLTE single registration enabled for the device.
10796 */
10797 @Override
10798 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10799 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10800 "setDeviceSingleRegistrationEnabledOverride");
10801 enforceModifyPermission();
10802
10803 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10804 : Boolean.parseBoolean(enabledStr);
10805 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010806 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010807 }
10808
10809 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010810 * Sends a device to device communication message. Only usable via shell.
10811 * @param message message to send.
10812 * @param value message value.
10813 */
10814 @Override
10815 public void sendDeviceToDeviceMessage(int message, int value) {
10816 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010817 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010818 enforceModifyPermission();
10819
10820 final long identity = Binder.clearCallingIdentity();
10821 try {
10822 TelephonyConnectionService service =
10823 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10824 if (service == null) {
10825 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10826 return;
10827 }
10828 service.sendTestDeviceToDeviceMessage(message, value);
10829 } finally {
10830 Binder.restoreCallingIdentity(identity);
10831 }
10832 }
10833
Tyler Gunnbabbda02021-02-10 11:05:02 -080010834 /**
10835 * Sets the specified device to device transport active.
10836 * @param transport The transport to set active.
10837 */
10838 @Override
10839 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10840 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10841 "setActiveDeviceToDeviceTransport");
10842 enforceModifyPermission();
10843
10844 final long identity = Binder.clearCallingIdentity();
10845 try {
10846 TelephonyConnectionService service =
10847 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10848 if (service == null) {
10849 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10850 return;
10851 }
10852 service.setActiveDeviceToDeviceTransport(transport);
10853 } finally {
10854 Binder.restoreCallingIdentity(identity);
10855 }
10856 }
Tyler Gunn92479152021-01-20 16:30:10 -080010857
Tyler Gunnd4339262021-05-03 14:46:49 -070010858 @Override
10859 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10860 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10861 "setDeviceToDeviceForceEnabled");
10862
10863 final long identity = Binder.clearCallingIdentity();
10864 try {
10865 Arrays.stream(PhoneFactory.getPhones()).forEach(
10866 p -> {
10867 Phone thePhone = p.getImsPhone();
10868 if (thePhone != null && thePhone instanceof ImsPhone) {
10869 ImsPhone imsPhone = (ImsPhone) thePhone;
10870 CallTracker tracker = imsPhone.getCallTracker();
10871 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10872 ImsPhoneCallTracker imsPhoneCallTracker =
10873 (ImsPhoneCallTracker) tracker;
10874 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10875 }
10876 }
10877 }
10878 );
10879 } finally {
10880 Binder.restoreCallingIdentity(identity);
10881 }
10882 }
10883
Tyler Gunn92479152021-01-20 16:30:10 -080010884 /**
Hui Wang761a6682020-10-31 05:12:53 +000010885 * Gets the config of RCS VoLTE single registration enabled for the device.
10886 */
10887 @Override
10888 public boolean getDeviceSingleRegistrationEnabled() {
10889 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10890 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10891 }
10892
10893 /**
10894 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10895 */
10896 @Override
10897 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10898 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10899 "setCarrierSingleRegistrationEnabledOverride");
10900 enforceModifyPermission();
10901
10902 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10903 : Boolean.parseBoolean(enabledStr);
10904 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10905 subId, enabled);
10906 }
10907
10908 /**
10909 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10910 */
10911 @Override
10912 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10913 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10914 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10915 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010916
10917 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010918 * Overrides the ims feature validation result
10919 */
10920 @Override
10921 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10922 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10923 "setImsFeatureValidationOverride");
10924
10925 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10926 : Boolean.parseBoolean(enabledStr);
10927 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10928 subId, enabled);
10929 }
10930
10931 /**
10932 * Gets the ims feature validation override value
10933 */
10934 @Override
10935 public boolean getImsFeatureValidationOverride(int subId) {
10936 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10937 "getImsFeatureValidationOverride");
10938 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10939 }
10940
10941 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010942 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10943 * their mobile plan.
10944 */
10945 @Override
10946 public String getMobileProvisioningUrl() {
10947 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10948 final long identity = Binder.clearCallingIdentity();
10949 try {
10950 return getDefaultPhone().getMobileProvisioningUrl();
10951 } finally {
10952 Binder.restoreCallingIdentity(identity);
10953 }
10954 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010955
James.cf Linbcdf8b32021-01-14 16:44:13 +080010956 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010957 * Get the EAB contact from the EAB database.
10958 */
10959 @Override
10960 public String getContactFromEab(String contact) {
10961 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10962 enforceModifyPermission();
10963 final long identity = Binder.clearCallingIdentity();
10964 try {
10965 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10966 } finally {
10967 Binder.restoreCallingIdentity(identity);
10968 }
10969 }
10970
10971 /**
Calvin Pana1434322021-07-01 19:27:01 +080010972 * Get the EAB capability from the EAB database.
10973 */
10974 @Override
10975 public String getCapabilityFromEab(String contact) {
10976 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10977 enforceModifyPermission();
10978 final long identity = Binder.clearCallingIdentity();
10979 try {
10980 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10981 } finally {
10982 Binder.restoreCallingIdentity(identity);
10983 }
10984 }
10985
10986 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010987 * Remove the EAB contacts from the EAB database.
10988 */
10989 @Override
10990 public int removeContactFromEab(int subId, String contacts) {
10991 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10992 enforceModifyPermission();
10993 final long identity = Binder.clearCallingIdentity();
10994 try {
10995 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10996 } finally {
10997 Binder.restoreCallingIdentity(identity);
10998 }
10999 }
11000
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011001 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011002 public boolean getDeviceUceEnabled() {
11003 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11004 final long identity = Binder.clearCallingIdentity();
11005 try {
11006 return mApp.getDeviceUceEnabled();
11007 } finally {
11008 Binder.restoreCallingIdentity(identity);
11009 }
11010 }
11011
11012 @Override
11013 public void setDeviceUceEnabled(boolean isEnabled) {
11014 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11015 final long identity = Binder.clearCallingIdentity();
11016 try {
11017 mApp.setDeviceUceEnabled(isEnabled);
11018 } finally {
11019 Binder.restoreCallingIdentity(identity);
11020 }
11021 }
11022
Brad Ebinger14d467f2021-02-12 06:18:28 +000011023 /**
11024 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11025 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11026 */
11027 // Used for SHELL command only right now.
11028 @Override
11029 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11030 List<String> featureTags) {
11031 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11032 "addUceRegistrationOverrideShell");
11033 final long identity = Binder.clearCallingIdentity();
11034 try {
11035 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11036 new ArraySet<>(featureTags));
11037 } catch (ImsException e) {
11038 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11039 } finally {
11040 Binder.restoreCallingIdentity(identity);
11041 }
11042 }
11043
11044 /**
11045 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11046 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11047 */
11048 // Used for SHELL command only right now.
11049 @Override
11050 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11051 List<String> featureTags) {
11052 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11053 "removeUceRegistrationOverrideShell");
11054 final long identity = Binder.clearCallingIdentity();
11055 try {
11056 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11057 new ArraySet<>(featureTags));
11058 } catch (ImsException e) {
11059 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11060 } finally {
11061 Binder.restoreCallingIdentity(identity);
11062 }
11063 }
11064
11065 /**
11066 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11067 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11068 */
11069 // Used for SHELL command only right now.
11070 @Override
11071 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11072 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11073 "clearUceRegistrationOverrideShell");
11074 final long identity = Binder.clearCallingIdentity();
11075 try {
11076 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11077 } catch (ImsException e) {
11078 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11079 } finally {
11080 Binder.restoreCallingIdentity(identity);
11081 }
11082 }
11083
11084 /**
11085 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11086 */
11087 // Used for SHELL command only right now.
11088 @Override
11089 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11090 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11091 "getLatestRcsContactUceCapabilityShell");
11092 final long identity = Binder.clearCallingIdentity();
11093 try {
11094 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11095 } catch (ImsException e) {
11096 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11097 } finally {
11098 Binder.restoreCallingIdentity(identity);
11099 }
11100 }
11101
11102 /**
11103 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11104 * device does not have an active PUBLISH.
11105 */
11106 // Used for SHELL command only right now.
11107 @Override
11108 public String getLastUcePidfXmlShell(int subId) {
11109 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11110 final long identity = Binder.clearCallingIdentity();
11111 try {
11112 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11113 } catch (ImsException e) {
11114 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11115 } finally {
11116 Binder.restoreCallingIdentity(identity);
11117 }
11118 }
11119
James.cf Line8713a42021-04-29 16:04:26 +080011120 /**
11121 * Remove UCE requests cannot be sent to the network status.
11122 */
11123 // Used for SHELL command only right now.
11124 @Override
11125 public boolean removeUceRequestDisallowedStatus(int subId) {
11126 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11127 final long identity = Binder.clearCallingIdentity();
11128 try {
11129 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11130 } catch (ImsException e) {
11131 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11132 } finally {
11133 Binder.restoreCallingIdentity(identity);
11134 }
11135 }
11136
James.cf Lin18bb9002021-05-25 01:37:38 +080011137 /**
11138 * Remove UCE requests cannot be sent to the network status.
11139 */
11140 // Used for SHELL command only.
11141 @Override
11142 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11143 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11144 final long identity = Binder.clearCallingIdentity();
11145 try {
11146 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11147 } catch (ImsException e) {
11148 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11149 } finally {
11150 Binder.restoreCallingIdentity(identity);
11151 }
11152 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011153
James.cf Lin4b784aa2021-01-31 03:25:15 +080011154 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011155 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11156 String callingPackage) {
11157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11158 mApp, subId, "setSignalStrengthUpdateRequest");
11159
11160 final int callingUid = Binder.getCallingUid();
11161 // Verify that tha callingPackage belongs to the calling UID
11162 mApp.getSystemService(AppOpsManager.class)
11163 .checkPackage(callingUid, callingPackage);
11164
Rambo Wang3607f502021-02-01 21:51:40 -080011165 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011166
11167 final long identity = Binder.clearCallingIdentity();
11168 try {
11169 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11170 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11171
11172 if (result instanceof IllegalStateException) {
11173 throw (IllegalStateException) result;
11174 }
11175 } finally {
11176 Binder.restoreCallingIdentity(identity);
11177 }
11178 }
11179
11180 @Override
11181 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11182 String callingPackage) {
11183 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11184 mApp, subId, "clearSignalStrengthUpdateRequest");
11185
11186 final int callingUid = Binder.getCallingUid();
11187 // Verify that tha callingPackage belongs to the calling UID
11188 mApp.getSystemService(AppOpsManager.class)
11189 .checkPackage(callingUid, callingPackage);
11190
11191 final long identity = Binder.clearCallingIdentity();
11192 try {
11193 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11194 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11195
11196 if (result instanceof IllegalStateException) {
11197 throw (IllegalStateException) result;
11198 }
11199 } finally {
11200 Binder.restoreCallingIdentity(identity);
11201 }
11202 }
11203
Rambo Wang3607f502021-02-01 21:51:40 -080011204 private static void validateSignalStrengthUpdateRequest(Context context,
11205 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011206 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11207 // phone/system process do not have further restriction on request
11208 return;
11209 }
11210
11211 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011212 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011213 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011214 context.enforceCallingOrSelfPermission(
11215 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11216 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011217 }
11218
11219 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11220 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11221 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11222 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11223 || info.isEnabled()) {
11224 throw new IllegalArgumentException(
11225 "Only system can set hide fields in SignalThresholdInfo");
11226 }
11227
11228 // Thresholds length for each RAN need in range. This has been validated in
11229 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11230 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11231 final int[] thresholds = info.getThresholds();
11232 Objects.requireNonNull(thresholds);
11233 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11234 || thresholds.length
11235 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11236 throw new IllegalArgumentException(
11237 "thresholds length is out of range: " + thresholds.length);
11238 }
11239 }
11240 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011241
11242 /**
11243 * Gets the current phone capability.
11244 *
11245 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11246 * @return the PhoneCapability which describes the data connection capability of modem.
11247 * It's used to evaluate possible phone config change, for example from single
11248 * SIM device to multi-SIM device.
11249 */
11250 @Override
11251 public PhoneCapability getPhoneCapability() {
11252 enforceReadPrivilegedPermission("getPhoneCapability");
11253 final long identity = Binder.clearCallingIdentity();
11254 try {
11255 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11256 } finally {
11257 Binder.restoreCallingIdentity(identity);
11258 }
11259 }
Michele Berionne5e411512020-11-13 02:36:59 +000011260
11261 /**
11262 * Prepare TelephonyManager for an unattended reboot. The reboot is
11263 * required to be done shortly after the API is invoked.
11264 */
11265 @Override
11266 @TelephonyManager.PrepareUnattendedRebootResult
11267 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011268 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011269 enforceRebootPermission();
11270
11271 final long identity = Binder.clearCallingIdentity();
11272 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011273 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011274 } finally {
11275 Binder.restoreCallingIdentity(identity);
11276 }
11277 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011278
11279 /**
11280 * Request to get the current slicing configuration including URSP rules and
11281 * NSSAIs (configured, allowed and rejected).
11282 *
11283 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11284 */
11285 @Override
11286 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011287 TelephonyPermissions
11288 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11289 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011290
11291 final long identity = Binder.clearCallingIdentity();
11292 try {
11293 Phone phone = getDefaultPhone();
11294 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11295 } finally {
11296 Binder.restoreCallingIdentity(identity);
11297 }
11298 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011299
11300 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011301 * Check whether the given premium capability is available for purchase from the carrier.
11302 *
11303 * @param capability The premium capability to check.
11304 * @param subId The subId to check the premium capability for.
11305 *
11306 * @return Whether the given premium capability is available to purchase.
11307 */
11308 @Override
11309 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11310 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11311 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11312 log("Premium capability "
11313 + TelephonyManager.convertPremiumCapabilityToString(capability)
11314 + " is not available for purchase due to missing permissions.");
11315 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11316 + "permission READ_BASIC_PHONE_STATE.");
11317 }
11318
11319 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011320 if (phone == null) {
11321 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11322 return false;
11323 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011324 final long identity = Binder.clearCallingIdentity();
11325 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011326 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011327 .isPremiumCapabilityAvailableForPurchase(capability);
11328 } finally {
11329 Binder.restoreCallingIdentity(identity);
11330 }
11331 }
11332
11333 /**
11334 * Purchase the given premium capability from the carrier.
11335 *
11336 * @param capability The premium capability to purchase.
11337 * @param callback The result of the purchase request.
11338 * @param subId The subId to purchase the premium capability for.
11339 */
11340 @Override
11341 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11342 log("purchasePremiumCapability: capability="
11343 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11344 + getCurrentPackageName());
11345
11346 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11347 mApp, "purchasePremiumCapability")) {
11348 log("purchasePremiumCapability "
11349 + TelephonyManager.convertPremiumCapabilityToString(capability)
11350 + " failed due to missing permissions.");
11351 throw new SecurityException("purchasePremiumCapability requires permission "
11352 + "READ_BASIC_PHONE_STATE.");
11353 }
11354
11355 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011356 if (phone == null) {
11357 try {
11358 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11359 callback.accept(result);
11360 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11361 } catch (RemoteException e) {
11362 String logStr = "Purchase premium capability "
11363 + TelephonyManager.convertPremiumCapabilityToString(capability)
11364 + " failed due to RemoteException handling null phone: " + e;
11365 if (DBG) log(logStr);
11366 AnomalyReporter.reportAnomaly(
11367 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11368 }
11369 return;
11370 }
Sarah Chin71b3a852022-09-28 15:54:19 -070011371 String appName;
11372 try {
11373 appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager()
11374 .getApplicationInfo(getCurrentPackageName(), 0)).toString();
11375 } catch (PackageManager.NameNotFoundException e) {
11376 appName = "An application";
11377 }
11378 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
11379 new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011380 }
11381
11382 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011383 * Register an IMS connection state callback
11384 */
11385 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011386 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11387 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011388 if (feature == ImsFeature.FEATURE_MMTEL) {
11389 // ImsMmTelManager
11390 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11391 TelephonyPermissions
11392 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11393 mApp, subId, "registerImsStateCallback");
11394 } else if (feature == ImsFeature.FEATURE_RCS) {
11395 // ImsRcsManager or SipDelegateManager
11396 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11397 Binder.getCallingUid(), "registerImsStateCallback",
11398 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11399 Manifest.permission.READ_PRECISE_PHONE_STATE,
11400 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11401 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11402 }
11403
11404 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11405 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11406 "IMS not available on device.");
11407 }
11408
11409 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11410 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11411 }
11412
11413 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11414 if (controller == null) {
11415 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11416 "IMS not available on device.");
11417 }
11418
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011419 if (callingPackage == null) {
11420 callingPackage = getCurrentPackageName();
11421 }
11422
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011423 final long token = Binder.clearCallingIdentity();
11424 try {
11425 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011426 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011427 } catch (ImsException e) {
11428 throw new ServiceSpecificException(e.getCode());
11429 } finally {
11430 Binder.restoreCallingIdentity(token);
11431 }
11432 }
11433
11434 /**
11435 * Unregister an IMS connection state callback
11436 */
11437 @Override
11438 public void unregisterImsStateCallback(IImsStateCallback cb) {
11439 final long token = Binder.clearCallingIdentity();
11440 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11441 if (controller == null) {
11442 return;
11443 }
11444 try {
11445 controller.unregisterImsStateCallback(cb);
11446 } finally {
11447 Binder.restoreCallingIdentity(token);
11448 }
11449 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011450
11451 /**
11452 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11453 *
11454 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11455 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11456 * SecurityException.
11457 * If there is current registered network this value will be same as the registered cell
11458 * identity. If the device goes out of service the previous cell identity is cached and
11459 * will be returned. If the cache age of the Cell identity is more than 24 hours
11460 * it will be cleared and null will be returned.
11461 *
11462 */
11463 @Override
11464 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11465 String callingFeatureId) {
11466 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11467 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11468 LocationAccessPolicy.checkLocationPermission(mApp,
11469 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11470 .setCallingPackage(callingPackage)
11471 .setCallingFeatureId(callingFeatureId)
11472 .setCallingPid(Binder.getCallingPid())
11473 .setCallingUid(Binder.getCallingUid())
11474 .setMethod("getLastKnownCellIdentity")
11475 .setLogAsInfo(true)
11476 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11477 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11478 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11479 .build());
11480
11481 boolean hasFinePermission =
11482 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11483 if (!hasFinePermission
11484 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11485 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011486 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011487 }
11488
11489 final long identity = Binder.clearCallingIdentity();
11490 try {
11491 Phone phone = getPhone(subId);
11492 if (phone == null) return null;
11493 ServiceStateTracker sst = phone.getServiceStateTracker();
11494 if (sst == null) return null;
11495 return sst.getLastKnownCellIdentity();
11496 } finally {
11497 Binder.restoreCallingIdentity(identity);
11498 }
11499 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011500
jimsun3b9ccac2021-10-26 15:01:23 +080011501 /**
11502 * Sets the modem service class Name that Telephony will bind to.
11503 *
11504 * @param serviceName The class name of the modem service.
11505 * @return true if the operation is succeed, otherwise false.
11506 */
11507 public boolean setModemService(String serviceName) {
11508 Log.d(LOG_TAG, "setModemService - " + serviceName);
11509 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11510 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11511 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11512 "setModemService");
11513 return mPhoneConfigurationManager.setModemService(serviceName);
11514 }
11515
11516 /**
11517 * Return the class name of the currently bounded modem service.
11518 *
11519 * @return the class name of the modem service.
11520 */
11521 public String getModemService() {
11522 String result;
11523 Log.d(LOG_TAG, "getModemService");
11524 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11525 TelephonyPermissions
11526 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11527 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11528 "getModemService");
11529 result = mPhoneConfigurationManager.getModemService();
11530 Log.d(LOG_TAG, "result = " + result);
11531 return result;
11532 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011533
11534 @Override
11535 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11536 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11537 mApp.enforceCallingOrSelfPermission(
11538 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11539 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11540
11541 final long identity = Binder.clearCallingIdentity();
11542 try {
11543 Phone phone = getPhone(subId);
11544 if (phone == null) return;
11545 phone.setVoiceServiceStateOverride(hasService);
11546 } finally {
11547 Binder.restoreCallingIdentity(identity);
11548 }
11549 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011550
11551 /**
11552 * set removable eSIM as default eUICC.
11553 *
11554 * @hide
11555 */
11556 @Override
11557 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11558 enforceModifyPermission();
11559 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11560
11561 final long identity = Binder.clearCallingIdentity();
11562 try {
11563 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11564 } finally {
11565 Binder.restoreCallingIdentity(identity);
11566 }
11567 }
11568
11569 /**
11570 * Returns whether the removable eSIM is default eUICC or not.
11571 *
11572 * @hide
11573 */
11574 @Override
11575 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11576 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11577 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11578
11579 final long identity = Binder.clearCallingIdentity();
11580 try {
11581 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11582 } finally {
11583 Binder.restoreCallingIdentity(identity);
11584 }
11585 }
11586
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011587 /**
11588 * Get the component name of the default app to direct respond-via-message intent for the
11589 * user associated with this subscription, update the cache if there is no respond-via-message
11590 * application currently configured for this user.
11591 * @return component name of the app and class to direct Respond Via Message intent to, or
11592 * {@code null} if the functionality is not supported.
11593 * @hide
11594 */
11595 @Override
11596 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11597 boolean updateIfNeeded) {
11598 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011599
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011600 Context context = getPhone(subId).getContext();
11601 UserHandle userHandle = null;
11602 final long identity = Binder.clearCallingIdentity();
11603 try {
11604 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11605 } finally {
11606 Binder.restoreCallingIdentity(identity);
11607 }
11608 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11609 updateIfNeeded, userHandle);
11610 }
11611}