blob: 40049fc1f79917bfe20a8858675a41f339d2284a [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;
Jack Yu285100e2022-12-02 22:48:35 -0800198import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
199import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700200import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700201import com.android.internal.telephony.uicc.IccIoResult;
202import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800203import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700204import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800205import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700206import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000207import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800208import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000209import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800210import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000211import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700212import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700213import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800214import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800215import com.android.phone.callcomposer.CallComposerPictureManager;
216import com.android.phone.callcomposer.CallComposerPictureTransfer;
217import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700218import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700219import com.android.phone.slice.SlicePurchaseController;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700220import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800221import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700222import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700223import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800224import com.android.services.telephony.TelecomAccountRegistry;
225import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800226import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800227
Hall Liu82694d52020-12-11 18:22:04 -0800228import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700229import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800230import java.io.IOException;
231import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700232import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700233import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800234import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000235import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800236import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800237import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800238import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800239import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100240import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800241import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700242import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800243import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800244import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700245import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800246import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800247import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800248import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249
250/**
251 * Implementation of the ITelephony interface.
252 */
Santos Cordon117fee72014-05-16 17:56:12 -0700253public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700254 private static final String LOG_TAG = "PhoneInterfaceManager";
255 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
256 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800257 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258
259 // Message codes used with mMainThreadHandler
260 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700261 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
262 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700263 private static final int CMD_OPEN_CHANNEL = 9;
264 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
265 private static final int CMD_CLOSE_CHANNEL = 11;
266 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800267 private static final int CMD_NV_READ_ITEM = 13;
268 private static final int EVENT_NV_READ_ITEM_DONE = 14;
269 private static final int CMD_NV_WRITE_ITEM = 15;
270 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
271 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
272 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700273 private static final int CMD_RESET_MODEM_CONFIG = 19;
274 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800275 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
276 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800277 private static final int CMD_SEND_ENVELOPE = 25;
278 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000279 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
280 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700281 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
282 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
283 private static final int CMD_EXCHANGE_SIM_IO = 31;
284 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800285 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
286 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700287 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
288 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700289 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
290 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700291 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
292 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
293 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
294 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700295 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
296 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
297 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
298 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700299 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800300 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
301 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000302 private static final int CMD_SWITCH_SLOTS = 50;
303 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700304 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
305 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
306 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
307 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
308 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
309 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
310 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
311 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700312 private static final int CMD_GET_ALL_CELL_INFO = 60;
313 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
314 private static final int CMD_GET_CELL_LOCATION = 62;
315 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700316 private static final int CMD_MODEM_REBOOT = 64;
317 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700318 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
319 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800320 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
321 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700322 private static final int CMD_GET_MODEM_STATUS = 70;
323 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700324 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
325 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700326 private static final int CMD_ERASE_MODEM_CONFIG = 74;
327 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800328 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
329 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
330 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
331 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800332 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
333 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800334 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800335 private static final int CMD_GET_CALL_FORWARDING = 83;
336 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
337 private static final int CMD_SET_CALL_FORWARDING = 85;
338 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
339 private static final int CMD_GET_CALL_WAITING = 87;
340 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
341 private static final int CMD_SET_CALL_WAITING = 89;
342 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700343 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
344 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
345 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
346 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700347 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
348 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800349 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
350 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800351 private static final int CMD_SET_DATA_THROTTLING = 99;
352 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800353 private static final int CMD_SET_SIM_POWER = 101;
354 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800355 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
356 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
357 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
358 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800359 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
360 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000361 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800362 private static final int CMD_GET_SLICING_CONFIG = 110;
363 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800364 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700365 private static final int CMD_ENABLE_VONR = 113;
366 private static final int EVENT_ENABLE_VONR_DONE = 114;
367 private static final int CMD_IS_VONR_ENABLED = 115;
368 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700369 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
370 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800372 // Parameters of select command.
373 private static final int SELECT_COMMAND = 0xA4;
374 private static final int SELECT_P1 = 0x04;
375 private static final int SELECT_P2 = 0;
376 private static final int SELECT_P3 = 0x10;
377
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378 /** The singleton instance. */
379 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800380 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381
Wink Saville3ab207e2014-11-20 13:07:20 -0800382 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800383 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800384 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700385 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800386 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700387 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800388 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800389 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800390 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700391 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800392 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Gil Cukierman6dac5eb2022-09-19 16:09:04 +0000393 private final Telephony2gUpdater mTelephony2gUpdater;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394
Peter Wangdafb9ac2020-01-15 14:13:38 -0800395 /** User Activity */
396 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800397 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
398
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700399 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
400
Derek Tan97ebb422014-09-05 16:55:38 -0700401 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
402 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800403 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800404 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700405
Michelecea4cf22018-12-21 15:00:11 -0800406 // String to store multi SIM allowed
407 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
408
Derek Tan740e1672017-06-27 14:56:27 -0700409 // The AID of ISD-R.
410 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
411
yinxub1bed742017-04-17 11:45:04 -0700412 private NetworkScanRequestTracker mNetworkScanRequestTracker;
413
David Kelly5e06a7f2018-03-12 14:10:59 +0000414 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
415 private static final int MANUFACTURER_CODE_LENGTH = 8;
416
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800417 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800418 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800419
Sarah Chin2ec39f62022-08-31 17:03:26 -0700420 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
421 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
422
Derek Tan89e89d42014-07-08 17:00:10 -0700423 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700424 * Experiment flag to enable erase modem config on reset network, default value is false
425 */
426 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
427 "reset_network_erase_modem_config_enabled";
428
Rambo Wang0f050d82021-02-12 11:43:36 -0800429 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800430
sandeepjsb6c87872021-09-27 15:34:44 +0000431 /**
432 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
433 * one ICCID active at the same time.
434 * Apps should use below API signatures if targeting SDK is T and beyond.
435 *
436 * @hide
437 */
438 @ChangeId
439 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
440 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800441
Naina Nallurid63128d2019-09-17 14:10:30 -0700442 /**
Chen Xu540470b2021-12-14 17:15:47 -0800443 * Apps targeting on Android T and beyond will get exception whenever icc close channel
444 * operation fails.
445 */
446 @ChangeId
447 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
448 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
449
450 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700451 * A request object to use for transmitting data to an ICC.
452 */
453 private static final class IccAPDUArgument {
454 public int channel, cla, command, p1, p2, p3;
455 public String data;
456
457 public IccAPDUArgument(int channel, int cla, int command,
458 int p1, int p2, int p3, String data) {
459 this.channel = channel;
460 this.cla = cla;
461 this.command = command;
462 this.p1 = p1;
463 this.p2 = p2;
464 this.p3 = p3;
465 this.data = data;
466 }
467 }
468
469 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700470 * A request object to use for transmitting data to an ICC.
471 */
472 private static final class ManualNetworkSelectionArgument {
473 public OperatorInfo operatorInfo;
474 public boolean persistSelection;
475
476 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
477 this.operatorInfo = operatorInfo;
478 this.persistSelection = persistSelection;
479 }
480 }
481
Sarah Chin71b3a852022-09-28 15:54:19 -0700482 private static final class PurchasePremiumCapabilityArgument {
483 public @TelephonyManager.PremiumCapability int capability;
484 public @NonNull String appName;
485 public @NonNull IIntegerConsumer callback;
486
487 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
488 @NonNull String appName, @NonNull IIntegerConsumer callback) {
489 this.capability = capability;
490 this.appName = appName;
491 this.callback = callback;
492 }
493 }
494
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700495 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700496 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
497 * request after sending. The main thread will notify the request when it is complete.
498 */
499 private static final class MainThreadRequest {
500 /** The argument to use for the request */
501 public Object argument;
502 /** The result of the request that is run on the main thread */
503 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800504 // The subscriber id that this request applies to. Defaults to
505 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
506 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700507
Nathan Harold92bed182018-10-12 18:16:49 -0700508 // In cases where subId is unavailable, the caller needs to specify the phone.
509 public Phone phone;
510
vagdeviaf9a5b92018-08-15 16:01:53 -0700511 public WorkSource workSource;
512
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700513 public MainThreadRequest(Object argument) {
514 this.argument = argument;
515 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800516
Nathan Harold92bed182018-10-12 18:16:49 -0700517 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
518 this.argument = argument;
519 if (phone != null) {
520 this.phone = phone;
521 }
522 this.workSource = workSource;
523 }
524
vagdeviaf9a5b92018-08-15 16:01:53 -0700525 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800526 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800527 if (subId != null) {
528 this.subId = subId;
529 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700530 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800531 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700532 }
533
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800534 private static final class IncomingThirdPartyCallArgs {
535 public final ComponentName component;
536 public final String callId;
537 public final String callerDisplayName;
538
539 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
540 String callerDisplayName) {
541 this.component = component;
542 this.callId = callId;
543 this.callerDisplayName = callerDisplayName;
544 }
545 }
546
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700547 /**
548 * A handler that processes messages on the main thread in the phone process. Since many
549 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
550 * inbound binder threads to the main thread in the phone process. The Binder thread
551 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
552 * on, which will be notified when the operation completes and will contain the result of the
553 * request.
554 *
555 * <p>If a MainThreadRequest object is provided in the msg.obj field,
556 * note that request.result must be set to something non-null for the calling thread to
557 * unblock.
558 */
559 private final class MainThreadHandler extends Handler {
560 @Override
561 public void handleMessage(Message msg) {
562 MainThreadRequest request;
563 Message onCompleted;
564 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000565 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800567 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700568
569 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700570 case CMD_HANDLE_USSD_REQUEST: {
571 request = (MainThreadRequest) msg.obj;
572 final Phone phone = getPhoneFromRequest(request);
573 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800574 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700575 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700576
Pengquan Menga1bb6272018-09-06 09:59:22 -0700577 if (!isUssdApiAllowed(request.subId)) {
578 // Carrier does not support use of this API, return failure.
579 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
580 UssdResponse response = new UssdResponse(ussdRequest, null);
581 Bundle returnData = new Bundle();
582 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
583 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700584
Pengquan Menga1bb6272018-09-06 09:59:22 -0700585 request.result = true;
586 notifyRequester(request);
587 return;
588 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700589
Pengquan Menga1bb6272018-09-06 09:59:22 -0700590 try {
591 request.result = phone != null
592 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
593 } catch (CallStateException cse) {
594 request.result = false;
595 }
596 // Wake up the requesting thread
597 notifyRequester(request);
598 break;
pkanwar32d516d2016-10-14 19:37:38 -0700599 }
600
Yorke Lee716f67e2015-06-17 15:39:16 -0700601 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700602 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700603 final Phone phone = getPhoneFromRequest(request);
604 request.result = phone != null ?
605 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
606 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700607 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700608 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700609 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700610 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700611
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000615 uiccPort = getUiccPortFromRequest(request);
616 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700617 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800618 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700620 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800622 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000623 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800624 iccArgument.channel, iccArgument.cla, iccArgument.command,
625 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
626 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700627 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 break;
629
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 ar = (AsyncResult) msg.obj;
632 request = (MainThreadRequest) ar.userObj;
633 if (ar.exception == null && ar.result != null) {
634 request.result = ar.result;
635 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800636 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 if (ar.result == null) {
638 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800639 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800641 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700642 } else {
643 loge("iccTransmitApduLogicalChannel: Unknown exception");
644 }
645 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700646 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 break;
648
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700649 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
650 request = (MainThreadRequest) msg.obj;
651 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000652 uiccPort = getUiccPortFromRequest(request);
653 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700654 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800655 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 } else {
658 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800659 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000660 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800661 iccArgument.cla, iccArgument.command, iccArgument.p1,
662 iccArgument.p2,
663 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700664 }
665 break;
666
667 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
668 ar = (AsyncResult) msg.obj;
669 request = (MainThreadRequest) ar.userObj;
670 if (ar.exception == null && ar.result != null) {
671 request.result = ar.result;
672 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800673 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700674 if (ar.result == null) {
675 loge("iccTransmitApduBasicChannel: Empty response");
676 } else if (ar.exception instanceof CommandException) {
677 loge("iccTransmitApduBasicChannel: CommandException: " +
678 ar.exception);
679 } else {
680 loge("iccTransmitApduBasicChannel: Unknown exception");
681 }
682 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700684 break;
685
686 case CMD_EXCHANGE_SIM_IO:
687 request = (MainThreadRequest) msg.obj;
688 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000689 uiccPort = getUiccPortFromRequest(request);
690 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700691 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800692 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700693 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700694 } else {
695 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
696 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000697 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700698 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
699 iccArgument.data, onCompleted);
700 }
701 break;
702
703 case EVENT_EXCHANGE_SIM_IO_DONE:
704 ar = (AsyncResult) msg.obj;
705 request = (MainThreadRequest) ar.userObj;
706 if (ar.exception == null && ar.result != null) {
707 request.result = ar.result;
708 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800709 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700710 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700711 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700712 break;
713
Derek Tan4d5e5c12014-02-04 11:54:58 -0800714 case CMD_SEND_ENVELOPE:
715 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000716 uiccPort = getUiccPortFromRequest(request);
717 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700718 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800719 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700720 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700721 } else {
722 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800723 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700724 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800725 break;
726
727 case EVENT_SEND_ENVELOPE_DONE:
728 ar = (AsyncResult) msg.obj;
729 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700730 if (ar.exception == null && ar.result != null) {
731 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800732 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800733 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700734 if (ar.result == null) {
735 loge("sendEnvelopeWithStatus: Empty response");
736 } else if (ar.exception instanceof CommandException) {
737 loge("sendEnvelopeWithStatus: CommandException: " +
738 ar.exception);
739 } else {
740 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
741 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800742 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700743 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800744 break;
745
Shishir Agrawal566b7612013-10-28 14:41:00 -0700746 case CMD_OPEN_CHANNEL:
747 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000748 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800749 IccLogicalChannelRequest openChannelRequest =
750 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000751 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700752 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800753 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800754 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700755 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700756 } else {
757 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800758 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
759 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700760 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700761 break;
762
763 case EVENT_OPEN_CHANNEL_DONE:
764 ar = (AsyncResult) msg.obj;
765 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700766 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700767 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700768 int[] result = (int[]) ar.result;
769 int channelId = result[0];
770 byte[] selectResponse = null;
771 if (result.length > 1) {
772 selectResponse = new byte[result.length - 1];
773 for (int i = 1; i < result.length; ++i) {
774 selectResponse[i - 1] = (byte) result[i];
775 }
776 }
777 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800778 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800779
780 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700781 if (uiccPort == null) {
782 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
783 } else {
784 IccLogicalChannelRequest channelRequest =
785 (IccLogicalChannelRequest) request.argument;
786 channelRequest.channel = channelId;
787 uiccPort.onLogicalChannelOpened(channelRequest);
788 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700789 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700790 if (ar.result == null) {
791 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700792 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700793 if (ar.exception != null) {
794 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
795 }
796
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700797 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700798 if (ar.exception instanceof CommandException) {
799 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800800 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700801 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700802 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700803 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700804 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700805 }
806 }
807 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800808 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700809 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700810 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700811 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700812 break;
813
814 case CMD_CLOSE_CHANNEL:
815 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000816 uiccPort = getUiccPortFromRequest(request);
817 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700818 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800819 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800820 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800821 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700822 } else {
823 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000824 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700825 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700826 break;
827
828 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800829 ar = (AsyncResult) msg.obj;
830 request = (MainThreadRequest) ar.userObj;
831 if (ar.exception == null) {
832 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800833 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700834 if (uiccPort == null) {
835 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
836 } else {
837 final int channelId = (Integer) request.argument;
838 uiccPort.onLogicalChannelClosed(channelId);
839 }
Chen Xu540470b2021-12-14 17:15:47 -0800840 } else {
841 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800842 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800843 if (ar.exception instanceof CommandException) {
844 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
845 CommandException.Error error =
846 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800847 if (error == CommandException.Error.INVALID_ARGUMENTS) {
848 // should only throw exceptions from the binder threads.
849 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800850 "iccCloseLogicalChannel: invalid argument ");
851 }
852 } else {
853 loge("iccCloseLogicalChannel: Unknown exception");
854 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800855 request.result = (exception != null) ? exception :
856 new IllegalStateException(
857 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800858 }
859 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800860 break;
861
862 case CMD_NV_READ_ITEM:
863 request = (MainThreadRequest) msg.obj;
864 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800865 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
866 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800867 break;
868
869 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700870 ar = (AsyncResult) msg.obj;
871 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800872 if (ar.exception == null && ar.result != null) {
873 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700874 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800875 request.result = "";
876 if (ar.result == null) {
877 loge("nvReadItem: Empty response");
878 } else if (ar.exception instanceof CommandException) {
879 loge("nvReadItem: CommandException: " +
880 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700881 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800882 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700883 }
884 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700885 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700886 break;
887
Jake Hambye994d462014-02-03 13:10:13 -0800888 case CMD_NV_WRITE_ITEM:
889 request = (MainThreadRequest) msg.obj;
890 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
891 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800892 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700893 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800894 break;
895
896 case EVENT_NV_WRITE_ITEM_DONE:
897 handleNullReturnEvent(msg, "nvWriteItem");
898 break;
899
900 case CMD_NV_WRITE_CDMA_PRL:
901 request = (MainThreadRequest) msg.obj;
902 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800903 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800904 break;
905
906 case EVENT_NV_WRITE_CDMA_PRL_DONE:
907 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
908 break;
909
chen xu6dac5ab2018-10-26 17:39:23 -0700910 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800911 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700912 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800913 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800914 break;
915
chen xu6dac5ab2018-10-26 17:39:23 -0700916 case EVENT_RESET_MODEM_CONFIG_DONE:
917 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800918 break;
919
Sooraj Sasindran37444802020-08-11 10:40:43 -0700920 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
921 request = (MainThreadRequest) msg.obj;
922 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
923 request);
924 Phone phone = getPhoneFromRequest(request);
925 if (phone != null) {
926 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
927 } else {
928 loge("isNRDualConnectivityEnabled: No phone object");
929 request.result = false;
930 notifyRequester(request);
931 }
932 break;
933 }
934
935 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
936 ar = (AsyncResult) msg.obj;
937 request = (MainThreadRequest) ar.userObj;
938 if (ar.exception == null && ar.result != null) {
939 request.result = ar.result;
940 } else {
941 // request.result must be set to something non-null
942 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700943 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700944 request.result = ar.result;
945 } else {
946 request.result = false;
947 }
948 if (ar.result == null) {
949 loge("isNRDualConnectivityEnabled: Empty response");
950 } else if (ar.exception instanceof CommandException) {
951 loge("isNRDualConnectivityEnabled: CommandException: "
952 + ar.exception);
953 } else {
954 loge("isNRDualConnectivityEnabled: Unknown exception");
955 }
956 }
957 notifyRequester(request);
958 break;
959
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700960 case CMD_IS_VONR_ENABLED: {
961 request = (MainThreadRequest) msg.obj;
962 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
963 request);
964 Phone phone = getPhoneFromRequest(request);
965 if (phone != null) {
966 phone.isVoNrEnabled(onCompleted, request.workSource);
967 } else {
968 loge("isVoNrEnabled: No phone object");
969 request.result = false;
970 notifyRequester(request);
971 }
972 break;
973 }
974
975 case EVENT_IS_VONR_ENABLED_DONE:
976 ar = (AsyncResult) msg.obj;
977 request = (MainThreadRequest) ar.userObj;
978 if (ar.exception == null && ar.result != null) {
979 request.result = ar.result;
980 } else {
981 // request.result must be set to something non-null
982 // for the calling thread to unblock
983 if (ar.result != null) {
984 request.result = ar.result;
985 } else {
986 request.result = false;
987 }
988 if (ar.result == null) {
989 loge("isVoNrEnabled: Empty response");
990 } else if (ar.exception instanceof CommandException) {
991 loge("isVoNrEnabled: CommandException: "
992 + ar.exception);
993 } else {
994 loge("isVoNrEnabled: Unknown exception");
995 }
996 }
997 notifyRequester(request);
998 break;
999
Sooraj Sasindran37444802020-08-11 10:40:43 -07001000 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1001 request = (MainThreadRequest) msg.obj;
1002 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1003 Phone phone = getPhoneFromRequest(request);
1004 if (phone != null) {
1005 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1006 request.workSource);
1007 } else {
1008 loge("enableNrDualConnectivity: No phone object");
1009 request.result =
1010 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1011 notifyRequester(request);
1012 }
1013 break;
1014 }
1015
1016 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1017 ar = (AsyncResult) msg.obj;
1018 request = (MainThreadRequest) ar.userObj;
1019 if (ar.exception == null) {
1020 request.result =
1021 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1022 } else {
1023 request.result =
1024 TelephonyManager
1025 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1026 if (ar.exception instanceof CommandException) {
1027 CommandException.Error error =
1028 ((CommandException) (ar.exception)).getCommandError();
1029 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1030 request.result =
1031 TelephonyManager
1032 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001033 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1034 request.result =
1035 TelephonyManager
1036 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001037 }
1038 loge("enableNrDualConnectivity" + ": CommandException: "
1039 + ar.exception);
1040 } else {
1041 loge("enableNrDualConnectivity" + ": Unknown exception");
1042 }
1043 }
1044 notifyRequester(request);
1045 break;
1046 }
1047
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001048 case CMD_ENABLE_VONR: {
1049 request = (MainThreadRequest) msg.obj;
1050 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1051 Phone phone = getPhoneFromRequest(request);
1052 if (phone != null) {
1053 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1054 request.workSource);
1055 } else {
1056 loge("setVoNrEnabled: No phone object");
1057 request.result =
1058 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1059 notifyRequester(request);
1060 }
1061 break;
1062 }
1063
1064 case EVENT_ENABLE_VONR_DONE: {
1065 ar = (AsyncResult) msg.obj;
1066 request = (MainThreadRequest) ar.userObj;
1067 if (ar.exception == null) {
1068 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1069 } else {
1070 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1071 if (ar.exception instanceof CommandException) {
1072 CommandException.Error error =
1073 ((CommandException) (ar.exception)).getCommandError();
1074 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1075 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1076 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1077 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1078 } else {
1079 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1080 }
1081 loge("setVoNrEnabled" + ": CommandException: "
1082 + ar.exception);
1083 } else {
1084 loge("setVoNrEnabled" + ": Unknown exception");
1085 }
1086 }
1087 notifyRequester(request);
1088 break;
1089 }
1090
SongFerngWang3ef3e072020-12-21 16:41:52 +08001091 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001092 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001093 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1094 request);
1095 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001096 break;
1097
SongFerngWang3ef3e072020-12-21 16:41:52 +08001098 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001099 ar = (AsyncResult) msg.obj;
1100 request = (MainThreadRequest) ar.userObj;
1101 if (ar.exception == null && ar.result != null) {
1102 request.result = ar.result; // Integer
1103 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301104 // request.result must be set to something non-null
1105 // for the calling thread to unblock
1106 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001107 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001108 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001109 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001110 loge("getAllowedNetworkTypesBitmask: CommandException: "
1111 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001112 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001113 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001114 }
1115 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001116 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001117 break;
1118
SongFerngWang3ef3e072020-12-21 16:41:52 +08001119 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001120 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001121 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1122 request);
1123 Pair<Integer, Long> reasonWithNetworkTypes =
1124 (Pair<Integer, Long>) request.argument;
1125 getPhoneFromRequest(request).setAllowedNetworkTypes(
1126 reasonWithNetworkTypes.first,
1127 reasonWithNetworkTypes.second,
1128 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001129 break;
1130
SongFerngWang3ef3e072020-12-21 16:41:52 +08001131 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1132 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001133 break;
1134
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001135 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1136 request = (MainThreadRequest)msg.obj;
1137 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001138 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001139 break;
1140
1141 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1142 ar = (AsyncResult)msg.obj;
1143 request = (MainThreadRequest)ar.userObj;
1144 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001145 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001146 break;
1147
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001148 case CMD_SET_VOICEMAIL_NUMBER:
1149 request = (MainThreadRequest) msg.obj;
1150 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1151 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001152 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1153 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001154 break;
1155
1156 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1157 handleNullReturnEvent(msg, "setVoicemailNumber");
1158 break;
1159
Stuart Scott54788802015-03-30 13:18:01 -07001160 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1161 request = (MainThreadRequest) msg.obj;
1162 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1163 request);
1164 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1165 break;
1166
1167 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1168 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1169 break;
1170
Shishir Agrawal302c8692015-06-19 13:49:39 -07001171 case CMD_PERFORM_NETWORK_SCAN:
1172 request = (MainThreadRequest) msg.obj;
1173 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1174 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1175 break;
1176
Hall Liu27d24262020-09-18 19:04:59 -07001177 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001178 request = (MainThreadRequest) msg.obj;
1179 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001180 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1181 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1182 request.argument;
1183 int callForwardingReason = args.first;
1184 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001185 break;
Hall Liu27d24262020-09-18 19:04:59 -07001186 }
1187 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001188 ar = (AsyncResult) msg.obj;
1189 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001190 TelephonyManager.CallForwardingInfoCallback callback =
1191 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1192 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001193 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001194 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001195 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1196 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1197 // Service Class is a bit mask per 3gpp 27.007. Search for
1198 // any service for voice call.
1199 if ((callForwardInfo.serviceClass
1200 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001201 callForwardingInfo = new CallForwardingInfo(
1202 callForwardInfo.status
1203 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001204 callForwardInfo.reason,
1205 callForwardInfo.number,
1206 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001207 break;
1208 }
1209 }
1210 // Didn't find a call forward info for voice call.
1211 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001212 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1213 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001214 }
Hall Liu27d24262020-09-18 19:04:59 -07001215 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001216 } else {
1217 if (ar.result == null) {
1218 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1219 }
1220 if (ar.exception != null) {
1221 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1222 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001223 int errorCode = TelephonyManager
1224 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001225 if (ar.exception instanceof CommandException) {
1226 CommandException.Error error =
1227 ((CommandException) (ar.exception)).getCommandError();
1228 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001229 errorCode = TelephonyManager
1230 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001231 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001232 errorCode = TelephonyManager
1233 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001234 }
1235 }
Hall Liu27d24262020-09-18 19:04:59 -07001236 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001237 }
Shuo Qian4a594052020-01-23 11:59:30 -08001238 break;
Hall Liu27d24262020-09-18 19:04:59 -07001239 }
Shuo Qian4a594052020-01-23 11:59:30 -08001240
Hall Liu27d24262020-09-18 19:04:59 -07001241 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001242 request = (MainThreadRequest) msg.obj;
1243 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001244 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001245 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001246 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1247 request.argument).first;
1248 request.phone.setCallForwardingOption(
1249 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001250 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001251 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001252 callForwardingInfoToSet.getReason(),
1253 callForwardingInfoToSet.getNumber(),
1254 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1255 break;
Hall Liu27d24262020-09-18 19:04:59 -07001256 }
Shuo Qian4a594052020-01-23 11:59:30 -08001257
Hall Liu27d24262020-09-18 19:04:59 -07001258 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001259 ar = (AsyncResult) msg.obj;
1260 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001261 Consumer<Integer> callback =
1262 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1263 request.argument).second;
1264 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001265 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001266 int errorCode = TelephonyManager.CallForwardingInfoCallback
1267 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001268 if (ar.exception instanceof CommandException) {
1269 CommandException.Error error =
1270 ((CommandException) (ar.exception)).getCommandError();
1271 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001272 errorCode = TelephonyManager.CallForwardingInfoCallback
1273 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001274 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001275 errorCode = TelephonyManager.CallForwardingInfoCallback
1276 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001277 }
1278 }
1279 callback.accept(errorCode);
1280 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001281 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001282 }
Shuo Qian4a594052020-01-23 11:59:30 -08001283 break;
Hall Liu27d24262020-09-18 19:04:59 -07001284 }
Shuo Qian4a594052020-01-23 11:59:30 -08001285
Hall Liu27d24262020-09-18 19:04:59 -07001286 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001287 request = (MainThreadRequest) msg.obj;
1288 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1289 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1290 break;
Hall Liu27d24262020-09-18 19:04:59 -07001291 }
Shuo Qian4a594052020-01-23 11:59:30 -08001292
Hall Liu27d24262020-09-18 19:04:59 -07001293 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001294 ar = (AsyncResult) msg.obj;
1295 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001296 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001297 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001298 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001299 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001300 // Service Class is a bit mask per 3gpp 27.007.
1301 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001302 if (callForwardResults.length > 1
1303 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001304 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001305 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001306 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1307 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001308 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001309 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001310 }
1311 } else {
1312 if (ar.result == null) {
1313 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1314 }
1315 if (ar.exception != null) {
1316 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1317 }
1318 if (ar.exception instanceof CommandException) {
1319 CommandException.Error error =
1320 ((CommandException) (ar.exception)).getCommandError();
1321 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001322 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001323 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001324 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1325 callWaitingStatus =
1326 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001327 }
1328 }
1329 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001330 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001331 break;
Hall Liu27d24262020-09-18 19:04:59 -07001332 }
Shuo Qian4a594052020-01-23 11:59:30 -08001333
Hall Liu27d24262020-09-18 19:04:59 -07001334 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001335 request = (MainThreadRequest) msg.obj;
1336 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001337 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1338 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001339 break;
Hall Liu27d24262020-09-18 19:04:59 -07001340 }
Shuo Qian4a594052020-01-23 11:59:30 -08001341
Hall Liu27d24262020-09-18 19:04:59 -07001342 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001343 ar = (AsyncResult) msg.obj;
1344 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001345 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1346 Consumer<Integer> callback =
1347 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1348 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001349 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001350 if (ar.exception instanceof CommandException) {
1351 CommandException.Error error =
1352 ((CommandException) (ar.exception)).getCommandError();
1353 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1354 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001355 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1356 callback.accept(
1357 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001358 } else {
1359 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1360 }
1361 } else {
1362 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1363 }
1364 } else {
1365 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1366 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001367 }
Shuo Qian4a594052020-01-23 11:59:30 -08001368 break;
Hall Liu27d24262020-09-18 19:04:59 -07001369 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001370 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1371 ar = (AsyncResult) msg.obj;
1372 request = (MainThreadRequest) ar.userObj;
1373 CellNetworkScanResult cellScanResult;
1374 if (ar.exception == null && ar.result != null) {
1375 cellScanResult = new CellNetworkScanResult(
1376 CellNetworkScanResult.STATUS_SUCCESS,
1377 (List<OperatorInfo>) ar.result);
1378 } else {
1379 if (ar.result == null) {
1380 loge("getCellNetworkScanResults: Empty response");
1381 }
1382 if (ar.exception != null) {
1383 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1384 }
1385 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1386 if (ar.exception instanceof CommandException) {
1387 CommandException.Error error =
1388 ((CommandException) (ar.exception)).getCommandError();
1389 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1390 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1391 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1392 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1393 }
1394 }
1395 cellScanResult = new CellNetworkScanResult(errorCode, null);
1396 }
1397 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001398 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001399 break;
1400
1401 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1402 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001403 ManualNetworkSelectionArgument selArg =
1404 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001405 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1406 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001407 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1408 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001409 break;
1410
1411 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001412 ar = (AsyncResult) msg.obj;
1413 request = (MainThreadRequest) ar.userObj;
1414 if (ar.exception == null) {
1415 request.result = true;
1416 } else {
1417 request.result = false;
1418 loge("setNetworkSelectionModeManual " + ar.exception);
1419 }
1420 notifyRequester(request);
1421 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001422 break;
1423
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001424 case CMD_GET_MODEM_ACTIVITY_INFO:
1425 request = (MainThreadRequest) msg.obj;
1426 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001427 if (defaultPhone != null) {
1428 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001429 } else {
1430 ResultReceiver result = (ResultReceiver) request.argument;
1431 Bundle bundle = new Bundle();
1432 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001433 new ModemActivityInfo(0, 0, 0,
1434 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001435 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001436 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001437 break;
1438
Hall Liud0f208c2020-10-14 16:54:44 -07001439 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001440 ar = (AsyncResult) msg.obj;
1441 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001442 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001443 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001444 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001445 if (mLastModemActivityInfo == null) {
1446 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1447 mLastModemActivitySpecificInfo[0] =
1448 new ActivityStatsTechSpecificInfo(
1449 0,
1450 0,
1451 new int[ModemActivityInfo.getNumTxPowerLevels()],
1452 0);
1453 mLastModemActivityInfo =
1454 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1455 }
1456
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001457 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001458 // Update the last modem activity info and the result of the request.
1459 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1460 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001461 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001462 }
Kai Shi917fdc62022-11-28 14:01:02 -08001463 // This is needed to decouple ret from mLastModemActivityInfo
1464 // We don't want to return mLastModemActivityInfo which is updated
1465 // inside mergeModemActivityInfo()
1466 ret = new ModemActivityInfo(
1467 mLastModemActivityInfo.getTimestampMillis(),
1468 mLastModemActivityInfo.getSleepTimeMillis(),
1469 mLastModemActivityInfo.getIdleTimeMillis(),
1470 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001471
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001472 } else {
1473 if (ar.result == null) {
1474 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001475 error = TelephonyManager.ModemActivityInfoException
1476 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001477 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001478 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001479 error = TelephonyManager.ModemActivityInfoException
1480 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001481 } else {
1482 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001483 error = TelephonyManager.ModemActivityInfoException
1484 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001485 }
1486 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001487 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001488 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001489 bundle.putParcelable(
1490 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001491 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001492 } else {
1493 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1494 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001495 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001496 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001497 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001498 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001499
Meng Wang1a7c35a2016-05-05 20:56:15 -07001500 case CMD_SET_ALLOWED_CARRIERS:
1501 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001502 CarrierRestrictionRules argument =
1503 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001504 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001505 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001506 break;
1507
1508 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1509 ar = (AsyncResult) msg.obj;
1510 request = (MainThreadRequest) ar.userObj;
1511 if (ar.exception == null && ar.result != null) {
1512 request.result = ar.result;
1513 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001514 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1515 if (ar.exception instanceof CommandException) {
1516 loge("setAllowedCarriers: CommandException: " + ar.exception);
1517 CommandException.Error error =
1518 ((CommandException) (ar.exception)).getCommandError();
1519 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1520 request.result =
1521 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1522 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001523 } else {
1524 loge("setAllowedCarriers: Unknown exception");
1525 }
1526 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001527 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001528 break;
1529
1530 case CMD_GET_ALLOWED_CARRIERS:
1531 request = (MainThreadRequest) msg.obj;
1532 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001533 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001534 break;
1535
1536 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1537 ar = (AsyncResult) msg.obj;
1538 request = (MainThreadRequest) ar.userObj;
1539 if (ar.exception == null && ar.result != null) {
1540 request.result = ar.result;
1541 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001542 request.result = new IllegalStateException(
1543 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001544 if (ar.result == null) {
1545 loge("getAllowedCarriers: Empty response");
1546 } else if (ar.exception instanceof CommandException) {
1547 loge("getAllowedCarriers: CommandException: " +
1548 ar.exception);
1549 } else {
1550 loge("getAllowedCarriers: Unknown exception");
1551 }
1552 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001553 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001554 break;
1555
Nathan Haroldb3014052017-01-25 15:57:32 -08001556 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1557 ar = (AsyncResult) msg.obj;
1558 request = (MainThreadRequest) ar.userObj;
1559 if (ar.exception == null && ar.result != null) {
1560 request.result = ar.result;
1561 } else {
1562 request.result = new IllegalArgumentException(
1563 "Failed to retrieve Forbidden Plmns");
1564 if (ar.result == null) {
1565 loge("getForbiddenPlmns: Empty response");
1566 } else {
1567 loge("getForbiddenPlmns: Unknown exception");
1568 }
1569 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001570 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001571 break;
1572
1573 case CMD_GET_FORBIDDEN_PLMNS:
1574 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001575 uiccPort = getUiccPortFromRequest(request);
1576 if (uiccPort == null) {
1577 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001578 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001579 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001580 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001581 break;
1582 }
1583 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001584 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001585 if (uiccApp == null) {
1586 loge("getForbiddenPlmns() no app with specified type -- "
1587 + appType);
1588 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001589 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001590 break;
1591 } else {
1592 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1593 + " specified type -- " + appType);
1594 }
1595 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1596 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1597 onCompleted);
1598 break;
1599
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001600 case CMD_SWITCH_SLOTS:
1601 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001602 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001603 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001604 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001605 break;
1606
1607 case EVENT_SWITCH_SLOTS_DONE:
1608 ar = (AsyncResult) msg.obj;
1609 request = (MainThreadRequest) ar.userObj;
1610 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001611 notifyRequester(request);
1612 break;
1613 case CMD_GET_NETWORK_SELECTION_MODE:
1614 request = (MainThreadRequest) msg.obj;
1615 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1616 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1617 break;
1618
1619 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1620 ar = (AsyncResult) msg.obj;
1621 request = (MainThreadRequest) ar.userObj;
1622 if (ar.exception != null) {
1623 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1624 } else {
1625 int mode = ((int[]) ar.result)[0];
1626 if (mode == 0) {
1627 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1628 } else {
1629 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1630 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001631 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001632 notifyRequester(request);
1633 break;
1634 case CMD_GET_CDMA_ROAMING_MODE:
1635 request = (MainThreadRequest) msg.obj;
1636 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1637 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1638 break;
1639 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1640 ar = (AsyncResult) msg.obj;
1641 request = (MainThreadRequest) ar.userObj;
1642 if (ar.exception != null) {
1643 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1644 } else {
1645 request.result = ((int[]) ar.result)[0];
1646 }
1647 notifyRequester(request);
1648 break;
1649 case CMD_SET_CDMA_ROAMING_MODE:
1650 request = (MainThreadRequest) msg.obj;
1651 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1652 int mode = (int) request.argument;
1653 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1654 break;
1655 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1656 ar = (AsyncResult) msg.obj;
1657 request = (MainThreadRequest) ar.userObj;
1658 request.result = ar.exception == null;
1659 notifyRequester(request);
1660 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001661 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1662 request = (MainThreadRequest) msg.obj;
1663 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1664 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1665 break;
1666 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1667 ar = (AsyncResult) msg.obj;
1668 request = (MainThreadRequest) ar.userObj;
1669 if (ar.exception != null) {
1670 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1671 } else {
1672 request.result = ((int[]) ar.result)[0];
1673 }
1674 notifyRequester(request);
1675 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001676 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1677 request = (MainThreadRequest) msg.obj;
1678 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1679 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001680 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1681 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001682 break;
1683 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1684 ar = (AsyncResult) msg.obj;
1685 request = (MainThreadRequest) ar.userObj;
1686 request.result = ar.exception == null;
1687 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001688 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001689 case CMD_GET_ALL_CELL_INFO:
1690 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001691 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001692 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001693 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001694 case EVENT_GET_ALL_CELL_INFO_DONE:
1695 ar = (AsyncResult) msg.obj;
1696 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001697 // If a timeout occurs, the response will be null
1698 request.result = (ar.exception == null && ar.result != null)
1699 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001700 synchronized (request) {
1701 request.notifyAll();
1702 }
1703 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001704 case CMD_REQUEST_CELL_INFO_UPDATE:
1705 request = (MainThreadRequest) msg.obj;
1706 request.phone.requestCellInfoUpdate(request.workSource,
1707 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1708 break;
1709 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1710 ar = (AsyncResult) msg.obj;
1711 request = (MainThreadRequest) ar.userObj;
1712 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1713 try {
1714 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001715 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001716 cb.onError(
1717 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1718 ar.exception.getClass().getName(),
1719 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001720 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001721 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001722 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001723 } else {
1724 // use the result as returned
1725 cb.onCellInfo((List<CellInfo>) ar.result);
1726 }
1727 } catch (RemoteException re) {
1728 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1729 }
1730 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001731 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001732 request = (MainThreadRequest) msg.obj;
1733 WorkSource ws = (WorkSource) request.argument;
1734 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001735 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001736 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001737 }
1738 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001739 ar = (AsyncResult) msg.obj;
1740 request = (MainThreadRequest) ar.userObj;
1741 if (ar.exception == null) {
1742 request.result = ar.result;
1743 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001744 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001745 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001746 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001747 }
1748
1749 synchronized (request) {
1750 request.notifyAll();
1751 }
1752 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001753 }
chen xu6dac5ab2018-10-26 17:39:23 -07001754 case CMD_MODEM_REBOOT:
1755 request = (MainThreadRequest) msg.obj;
1756 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001757 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001758 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001759 case EVENT_CMD_MODEM_REBOOT_DONE:
1760 handleNullReturnEvent(msg, "rebootModem");
1761 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001762 case CMD_REQUEST_ENABLE_MODEM:
1763 request = (MainThreadRequest) msg.obj;
1764 boolean enable = (boolean) request.argument;
1765 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001766 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001767 PhoneConfigurationManager.getInstance()
1768 .enablePhone(request.phone, enable, onCompleted);
1769 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001770 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001771 ar = (AsyncResult) msg.obj;
1772 request = (MainThreadRequest) ar.userObj;
1773 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001774 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001775 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001776 if ((boolean) request.result) {
1777 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1778 updateModemStateMetrics();
1779 } else {
1780 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1781 + ar.exception);
1782 }
1783 notifyRequester(request);
1784 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001785 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001786 case CMD_GET_MODEM_STATUS:
1787 request = (MainThreadRequest) msg.obj;
1788 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1789 PhoneConfigurationManager.getInstance()
1790 .getPhoneStatusFromModem(request.phone, onCompleted);
1791 break;
1792 case EVENT_GET_MODEM_STATUS_DONE:
1793 ar = (AsyncResult) msg.obj;
1794 request = (MainThreadRequest) ar.userObj;
1795 int id = request.phone.getPhoneId();
1796 if (ar.exception == null && ar.result != null) {
1797 request.result = ar.result;
1798 //update the cache as modem status has changed
1799 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1800 (boolean) request.result);
1801 } else {
1802 // Return true if modem status cannot be retrieved. For most cases,
1803 // modem status is on. And for older version modems, GET_MODEM_STATUS
1804 // and disable modem are not supported. Modem is always on.
1805 // TODO: this should be fixed in R to support a third
1806 // status UNKNOWN b/131631629
1807 request.result = true;
1808 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1809 + ar.exception);
1810 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001811 notifyRequester(request);
1812 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001813 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1814 request = (MainThreadRequest) msg.obj;
1815 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1816 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1817 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1818 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1819 break;
1820 }
1821 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1822 ar = (AsyncResult) msg.obj;
1823 request = (MainThreadRequest) ar.userObj;
1824 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1825 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1826 args.second.accept(ar.exception == null);
1827 notifyRequester(request);
1828 break;
1829 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001830 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1831 request = (MainThreadRequest) msg.obj;
1832 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1833 Phone phone = getPhoneFromRequest(request);
1834 if (phone != null) {
1835 phone.getSystemSelectionChannels(onCompleted);
1836 } else {
1837 loge("getSystemSelectionChannels: No phone object");
1838 request.result = new ArrayList<RadioAccessSpecifier>();
1839 notifyRequester(request);
1840 }
1841 break;
1842 }
1843 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1844 ar = (AsyncResult) msg.obj;
1845 request = (MainThreadRequest) ar.userObj;
1846 if (ar.exception == null && ar.result != null) {
1847 request.result = ar.result;
1848 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001849 request.result = new IllegalStateException(
1850 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001851 if (ar.result == null) {
1852 loge("getSystemSelectionChannels: Empty response");
1853 } else {
1854 loge("getSystemSelectionChannels: Unknown exception");
1855 }
1856 }
1857 notifyRequester(request);
1858 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001859 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1860 ar = (AsyncResult) msg.obj;
1861 request = (MainThreadRequest) ar.userObj;
1862 if (ar.exception == null && ar.result != null) {
1863 request.result = ar.result;
1864 } else {
1865 request.result = -1;
1866 loge("Failed to set Forbidden Plmns");
1867 if (ar.result == null) {
1868 loge("setForbidenPlmns: Empty response");
1869 } else if (ar.exception != null) {
1870 loge("setForbiddenPlmns: Exception: " + ar.exception);
1871 request.result = -1;
1872 } else {
1873 loge("setForbiddenPlmns: Unknown exception");
1874 }
1875 }
1876 notifyRequester(request);
1877 break;
1878 case CMD_SET_FORBIDDEN_PLMNS:
1879 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001880 uiccPort = getUiccPortFromRequest(request);
1881 if (uiccPort == null) {
1882 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001883 request.result = -1;
1884 notifyRequester(request);
1885 break;
1886 }
1887 Pair<Integer, List<String>> setFplmnsArgs =
1888 (Pair<Integer, List<String>>) request.argument;
1889 appType = setFplmnsArgs.first;
1890 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001891 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001892 if (uiccApp == null) {
1893 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1894 request.result = -1;
1895 loge("Failed to get UICC App");
1896 notifyRequester(request);
1897 } else {
1898 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1899 ((SIMRecords) uiccApp.getIccRecords())
1900 .setForbiddenPlmns(onCompleted, fplmns);
1901 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001902 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001903 case CMD_ERASE_MODEM_CONFIG:
1904 request = (MainThreadRequest) msg.obj;
1905 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1906 defaultPhone.eraseModemConfig(onCompleted);
1907 break;
1908 case EVENT_ERASE_MODEM_CONFIG_DONE:
1909 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001910 break;
zoey chene02881a2019-12-30 16:11:23 +08001911
Kai Shif70f46f2021-03-03 13:59:46 -08001912 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1913 request = (MainThreadRequest) msg.obj;
1914 request.result = defaultPhone.eraseDataInSharedPreferences();
1915 notifyRequester(request);
1916 break;
1917
zoey chene02881a2019-12-30 16:11:23 +08001918 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1919 request = (MainThreadRequest) msg.obj;
1920 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1921 Pair<String, String> changed = (Pair<String, String>) request.argument;
1922 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1923 changed.first, changed.second, onCompleted);
1924 break;
1925 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1926 ar = (AsyncResult) msg.obj;
1927 request = (MainThreadRequest) ar.userObj;
1928 if (ar.exception == null) {
1929 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001930 // If the operation is successful, update the PIN storage
1931 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1932 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001933 UiccController.getInstance().getPinStorage()
1934 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001935 } else {
1936 request.result = msg.arg1;
1937 }
1938 notifyRequester(request);
1939 break;
1940
Michele Berionne5e411512020-11-13 02:36:59 +00001941 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001942 request = (MainThreadRequest) msg.obj;
1943 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1944 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1945 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1946 enabled.first, enabled.second, onCompleted);
1947 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001948 }
zoey chene02881a2019-12-30 16:11:23 +08001949 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1950 ar = (AsyncResult) msg.obj;
1951 request = (MainThreadRequest) ar.userObj;
1952 if (ar.exception == null) {
1953 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001954 // If the operation is successful, update the PIN storage
1955 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1956 int phoneId = getPhoneFromRequest(request).getPhoneId();
1957 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001958 UiccController.getInstance().getPinStorage()
1959 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001960 } else {
1961 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1962 }
zoey chene02881a2019-12-30 16:11:23 +08001963 } else {
1964 request.result = msg.arg1;
1965 }
Michele Berionne5e411512020-11-13 02:36:59 +00001966
1967
zoey chene02881a2019-12-30 16:11:23 +08001968 notifyRequester(request);
1969 break;
1970
Peter Wangdafb9ac2020-01-15 14:13:38 -08001971 case MSG_NOTIFY_USER_ACTIVITY:
1972 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001973 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001974 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1975 getDefaultPhone().getContext().sendBroadcastAsUser(
1976 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1977 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001978
1979 case CMD_SET_DATA_THROTTLING: {
1980 request = (MainThreadRequest) msg.obj;
1981 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1982 DataThrottlingRequest dataThrottlingRequest =
1983 (DataThrottlingRequest) request.argument;
1984 Phone phone = getPhoneFromRequest(request);
1985 if (phone != null) {
1986 phone.setDataThrottling(onCompleted,
1987 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1988 dataThrottlingRequest.getCompletionDurationMillis());
1989 } else {
1990 loge("setDataThrottling: No phone object");
1991 request.result =
1992 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1993 notifyRequester(request);
1994 }
1995
1996 break;
1997 }
1998 case EVENT_SET_DATA_THROTTLING_DONE:
1999 ar = (AsyncResult) msg.obj;
2000 request = (MainThreadRequest) ar.userObj;
2001
2002 if (ar.exception == null) {
2003 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2004 } else if (ar.exception instanceof CommandException) {
2005 loge("setDataThrottling: CommandException: " + ar.exception);
2006 CommandException.Error error =
2007 ((CommandException) (ar.exception)).getCommandError();
2008
2009 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2010 request.result = TelephonyManager
2011 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2012 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2013 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002014 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2015 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002016 } else {
2017 request.result =
2018 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2019 }
2020 } else {
2021 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2022 }
2023 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2024 notifyRequester(request);
2025 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002026
2027 case CMD_SET_SIM_POWER: {
2028 request = (MainThreadRequest) msg.obj;
2029 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2030 request = (MainThreadRequest) msg.obj;
2031 int stateToSet =
2032 ((Pair<Integer, IIntegerConsumer>)
2033 request.argument).first;
2034 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2035 break;
2036 }
2037 case EVENT_SET_SIM_POWER_DONE: {
2038 ar = (AsyncResult) msg.obj;
2039 request = (MainThreadRequest) ar.userObj;
2040 IIntegerConsumer callback =
2041 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2042 if (ar.exception != null) {
2043 loge("setSimPower exception: " + ar.exception);
2044 int errorCode = TelephonyManager.CallForwardingInfoCallback
2045 .RESULT_ERROR_UNKNOWN;
2046 if (ar.exception instanceof CommandException) {
2047 CommandException.Error error =
2048 ((CommandException) (ar.exception)).getCommandError();
2049 if (error == CommandException.Error.SIM_ERR) {
2050 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2051 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2052 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2053 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2054 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2055 } else {
2056 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2057 }
2058 }
2059 try {
2060 callback.accept(errorCode);
2061 } catch (RemoteException e) {
2062 // Ignore if the remote process is no longer available to call back.
2063 Log.w(LOG_TAG, "setSimPower: callback not available.");
2064 }
2065 } else {
2066 try {
2067 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2068 } catch (RemoteException e) {
2069 // Ignore if the remote process is no longer available to call back.
2070 Log.w(LOG_TAG, "setSimPower: callback not available.");
2071 }
2072 }
2073 break;
2074 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002075 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2076 request = (MainThreadRequest) msg.obj;
2077
2078 final Phone phone = getPhoneFromRequest(request);
2079 if (phone == null || phone.getServiceStateTracker() == null) {
2080 request.result = new IllegalStateException("Phone or SST is null");
2081 notifyRequester(request);
2082 break;
2083 }
2084
2085 Pair<Integer, SignalStrengthUpdateRequest> pair =
2086 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2087 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2088 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002089 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002090 request.subId, pair.first /*callingUid*/,
2091 pair.second /*request*/, onCompleted);
2092 break;
2093 }
2094 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2095 ar = (AsyncResult) msg.obj;
2096 request = (MainThreadRequest) ar.userObj;
2097 // request.result will be the exception of ar if present, true otherwise.
2098 // Be cautious not to leave result null which will wait() forever
2099 request.result = ar.exception != null ? ar.exception : true;
2100 notifyRequester(request);
2101 break;
2102 }
2103 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2104 request = (MainThreadRequest) msg.obj;
2105
2106 Phone phone = getPhoneFromRequest(request);
2107 if (phone == null || phone.getServiceStateTracker() == null) {
2108 request.result = new IllegalStateException("Phone or SST is null");
2109 notifyRequester(request);
2110 break;
2111 }
2112
2113 Pair<Integer, SignalStrengthUpdateRequest> pair =
2114 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2115 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2116 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002117 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002118 request.subId, pair.first /*callingUid*/,
2119 pair.second /*request*/, onCompleted);
2120 break;
2121 }
2122 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2123 ar = (AsyncResult) msg.obj;
2124 request = (MainThreadRequest) ar.userObj;
2125 request.result = ar.exception != null ? ar.exception : true;
2126 notifyRequester(request);
2127 break;
2128 }
Jordan Liu109698e2020-11-24 14:50:34 -08002129
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002130 case CMD_GET_SLICING_CONFIG: {
2131 request = (MainThreadRequest) msg.obj;
2132 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2133 request.phone.getSlicingConfig(onCompleted);
2134 break;
2135 }
2136 case EVENT_GET_SLICING_CONFIG_DONE: {
2137 ar = (AsyncResult) msg.obj;
2138 request = (MainThreadRequest) ar.userObj;
2139 ResultReceiver result = (ResultReceiver) request.argument;
2140
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002141 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002142 Bundle bundle = new Bundle();
2143 int resultCode = 0;
2144 if (ar.exception != null) {
2145 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2146 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002147 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002148 } else if (ar.result == null) {
2149 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002150 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002151 } else {
2152 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002153 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2154 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002155 }
2156
2157 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002158 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002159 }
2160 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2161 result.send(resultCode, bundle);
2162 notifyRequester(request);
2163 break;
2164 }
2165
Sarah Chin71b3a852022-09-28 15:54:19 -07002166 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002167 request = (MainThreadRequest) msg.obj;
2168 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002169 PurchasePremiumCapabilityArgument arg =
2170 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002171 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chin71b3a852022-09-28 15:54:19 -07002172 arg.capability, arg.appName, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002173 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002174 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002175
Sarah Chin71b3a852022-09-28 15:54:19 -07002176 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002177 ar = (AsyncResult) msg.obj;
2178 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002179 PurchasePremiumCapabilityArgument arg =
2180 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002181 try {
2182 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002183 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002184 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002185 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002186 + ", result= "
2187 + TelephonyManager.convertPurchaseResultToString(result));
2188 } catch (RemoteException e) {
2189 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002190 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002191 + " failed: " + e;
2192 if (DBG) log(logStr);
2193 AnomalyReporter.reportAnomaly(
2194 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2195 }
2196 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002197 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002198
Michele Berionne5e411512020-11-13 02:36:59 +00002199 case CMD_PREPARE_UNATTENDED_REBOOT:
2200 request = (MainThreadRequest) msg.obj;
2201 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002202 UiccController.getInstance().getPinStorage()
2203 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002204 notifyRequester(request);
2205 break;
2206
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002207 default:
2208 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2209 break;
2210 }
2211 }
Jake Hambye994d462014-02-03 13:10:13 -08002212
Pengquan Menga1bb6272018-09-06 09:59:22 -07002213 private void notifyRequester(MainThreadRequest request) {
2214 synchronized (request) {
2215 request.notifyAll();
2216 }
2217 }
2218
Jake Hambye994d462014-02-03 13:10:13 -08002219 private void handleNullReturnEvent(Message msg, String command) {
2220 AsyncResult ar = (AsyncResult) msg.obj;
2221 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2222 if (ar.exception == null) {
2223 request.result = true;
2224 } else {
2225 request.result = false;
2226 if (ar.exception instanceof CommandException) {
2227 loge(command + ": CommandException: " + ar.exception);
2228 } else {
2229 loge(command + ": Unknown exception");
2230 }
2231 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002232 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002233 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234 }
2235
2236 /**
2237 * Posts the specified command to be executed on the main thread,
2238 * waits for the request to complete, and returns the result.
2239 * @see #sendRequestAsync
2240 */
2241 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002242 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2243 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002244 }
2245
2246 /**
2247 * Posts the specified command to be executed on the main thread,
2248 * waits for the request to complete, and returns the result.
2249 * @see #sendRequestAsync
2250 */
2251 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2252 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002253 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002254 }
2255
2256 /**
2257 * Posts the specified command to be executed on the main thread,
2258 * waits for the request to complete, and returns the result.
2259 * @see #sendRequestAsync
2260 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002261 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002262 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2263 }
2264
2265 /**
2266 * Posts the specified command to be executed on the main thread,
2267 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2268 * if not timeout or null otherwise.
2269 * @see #sendRequestAsync
2270 */
2271 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2272 long timeoutInMs) {
2273 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002274 }
2275
2276 /**
2277 * Posts the specified command to be executed on the main thread,
2278 * waits for the request to complete, and returns the result.
2279 * @see #sendRequestAsync
2280 */
Nathan Harold92bed182018-10-12 18:16:49 -07002281 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002282 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002283 }
2284
2285 /**
2286 * Posts the specified command to be executed on the main thread,
2287 * waits for the request to complete, and returns the result.
2288 * @see #sendRequestAsync
2289 */
2290 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002291 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2292 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002293 }
2294
2295 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002296 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2297 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2298 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002299 * @see #sendRequestAsync
2300 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002301 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2302 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2304 throw new RuntimeException("This method will deadlock if called from the main thread.");
2305 }
2306
Nathan Harold92bed182018-10-12 18:16:49 -07002307 MainThreadRequest request = null;
2308 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2309 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2310 } else if (phone != null) {
2311 request = new MainThreadRequest(argument, phone, workSource);
2312 } else {
2313 request = new MainThreadRequest(argument, subId, workSource);
2314 }
2315
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316 Message msg = mMainThreadHandler.obtainMessage(command, request);
2317 msg.sendToTarget();
2318
Rambo Wang0f050d82021-02-12 11:43:36 -08002319
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002320 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002321 if (timeoutInMs >= 0) {
2322 // Wait for at least timeoutInMs before returning null request result
2323 long now = SystemClock.elapsedRealtime();
2324 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002325 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002326 try {
2327 request.wait(deadline - now);
2328 } catch (InterruptedException e) {
2329 // Do nothing, go back and check if request is completed or timeout
2330 } finally {
2331 now = SystemClock.elapsedRealtime();
2332 }
2333 }
2334 } else {
2335 // Wait for the request to complete
2336 while (request.result == null) {
2337 try {
2338 request.wait();
2339 } catch (InterruptedException e) {
2340 // Do nothing, go back and wait until the request is complete
2341 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 }
2343 }
2344 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002345 if (request.result == null) {
2346 Log.wtf(LOG_TAG,
2347 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2348 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002349 return request.result;
2350 }
2351
2352 /**
2353 * Asynchronous ("fire and forget") version of sendRequest():
2354 * Posts the specified command to be executed on the main thread, and
2355 * returns immediately.
2356 * @see #sendRequest
2357 */
2358 private void sendRequestAsync(int command) {
2359 mMainThreadHandler.sendEmptyMessage(command);
2360 }
2361
2362 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002363 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002364 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002365 */
2366 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002367 sendRequestAsync(command, argument, null, null);
2368 }
2369
2370 /**
2371 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2372 * @see {@link #sendRequest(int,Object)}
2373 */
2374 private void sendRequestAsync(
2375 int command, Object argument, Phone phone, WorkSource workSource) {
2376 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002377 Message msg = mMainThreadHandler.obtainMessage(command, request);
2378 msg.sendToTarget();
2379 }
2380
2381 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002382 * Initialize the singleton PhoneInterfaceManager instance.
2383 * This is only done once, at startup, from PhoneApp.onCreate().
2384 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002385 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002386 synchronized (PhoneInterfaceManager.class) {
2387 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002388 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002389 } else {
2390 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2391 }
2392 return sInstance;
2393 }
2394 }
2395
2396 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002397 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002398 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002400 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002401 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002402 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002403 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002405 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002406 mTelephonySharedPreferences =
2407 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002408 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002409 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002410 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002411 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002412 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002413 mTelephony2gUpdater = new Telephony2gUpdater(
2414 Executors.newSingleThreadExecutor(), mApp);
2415 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 publish();
2417 }
2418
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002419 private Phone getDefaultPhone() {
2420 Phone thePhone = getPhone(getDefaultSubscription());
2421 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2422 }
2423
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 private void publish() {
2425 if (DBG) log("publish: " + this);
2426
Peter Wangc035ce42020-01-08 21:00:22 -08002427 TelephonyFrameworkInitializer
2428 .getTelephonyServiceManager()
2429 .getTelephonyServiceRegisterer()
2430 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 }
2432
Stuart Scott584921c2015-01-15 17:10:34 -08002433 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002434 if (request.phone != null) {
2435 return request.phone;
2436 } else {
2437 return getPhoneFromSubId(request.subId);
2438 }
2439 }
2440
2441 private Phone getPhoneFromSubId(int subId) {
2442 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2443 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002444 }
2445
Rambo Wange53e07d2022-05-10 13:01:13 -07002446 @Nullable
2447 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002448 Phone phone = getPhoneFromRequest(request);
2449 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002450 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002451 }
2452
Wink Saville36469e72014-06-11 15:17:00 -07002453 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002454 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002455 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002456 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457
Kai Shif70f46f2021-03-03 13:59:46 -08002458 private void sendEraseModemConfig(@NonNull Phone phone) {
2459 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2460 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2461 }
2462
2463 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2464 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2465 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002466 }
2467
Peter Wang44b186e2020-01-13 23:33:09 -08002468 private boolean isImsAvailableOnDevice() {
2469 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2470 if (pm == null) {
2471 // For some reason package manger is not available.. This will fail internally anyway,
2472 // so do not throw error and allow.
2473 return true;
2474 }
2475 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2476 }
2477
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002479 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002480 }
2481
Wink Savilleb564aae2014-10-23 10:18:09 -07002482 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002483 if (DBG) log("dial: " + number);
2484 // No permission check needed here: This is just a wrapper around the
2485 // ACTION_DIAL intent, which is available to any app since it puts up
2486 // the UI before it does anything.
2487
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002488 final long identity = Binder.clearCallingIdentity();
2489 try {
2490 String url = createTelUrl(number);
2491 if (url == null) {
2492 return;
2493 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002494
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002495 // PENDING: should we just silently fail if phone is offhook or ringing?
2496 PhoneConstants.State state = mCM.getState(subId);
2497 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2498 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2499 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2500 mApp.startActivity(intent);
2501 }
2502 } finally {
2503 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002504 }
2505 }
2506
2507 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002508 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002509 }
2510
Wink Savilleb564aae2014-10-23 10:18:09 -07002511 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002512 if (DBG) log("call: " + number);
2513
2514 // This is just a wrapper around the ACTION_CALL intent, but we still
2515 // need to do a permission check since we're calling startActivity()
2516 // from the context of the phone app.
2517 enforceCallPermission();
2518
Jordan Liu1617b712019-07-10 15:06:26 -07002519 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002520 != AppOpsManager.MODE_ALLOWED) {
2521 return;
2522 }
2523
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002524 final long identity = Binder.clearCallingIdentity();
2525 try {
2526 String url = createTelUrl(number);
2527 if (url == null) {
2528 return;
2529 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002530
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002531 boolean isValid = false;
2532 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2533 if (slist != null) {
2534 for (SubscriptionInfo subInfoRecord : slist) {
2535 if (subInfoRecord.getSubscriptionId() == subId) {
2536 isValid = true;
2537 break;
2538 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002539 }
Wink Saville08874612014-08-31 19:19:58 -07002540 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002541 if (!isValid) {
2542 return;
2543 }
Wink Saville08874612014-08-31 19:19:58 -07002544
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002545 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2546 intent.putExtra(SUBSCRIPTION_KEY, subId);
2547 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2548 mApp.startActivity(intent);
2549 } finally {
2550 Binder.restoreCallingIdentity(identity);
2551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002552 }
2553
Wink Savilleb564aae2014-10-23 10:18:09 -07002554 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002555 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002556 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2557 }
2558
Wink Savilleb564aae2014-10-23 10:18:09 -07002559 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002560 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002561 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2562 }
2563
Wink Savilleb564aae2014-10-23 10:18:09 -07002564 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002565 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002566
2567 final long identity = Binder.clearCallingIdentity();
2568 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002569 Phone phone = getPhone(subId);
2570 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002571 checkSimPin.start();
2572 return checkSimPin.unlockSim(null, pin);
2573 } finally {
2574 Binder.restoreCallingIdentity(identity);
2575 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002576 }
2577
Wink Savilleb564aae2014-10-23 10:18:09 -07002578 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002579 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002580
2581 final long identity = Binder.clearCallingIdentity();
2582 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002583 Phone phone = getPhone(subId);
2584 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002585 checkSimPuk.start();
2586 return checkSimPuk.unlockSim(puk, pin);
2587 } finally {
2588 Binder.restoreCallingIdentity(identity);
2589 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002590 }
2591
2592 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002593 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002594 * a synchronous one.
2595 */
2596 private static class UnlockSim extends Thread {
2597
2598 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002599 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002600
2601 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002602 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2603 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002604
2605 // For replies from SimCard interface
2606 private Handler mHandler;
2607
2608 // For async handler to identify request type
2609 private static final int SUPPLY_PIN_COMPLETE = 100;
2610
Michele Berionne5e411512020-11-13 02:36:59 +00002611 UnlockSim(int phoneId, IccCard simCard) {
2612 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002613 mSimCard = simCard;
2614 }
2615
2616 @Override
2617 public void run() {
2618 Looper.prepare();
2619 synchronized (UnlockSim.this) {
2620 mHandler = new Handler() {
2621 @Override
2622 public void handleMessage(Message msg) {
2623 AsyncResult ar = (AsyncResult) msg.obj;
2624 switch (msg.what) {
2625 case SUPPLY_PIN_COMPLETE:
2626 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2627 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002628 mRetryCount = msg.arg1;
2629 if (ar.exception != null) {
2630 if (ar.exception instanceof CommandException &&
2631 ((CommandException)(ar.exception)).getCommandError()
2632 == CommandException.Error.PASSWORD_INCORRECT) {
2633 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002634 } //When UiccCardApp dispose,handle message and return exception
2635 else if (ar.exception instanceof CommandException &&
2636 ((CommandException) (ar.exception)).getCommandError()
2637 == CommandException.Error.ABORTED) {
2638 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002639 } else {
2640 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2641 }
2642 } else {
2643 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2644 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002645 mDone = true;
2646 UnlockSim.this.notifyAll();
2647 }
2648 break;
2649 }
2650 }
2651 };
2652 UnlockSim.this.notifyAll();
2653 }
2654 Looper.loop();
2655 }
2656
2657 /*
2658 * Use PIN or PUK to unlock SIM card
2659 *
2660 * If PUK is null, unlock SIM card with PIN
2661 *
2662 * If PUK is not null, unlock SIM card with PUK and set PIN code
2663 */
Wink Saville9de0f752013-10-22 19:04:03 -07002664 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665
2666 while (mHandler == null) {
2667 try {
2668 wait();
2669 } catch (InterruptedException e) {
2670 Thread.currentThread().interrupt();
2671 }
2672 }
2673 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2674
2675 if (puk == null) {
2676 mSimCard.supplyPin(pin, callback);
2677 } else {
2678 mSimCard.supplyPuk(puk, pin, callback);
2679 }
2680
2681 while (!mDone) {
2682 try {
2683 Log.d(LOG_TAG, "wait for done");
2684 wait();
2685 } catch (InterruptedException e) {
2686 // Restore the interrupted status
2687 Thread.currentThread().interrupt();
2688 }
2689 }
2690 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002691 int[] resultArray = new int[2];
2692 resultArray[0] = mResult;
2693 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002694
2695 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002696 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002697 }
2698
Wink Saville9de0f752013-10-22 19:04:03 -07002699 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 }
2701 }
2702
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002703 /**
2704 * This method has been removed due to privacy and stability concerns.
2705 */
2706 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002707 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002708 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2709 return;
Wink Saville36469e72014-06-11 15:17:00 -07002710 }
2711
Nathan Harold1f889d82020-06-04 17:05:26 -07002712 @Override
2713 public void updateServiceLocationWithPackageName(String callingPackage) {
2714 mApp.getSystemService(AppOpsManager.class)
2715 .checkPackage(Binder.getCallingUid(), callingPackage);
2716
Nathan Haroldf096d982020-11-18 17:18:06 -08002717 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002718 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2719 // Callers targeting S have no business invoking this method.
2720 return;
2721 }
2722
2723 LocationAccessPolicy.LocationPermissionResult locationResult =
2724 LocationAccessPolicy.checkLocationPermission(mApp,
2725 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2726 .setCallingPackage(callingPackage)
2727 .setCallingFeatureId(null)
2728 .setCallingPid(Binder.getCallingPid())
2729 .setCallingUid(Binder.getCallingUid())
2730 .setMethod("updateServiceLocation")
2731 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2732 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2733 .build());
2734 // Apps that lack location permission have no business calling this method;
2735 // however, because no permission was declared in the public API, denials must
2736 // all be "soft".
2737 switch (locationResult) {
2738 case DENIED_HARD: /* fall through */
2739 case DENIED_SOFT:
2740 return;
2741 }
2742
2743 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002744 final long identity = Binder.clearCallingIdentity();
2745 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002746 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002747 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002748 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002749 }
2750 } finally {
2751 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002752 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002753 }
2754
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002755 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002756 @Override
2757 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002758 return isRadioOnWithFeature(callingPackage, null);
2759 }
2760
2761
2762 @Override
2763 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2764 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2765 callingFeatureId);
2766 }
2767
2768 @Deprecated
2769 @Override
2770 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2771 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002772 }
2773
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002774 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002775 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2776 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002777 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002778 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002779 return false;
2780 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002781
2782 final long identity = Binder.clearCallingIdentity();
2783 try {
2784 return isRadioOnForSubscriber(subId);
2785 } finally {
2786 Binder.restoreCallingIdentity(identity);
2787 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002788 }
2789
2790 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002791 final long identity = Binder.clearCallingIdentity();
2792 try {
2793 final Phone phone = getPhone(subId);
2794 if (phone != null) {
2795 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2796 } else {
2797 return false;
2798 }
2799 } finally {
2800 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002801 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002802 }
2803
2804 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002805 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002806 }
Wink Saville36469e72014-06-11 15:17:00 -07002807
Wink Savilleb564aae2014-10-23 10:18:09 -07002808 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002809 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002810
2811 final long identity = Binder.clearCallingIdentity();
2812 try {
2813 final Phone phone = getPhone(subId);
2814 if (phone != null) {
2815 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2816 }
2817 } finally {
2818 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002819 }
Wink Saville36469e72014-06-11 15:17:00 -07002820 }
2821
2822 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002823 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002824 }
2825
Wink Savilleb564aae2014-10-23 10:18:09 -07002826 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002827 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002828
2829 final long identity = Binder.clearCallingIdentity();
2830 try {
2831 final Phone phone = getPhone(subId);
2832 if (phone == null) {
2833 return false;
2834 }
2835 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2836 toggleRadioOnOffForSubscriber(subId);
2837 }
2838 return true;
2839 } finally {
2840 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002841 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002842 }
Wink Saville36469e72014-06-11 15:17:00 -07002843
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002844 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002845 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002846 /*
2847 * If any of the Radios are available, it will need to be
2848 * shutdown. So return true if any Radio is available.
2849 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002850 final long identity = Binder.clearCallingIdentity();
2851 try {
2852 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2853 Phone phone = PhoneFactory.getPhone(i);
2854 if (phone != null && phone.isRadioAvailable()) return true;
2855 }
2856 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2857 return false;
2858 } finally {
2859 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002860 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002861 }
2862
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002863 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002864 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865 enforceModifyPermission();
2866
2867 final long identity = Binder.clearCallingIdentity();
2868 try {
2869 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2870 logv("Shutting down Phone " + i);
2871 shutdownRadioUsingPhoneId(i);
2872 }
2873 } finally {
2874 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002875 }
2876 }
2877
2878 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002879 Phone phone = PhoneFactory.getPhone(phoneId);
2880 if (phone != null && phone.isRadioAvailable()) {
2881 phone.shutdownRadio();
2882 }
2883 }
2884
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002885 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002886 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002887
2888 final long identity = Binder.clearCallingIdentity();
2889 try {
2890 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2891 if (defaultPhone != null) {
2892 defaultPhone.setRadioPower(turnOn);
2893 return true;
2894 } else {
2895 loge("There's no default phone.");
2896 return false;
2897 }
2898 } finally {
2899 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002900 }
Wink Saville36469e72014-06-11 15:17:00 -07002901 }
2902
Wink Savilleb564aae2014-10-23 10:18:09 -07002903 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002904 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905
2906 final long identity = Binder.clearCallingIdentity();
2907 try {
2908 final Phone phone = getPhone(subId);
2909 if (phone != null) {
2910 phone.setRadioPower(turnOn);
2911 return true;
2912 } else {
2913 return false;
2914 }
2915 } finally {
2916 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002917 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002918 }
2919
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002920 /**
2921 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2922 * no reason to power it off. When any of the voters want to power it off, it will be turned
2923 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2924 * powering it off, and these radio off votes will be cleared.
2925 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
2926 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
2927 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
2928 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
2929 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
2930 * check its vote.
2931 *
2932 * @param subId The subscription ID.
2933 * @param reason The reason for powering off radio.
2934 * @return true on success and false on failure.
2935 */
2936 public boolean requestRadioPowerOffForReason(int subId,
2937 @TelephonyManager.RadioPowerReason int reason) {
2938 enforceModifyPermission();
2939
2940 final long identity = Binder.clearCallingIdentity();
2941 try {
2942 final Phone phone = getPhone(subId);
2943 if (phone != null) {
2944 phone.setRadioPowerForReason(false, reason);
2945 return true;
2946 } else {
2947 return false;
2948 }
2949 } finally {
2950 Binder.restoreCallingIdentity(identity);
2951 }
2952 }
2953
2954 /**
2955 * Remove the vote on powering off the radio for a reason, as requested by
2956 * {@link requestRadioPowerOffForReason}.
2957 *
2958 * @param subId The subscription ID.
2959 * @param reason The reason for powering off radio.
2960 * @return true on success and false on failure.
2961 */
2962 public boolean clearRadioPowerOffForReason(int subId,
2963 @TelephonyManager.RadioPowerReason int reason) {
2964 enforceModifyPermission();
2965
2966 final long identity = Binder.clearCallingIdentity();
2967 try {
2968 final Phone phone = getPhone(subId);
2969 if (phone != null) {
2970 phone.setRadioPowerForReason(true, reason);
2971 return true;
2972 } else {
2973 return false;
2974 }
2975 } finally {
2976 Binder.restoreCallingIdentity(identity);
2977 }
2978 }
2979
2980 /**
2981 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
2982 *
2983 * @param subId The subscription ID.
2984 * @param callingPackage The package making the call.
2985 * @param callingFeatureId The feature in the package.
2986 * @return List of reasons for powering off radio.
2987 */
2988 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
2989 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
2990
2991 final long identity = Binder.clearCallingIdentity();
2992 List result = new ArrayList();
2993 try {
2994 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
2995 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
2996 return result;
2997 }
2998
2999 final Phone phone = getPhone(subId);
3000 if (phone != null) {
3001 result.addAll(phone.getRadioPowerOffReasons());
3002 }
3003 } finally {
3004 Binder.restoreCallingIdentity(identity);
3005 }
3006 return result;
3007 }
3008
Wink Saville36469e72014-06-11 15:17:00 -07003009 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003010 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003011 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003012 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003013
3014 final long identity = Binder.clearCallingIdentity();
3015 try {
Jack Yu285100e2022-12-02 22:48:35 -08003016 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003017 final Phone phone = getPhone(subId);
3018 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003019 phone.getDataSettingsManager().setDataEnabled(
3020 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021 return true;
3022 } else {
3023 return false;
3024 }
3025 } finally {
3026 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003028 }
3029
Wink Saville36469e72014-06-11 15:17:00 -07003030 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003031 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003032 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003033 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003034
3035 final long identity = Binder.clearCallingIdentity();
3036 try {
Jack Yu285100e2022-12-02 22:48:35 -08003037 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003038 final Phone phone = getPhone(subId);
3039 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003040 phone.getDataSettingsManager().setDataEnabled(
3041 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003042 return true;
3043 } else {
3044 return false;
3045 }
3046 } finally {
3047 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003048 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003049 }
3050
Sanket Padawe356d7632015-06-22 14:03:32 -07003051 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003052 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003053 final long identity = Binder.clearCallingIdentity();
3054 try {
3055 final Phone phone = getPhone(subId);
3056 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003057 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003058 } else {
3059 return false;
3060 }
3061 } finally {
3062 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003063 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003064 }
3065
3066 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003067 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003068 }
3069
pkanwarae03a6b2016-11-06 20:37:09 -08003070 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003071 enforceCallPermission();
3072
3073 final long identity = Binder.clearCallingIdentity();
3074 try {
3075 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3076 return;
3077 }
3078 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3079 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3080 } finally {
3081 Binder.restoreCallingIdentity(identity);
3082 }
pkanwar32d516d2016-10-14 19:37:38 -07003083 };
3084
Wink Savilleb564aae2014-10-23 10:18:09 -07003085 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003086 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003087
3088 final long identity = Binder.clearCallingIdentity();
3089 try {
3090 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3091 return false;
3092 }
3093 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3094 } finally {
3095 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003096 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003097 }
3098
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003099 /**
3100 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3101 * tag on getCallState Binder call.
3102 */
3103 @Deprecated
3104 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003105 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003106 if (CompatChanges.isChangeEnabled(
3107 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3108 Binder.getCallingUid())) {
3109 // Do not allow this API to be called on API version 31+, it should only be
3110 // called on old apps using this Binder call directly.
3111 throw new SecurityException("This method can only be used for applications "
3112 + "targeting API version 30 or less.");
3113 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003114 final long identity = Binder.clearCallingIdentity();
3115 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003116 Phone phone = getPhone(getDefaultSubscription());
3117 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3118 PhoneConstantConversions.convertCallState(phone.getState());
3119 } finally {
3120 Binder.restoreCallingIdentity(identity);
3121 }
3122 }
3123
3124 @Override
3125 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3126 if (CompatChanges.isChangeEnabled(
3127 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3128 Binder.getCallingUid())) {
3129 // Check READ_PHONE_STATE for API version 31+
3130 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3131 featureId, "getCallStateForSubscription")) {
3132 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3133 + "targeting API level 31+.");
3134 }
3135 }
3136 final long identity = Binder.clearCallingIdentity();
3137 try {
3138 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003139 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3140 PhoneConstantConversions.convertCallState(phone.getState());
3141 } finally {
3142 Binder.restoreCallingIdentity(identity);
3143 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003144 }
3145
Sanket Padawe356d7632015-06-22 14:03:32 -07003146 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003147 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003148 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003149 }
3150
3151 @Override
3152 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003153 final long identity = Binder.clearCallingIdentity();
3154 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003155 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003156 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003157 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003158 } else {
3159 return PhoneConstantConversions.convertDataState(
3160 PhoneConstants.DataState.DISCONNECTED);
3161 }
3162 } finally {
3163 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003164 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003165 }
3166
Sanket Padawe356d7632015-06-22 14:03:32 -07003167 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003168 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003169 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003170 }
3171
3172 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003173 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003174 final long identity = Binder.clearCallingIdentity();
3175 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003176 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003177 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003178 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003179 } else {
3180 return TelephonyManager.DATA_ACTIVITY_NONE;
3181 }
3182 } finally {
3183 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003184 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003185 }
3186
3187 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003188 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003189 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003190 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003191
3192 LocationAccessPolicy.LocationPermissionResult locationResult =
3193 LocationAccessPolicy.checkLocationPermission(mApp,
3194 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3195 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003196 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003197 .setCallingPid(Binder.getCallingPid())
3198 .setCallingUid(Binder.getCallingUid())
3199 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003200 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003201 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3202 .build());
3203 switch (locationResult) {
3204 case DENIED_HARD:
3205 throw new SecurityException("Not allowed to access cell location");
3206 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003207 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3208 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003209 }
3210
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003211 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212 final long identity = Binder.clearCallingIdentity();
3213 try {
3214 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003215 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003216 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003217 } finally {
3218 Binder.restoreCallingIdentity(identity);
3219 }
Svetoslav64fad262015-04-14 14:35:21 -07003220 }
3221
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003222 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003223 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003224 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3225 // registered cell info, so return a NULL country instead.
3226 final long identity = Binder.clearCallingIdentity();
3227 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003228 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3229 // Get default phone in this case.
3230 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3231 }
Jack Yu285100e2022-12-02 22:48:35 -08003232 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003233 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003234 if (phone == null) return "";
3235 ServiceStateTracker sst = phone.getServiceStateTracker();
3236 if (sst == null) return "";
3237 LocaleTracker lt = sst.getLocaleTracker();
3238 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003239 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003240 } finally {
3241 Binder.restoreCallingIdentity(identity);
3242 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003243 }
3244
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003245 /**
3246 * This method was removed due to potential issues caused by performing partial
3247 * updates of service state, and lack of a credible use case.
3248 *
3249 * This has the ability to break the telephony implementation by disabling notification of
3250 * changes in device connectivity. DO NOT USE THIS!
3251 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003252 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003253 public void enableLocationUpdates() {
3254 mApp.enforceCallingOrSelfPermission(
3255 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003256 }
3257
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003258 /**
3259 * This method was removed due to potential issues caused by performing partial
3260 * updates of service state, and lack of a credible use case.
3261 *
3262 * This has the ability to break the telephony implementation by disabling notification of
3263 * changes in device connectivity. DO NOT USE THIS!
3264 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003265 @Override
3266 public void disableLocationUpdates() {
3267 mApp.enforceCallingOrSelfPermission(
3268 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003269 }
3270
3271 @Override
3272 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003273 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3274 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003275 try {
3276 mApp.getSystemService(AppOpsManager.class)
3277 .checkPackage(Binder.getCallingUid(), callingPackage);
3278 } catch (SecurityException e) {
3279 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3280 throw e;
3281 }
3282
Nathan Haroldf096d982020-11-18 17:18:06 -08003283 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003284 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3285 throw new SecurityException(
3286 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3287 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003288
Jordan Liu1617b712019-07-10 15:06:26 -07003289 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003290 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3291 return null;
3292 }
Svetoslav64fad262015-04-14 14:35:21 -07003293
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003294 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003295
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003296 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003297 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003298
Nathan Haroldf180aac2018-06-01 18:43:55 -07003299 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3300 for (CellInfo ci : info) {
3301 if (ci instanceof CellInfoGsm) {
3302 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3303 } else if (ci instanceof CellInfoWcdma) {
3304 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3305 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003306 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003307 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003308 }
3309
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003310 private List<CellInfo> getCachedCellInfo() {
3311 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3312 for (Phone phone : PhoneFactory.getPhones()) {
3313 List<CellInfo> info = phone.getAllCellInfo();
3314 if (info != null) cellInfos.addAll(info);
3315 }
3316 return cellInfos;
3317 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003318
3319 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003320 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003321 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003322 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003323
3324 LocationAccessPolicy.LocationPermissionResult locationResult =
3325 LocationAccessPolicy.checkLocationPermission(mApp,
3326 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3327 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003328 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003329 .setCallingPid(Binder.getCallingPid())
3330 .setCallingUid(Binder.getCallingUid())
3331 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003332 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003333 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3334 .build());
3335 switch (locationResult) {
3336 case DENIED_HARD:
3337 throw new SecurityException("Not allowed to access cell info");
3338 case DENIED_SOFT:
3339 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003340 }
3341
Nathan Haroldf096d982020-11-18 17:18:06 -08003342 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003343 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3344 return getCachedCellInfo();
3345 }
3346
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003347 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003348 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003349 final long identity = Binder.clearCallingIdentity();
3350 try {
3351 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3352 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003353 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003354 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003355 if (info != null) cellInfos.addAll(info);
3356 }
3357 return cellInfos;
3358 } finally {
3359 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003360 }
3361 }
3362
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003363 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003364 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3365 String callingFeatureId) {
3366 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3367 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003368 }
3369
3370 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003371 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3372 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003373 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003374 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003375 }
3376
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003377 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3378 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003379 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003380 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003381
3382 LocationAccessPolicy.LocationPermissionResult locationResult =
3383 LocationAccessPolicy.checkLocationPermission(mApp,
3384 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3385 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003386 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003387 .setCallingPid(Binder.getCallingPid())
3388 .setCallingUid(Binder.getCallingUid())
3389 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003390 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3391 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003392 .build());
3393 switch (locationResult) {
3394 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003395 if (TelephonyPermissions
3396 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003397 // Safetynet logging for b/154934934
3398 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3399 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003400 throw new SecurityException("Not allowed to access cell info");
3401 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003402 if (TelephonyPermissions
3403 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003404 // Safetynet logging for b/154934934
3405 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3406 }
Nathan Harold5320c422019-05-09 10:26:08 -07003407 try {
3408 cb.onCellInfo(new ArrayList<CellInfo>());
3409 } catch (RemoteException re) {
3410 // Drop without consequences
3411 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003412 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003413 }
3414
Nathan Harolda939a962019-05-09 10:13:47 -07003415
3416 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003417 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3418
3419 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3420 }
3421
3422 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003423 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003424 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003425 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003426
3427 final long identity = Binder.clearCallingIdentity();
3428 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003429 Phone phone = getPhone(subId);
3430 if (phone == null) {
3431 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3432 } else {
3433 phone.setCellInfoListRate(rateInMillis, workSource);
3434 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003435 } finally {
3436 Binder.restoreCallingIdentity(identity);
3437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003438 }
3439
Shishir Agrawala9f32182016-04-12 12:00:16 -07003440 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003441 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003442 Phone phone = PhoneFactory.getPhone(slotIndex);
3443 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003444 return null;
3445 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003446 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003447 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003448 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003449 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003450 return null;
3451 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003452
3453 final long identity = Binder.clearCallingIdentity();
3454 try {
3455 return phone.getImei();
3456 } finally {
3457 Binder.restoreCallingIdentity(identity);
3458 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003459 }
3460
3461 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003462 public String getTypeAllocationCodeForSlot(int slotIndex) {
3463 Phone phone = PhoneFactory.getPhone(slotIndex);
3464 String tac = null;
3465 if (phone != null) {
3466 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003467 try {
3468 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3469 } catch (IndexOutOfBoundsException e) {
3470 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3471 return null;
3472 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003473 }
3474 return tac;
3475 }
3476
3477 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003478 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003479 try {
3480 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3481 } catch (SecurityException se) {
3482 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3483 throw new SecurityException("Package " + callingPackage + " does not belong to "
3484 + Binder.getCallingUid());
3485 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003486 Phone phone = PhoneFactory.getPhone(slotIndex);
3487 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003488 return null;
3489 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003490
Jeff Davidson913390f2018-02-23 17:11:49 -08003491 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003492 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003493 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003494 return null;
3495 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003496
3497 final long identity = Binder.clearCallingIdentity();
3498 try {
3499 return phone.getMeid();
3500 } finally {
3501 Binder.restoreCallingIdentity(identity);
3502 }
Jack Yu2af8d712017-03-15 17:14:14 -07003503 }
3504
3505 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003506 public String getManufacturerCodeForSlot(int slotIndex) {
3507 Phone phone = PhoneFactory.getPhone(slotIndex);
3508 String manufacturerCode = null;
3509 if (phone != null) {
3510 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003511 try {
3512 manufacturerCode =
3513 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3514 } catch (IndexOutOfBoundsException e) {
3515 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3516 return null;
3517 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003518 }
3519 return manufacturerCode;
3520 }
3521
3522 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003523 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3524 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003525 Phone phone = PhoneFactory.getPhone(slotIndex);
3526 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003527 return null;
3528 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003529 int subId = phone.getSubId();
3530 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003531 mApp, subId, callingPackage, callingFeatureId,
3532 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003533 return null;
3534 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003535
3536 final long identity = Binder.clearCallingIdentity();
3537 try {
3538 return phone.getDeviceSvn();
3539 } finally {
3540 Binder.restoreCallingIdentity(identity);
3541 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003542 }
3543
fionaxu43304da2017-11-27 22:51:16 -08003544 @Override
3545 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003546 final long identity = Binder.clearCallingIdentity();
3547 try {
3548 final Phone phone = getPhone(subId);
3549 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3550 } finally {
3551 Binder.restoreCallingIdentity(identity);
3552 }
fionaxu43304da2017-11-27 22:51:16 -08003553 }
3554
3555 @Override
3556 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003557 final long identity = Binder.clearCallingIdentity();
3558 try {
3559 final Phone phone = getPhone(subId);
3560 return phone == null ? null : phone.getCarrierName();
3561 } finally {
3562 Binder.restoreCallingIdentity(identity);
3563 }
fionaxu43304da2017-11-27 22:51:16 -08003564 }
3565
calvinpanffe225e2018-11-01 19:43:06 +08003566 @Override
chen xu0026ca62019-03-06 15:28:50 -08003567 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 final Phone phone = getPhone(subId);
3571 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003572 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003573 } finally {
3574 Binder.restoreCallingIdentity(identity);
3575 }
3576 }
3577
3578 @Override
chen xu0026ca62019-03-06 15:28:50 -08003579 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003580 final long identity = Binder.clearCallingIdentity();
3581 try {
3582 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003583 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003584 } finally {
3585 Binder.restoreCallingIdentity(identity);
3586 }
3587 }
3588
chen xu651eec72018-11-11 19:03:44 -08003589 @Override
chen xu864e11c2018-12-06 22:10:03 -08003590 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3591 if (!isSubscriptionMccMnc) {
3592 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3593 }
chen xu651eec72018-11-11 19:03:44 -08003594 final Phone phone = PhoneFactory.getPhone(slotIndex);
3595 if (phone == null) {
3596 return TelephonyManager.UNKNOWN_CARRIER_ID;
3597 }
3598 final long identity = Binder.clearCallingIdentity();
3599 try {
3600 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3601 } finally {
3602 Binder.restoreCallingIdentity(identity);
3603 }
3604 }
3605
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003606 //
3607 // Internal helper methods.
3608 //
3609
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003610 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003611 * Make sure the caller is the calling package itself
3612 *
3613 * @throws SecurityException if the caller is not the calling package
3614 */
3615 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3616 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003617 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3618 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003619 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003620 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003621 } catch (PackageManager.NameNotFoundException e) {
3622 // packageUid is -1
3623 }
3624 if (packageUid != callingUid) {
3625 throw new SecurityException(message + ": Package " + callingPackage
3626 + " does not belong to " + callingUid);
3627 }
3628 }
3629
3630 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003631 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3632 *
3633 * @throws SecurityException if the caller does not have the required permission
3634 */
3635 private void enforceModifyPermission() {
3636 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3637 }
3638
Shuo Qian3b6ee772019-11-13 17:43:31 -08003639 private void enforceActiveEmergencySessionPermission() {
3640 mApp.enforceCallingOrSelfPermission(
3641 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3642 }
3643
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003644 /**
3645 * Make sure the caller has the CALL_PHONE permission.
3646 *
3647 * @throws SecurityException if the caller does not have the required permission
3648 */
3649 private void enforceCallPermission() {
3650 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3651 }
3652
paulhu5a773602019-08-23 19:17:33 +08003653 private void enforceSettingsPermission() {
3654 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003655 }
3656
Michele Berionne5e411512020-11-13 02:36:59 +00003657 private void enforceRebootPermission() {
3658 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3659 }
3660
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003661 private String createTelUrl(String number) {
3662 if (TextUtils.isEmpty(number)) {
3663 return null;
3664 }
3665
Jake Hambye994d462014-02-03 13:10:13 -08003666 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003667 }
3668
Ihab Awadf9e92732013-12-05 18:02:52 -08003669 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003670 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3671 }
3672
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003673 private static void logv(String msg) {
3674 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3675 }
3676
Ihab Awadf9e92732013-12-05 18:02:52 -08003677 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003678 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3679 }
3680
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003681 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003682 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003683 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003684 }
3685
Sanket Padawe356d7632015-06-22 14:03:32 -07003686 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003687 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003688 final long identity = Binder.clearCallingIdentity();
3689 try {
3690 final Phone phone = PhoneFactory.getPhone(slotIndex);
3691 if (phone == null) {
3692 return PhoneConstants.PHONE_TYPE_NONE;
3693 } else {
3694 return phone.getPhoneType();
3695 }
3696 } finally {
3697 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003699 }
3700
3701 /**
3702 * Returns the CDMA ERI icon index to display
3703 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003704 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003705 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3706 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3707 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003708 }
3709
Sanket Padawe356d7632015-06-22 14:03:32 -07003710 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003711 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3712 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003713 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003714 mApp, subId, callingPackage, callingFeatureId,
3715 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003716 return -1;
3717 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003718
3719 final long identity = Binder.clearCallingIdentity();
3720 try {
3721 final Phone phone = getPhone(subId);
3722 if (phone != null) {
3723 return phone.getCdmaEriIconIndex();
3724 } else {
3725 return -1;
3726 }
3727 } finally {
3728 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003729 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003730 }
3731
3732 /**
3733 * Returns the CDMA ERI icon mode,
3734 * 0 - ON
3735 * 1 - FLASHING
3736 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003737 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003738 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3739 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3740 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003741 }
3742
Sanket Padawe356d7632015-06-22 14:03:32 -07003743 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003744 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3745 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003746 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003747 mApp, subId, callingPackage, callingFeatureId,
3748 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003749 return -1;
3750 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003751
3752 final long identity = Binder.clearCallingIdentity();
3753 try {
3754 final Phone phone = getPhone(subId);
3755 if (phone != null) {
3756 return phone.getCdmaEriIconMode();
3757 } else {
3758 return -1;
3759 }
3760 } finally {
3761 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003762 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003763 }
3764
3765 /**
3766 * Returns the CDMA ERI text,
3767 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003768 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003769 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3770 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3771 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003772 }
3773
Sanket Padawe356d7632015-06-22 14:03:32 -07003774 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003775 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3776 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003777 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003778 mApp, subId, callingPackage, callingFeatureId,
3779 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003780 return null;
3781 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003782
3783 final long identity = Binder.clearCallingIdentity();
3784 try {
3785 final Phone phone = getPhone(subId);
3786 if (phone != null) {
3787 return phone.getCdmaEriText();
3788 } else {
3789 return null;
3790 }
3791 } finally {
3792 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003793 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003794 }
3795
3796 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003797 * Returns the CDMA MDN.
3798 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003799 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003800 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003801 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3802 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003803
3804 final long identity = Binder.clearCallingIdentity();
3805 try {
3806 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003807 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003808 return phone.getLine1Number();
3809 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003810 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003811 return null;
3812 }
3813 } finally {
3814 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003815 }
3816 }
3817
3818 /**
3819 * Returns the CDMA MIN.
3820 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003821 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003822 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3824 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003825
3826 final long identity = Binder.clearCallingIdentity();
3827 try {
3828 final Phone phone = getPhone(subId);
3829 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3830 return phone.getCdmaMin();
3831 } else {
3832 return null;
3833 }
3834 } finally {
3835 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003836 }
3837 }
3838
Hall Liud892bec2018-11-30 14:51:45 -08003839 @Override
3840 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3841 INumberVerificationCallback callback, String callingPackage) {
3842 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3843 != PERMISSION_GRANTED) {
3844 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3845 }
3846 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3847
3848 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3849 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003850 throw new SecurityException("Calling package must be configured in the device config: "
3851 + "calling package: " + callingPackage
3852 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003853 }
3854
3855 if (range == null) {
3856 throw new NullPointerException("Range must be non-null");
3857 }
3858
3859 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003860 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003861
3862 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3863 }
3864
Junda Liuca05d5d2014-08-14 22:36:34 -07003865 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003866 * Returns true if CDMA provisioning needs to run.
3867 */
3868 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003869 final long identity = Binder.clearCallingIdentity();
3870 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003871 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003872 } finally {
3873 Binder.restoreCallingIdentity(identity);
3874 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003875 }
3876
3877 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003878 * Sets the voice mail number of a given subId.
3879 */
3880 @Override
3881 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003882 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3883 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003884
3885 final long identity = Binder.clearCallingIdentity();
3886 try {
3887 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3888 new Pair<String, String>(alphaTag, number), new Integer(subId));
3889 return success;
3890 } finally {
3891 Binder.restoreCallingIdentity(identity);
3892 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003893 }
3894
Ta-wei Yen87c49842016-05-13 21:19:52 -07003895 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003896 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3897 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003898 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3899 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003900 if (!TextUtils.equals(callingPackage, systemDialer)) {
3901 throw new SecurityException("caller must be system dialer");
3902 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003903
3904 final long identity = Binder.clearCallingIdentity();
3905 try {
3906 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3907 if (phoneAccountHandle == null) {
3908 return null;
3909 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003910 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003911 } finally {
3912 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003913 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003914 }
3915
3916 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003917 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3918 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003919 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003920 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003921 mApp, subId, callingPackage, callingFeatureId,
3922 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003923 return null;
3924 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003925
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003926 final long identity = Binder.clearCallingIdentity();
3927 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003928 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003929 } finally {
3930 Binder.restoreCallingIdentity(identity);
3931 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003932 }
3933
3934 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003935 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3936 VisualVoicemailSmsFilterSettings settings) {
3937 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003938
3939 final long identity = Binder.clearCallingIdentity();
3940 try {
3941 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003942 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003943 } finally {
3944 Binder.restoreCallingIdentity(identity);
3945 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003946 }
3947
3948 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003949 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3950 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003951
3952 final long identity = Binder.clearCallingIdentity();
3953 try {
3954 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003955 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003956 } finally {
3957 Binder.restoreCallingIdentity(identity);
3958 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003959 }
3960
3961 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003962 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3963 String callingPackage, int subId) {
3964 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003965
3966 final long identity = Binder.clearCallingIdentity();
3967 try {
3968 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003969 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003970 } finally {
3971 Binder.restoreCallingIdentity(identity);
3972 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003973 }
3974
3975 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003976 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003977 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003978
3979 final long identity = Binder.clearCallingIdentity();
3980 try {
3981 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003982 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003983 } finally {
3984 Binder.restoreCallingIdentity(identity);
3985 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003986 }
3987
3988 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003989 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3990 String callingAttributionTag, int subId, String number, int port, String text,
3991 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003992 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003993 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003994 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003995 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003996 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3997 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003998 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003999
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004000 /**
fionaxu0152e512016-11-14 13:36:14 -08004001 * Sets the voice activation state of a given subId.
4002 */
4003 @Override
4004 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004005 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4006 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004007
4008 final long identity = Binder.clearCallingIdentity();
4009 try {
4010 final Phone phone = getPhone(subId);
4011 if (phone != null) {
4012 phone.setVoiceActivationState(activationState);
4013 } else {
4014 loge("setVoiceActivationState fails with invalid subId: " + subId);
4015 }
4016 } finally {
4017 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004018 }
4019 }
4020
4021 /**
4022 * Sets the data activation state of a given subId.
4023 */
4024 @Override
4025 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4027 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004028
4029 final long identity = Binder.clearCallingIdentity();
4030 try {
4031 final Phone phone = getPhone(subId);
4032 if (phone != null) {
4033 phone.setDataActivationState(activationState);
4034 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004035 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004036 }
4037 } finally {
4038 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004039 }
4040 }
4041
4042 /**
4043 * Returns the voice activation state of a given subId.
4044 */
4045 @Override
4046 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004047 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004048
fionaxu0152e512016-11-14 13:36:14 -08004049 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004050 final long identity = Binder.clearCallingIdentity();
4051 try {
4052 if (phone != null) {
4053 return phone.getVoiceActivationState();
4054 } else {
4055 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4056 }
4057 } finally {
4058 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004059 }
4060 }
4061
4062 /**
4063 * Returns the data activation state of a given subId.
4064 */
4065 @Override
4066 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004067 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004068
fionaxu0152e512016-11-14 13:36:14 -08004069 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004070 final long identity = Binder.clearCallingIdentity();
4071 try {
4072 if (phone != null) {
4073 return phone.getDataActivationState();
4074 } else {
4075 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4076 }
4077 } finally {
4078 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004079 }
4080 }
4081
4082 /**
Wink Saville36469e72014-06-11 15:17:00 -07004083 * Returns the unread count of voicemails for a subId
4084 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004085 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004086 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4087 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004088 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004089 mApp, subId, callingPackage, callingFeatureId,
4090 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004091 return 0;
4092 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004093 final long identity = Binder.clearCallingIdentity();
4094 try {
4095 final Phone phone = getPhone(subId);
4096 if (phone != null) {
4097 return phone.getVoiceMessageCount();
4098 } else {
4099 return 0;
4100 }
4101 } finally {
4102 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004103 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004104 }
4105
4106 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004107 * returns true, if the device is in a state where both voice and data
4108 * are supported simultaneously. This can change based on location or network condition.
4109 */
4110 @Override
4111 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004112 final long identity = Binder.clearCallingIdentity();
4113 try {
4114 final Phone phone = getPhone(subId);
4115 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4116 } finally {
4117 Binder.restoreCallingIdentity(identity);
4118 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004119 }
4120
4121 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004122 * Send the dialer code if called from the current default dialer or the caller has
4123 * carrier privilege.
4124 * @param inputCode The dialer code to send
4125 */
4126 @Override
4127 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004128 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004129 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004130 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4131 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004132 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004133 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004134 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004135 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004136
4137 final long identity = Binder.clearCallingIdentity();
4138 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004139 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004140 } finally {
4141 Binder.restoreCallingIdentity(identity);
4142 }
fionaxu235cc5e2017-03-06 22:25:57 -08004143 }
4144
Pengquan Menga1bb6272018-09-06 09:59:22 -07004145 @Override
4146 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004147 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004148 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004149 mApp, subId, "getNetworkSelectionMode");
4150 final long identity = Binder.clearCallingIdentity();
4151 try {
4152 if (!isActiveSubscription(subId)) {
4153 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4154 }
4155 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4156 } finally {
4157 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004158 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004159 }
4160
Brad Ebinger35c841c2018-10-01 10:40:55 -07004161 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004162 public boolean isInEmergencySmsMode() {
4163 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4164 final long identity = Binder.clearCallingIdentity();
4165 try {
4166 for (Phone phone : PhoneFactory.getPhones()) {
4167 if (phone.isInEmergencySmsMode()) {
4168 return true;
4169 }
4170 }
4171 } finally {
4172 Binder.restoreCallingIdentity(identity);
4173 }
4174 return false;
4175 }
4176
shilu366312e2019-12-17 09:28:10 -08004177 /**
4178 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4179 * @param subId The subscription to use to check the configuration.
4180 * @param c The callback that will be used to send the result.
4181 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004182 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004183 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4184 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004185 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004186 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004187
4188 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4189 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4190 "IMS not available on device.");
4191 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004192 final long token = Binder.clearCallingIdentity();
4193 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004194 int slotId = getSlotIndexOrException(subId);
4195 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004196
4197 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4198 if (controller != null) {
4199 ImsManager imsManager = controller.getImsManager(subId);
4200 if (imsManager != null) {
4201 imsManager.addRegistrationCallbackForSubscription(c, subId);
4202 } else {
4203 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4204 }
4205 } else {
4206 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4207 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004208 } catch (ImsException e) {
4209 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004210 } finally {
4211 Binder.restoreCallingIdentity(token);
4212 }
4213 }
4214
shilu366312e2019-12-17 09:28:10 -08004215 /**
4216 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4217 * @param subId The subscription to use to check the configuration.
4218 * @param c The callback that will be used to send the result.
4219 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004220 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004221 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004222 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004223 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004224 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4225 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4226 }
Meng Wangafbc5852019-09-19 17:37:13 -07004227 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004228
Meng Wangafbc5852019-09-19 17:37:13 -07004229 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004230 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4231 if (controller != null) {
4232 ImsManager imsManager = controller.getImsManager(subId);
4233 if (imsManager != null) {
4234 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4235 } else {
4236 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4237 + "is inactive, ignoring unregister.");
4238 // If the ImsManager is not valid, just return, since the callback
4239 // will already have been removed internally.
4240 }
4241 }
Meng Wangafbc5852019-09-19 17:37:13 -07004242 } finally {
4243 Binder.restoreCallingIdentity(token);
4244 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004245 }
4246
Brad Ebingera34a6c22019-10-22 17:36:18 -07004247 /**
4248 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4249 */
4250 @Override
4251 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4252 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4253 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4254 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4255 "IMS not available on device.");
4256 }
4257 final long token = Binder.clearCallingIdentity();
4258 try {
4259 Phone phone = getPhone(subId);
4260 if (phone == null) {
4261 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4262 + subId + "'");
4263 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4264 }
4265 phone.getImsRegistrationState(regState -> {
4266 try {
4267 consumer.accept((regState == null)
4268 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4269 } catch (RemoteException e) {
4270 // Ignore if the remote process is no longer available to call back.
4271 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4272 }
4273 });
4274 } finally {
4275 Binder.restoreCallingIdentity(token);
4276 }
4277 }
4278
4279 /**
4280 * Get the transport type for the IMS service registration state.
4281 */
4282 @Override
4283 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004284 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004285 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004286 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4287 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4288 "IMS not available on device.");
4289 }
4290 final long token = Binder.clearCallingIdentity();
4291 try {
4292 Phone phone = getPhone(subId);
4293 if (phone == null) {
4294 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4295 + subId + "'");
4296 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4297 }
4298 phone.getImsRegistrationTech(regTech -> {
4299 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4300 int regTechConverted = (regTech == null)
4301 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4302 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4303 regTechConverted);
4304 try {
4305 consumer.accept(regTechConverted);
4306 } catch (RemoteException e) {
4307 // Ignore if the remote process is no longer available to call back.
4308 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4309 }
4310 });
4311 } finally {
4312 Binder.restoreCallingIdentity(token);
4313 }
4314 }
4315
shilu366312e2019-12-17 09:28:10 -08004316 /**
4317 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4318 * @param subId The subscription to use to check the configuration.
4319 * @param c The callback that will be used to send the result.
4320 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004321 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004322 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4323 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004324 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004325 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004326 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4327 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4328 "IMS not available on device.");
4329 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004330 final long token = Binder.clearCallingIdentity();
4331 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004332 int slotId = getSlotIndexOrException(subId);
4333 verifyImsMmTelConfiguredOrThrow(slotId);
4334 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004335 } catch (ImsException e) {
4336 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004337 } finally {
4338 Binder.restoreCallingIdentity(token);
4339 }
4340 }
4341
shilu366312e2019-12-17 09:28:10 -08004342 /**
4343 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4344 * @param subId The subscription to use to check the configuration.
4345 * @param c The callback that will be used to send the result.
4346 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004347 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004348 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004349 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004350 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004351 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4352 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4353 }
Meng Wangafbc5852019-09-19 17:37:13 -07004354
4355 final long token = Binder.clearCallingIdentity();
4356 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004357 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004358 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004359 } catch (ImsException e) {
4360 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4361 + "is inactive, ignoring unregister.");
4362 // If the subscription is no longer active, just return, since the callback
4363 // will already have been removed internally.
4364 } finally {
4365 Binder.restoreCallingIdentity(token);
4366 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004367 }
4368
4369 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004370 public boolean isCapable(int subId, int capability, int regTech) {
4371 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004372 final long token = Binder.clearCallingIdentity();
4373 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004374 int slotId = getSlotIndexOrException(subId);
4375 verifyImsMmTelConfiguredOrThrow(slotId);
4376 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4377 } catch (com.android.ims.ImsException e) {
4378 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4379 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004380 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004381 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4382 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004383 } finally {
4384 Binder.restoreCallingIdentity(token);
4385 }
4386 }
4387
4388 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004389 public boolean isAvailable(int subId, int capability, int regTech) {
4390 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004391 final long token = Binder.clearCallingIdentity();
4392 try {
4393 Phone phone = getPhone(subId);
4394 if (phone == null) return false;
4395 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004396 } catch (com.android.ims.ImsException e) {
4397 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4398 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004399 } finally {
4400 Binder.restoreCallingIdentity(token);
4401 }
4402 }
4403
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004404 /**
4405 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4406 * subscription.
4407 * @param subId The subscription to use to check the configuration.
4408 * @param callback The callback that will be used to send the result.
4409 * @param capability The MmTelFeature capability that will be used to send the result.
4410 * @param transportType The transport type of the MmTelFeature capability.
4411 */
4412 @Override
4413 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4414 int transportType) {
4415 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004416 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4417 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4418 "IMS not available on device.");
4419 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004420 final long token = Binder.clearCallingIdentity();
4421 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004422 int slotId = getSlotIndex(subId);
4423 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4424 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4425 + subId + "'");
4426 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4427 }
4428 verifyImsMmTelConfiguredOrThrow(slotId);
4429 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4430 transportType, aBoolean -> {
4431 try {
4432 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4433 } catch (RemoteException e) {
4434 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4435 + "running. Ignore");
4436 }
4437 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004438 } catch (ImsException e) {
4439 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004440 } finally {
4441 Binder.restoreCallingIdentity(token);
4442 }
4443 }
4444
shilu366312e2019-12-17 09:28:10 -08004445 /**
4446 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4447 * @param subId The subscription to use to check the configuration.
4448 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004449 @Override
4450 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004451 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004452 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004453
Brad Ebinger35c841c2018-10-01 10:40:55 -07004454 final long token = Binder.clearCallingIdentity();
4455 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004456 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004457 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004458 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004459 } catch (ImsException e) {
4460 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004461 } finally {
4462 Binder.restoreCallingIdentity(token);
4463 }
4464 }
4465
4466 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004467 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004468 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004469 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004470 final long identity = Binder.clearCallingIdentity();
4471 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004472 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004473 // This setting doesn't require an active ImsService connection, so do not verify. The
4474 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004475 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004476 } catch (ImsException e) {
4477 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004478 } finally {
4479 Binder.restoreCallingIdentity(identity);
4480 }
4481 }
4482
shilu366312e2019-12-17 09:28:10 -08004483 /**
4484 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4485 * @param subId The subscription to use to check the configuration.
4486 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004487 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004488 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004489 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004490 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004491 final long identity = Binder.clearCallingIdentity();
4492 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004493 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004494 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004495 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004496 } catch (ImsException e) {
4497 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004498 } finally {
4499 Binder.restoreCallingIdentity(identity);
4500 }
4501 }
4502
4503 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004504 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004505 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004506 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004507 final long identity = Binder.clearCallingIdentity();
4508 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004509 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004510 // This setting doesn't require an active ImsService connection, so do not verify. The
4511 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004512 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004513 } catch (ImsException e) {
4514 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004515 } finally {
4516 Binder.restoreCallingIdentity(identity);
4517 }
4518 }
4519
shilu366312e2019-12-17 09:28:10 -08004520 /**
4521 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4522 * @param subId The subscription to use to check the configuration.
4523 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004524 @Override
4525 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004526 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004527 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004528 final long identity = Binder.clearCallingIdentity();
4529 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004530 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004531 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004532 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004533 } catch (ImsException e) {
4534 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004535 } finally {
4536 Binder.restoreCallingIdentity(identity);
4537 }
4538 }
4539
4540 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004541 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004542 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004543 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004544 final long identity = Binder.clearCallingIdentity();
4545 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004546 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004547 // This setting doesn't require an active ImsService connection, so do not verify. The
4548 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004549 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004550 } catch (ImsException e) {
4551 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004552 } finally {
4553 Binder.restoreCallingIdentity(identity);
4554 }
4555 }
4556
shilu366312e2019-12-17 09:28:10 -08004557 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004558 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4559 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4560 * @param subId The subscription to use to check the configuration.
4561 */
4562 @Override
4563 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004564 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004565 mApp, subId, "isCrossSimCallingEnabledByUser");
4566 final long identity = Binder.clearCallingIdentity();
4567 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004568 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004569 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004570 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004571 } catch (ImsException e) {
4572 throw new ServiceSpecificException(e.getCode());
4573 } finally {
4574 Binder.restoreCallingIdentity(identity);
4575 }
4576 }
4577
4578 /**
4579 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4580 * Requires MODIFY_PHONE_STATE permission.
4581 * @param subId The subscription to use to check the configuration.
4582 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4583 * false otherwise
4584 */
4585 @Override
4586 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4587 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4588 "setCrossSimCallingEnabled");
4589 final long identity = Binder.clearCallingIdentity();
4590 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004591 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004592 // This setting doesn't require an active ImsService connection, so do not verify. The
4593 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004594 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004595 } catch (ImsException e) {
4596 throw new ServiceSpecificException(e.getCode());
4597 } finally {
4598 Binder.restoreCallingIdentity(identity);
4599 }
4600 }
4601
4602 /**
shilu366312e2019-12-17 09:28:10 -08004603 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4604 * @param subId The subscription to use to check the configuration.
4605 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004606 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004607
Brad Ebinger35c841c2018-10-01 10:40:55 -07004608 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004609 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004610 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004611 final long identity = Binder.clearCallingIdentity();
4612 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004613 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004614 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004615 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004616 } catch (ImsException e) {
4617 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004618 } finally {
4619 Binder.restoreCallingIdentity(identity);
4620 }
4621 }
4622
4623 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004624 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004626 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004627 final long identity = Binder.clearCallingIdentity();
4628 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004629 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004630 // This setting doesn't require an active ImsService connection, so do not verify. The
4631 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004632 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004633 } catch (ImsException e) {
4634 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004635 } finally {
4636 Binder.restoreCallingIdentity(identity);
4637 }
4638 }
4639
4640 @Override
4641 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4643 "setVoWiFiNonPersistent");
4644 final long identity = Binder.clearCallingIdentity();
4645 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004646 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004647 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004648 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004649 } catch (ImsException e) {
4650 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004651 } finally {
4652 Binder.restoreCallingIdentity(identity);
4653 }
4654 }
4655
shilu366312e2019-12-17 09:28:10 -08004656 /**
4657 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4658 * @param subId The subscription to use to check the configuration.
4659 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004660 @Override
4661 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004662 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004663 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004664 final long identity = Binder.clearCallingIdentity();
4665 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004666 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004667 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004668 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004669 } catch (ImsException e) {
4670 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004671 } finally {
4672 Binder.restoreCallingIdentity(identity);
4673 }
4674 }
4675
4676 @Override
4677 public void setVoWiFiModeSetting(int subId, int mode) {
4678 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4679 "setVoWiFiModeSetting");
4680 final long identity = Binder.clearCallingIdentity();
4681 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004682 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004683 // This setting doesn't require an active ImsService connection, so do not verify. The
4684 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004685 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004686 } catch (ImsException e) {
4687 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004688 } finally {
4689 Binder.restoreCallingIdentity(identity);
4690 }
4691 }
4692
4693 @Override
4694 public int getVoWiFiRoamingModeSetting(int subId) {
4695 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4696 final long identity = Binder.clearCallingIdentity();
4697 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004698 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004699 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004700 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004701 } catch (ImsException e) {
4702 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004703 } finally {
4704 Binder.restoreCallingIdentity(identity);
4705 }
4706 }
4707
4708 @Override
4709 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4710 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4711 "setVoWiFiRoamingModeSetting");
4712 final long identity = Binder.clearCallingIdentity();
4713 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004714 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004715 // This setting doesn't require an active ImsService connection, so do not verify. The
4716 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004717 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004718 } catch (ImsException e) {
4719 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004720 } finally {
4721 Binder.restoreCallingIdentity(identity);
4722 }
4723 }
4724
4725 @Override
4726 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4727 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4728 "setRttCapabilityEnabled");
4729 final long identity = Binder.clearCallingIdentity();
4730 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004731 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004732 // This setting doesn't require an active ImsService connection, so do not verify. The
4733 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004734 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004735 } catch (ImsException e) {
4736 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004737 } finally {
4738 Binder.restoreCallingIdentity(identity);
4739 }
4740 }
4741
shilu366312e2019-12-17 09:28:10 -08004742 /**
4743 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4744 * @param subId The subscription to use to check the configuration.
4745 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004746 @Override
4747 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004748 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004749 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004750 final long identity = Binder.clearCallingIdentity();
4751 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004752 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004753 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004754 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004755 } catch (ImsException e) {
4756 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004757 } finally {
4758 Binder.restoreCallingIdentity(identity);
4759 }
4760 }
4761
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004762 @Override
4763 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4764 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004765
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004766 final long identity = Binder.clearCallingIdentity();
4767 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004768 if (!isImsAvailableOnDevice()) {
4769 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4770 "IMS not available on device.");
4771 }
4772 int slotId = getSlotIndexOrException(subId);
4773 verifyImsMmTelConfiguredOrThrow(slotId);
4774 ImsManager.getInstance(mApp, slotId)
4775 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004776 } catch (ImsException e) {
4777 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004778 } finally {
4779 Binder.restoreCallingIdentity(identity);
4780 }
4781 }
4782
4783 @Override
4784 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4785 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004786
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004787 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004788 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4789 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4790 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004791 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004792 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004793 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004794 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004795 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4796 + "is inactive, ignoring unregister.");
4797 // If the subscription is no longer active, just return, since the callback will already
4798 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004799 } finally {
4800 Binder.restoreCallingIdentity(identity);
4801 }
4802 }
4803
joonhunshincffb7fc2021-11-28 07:32:01 +00004804 @Override
4805 public void registerFeatureProvisioningChangedCallback(int subId,
4806 IFeatureProvisioningCallback callback) {
4807 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4808 mApp, subId, "registerFeatureProvisioningChangedCallback");
4809
4810 final long identity = Binder.clearCallingIdentity();
4811 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4812 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4813 }
4814
joonhunshin91bc1952022-04-29 08:47:15 +00004815 try {
4816 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4817 if (controller == null) {
4818 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4819 "Device does not support IMS");
4820 }
4821 controller.addFeatureProvisioningChangedCallback(subId, callback);
4822 } finally {
4823 Binder.restoreCallingIdentity(identity);
4824 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004825 }
4826
4827 @Override
4828 public void unregisterFeatureProvisioningChangedCallback(int subId,
4829 IFeatureProvisioningCallback callback) {
4830 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4831 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4832
4833 final long identity = Binder.clearCallingIdentity();
4834 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4835 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4836 }
4837
joonhunshin91bc1952022-04-29 08:47:15 +00004838 try {
4839 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4840 if (controller == null) {
4841 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4842 return;
4843 }
4844 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4845 } finally {
4846 Binder.restoreCallingIdentity(identity);
4847 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004848 }
allenwtsu99c623b2020-01-03 18:24:23 +08004849
4850 private void checkModifyPhoneStatePermission(int subId, String message) {
4851 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4852 message);
4853 }
4854
allenwtsu99c623b2020-01-03 18:24:23 +08004855 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004856 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004857 boolean isProvisioned) {
4858 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4859
4860 final long identity = Binder.clearCallingIdentity();
4861 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004862 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4863 if (controller == null) {
4864 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4865 return;
4866 }
4867 controller.setRcsProvisioningStatusForCapability(
4868 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004869 } finally {
4870 Binder.restoreCallingIdentity(identity);
4871 }
allenwtsu99c623b2020-01-03 18:24:23 +08004872 }
4873
4874
4875 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004876 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4877 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4878 mApp, subId, "getRcsProvisioningStatusForCapability");
4879
allenwtsu99c623b2020-01-03 18:24:23 +08004880 final long identity = Binder.clearCallingIdentity();
4881 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004882 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4883 if (controller == null) {
4884 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4885
4886 // device does not support IMS, this method will return true always.
4887 return true;
4888 }
4889 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004890 } finally {
4891 Binder.restoreCallingIdentity(identity);
4892 }
4893 }
4894
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004895 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004896 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4897 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004898 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004899
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004900 final long identity = Binder.clearCallingIdentity();
4901 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004902 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4903 if (controller == null) {
4904 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4905 return;
4906 }
4907 controller.setImsProvisioningStatusForCapability(
4908 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004909 } finally {
4910 Binder.restoreCallingIdentity(identity);
4911 }
4912 }
4913
4914 @Override
4915 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004916 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4917 mApp, subId, "getProvisioningStatusForCapability");
4918
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004919 final long identity = Binder.clearCallingIdentity();
4920 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004921 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4922 if (controller == null) {
4923 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004924
joonhunshin91bc1952022-04-29 08:47:15 +00004925 // device does not support IMS, this method will return true always.
4926 return true;
4927 }
4928 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004929 } finally {
4930 Binder.restoreCallingIdentity(identity);
4931 }
4932 }
4933
4934 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004935 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4936 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4937 mApp, subId, "isProvisioningRequiredForCapability");
4938
4939 final long identity = Binder.clearCallingIdentity();
4940 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004941 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4942 if (controller == null) {
4943 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4944
4945 // device does not support IMS, this method will return false
4946 return false;
4947 }
4948 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004949 } finally {
4950 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004951 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004952 }
4953
4954 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004955 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4956 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4957 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004958
joonhunshincffb7fc2021-11-28 07:32:01 +00004959 final long identity = Binder.clearCallingIdentity();
4960 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004961 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4962 if (controller == null) {
4963 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4964
4965 // device does not support IMS, this method will return false
4966 return false;
4967 }
4968 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004969 } finally {
4970 Binder.restoreCallingIdentity(identity);
4971 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004972 }
4973
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004974 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004975 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004976 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4977 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4978 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004979 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4980 mApp, subId, "getImsProvisioningInt");
4981
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004982 final long identity = Binder.clearCallingIdentity();
4983 try {
4984 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004985 int slotId = getSlotIndex(subId);
4986 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4987 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4988 + subId + "' for key:" + key);
4989 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4990 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004991
joonhunshin91bc1952022-04-29 08:47:15 +00004992 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4993 if (controller == null) {
4994 loge("getImsProvisioningInt: Device does not support IMS");
4995
4996 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4997 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4998 }
4999 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005000 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5001 return retVal;
5002 }
5003
calvinpanb5a34062021-02-08 19:59:36 +08005004 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005005 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005006 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5007 + subId + "' for key:" + key);
5008 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005009 } finally {
5010 Binder.restoreCallingIdentity(identity);
5011 }
5012 }
5013
5014 @Override
5015 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005016 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5017 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5018 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005019 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5020 mApp, subId, "getImsProvisioningString");
5021
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005022 final long identity = Binder.clearCallingIdentity();
5023 try {
5024 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005025 int slotId = getSlotIndex(subId);
5026 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5027 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5028 + subId + "' for key:" + key);
5029 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5030 }
calvinpanb5a34062021-02-08 19:59:36 +08005031 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005032 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005033 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5034 + subId + "' for key:" + key);
5035 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005036 } finally {
5037 Binder.restoreCallingIdentity(identity);
5038 }
5039 }
5040
5041 @Override
5042 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005043 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5044 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5045 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5047 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005048
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005049 final long identity = Binder.clearCallingIdentity();
5050 try {
5051 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005052 int slotId = getSlotIndex(subId);
5053 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5054 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5055 + subId + "' for key:" + key);
5056 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5057 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005058
joonhunshin91bc1952022-04-29 08:47:15 +00005059 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5060 if (controller == null) {
5061 loge("setImsProvisioningInt: Device does not support IMS");
5062
5063 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5064 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5065 }
5066 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005067 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5068 return retVal;
5069 }
5070
calvinpanb5a34062021-02-08 19:59:36 +08005071 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5072 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005073 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005074 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005075 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005076 } finally {
5077 Binder.restoreCallingIdentity(identity);
5078 }
5079 }
5080
5081 @Override
5082 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005083 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5084 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5085 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5087 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005088 final long identity = Binder.clearCallingIdentity();
5089 try {
5090 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005091 int slotId = getSlotIndex(subId);
5092 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5093 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5094 + subId + "' for key:" + key);
5095 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5096 }
calvinpanb5a34062021-02-08 19:59:36 +08005097 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5098 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005099 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005100 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005101 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005102 } finally {
5103 Binder.restoreCallingIdentity(identity);
5104 }
5105 }
5106
Brad Ebinger919631e2021-06-02 17:46:35 -07005107 /**
5108 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5109 * for the given slot ID or no ImsResolver instance has been created.
5110 * @param slotId The slot ID that the IMS service is created for.
5111 * @throws ImsException If there is no ImsService configured for this slot.
5112 */
5113 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5114 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5115 ImsFeature.FEATURE_MMTEL)) {
5116 throw new ImsException("This subscription does not support MMTEL over IMS",
5117 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5118 }
5119 }
5120
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005121 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005122 int slotId = SubscriptionManager.getSlotIndex(subId);
5123 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005124 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5125 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005126 }
5127 return slotId;
5128 }
5129
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005130 private int getSlotIndex(int subId) {
5131 int slotId = SubscriptionManager.getSlotIndex(subId);
5132 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5133 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5134 }
5135 return slotId;
5136 }
5137
Wink Saville36469e72014-06-11 15:17:00 -07005138 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005139 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005140 */
5141 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005142 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5143 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005144 try {
5145 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5146 } catch (SecurityException se) {
5147 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5148 throw new SecurityException("Package " + callingPackage + " does not belong to "
5149 + Binder.getCallingUid());
5150 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005151 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005152 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005153 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005154 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005155 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005156 mApp, subId, callingPackage, callingFeatureId,
5157 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005158 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5159 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005160
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005161 final long identity = Binder.clearCallingIdentity();
5162 try {
5163 final Phone phone = getPhone(subId);
5164 if (phone != null) {
5165 return phone.getServiceState().getDataNetworkType();
5166 } else {
5167 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5168 }
5169 } finally {
5170 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005171 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005172 }
5173
5174 /**
5175 * Returns the data network type
5176 */
5177 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005178 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005179 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005180 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005181 }
5182
5183 /**
5184 * Returns the data network type for a subId
5185 */
5186 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005187 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5188 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005189 String functionName = "getDataNetworkTypeForSubscriber";
5190 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5191 mApp, functionName)) {
5192 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5193 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5194 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5195 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005196 }
5197
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005198 final long identity = Binder.clearCallingIdentity();
5199 try {
5200 final Phone phone = getPhone(subId);
5201 if (phone != null) {
5202 return phone.getServiceState().getDataNetworkType();
5203 } else {
5204 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5205 }
5206 } finally {
5207 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005208 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005209 }
5210
5211 /**
Wink Saville36469e72014-06-11 15:17:00 -07005212 * Returns the Voice network type for a subId
5213 */
5214 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005215 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5216 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005217 String functionName = "getVoiceNetworkTypeForSubscriber";
5218 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5219 mApp, functionName)) {
5220 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5221 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5222 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5223 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005224 }
5225
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005226 final long identity = Binder.clearCallingIdentity();
5227 try {
5228 final Phone phone = getPhone(subId);
5229 if (phone != null) {
5230 return phone.getServiceState().getVoiceNetworkType();
5231 } else {
5232 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5233 }
5234 } finally {
5235 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005236 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005237 }
5238
5239 /**
5240 * @return true if a ICC card is present
5241 */
5242 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005243 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005244 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005245 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005246 }
5247
5248 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005249 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005250 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005251 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005252 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005253 final long identity = Binder.clearCallingIdentity();
5254 try {
5255 final Phone phone = PhoneFactory.getPhone(slotIndex);
5256 if (phone != null) {
5257 return phone.getIccCard().hasIccCard();
5258 } else {
5259 return false;
5260 }
5261 } finally {
5262 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005263 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005264 }
5265
5266 /**
5267 * Return if the current radio is LTE on CDMA. This
5268 * is a tri-state return value as for a period of time
5269 * the mode may be unknown.
5270 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005271 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005272 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005273 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005274 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005275 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005276 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5277 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5278 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005279 }
5280
Sanket Padawe356d7632015-06-22 14:03:32 -07005281 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005282 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5283 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005284 try {
5285 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5286 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005287 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5288 }
5289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005290 final long identity = Binder.clearCallingIdentity();
5291 try {
5292 final Phone phone = getPhone(subId);
5293 if (phone == null) {
5294 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5295 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005296 return TelephonyProperties.lte_on_cdma_device()
5297 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 }
5299 } finally {
5300 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005301 }
Wink Saville36469e72014-06-11 15:17:00 -07005302 }
5303
Wink Saville36469e72014-06-11 15:17:00 -07005304 /**
5305 * {@hide}
5306 * Returns Default subId, 0 in the case of single standby.
5307 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005308 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005309 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005310 }
5311
Shishir Agrawala9f32182016-04-12 12:00:16 -07005312 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005313 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005314 }
5315
Wink Savilleb564aae2014-10-23 10:18:09 -07005316 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005317 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005318 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005319
Pengquan Menge92a50d2018-09-21 15:54:48 -07005320 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08005321 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
5322 return SubscriptionManagerService.getInstance().isActiveSubId(subId,
5323 mApp.getOpPackageName(), mApp.getFeatureId());
5324 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005325 return mSubscriptionController.isActiveSubId(subId);
5326 }
5327
Ihab Awadf2177b72013-11-25 13:33:23 -08005328 /**
5329 * @see android.telephony.TelephonyManager.WifiCallingChoices
5330 */
5331 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005332 final long identity = Binder.clearCallingIdentity();
5333 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005334 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005335 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5336 getWhenToMakeWifiCallsDefaultPreference());
5337 } finally {
5338 Binder.restoreCallingIdentity(identity);
5339 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005340 }
5341
5342 /**
5343 * @see android.telephony.TelephonyManager.WifiCallingChoices
5344 */
5345 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005346 final long identity = Binder.clearCallingIdentity();
5347 try {
5348 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005349 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005350 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5351 } finally {
5352 Binder.restoreCallingIdentity(identity);
5353 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005354 }
5355
Sailesh Nepald1e68152013-12-12 19:08:02 -08005356 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005357 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005358 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005359 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005360
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005361 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5362 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5363 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005364 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005365 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5366 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005367 }
5368 return PhoneFactory.getPhone(phoneId);
5369 }
5370
Shishir Agrawal566b7612013-10-28 14:41:00 -07005371 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005372 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005373 @NonNull IccLogicalChannelRequest request) {
5374 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5375 /*message=*/ "iccOpenLogicalChannel");
5376
5377 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5378 // Verify that the callingPackage in the request belongs to the calling UID
5379 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5380
5381 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005382 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005383
Rambo Wanga1782702021-11-10 20:15:19 -08005384 private Phone getPhoneFromValidIccLogicalChannelRequest(
5385 @NonNull IccLogicalChannelRequest request, String message) {
5386 Phone phone;
5387 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5389 mApp, request.subId, message);
5390 phone = getPhoneFromSubId(request.subId);
5391 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5392 enforceModifyPermission();
5393 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5394 } else {
5395 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005396 }
Rambo Wanga1782702021-11-10 20:15:19 -08005397 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005398 }
5399
5400 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005401 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005402 final long identity = Binder.clearCallingIdentity();
5403 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005404 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005405 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005406 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5407 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005408 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5409 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 loge("The calling package is not allowed to access ISD-R.");
5411 throw new SecurityException(
5412 "The calling package is not allowed to access ISD-R.");
5413 }
Derek Tan740e1672017-06-27 14:56:27 -07005414 }
Derek Tan740e1672017-06-27 14:56:27 -07005415
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005416 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005417 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5418 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005419 return response;
5420 } finally {
5421 Binder.restoreCallingIdentity(identity);
5422 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005423 }
5424
5425 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005426 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5427 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5428 /*message=*/"iccCloseLogicalChannel");
5429
5430 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5431
5432 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005433 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005434
Rambo Wanga1782702021-11-10 20:15:19 -08005435 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5436 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005437 // before this feature is enabled, this API should only return false if
5438 // the operation fails instead of throwing runtime exception for
5439 // backward-compatibility.
5440 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5441 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005442 final long identity = Binder.clearCallingIdentity();
5443 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005444 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005445 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005446 }
Chen Xue9d737e2022-01-01 23:41:31 -08005447 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005448 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005449 Boolean success = false;
5450 if (result instanceof RuntimeException) {
5451 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005452 if (shouldThrowExceptionOnFailure) {
5453 throw (RuntimeException) result;
5454 } else {
5455 return false;
5456 }
Chen Xue9d737e2022-01-01 23:41:31 -08005457 } else if (result instanceof Boolean) {
5458 success = (Boolean) result;
5459 } else {
5460 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5461 }
Rambo Wanga1782702021-11-10 20:15:19 -08005462 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005463 return success;
5464 } finally {
5465 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005466 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005467 }
5468
5469 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005470 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005471 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005472 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5473 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005474 if (DBG) {
5475 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5476 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5477 + p3 + " data=" + data);
5478 }
5479 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5480 command, p1, p2, p3, data);
5481 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005482
Jordan Liu4c733742019-02-28 12:03:40 -08005483 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005484 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5485 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005486 enforceModifyPermission();
5487 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005488 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5489 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5490 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005491 }
5492 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005493 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5494 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005495 }
5496
5497 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5498 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005499 final long identity = Binder.clearCallingIdentity();
5500 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005501 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005502 return "";
5503 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005504
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005505 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005506 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5507 null /* workSource */);
5508 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005509
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005510 // Append the returned status code to the end of the response payload.
5511 String s = Integer.toHexString(
5512 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5513 if (response.payload != null) {
5514 s = IccUtils.bytesToHexString(response.payload) + s;
5515 }
5516 return s;
5517 } finally {
5518 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005519 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005520 }
Jake Hambye994d462014-02-03 13:10:13 -08005521
Evan Charltonc66da362014-05-16 14:06:40 -07005522 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005523 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5524 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005525 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5526 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005527 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005528 if (DBG) {
5529 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5530 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5531 }
5532 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5533 cla, command, p1, p2, p3, data);
5534 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005535
Jordan Liu4c733742019-02-28 12:03:40 -08005536 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005537 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5538 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005539 enforceModifyPermission();
5540 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5541 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005542 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5543 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5544 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005545 }
5546
5547 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005548 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5549 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005550 }
5551
5552 // open APDU basic channel assuming the caller has sufficient permissions
5553 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5554 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005555 final long identity = Binder.clearCallingIdentity();
5556 try {
5557 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5558 && TextUtils.equals(ISDR_AID, data)) {
5559 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005560 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5561 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005562 if (bestComponent == null
5563 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5564 loge("The calling package is not allowed to select ISD-R.");
5565 throw new SecurityException(
5566 "The calling package is not allowed to select ISD-R.");
5567 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005568 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005569
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005570 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005571 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5572 null /* workSource */);
5573 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005574
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005575 // Append the returned status code to the end of the response payload.
5576 String s = Integer.toHexString(
5577 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5578 if (response.payload != null) {
5579 s = IccUtils.bytesToHexString(response.payload) + s;
5580 }
5581 return s;
5582 } finally {
5583 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005584 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005585 }
5586
5587 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005588 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005589 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005590 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5591 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005592
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005593 final long identity = Binder.clearCallingIdentity();
5594 try {
5595 if (DBG) {
5596 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5597 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5598 }
5599
5600 IccIoResult response =
5601 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5602 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5603 subId);
5604
5605 if (DBG) {
5606 log("Exchange SIM_IO [R]" + response);
5607 }
5608
5609 byte[] result = null;
5610 int length = 2;
5611 if (response.payload != null) {
5612 length = 2 + response.payload.length;
5613 result = new byte[length];
5614 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5615 } else {
5616 result = new byte[length];
5617 }
5618
5619 result[length - 1] = (byte) response.sw2;
5620 result[length - 2] = (byte) response.sw1;
5621 return result;
5622 } finally {
5623 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005624 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005625 }
5626
Nathan Haroldb3014052017-01-25 15:57:32 -08005627 /**
5628 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5629 * on a particular subscription
5630 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005631 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5632 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005633 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005634 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005635 return null;
5636 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005637
5638 final long identity = Binder.clearCallingIdentity();
5639 try {
5640 if (appType != TelephonyManager.APPTYPE_USIM
5641 && appType != TelephonyManager.APPTYPE_SIM) {
5642 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5643 return null;
5644 }
5645 Object response = sendRequest(
5646 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5647 if (response instanceof String[]) {
5648 return (String[]) response;
5649 }
yincheng zhao2737e882019-09-06 17:06:54 -07005650 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005651 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005652 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005653 } finally {
5654 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005655 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005656 }
5657
yincheng zhao2737e882019-09-06 17:06:54 -07005658 /**
5659 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5660 * subscription.
5661 *
5662 * @param subId the id of the subscription.
5663 * @param appType the uicc app type, must be USIM or SIM.
5664 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5665 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005666 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005667 * @return number of fplmns that is successfully written to the SIM.
5668 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005669 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5670 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5672 mApp, subId, "setForbiddenPlmns");
5673
yincheng zhao2737e882019-09-06 17:06:54 -07005674 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5675 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5676 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5677 }
5678 if (fplmns == null) {
5679 throw new IllegalArgumentException("Fplmn List provided is null");
5680 }
5681 for (String fplmn : fplmns) {
5682 if (!CellIdentity.isValidPlmn(fplmn)) {
5683 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5684 }
5685 }
5686 final long identity = Binder.clearCallingIdentity();
5687 try {
5688 Object response = sendRequest(
5689 CMD_SET_FORBIDDEN_PLMNS,
5690 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5691 subId);
5692 return (int) response;
5693 } finally {
5694 Binder.restoreCallingIdentity(identity);
5695 }
5696 }
5697
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005698 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005699 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5701 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005702
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005703 final long identity = Binder.clearCallingIdentity();
5704 try {
5705 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5706 if (response.payload == null) {
5707 return "";
5708 }
Evan Charltonc66da362014-05-16 14:06:40 -07005709
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005710 // Append the returned status code to the end of the response payload.
5711 String s = Integer.toHexString(
5712 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5713 s = IccUtils.bytesToHexString(response.payload) + s;
5714 return s;
5715 } finally {
5716 Binder.restoreCallingIdentity(identity);
5717 }
Evan Charltonc66da362014-05-16 14:06:40 -07005718 }
5719
Jake Hambye994d462014-02-03 13:10:13 -08005720 /**
5721 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5722 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5723 *
5724 * @param itemID the ID of the item to read
5725 * @return the NV item as a String, or null on error.
5726 */
5727 @Override
5728 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005729 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5731 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005732
5733 final long identity = Binder.clearCallingIdentity();
5734 try {
5735 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005736 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005737 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5738 return value;
5739 } finally {
5740 Binder.restoreCallingIdentity(identity);
5741 }
Jake Hambye994d462014-02-03 13:10:13 -08005742 }
5743
5744 /**
5745 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5746 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5747 *
5748 * @param itemID the ID of the item to read
5749 * @param itemValue the value to write, as a String
5750 * @return true on success; false on any failure
5751 */
5752 @Override
5753 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005754 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005755 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5756 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005757
5758 final long identity = Binder.clearCallingIdentity();
5759 try {
5760 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5761 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005762 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005763 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5764 return success;
5765 } finally {
5766 Binder.restoreCallingIdentity(identity);
5767 }
Jake Hambye994d462014-02-03 13:10:13 -08005768 }
5769
5770 /**
5771 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5772 * Used for device configuration by some CDMA operators.
5773 *
5774 * @param preferredRoamingList byte array containing the new PRL
5775 * @return true on success; false on any failure
5776 */
5777 @Override
5778 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5780 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005781
5782 final long identity = Binder.clearCallingIdentity();
5783 try {
5784 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5785 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5786 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5787 return success;
5788 } finally {
5789 Binder.restoreCallingIdentity(identity);
5790 }
Jake Hambye994d462014-02-03 13:10:13 -08005791 }
5792
5793 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005794 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005795 * Used for device configuration by some CDMA operators.
5796 *
chen xu6dac5ab2018-10-26 17:39:23 -07005797 * @param slotIndex - device slot.
5798 *
Jake Hambye994d462014-02-03 13:10:13 -08005799 * @return true on success; false on any failure
5800 */
5801 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005802 public boolean resetModemConfig(int slotIndex) {
5803 Phone phone = PhoneFactory.getPhone(slotIndex);
5804 if (phone != null) {
5805 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5806 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005807
chen xu6dac5ab2018-10-26 17:39:23 -07005808 final long identity = Binder.clearCallingIdentity();
5809 try {
5810 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5811 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5812 return success;
5813 } finally {
5814 Binder.restoreCallingIdentity(identity);
5815 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005816 }
chen xu6dac5ab2018-10-26 17:39:23 -07005817 return false;
5818 }
5819
5820 /**
5821 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5822 *
5823 * @param slotIndex - device slot.
5824 *
5825 * @return true on success; false on any failure
5826 */
5827 @Override
5828 public boolean rebootModem(int slotIndex) {
5829 Phone phone = PhoneFactory.getPhone(slotIndex);
5830 if (phone != null) {
5831 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5832 mApp, phone.getSubId(), "rebootModem");
5833
5834 final long identity = Binder.clearCallingIdentity();
5835 try {
5836 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5837 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5838 return success;
5839 } finally {
5840 Binder.restoreCallingIdentity(identity);
5841 }
5842 }
5843 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005844 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005845
Brad Ebinger51f743a2017-01-23 13:50:20 -08005846 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005847 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5848 * {@link #disableIms(int)}.
5849 * @param slotIndex device slot.
5850 */
5851 public void resetIms(int slotIndex) {
5852 enforceModifyPermission();
5853
5854 final long identity = Binder.clearCallingIdentity();
5855 try {
5856 if (mImsResolver == null) {
5857 // may happen if the does not support IMS.
5858 return;
5859 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00005860 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005861 } finally {
5862 Binder.restoreCallingIdentity(identity);
5863 }
5864 }
5865
5866 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005867 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5868 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005869 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005870 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005871 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005872
5873 final long identity = Binder.clearCallingIdentity();
5874 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005875 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005876 // may happen if the device does not support IMS.
5877 return;
5878 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005879 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005880 } finally {
5881 Binder.restoreCallingIdentity(identity);
5882 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005883 }
5884
5885 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005886 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5887 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005888 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005889 public void disableIms(int slotId) {
5890 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891
5892 final long identity = Binder.clearCallingIdentity();
5893 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005894 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005895 // may happen if the device does not support IMS.
5896 return;
5897 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005898 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005899 } finally {
5900 Binder.restoreCallingIdentity(identity);
5901 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005902 }
5903
5904 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005905 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5906 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005907 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005908 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005909 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005910 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005911
5912 final long identity = Binder.clearCallingIdentity();
5913 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005914 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005915 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5916 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005917 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005918 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005919 } finally {
5920 Binder.restoreCallingIdentity(identity);
5921 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005922 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005923 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005924 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5925 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005926 @Override
5927 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005928 enforceModifyPermission();
5929
5930 final long identity = Binder.clearCallingIdentity();
5931 try {
5932 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005933 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005934 } finally {
5935 Binder.restoreCallingIdentity(identity);
5936 }
5937 }
5938
5939 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005940 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005941 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005942 */
5943 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5944 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005945
5946 final long identity = Binder.clearCallingIdentity();
5947 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005948 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005949 // may happen if the device does not support IMS.
5950 return null;
5951 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005952 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005953 } finally {
5954 Binder.restoreCallingIdentity(identity);
5955 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005956 }
5957
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005958 /**
5959 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005960 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005961 */
5962 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5963 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005964
5965 final long identity = Binder.clearCallingIdentity();
5966 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005967 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005968 // may happen if the device does not support IMS.
5969 return null;
5970 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005971 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005972 } finally {
5973 Binder.restoreCallingIdentity(identity);
5974 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005975 }
5976
Brad Ebinger884c07b2018-02-15 16:17:40 -08005977 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005978 * Sets the ImsService Package Name that Telephony will bind to.
5979 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005980 * @param slotIndex the slot ID that the ImsService should bind for.
5981 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005982 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005983 * @param featureTypes An integer array of feature types associated with a packageName.
5984 * @param packageName The name of the package that the current configuration will be replaced
5985 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005986 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005987 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005988 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5989 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08005990 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08005992 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994 final long identity = Binder.clearCallingIdentity();
5995 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005996 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005997 // may happen if the device does not support IMS.
5998 return false;
5999 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006000 Map<Integer, String> featureConfig = new HashMap<>();
6001 for (int featureType : featureTypes) {
6002 featureConfig.put(featureType, packageName);
6003 }
6004 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6005 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006 } finally {
6007 Binder.restoreCallingIdentity(identity);
6008 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006009 }
6010
6011 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006012 * Clears any carrier ImsService overrides for the slot index specified that were previously
6013 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6014 *
6015 * This should only be used for testing.
6016 *
6017 * @param slotIndex the slot ID that the ImsService should bind for.
6018 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6019 */
6020 @Override
6021 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006022 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6023 "clearCarrierImsServiceOverride");
6024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006025 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006026
6027 final long identity = Binder.clearCallingIdentity();
6028 try {
6029 if (mImsResolver == null) {
6030 // may happen if the device does not support IMS.
6031 return false;
6032 }
6033 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6034 } finally {
6035 Binder.restoreCallingIdentity(identity);
6036 }
6037 }
6038
6039 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006040 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006041 *
6042 * @param slotId The slot that the ImsService is associated with.
6043 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6044 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006045 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006046 * @return the package name of the ImsService configuration.
6047 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006048 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6049 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006050 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006051 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6052 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006053
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006054 final long identity = Binder.clearCallingIdentity();
6055 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006056 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006057 // may happen if the device does not support IMS.
6058 return "";
6059 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006060 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006061 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6062 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006063 } finally {
6064 Binder.restoreCallingIdentity(identity);
6065 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006066 }
6067
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006068 /**
6069 * Get the MmTelFeature state associated with the requested subscription id.
6070 * @param subId The subscription that the MmTelFeature is associated with.
6071 * @param callback A callback with an integer containing the
6072 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6073 */
6074 @Override
6075 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6076 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006077 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6078 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6079 "IMS not available on device.");
6080 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006081 final long token = Binder.clearCallingIdentity();
6082 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006083 int slotId = getSlotIndex(subId);
6084 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6085 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6086 + subId + "'");
6087 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6088 }
6089 verifyImsMmTelConfiguredOrThrow(slotId);
6090 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6091 try {
6092 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6093 } catch (RemoteException e) {
6094 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6095 + "Ignore");
6096 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006097 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006098 } catch (ImsException e) {
6099 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006100 } finally {
6101 Binder.restoreCallingIdentity(token);
6102 }
6103 }
6104
Daniel Brightbb5840b2021-01-12 15:48:18 -08006105 /**
6106 * Sets the ims registration state on all valid {@link Phone}s.
6107 */
6108 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006109 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006110
6111 final long identity = Binder.clearCallingIdentity();
6112 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006113 // NOTE: Before S, this method only set the default phone.
6114 for (final Phone phone : PhoneFactory.getPhones()) {
6115 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6116 phone.setImsRegistrationState(registered);
6117 }
6118 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006119 } finally {
6120 Binder.restoreCallingIdentity(identity);
6121 }
Wink Saville36469e72014-06-11 15:17:00 -07006122 }
6123
6124 /**
Stuart Scott54788802015-03-30 13:18:01 -07006125 * Set the network selection mode to automatic.
6126 *
6127 */
6128 @Override
6129 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006130 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6131 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132
6133 final long identity = Binder.clearCallingIdentity();
6134 try {
shilufc958392020-01-20 11:36:01 -08006135 if (!isActiveSubscription(subId)) {
6136 return;
6137 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006138 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006139 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6140 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006141 } finally {
6142 Binder.restoreCallingIdentity(identity);
6143 }
Stuart Scott54788802015-03-30 13:18:01 -07006144 }
6145
Jack Yud10cdd42020-09-28 20:28:01 -07006146 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006147 * Ask the radio to connect to the input network and change selection mode to manual.
6148 *
6149 * @param subId the id of the subscription.
6150 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6151 * the operator to attach to.
6152 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6153 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6154 * normal network selection next time.
6155 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006156 */
6157 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006158 public boolean setNetworkSelectionModeManual(
6159 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6161 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006162
Jack Yu285100e2022-12-02 22:48:35 -08006163 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006164 if (!isActiveSubscription(subId)) {
6165 return false;
6166 }
6167
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006168 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006169 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006170 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006171 if (DBG) {
6172 log("setNetworkSelectionModeManual: subId: " + subId
6173 + " operator: " + operatorInfo);
6174 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006175 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6176 } finally {
6177 Binder.restoreCallingIdentity(identity);
6178 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006179 }
shilu84f6e8b2019-12-19 13:58:01 -08006180 /**
6181 * Get the manual network selection
6182 *
6183 * @param subId the id of the subscription.
6184 *
6185 * @return the previously saved user selected PLMN
6186 */
6187 @Override
6188 public String getManualNetworkSelectionPlmn(int subId) {
6189 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006190 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006191 mApp, subId, "getManualNetworkSelectionPlmn");
6192
6193 final long identity = Binder.clearCallingIdentity();
6194 try {
6195 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006196 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006197 }
6198
6199 final Phone phone = getPhone(subId);
6200 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006201 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006202 }
6203 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6204 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6205 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6206 } finally {
6207 Binder.restoreCallingIdentity(identity);
6208 }
6209 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006210
6211 /**
6212 * Scans for available networks.
6213 */
6214 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006215 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6216 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006217 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6218 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006219 LocationAccessPolicy.LocationPermissionResult locationResult =
6220 LocationAccessPolicy.checkLocationPermission(mApp,
6221 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6222 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006223 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006224 .setCallingPid(Binder.getCallingPid())
6225 .setCallingUid(Binder.getCallingUid())
6226 .setMethod("getCellNetworkScanResults")
6227 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006228 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6229 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006230 .build());
6231 switch (locationResult) {
6232 case DENIED_HARD:
6233 throw new SecurityException("Not allowed to access scan results -- location");
6234 case DENIED_SOFT:
6235 return null;
6236 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006237
Pengquan Menga1bb6272018-09-06 09:59:22 -07006238 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006239 try {
6240 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006241 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006242 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006243 } finally {
6244 Binder.restoreCallingIdentity(identity);
6245 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006246 }
6247
6248 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006249 * Get the call forwarding info, given the call forwarding reason.
6250 */
6251 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006252 public void getCallForwarding(int subId, int callForwardingReason,
6253 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006254 enforceReadPrivilegedPermission("getCallForwarding");
6255 long identity = Binder.clearCallingIdentity();
6256 try {
6257 if (DBG) {
6258 log("getCallForwarding: subId " + subId
6259 + " callForwardingReason" + callForwardingReason);
6260 }
Hall Liu27d24262020-09-18 19:04:59 -07006261
6262 Phone phone = getPhone(subId);
6263 if (phone == null) {
6264 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006265 callback.onError(
6266 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006267 } catch (RemoteException e) {
6268 // ignore
6269 }
6270 return;
6271 }
6272
6273 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6274 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6275 @Override
6276 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6277 try {
6278 callback.onCallForwardingInfoAvailable(info);
6279 } catch (RemoteException e) {
6280 // ignore
6281 }
6282 }
6283
6284 @Override
6285 public void onError(int error) {
6286 try {
6287 callback.onError(error);
6288 } catch (RemoteException e) {
6289 // ignore
6290 }
6291 }
6292 });
6293 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006294 } finally {
6295 Binder.restoreCallingIdentity(identity);
6296 }
6297 }
6298
6299 /**
6300 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6301 * reason, the number to forward, and the timeout before the forwarding is attempted.
6302 */
6303 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006304 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6305 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006306 enforceModifyPermission();
6307 long identity = Binder.clearCallingIdentity();
6308 try {
6309 if (DBG) {
6310 log("setCallForwarding: subId " + subId
6311 + " callForwardingInfo" + callForwardingInfo);
6312 }
Hall Liu27d24262020-09-18 19:04:59 -07006313
6314 Phone phone = getPhone(subId);
6315 if (phone == null) {
6316 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006317 callback.accept(
6318 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006319 } catch (RemoteException e) {
6320 // ignore
6321 }
6322 return;
6323 }
6324
6325 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6326 FunctionalUtils.ignoreRemoteException(callback::accept));
6327
6328 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006329 } finally {
6330 Binder.restoreCallingIdentity(identity);
6331 }
6332 }
6333
6334 /**
Hall Liu27d24262020-09-18 19:04:59 -07006335 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006336 */
6337 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006338 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006339 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006340 long identity = Binder.clearCallingIdentity();
6341 try {
Hall Liu27d24262020-09-18 19:04:59 -07006342 Phone phone = getPhone(subId);
6343 if (phone == null) {
6344 try {
6345 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6346 } catch (RemoteException e) {
6347 // ignore
6348 }
6349 return;
6350 }
SongFerngWang0e767992021-03-31 22:08:45 +08006351 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6352 PersistableBundle c = configManager.getConfigForSubId(subId);
6353 boolean requireUssd = c.getBoolean(
6354 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006355
Shuo Qian4a594052020-01-23 11:59:30 -08006356 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006357 if (requireUssd) {
6358 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6359 getSubscriptionCarrierId(subId));
6360 String newUssdCommand = "";
6361 try {
6362 newUssdCommand = carrierXmlParser.getFeature(
6363 CarrierXmlParser.FEATURE_CALL_WAITING)
6364 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6365 } catch (NullPointerException e) {
6366 loge("Failed to generate USSD number" + e);
6367 }
6368 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6369 mMainThreadHandler, callback, carrierXmlParser,
6370 CarrierXmlParser.SsEntry.SSAction.QUERY);
6371 final String ussdCommand = newUssdCommand;
6372 Executors.newSingleThreadExecutor().execute(() -> {
6373 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6374 });
6375 } else {
6376 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6377 callback::accept);
6378 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6379 }
Shuo Qian4a594052020-01-23 11:59:30 -08006380 } finally {
6381 Binder.restoreCallingIdentity(identity);
6382 }
6383 }
6384
6385 /**
Hall Liu27d24262020-09-18 19:04:59 -07006386 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006387 */
6388 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006389 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006390 enforceModifyPermission();
6391 long identity = Binder.clearCallingIdentity();
6392 try {
Hall Liu27d24262020-09-18 19:04:59 -07006393 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6394
6395 Phone phone = getPhone(subId);
6396 if (phone == null) {
6397 try {
6398 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6399 } catch (RemoteException e) {
6400 // ignore
6401 }
6402 return;
6403 }
6404
SongFerngWang0e767992021-03-31 22:08:45 +08006405 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6406 PersistableBundle c = configManager.getConfigForSubId(subId);
6407 boolean requireUssd = c.getBoolean(
6408 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006409
SongFerngWang0e767992021-03-31 22:08:45 +08006410 if (DBG) log("getCallWaitingStatus: subId " + subId);
6411 if (requireUssd) {
6412 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6413 getSubscriptionCarrierId(subId));
6414 CarrierXmlParser.SsEntry.SSAction ssAction =
6415 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6416 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6417 String newUssdCommand = "";
6418 try {
6419 newUssdCommand = carrierXmlParser.getFeature(
6420 CarrierXmlParser.FEATURE_CALL_WAITING)
6421 .makeCommand(ssAction, null);
6422 } catch (NullPointerException e) {
6423 loge("Failed to generate USSD number" + e);
6424 }
6425 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6426 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6427 final String ussdCommand = newUssdCommand;
6428 Executors.newSingleThreadExecutor().execute(() -> {
6429 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6430 });
6431 } else {
6432 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6433 FunctionalUtils.ignoreRemoteException(callback::accept));
6434
6435 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6436 }
Shuo Qian4a594052020-01-23 11:59:30 -08006437 } finally {
6438 Binder.restoreCallingIdentity(identity);
6439 }
6440 }
6441
6442 /**
yinxub1bed742017-04-17 11:45:04 -07006443 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006444 *
yinxub1bed742017-04-17 11:45:04 -07006445 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006446 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6447 * location related information which will be sent if the caller already possess
6448 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006449 * @param request contains the radio access networks with bands/channels to scan
6450 * @param messenger callback messenger for scan results or errors
6451 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006452 * @return the id of the requested scan which can be used to stop the scan.
6453 */
6454 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006455 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6456 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006457 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6459 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006460 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006461 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6462 if (!renounceFineLocationAccess) {
6463 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6464 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6465 .setCallingPackage(callingPackage)
6466 .setCallingFeatureId(callingFeatureId)
6467 .setCallingPid(Binder.getCallingPid())
6468 .setCallingUid(Binder.getCallingUid())
6469 .setMethod("requestNetworkScan")
6470 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6471 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6472 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6473 .build());
6474 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006475 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006476 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6477 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006478 if (e != null) {
6479 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6480 throw e;
6481 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006482 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006483 return TelephonyScanManager.INVALID_SCAN_ID;
6484 }
6485 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006486 }
Hall Liu912dfd32019-04-25 14:02:26 -07006487 int callingUid = Binder.getCallingUid();
6488 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006489 final long identity = Binder.clearCallingIdentity();
6490 try {
6491 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006492 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006493 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006494 } finally {
6495 Binder.restoreCallingIdentity(identity);
6496 }
yinxu504e1392017-04-12 16:03:22 -07006497 }
6498
Hall Liub2ac8ef2019-02-28 15:56:23 -08006499 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006500 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006501 boolean hasCarrierPriv;
6502 final long identity = Binder.clearCallingIdentity();
6503 try {
6504 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6505 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6506 } finally {
6507 Binder.restoreCallingIdentity(identity);
6508 }
Hall Liu558027f2019-05-15 19:14:05 -07006509 boolean hasNetworkScanPermission =
6510 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6511 == PERMISSION_GRANTED;
6512
6513 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6514 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6515 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006516 }
6517
6518 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6519 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006520 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6521 return new SecurityException("Specific channels must not be"
6522 + " scanned without location access.");
6523 }
6524 }
6525 }
6526
Hall Liub2ac8ef2019-02-28 15:56:23 -08006527 return null;
6528 }
6529
yinxu504e1392017-04-12 16:03:22 -07006530 /**
6531 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006532 *
6533 * @param subId id of the subscription
6534 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006535 */
6536 @Override
6537 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006538 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6539 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006540
Hall Liu912dfd32019-04-25 14:02:26 -07006541 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006542 final long identity = Binder.clearCallingIdentity();
6543 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006544 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006545 } finally {
6546 Binder.restoreCallingIdentity(identity);
6547 }
yinxu504e1392017-04-12 16:03:22 -07006548 }
6549
6550 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006551 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006552 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006553 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006554 */
6555 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006556 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006557 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006558 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006559 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006560
6561 final long identity = Binder.clearCallingIdentity();
6562 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006563 if (DBG) log("getAllowedNetworkTypesBitmask");
6564 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6565 int networkTypesBitmask = (result != null ? result[0] : -1);
6566 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6567 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006568 } finally {
6569 Binder.restoreCallingIdentity(identity);
6570 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006571 }
6572
6573 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006574 * Get the allowed network types for certain reason.
6575 *
6576 * @param subId the id of the subscription.
6577 * @param reason the reason the allowed network type change is taking place
6578 * @return the allowed network types.
6579 */
6580 @Override
6581 public long getAllowedNetworkTypesForReason(int subId,
6582 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006583 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006584 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006585 final long identity = Binder.clearCallingIdentity();
6586 try {
6587 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6588 } finally {
6589 Binder.restoreCallingIdentity(identity);
6590 }
6591 }
6592
6593 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006594 * Enable/Disable E-UTRA-NR Dual Connectivity
6595 * @param subId subscription id of the sim card
6596 * @param nrDualConnectivityState expected NR dual connectivity state
6597 * This can be passed following states
6598 * <ol>
6599 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6600 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6601 * <li>Disable NR dual connectivity and force secondary cell to be released
6602 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6603 * </ol>
6604 * @return operation result.
6605 */
6606 @Override
6607 public int setNrDualConnectivityState(int subId,
6608 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6609 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6610 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006611 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006612 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6613 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6614 }
6615
Sooraj Sasindran37444802020-08-11 10:40:43 -07006616 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6617 final long identity = Binder.clearCallingIdentity();
6618 try {
6619 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6620 nrDualConnectivityState, subId,
6621 workSource);
6622 if (DBG) log("enableNRDualConnectivity result: " + result);
6623 return result;
6624 } finally {
6625 Binder.restoreCallingIdentity(identity);
6626 }
6627 }
6628
6629 /**
6630 * Is E-UTRA-NR Dual Connectivity enabled
6631 * @return true if dual connectivity is enabled else false
6632 */
6633 @Override
6634 public boolean isNrDualConnectivityEnabled(int subId) {
6635 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006636 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006637 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006638 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006639 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6640 return false;
6641 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006642 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6643 final long identity = Binder.clearCallingIdentity();
6644 try {
6645 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6646 null, subId, workSource);
6647 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6648 return isEnabled;
6649 } finally {
6650 Binder.restoreCallingIdentity(identity);
6651 }
6652 }
6653
6654 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006655 * Set the allowed network types of the device and
6656 * provide the reason triggering the allowed network change.
6657 *
6658 * @param subId the id of the subscription.
6659 * @param reason the reason the allowed network type change is taking place
6660 * @param allowedNetworkTypes the allowed network types.
6661 * @return true on success; false on any failure.
6662 */
6663 @Override
6664 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006665 @TelephonyManager.AllowedNetworkTypesReason int reason,
6666 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6668 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006669 // If the caller only has carrier privileges, then they should not be able to override
6670 // any network types which were set for security reasons.
6671 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6672 != PERMISSION_GRANTED
6673 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6674 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6675 throw new SecurityException(
6676 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6677 + " reason "
6678 + reason);
6679 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006680 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006681 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6682 return false;
6683 }
6684 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6685 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006686 return false;
6687 }
6688
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006689 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6690 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6691
6692
6693 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6694 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6695 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006696 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006697
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006698 final long identity = Binder.clearCallingIdentity();
6699 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006700 Boolean success = (Boolean) sendRequest(
6701 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6702 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6703
6704 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6705 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006706 } finally {
6707 Binder.restoreCallingIdentity(identity);
6708 }
6709 }
6710
6711 /**
Miaoa84611c2019-03-15 09:21:10 +08006712 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006713 *
Miaoa84611c2019-03-15 09:21:10 +08006714 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006715 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006716 * @hide
6717 */
6718 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006719 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006720 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006721 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006722 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006723 try {
Miaoa84611c2019-03-15 09:21:10 +08006724 if (phone != null) {
6725 return phone.hasMatchedTetherApnSetting();
6726 } else {
6727 return false;
6728 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006729 } finally {
6730 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006731 }
Junda Liu475951f2014-11-07 16:45:03 -08006732 }
6733
6734 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006735 * Get the user enabled state of Mobile Data.
6736 *
6737 * TODO: remove and use isUserDataEnabled.
6738 * This can't be removed now because some vendor codes
6739 * calls through ITelephony directly while they should
6740 * use TelephonyManager.
6741 *
6742 * @return true on enabled
6743 */
6744 @Override
6745 public boolean getDataEnabled(int subId) {
6746 return isUserDataEnabled(subId);
6747 }
6748
6749 /**
6750 * Get whether mobile data is enabled per user setting.
6751 *
6752 * There are other factors deciding whether mobile data is actually enabled, but they are
6753 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006754 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006755 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6756 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006757 *
6758 * @return {@code true} if data is enabled else {@code false}
6759 */
6760 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006761 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006762 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006763 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006764 try {
6765 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6766 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006767 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006768 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6769 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006770 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006772 mApp, subId, functionName);
6773
Robert Greenwalt646120a2014-05-23 11:54:03 -07006774 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006775
6776 final long identity = Binder.clearCallingIdentity();
6777 try {
Jack Yu285100e2022-12-02 22:48:35 -08006778 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006779 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6780 Phone phone = PhoneFactory.getPhone(phoneId);
6781 if (phone != null) {
6782 boolean retVal = phone.isUserDataEnabled();
6783 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6784 return retVal;
6785 } else {
6786 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6787 return false;
6788 }
6789 } finally {
6790 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006791 }
6792 }
6793
6794 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006795 * Checks if the device is capable of mobile data by considering whether whether the
6796 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6797 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006798 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006799 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006800 */
6801 @Override
6802 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006803 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006804 try {
6805 try {
6806 mApp.enforceCallingOrSelfPermission(
6807 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006808 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006809 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006810 try {
6811 mApp.enforceCallingOrSelfPermission(
6812 android.Manifest.permission.READ_PHONE_STATE,
6813 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006814 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006815 mApp.enforceCallingOrSelfPermission(
6816 permission.READ_BASIC_PHONE_STATE, functionName);
6817 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006818 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006819 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006820 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006821 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006822
6823 final long identity = Binder.clearCallingIdentity();
6824 try {
Jack Yu285100e2022-12-02 22:48:35 -08006825 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006826 Phone phone = PhoneFactory.getPhone(phoneId);
6827 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006828 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006829 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006830 return retVal;
6831 } else {
6832 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6833 return false;
6834 }
6835 } finally {
6836 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006837 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006838 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006839
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006840 /**
6841 * Check if data is enabled for a specific reason
6842 * @param subId Subscription index
6843 * @param reason the reason the data enable change is taking place
6844 * @return {@code true} if the overall data is enabled; {@code false} if not.
6845 */
6846 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006847 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006848 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006849 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006850 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006851 try {
6852 mApp.enforceCallingOrSelfPermission(
6853 android.Manifest.permission.ACCESS_NETWORK_STATE,
6854 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006855 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006856 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6857 functionName);
6858 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006859 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006860 try {
6861 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006862 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006863 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006865 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006866 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006867 }
6868
6869
6870 final long identity = Binder.clearCallingIdentity();
6871 try {
Jack Yu285100e2022-12-02 22:48:35 -08006872 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006873 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006874 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006875 + " reason=" + reason);
6876 }
6877 Phone phone = PhoneFactory.getPhone(phoneId);
6878 if (phone != null) {
6879 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006880 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006881 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006882 return retVal;
6883 } else {
6884 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006885 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006886 + subId + " retVal=false");
6887 }
6888 return false;
6889 }
6890 } finally {
6891 Binder.restoreCallingIdentity(identity);
6892 }
6893 }
6894
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006895 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006896 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006897 // No permission needed; this only lets the caller inspect their own status.
6898 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006899 }
Junda Liu29340342014-07-10 15:23:27 -07006900
6901 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006902 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006903 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006904 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6905 }
6906
6907 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6908 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006909 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006910 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006911 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6912 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006913 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6914 if (cpt == null) {
6915 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006916 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6917 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006918 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006919 }
6920
6921 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006922 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006923 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006924 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006925 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006926 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006927 Phone phone = getPhone(subId);
6928 if (phone == null) {
6929 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6930 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6931 }
6932 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6933 if (cpt == null) {
6934 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006935 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6936 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006937 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006938 }
6939
6940 @Override
6941 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006942 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006943 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6944 }
6945
6946 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006947 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006948 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006949 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006950 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006951 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6952 Phone phone = PhoneFactory.getPhone(phoneId);
6953 if (phone == null) {
6954 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006955 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006956 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6957 if (cpt == null) {
6958 continue;
6959 }
6960 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006961 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6962 break;
6963 }
6964 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006965 return result;
Junda Liu29340342014-07-10 15:23:27 -07006966 }
Derek Tan89e89d42014-07-08 17:00:10 -07006967
6968 @Override
Junda Liue64de782015-04-16 17:19:16 -07006969 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006970 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006971 Phone phone = PhoneFactory.getPhone(phoneId);
6972 if (phone == null) {
6973 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006974 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006975 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6976 if (cpt == null) {
6977 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006978 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006979 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006980 }
6981
Amith Yamasani6e118872016-02-19 12:53:51 -08006982 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006983 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006984 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006985 Phone phone = PhoneFactory.getPhone(phoneId);
6986 if (phone == null) {
6987 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006988 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006989 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6990 if (cpt == null) {
6991 return Collections.emptyList();
6992 }
6993 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006994 }
6995
chen xuf7e9fe82019-05-09 19:31:02 -07006996 @Override
6997 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006998 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006999 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007000 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007001 try {
7002 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7003 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7004 }
7005 } finally {
7006 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007007 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007008 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007009 }
7010
Rambo Wang6812ffb2022-03-15 16:54:17 -07007011 @Override
7012 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7013 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7014
7015 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7016 if (phone == null) {
7017 return null;
7018 }
7019 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7020 if (cpt == null) {
7021 return null;
7022 }
7023 return cpt.getCarrierServicePackageName();
7024 }
7025
Wink Savilleb564aae2014-10-23 10:18:09 -07007026 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007027 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007028 UiccPort port = phone == null ? null : phone.getUiccPort();
7029 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007030 return null;
7031 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007032 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007033 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007034 return null;
7035 }
7036 return iccId;
7037 }
7038
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007039 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007040 public void setCallComposerStatus(int subId, int status) {
7041 enforceModifyPermission();
7042
7043 final long identity = Binder.clearCallingIdentity();
7044 try {
7045 Phone phone = getPhone(subId);
7046 if (phone != null) {
7047 Phone defaultPhone = phone.getImsPhone();
7048 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7049 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7050 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007051 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7052 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007053 }
7054 }
Shuo Qian284ae752020-12-22 19:10:14 -08007055 } catch (ImsException e) {
7056 throw new ServiceSpecificException(e.getCode());
7057 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007058 Binder.restoreCallingIdentity(identity);
7059 }
7060 }
7061
7062 @Override
7063 public int getCallComposerStatus(int subId) {
7064 enforceReadPrivilegedPermission("getCallComposerStatus");
7065
7066 final long identity = Binder.clearCallingIdentity();
7067 try {
7068 Phone phone = getPhone(subId);
7069 if (phone != null) {
7070 Phone defaultPhone = phone.getImsPhone();
7071 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7072 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7073 return imsPhone.getCallComposerStatus();
7074 }
7075 }
7076 } finally {
7077 Binder.restoreCallingIdentity(identity);
7078 }
7079 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7080 }
7081
7082 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007083 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7084 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007085 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007086 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007087
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007088 final long identity = Binder.clearCallingIdentity();
7089 try {
7090 final String iccId = getIccId(subId);
7091 final Phone phone = getPhone(subId);
7092 if (phone == null) {
7093 return false;
7094 }
7095 final String subscriberId = phone.getSubscriberId();
7096
7097 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007098 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007099 + subscriberId + " to " + number);
7100 }
7101
7102 if (TextUtils.isEmpty(iccId)) {
7103 return false;
7104 }
7105
7106 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7107
7108 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7109 if (alphaTag == null) {
7110 editor.remove(alphaTagPrefKey);
7111 } else {
7112 editor.putString(alphaTagPrefKey, alphaTag);
7113 }
7114
7115 // Record both the line number and IMSI for this ICCID, since we need to
7116 // track all merged IMSIs based on line number
7117 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7118 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7119 if (number == null) {
7120 editor.remove(numberPrefKey);
7121 editor.remove(subscriberPrefKey);
7122 } else {
7123 editor.putString(numberPrefKey, number);
7124 editor.putString(subscriberPrefKey, subscriberId);
7125 }
7126
7127 editor.commit();
7128 return true;
7129 } finally {
7130 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007131 }
Derek Tan7226c842014-07-02 17:42:23 -07007132 }
7133
7134 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007135 public String getLine1NumberForDisplay(int subId, String callingPackage,
7136 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007137 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007138 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007139 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007140 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007141 return null;
7142 }
Derek Tan97ebb422014-09-05 16:55:38 -07007143
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007144 final long identity = Binder.clearCallingIdentity();
7145 try {
7146 String iccId = getIccId(subId);
7147 if (iccId != null) {
7148 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7149 if (DBG_MERGE) {
7150 log("getLine1NumberForDisplay returning "
7151 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7152 }
7153 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007154 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007155 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7156 return null;
7157 } finally {
7158 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007159 }
Derek Tan7226c842014-07-02 17:42:23 -07007160 }
7161
7162 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007163 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7164 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007165 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007166 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007167 return null;
7168 }
Derek Tan97ebb422014-09-05 16:55:38 -07007169
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007170 final long identity = Binder.clearCallingIdentity();
7171 try {
7172 String iccId = getIccId(subId);
7173 if (iccId != null) {
7174 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7175 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7176 }
7177 return null;
7178 } finally {
7179 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007180 }
Derek Tan7226c842014-07-02 17:42:23 -07007181 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007182
7183 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007184 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7185 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007186 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7187 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007188 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007189 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007190 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007191 return null;
7192 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007193
Jordan Liub49b04b2019-05-06 14:45:15 -07007194 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7195 // the process, where TelephonyManager was instantiated.
7196 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007197 final long identity = Binder.clearCallingIdentity();
7198 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007199 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007200 final TelephonyManager tele = TelephonyManager.from(context);
7201 final SubscriptionManager sub = SubscriptionManager.from(context);
7202
7203 // Figure out what subscribers are currently active
7204 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007205
Jordan Liub49b04b2019-05-06 14:45:15 -07007206 // Only consider subs which match the current subId
7207 // This logic can be simplified. See b/131189269 for progress.
7208 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007209 activeSubscriberIds.add(tele.getSubscriberId(subId));
7210 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007211
7212 // First pass, find a number override for an active subscriber
7213 String mergeNumber = null;
7214 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7215 for (String key : prefs.keySet()) {
7216 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7217 final String subscriberId = (String) prefs.get(key);
7218 if (activeSubscriberIds.contains(subscriberId)) {
7219 final String iccId = key.substring(
7220 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7221 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7222 mergeNumber = (String) prefs.get(numberKey);
7223 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007224 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007225 + " for active subscriber " + subscriberId);
7226 }
7227 if (!TextUtils.isEmpty(mergeNumber)) {
7228 break;
7229 }
7230 }
7231 }
7232 }
7233
7234 // Shortcut when no active merged subscribers
7235 if (TextUtils.isEmpty(mergeNumber)) {
7236 return null;
7237 }
7238
7239 // Second pass, find all subscribers under that line override
7240 final ArraySet<String> result = new ArraySet<>();
7241 for (String key : prefs.keySet()) {
7242 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7243 final String number = (String) prefs.get(key);
7244 if (mergeNumber.equals(number)) {
7245 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7246 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7247 final String subscriberId = (String) prefs.get(subscriberKey);
7248 if (!TextUtils.isEmpty(subscriberId)) {
7249 result.add(subscriberId);
7250 }
7251 }
7252 }
7253 }
7254
7255 final String[] resultArray = result.toArray(new String[result.size()]);
7256 Arrays.sort(resultArray);
7257 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007258 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007259 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7260 }
7261 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007262 } finally {
7263 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007264 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007265 }
7266
7267 @Override
zoey chen38003472019-12-13 17:16:31 +08007268 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7269 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007270
7271 final long identity = Binder.clearCallingIdentity();
7272 try {
7273 final TelephonyManager telephonyManager = mApp.getSystemService(
7274 TelephonyManager.class);
7275 String subscriberId = telephonyManager.getSubscriberId(subId);
7276 if (subscriberId == null) {
7277 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007278 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007279 + subId);
7280 }
7281 return null;
7282 }
7283
Jack Yu285100e2022-12-02 22:48:35 -08007284 ParcelUuid groupUuid;
7285 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7286 final SubscriptionInfo info = SubscriptionManagerService.getInstance()
7287 .getSubscriptionInfo(subId);
7288 groupUuid = info.getGroupUuid();
7289 } else {
7290 final SubscriptionInfo info = mSubscriptionController
7291 .getSubscriptionInfo(subId);
7292 groupUuid = info.getGroupUuid();
7293 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007294 // If it doesn't belong to any group, return just subscriberId of itself.
7295 if (groupUuid == null) {
7296 return new String[]{subscriberId};
7297 }
7298
7299 // Get all subscriberIds from the group.
7300 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007301 List<SubscriptionInfo> groupInfos;
7302 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7303 groupInfos = SubscriptionManagerService.getInstance()
7304 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7305 mApp.getAttributionTag());
7306 } else {
7307 groupInfos = mSubscriptionController
7308 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7309 mApp.getAttributionTag());
7310 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007311 for (SubscriptionInfo subInfo : groupInfos) {
7312 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7313 if (subscriberId != null) {
7314 mergedSubscriberIds.add(subscriberId);
7315 }
7316 }
7317
7318 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7319 } finally {
7320 Binder.restoreCallingIdentity(identity);
7321
7322 }
7323 }
7324
7325 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007326 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007327 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007328 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007329
7330 final long identity = Binder.clearCallingIdentity();
7331 try {
7332 final Phone phone = getPhone(subId);
7333 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7334 } finally {
7335 Binder.restoreCallingIdentity(identity);
7336 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007337 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007338
7339 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007340 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007341 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7342 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007343 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7344 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007345
7346 final long identity = Binder.clearCallingIdentity();
7347 try {
7348 final Phone phone = getPhone(subId);
7349 if (phone == null) {
7350 return false;
7351 }
7352 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7353 cdmaNonRoamingList);
7354 } finally {
7355 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007356 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007357 }
7358
7359 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007360 @Deprecated
7361 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7362 enforceModifyPermission();
7363
7364 int returnValue = 0;
7365 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007366 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007367 if(result.exception == null) {
7368 if (result.result != null) {
7369 byte[] responseData = (byte[])(result.result);
7370 if(responseData.length > oemResp.length) {
7371 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7372 responseData.length + "bytes. Buffer Size is " +
7373 oemResp.length + "bytes.");
7374 }
7375 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7376 returnValue = responseData.length;
7377 }
7378 } else {
7379 CommandException ex = (CommandException) result.exception;
7380 returnValue = ex.getCommandError().ordinal();
7381 if(returnValue > 0) returnValue *= -1;
7382 }
7383 } catch (RuntimeException e) {
7384 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7385 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7386 if(returnValue > 0) returnValue *= -1;
7387 }
7388
7389 return returnValue;
7390 }
7391
7392 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007393 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007394 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007395 try {
7396 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007397 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007398 mApp, phone.getSubId(), "getRadioAccessFamily");
7399 } catch (SecurityException e) {
7400 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7401 throw e;
7402 }
chen xub97461a2018-10-26 14:17:57 -07007403 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007404 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007405 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007406 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007407 final long identity = Binder.clearCallingIdentity();
7408 try {
chen xub97461a2018-10-26 14:17:57 -07007409 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007410 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007411 mApp, phone.getSubId(), "getRadioAccessFamily");
7412 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007413 } finally {
7414 Binder.restoreCallingIdentity(identity);
7415 }
chen xub97461a2018-10-26 14:17:57 -07007416 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007417 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007418
7419 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007420 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007421 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007422 try {
7423 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7424 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007425 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007426 }
7427 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007428 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007429 }
7430 RoleManager rm = mApp.getSystemService(RoleManager.class);
7431 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7432 if (!dialerRoleHolders.contains(callingPackage)) {
7433 throw new SecurityException("App must be the dialer role holder to"
7434 + " upload a call composer pic");
7435 }
7436
7437 Executors.newSingleThreadExecutor().execute(() -> {
7438 ByteArrayOutputStream output = new ByteArrayOutputStream(
7439 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7440 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7441 boolean readUntilEnd = false;
7442 int totalBytesRead = 0;
7443 byte[] buffer = new byte[16 * 1024];
7444 while (true) {
7445 int numRead;
7446 try {
7447 numRead = input.read(buffer);
7448 } catch (IOException e) {
7449 try {
7450 fd.checkError();
7451 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7452 null);
7453 } catch (IOException e1) {
7454 // This means that the other side closed explicitly with an error. If this
7455 // happens, log and ignore.
7456 loge("Remote end of call composer picture pipe closed: " + e1);
7457 }
7458 break;
7459 }
7460 if (numRead == -1) {
7461 readUntilEnd = true;
7462 break;
7463 }
7464 totalBytesRead += numRead;
7465 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7466 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7467 try {
7468 input.close();
7469 } catch (IOException e) {
7470 // ignore
7471 }
7472 break;
7473 }
7474 output.write(buffer, 0, numRead);
7475 }
7476 // Generally, the remote end will close the file descriptors. The only case where we
7477 // close is above, where the picture size is too big.
7478
7479 try {
7480 fd.checkError();
7481 } catch (IOException e) {
7482 loge("Remote end for call composer closed with an error: " + e);
7483 return;
7484 }
7485
Hall Liuaa4211e2021-01-20 15:43:39 -08007486 if (!readUntilEnd) {
7487 loge("Did not finish reading entire image; aborting");
7488 return;
7489 }
Hall Liu82694d52020-12-11 18:22:04 -08007490
Hall Liuaa4211e2021-01-20 15:43:39 -08007491 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7492 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7493 new CallComposerPictureTransfer.Factory() {},
7494 imageData,
7495 (result) -> {
7496 if (result.first != null) {
7497 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7498 Bundle outputResult = new Bundle();
7499 outputResult.putParcelable(
7500 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7501 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7502 outputResult);
7503 } else {
7504 callback.send(result.second, null);
7505 }
7506 }
7507 );
Hall Liu82694d52020-12-11 18:22:04 -08007508 });
7509 }
7510
7511 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007512 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007513 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007514 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007515
7516 final long identity = Binder.clearCallingIdentity();
7517 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007518 ImsManager.getInstance(defaultPhone.getContext(),
7519 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007520 } finally {
7521 Binder.restoreCallingIdentity(identity);
7522 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007523 }
7524
7525 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007526 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007527 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007528 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7529 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007530 return false;
7531 }
Svet Ganovb320e182015-04-16 12:30:10 -07007532
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007533 final long identity = Binder.clearCallingIdentity();
7534 try {
7535 // Check the user preference and the system-level IMS setting. Even if the user has
7536 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7537 // In the long run, we may instead need to check if there exists a connection service
7538 // which can support video calling.
7539 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007540 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541 return imsManager.isVtEnabledByPlatform()
7542 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7543 && imsManager.isVtEnabledByUser();
7544 } finally {
7545 Binder.restoreCallingIdentity(identity);
7546 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007547 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007548
Andrew Leea1239f22015-03-02 17:44:07 -08007549 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007550 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7551 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007552 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007553 mApp, subId, callingPackage, callingFeatureId,
7554 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007555 return false;
7556 }
7557
7558 final long identity = Binder.clearCallingIdentity();
7559 try {
7560 CarrierConfigManager configManager =
7561 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007562 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007563 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7564 } finally {
7565 Binder.restoreCallingIdentity(identity);
7566 }
Andrew Leea1239f22015-03-02 17:44:07 -08007567 }
7568
7569 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007570 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007571 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007572 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007573 return false;
7574 }
7575
7576 final long identity = Binder.clearCallingIdentity();
7577 try {
7578 CarrierConfigManager configManager =
7579 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007580 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007581 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7582 } finally {
7583 Binder.restoreCallingIdentity(identity);
7584 }
Andrew Leea1239f22015-03-02 17:44:07 -08007585 }
7586
Andrew Lee9431b832015-03-09 18:46:45 -07007587 @Override
7588 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007589 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007590 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007591 }
7592
7593 @Override
7594 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007595 final long identity = Binder.clearCallingIdentity();
7596 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007597 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007598 } finally {
7599 Binder.restoreCallingIdentity(identity);
7600 }
Andrew Lee9431b832015-03-09 18:46:45 -07007601 }
7602
Hall Liuf6668912018-10-31 17:05:23 -07007603 /**
7604 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7605 * support for the feature and device firmware support.
7606 *
7607 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7608 */
7609 @Override
7610 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007611 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007612 final Phone phone = getPhone(subscriptionId);
7613 if (phone == null) {
7614 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7615 return false;
7616 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007617 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007618 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007619 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7620 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007621 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007622 return isCarrierSupported && isDeviceSupported;
7623 } finally {
7624 Binder.restoreCallingIdentity(identity);
7625 }
Hall Liu98187582018-01-22 19:15:32 -08007626 }
7627
Hall Liuf6668912018-10-31 17:05:23 -07007628 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007629 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7630 * RTT setting, will return true if the device and carrier both support RTT.
7631 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007632 */
7633 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007634 final long identity = Binder.clearCallingIdentity();
7635 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007636 boolean isRttSupported = isRttSupported(subscriptionId);
7637 boolean isUserRttSettingOn = Settings.Secure.getInt(
7638 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7639 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7640 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7641 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007642 } finally {
7643 Binder.restoreCallingIdentity(identity);
7644 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007645 }
7646
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007647 @Deprecated
7648 @Override
7649 public String getDeviceId(String callingPackage) {
7650 return getDeviceIdWithFeature(callingPackage, null);
7651 }
7652
Sanket Padawe7310cc72015-01-14 09:53:20 -08007653 /**
7654 * Returns the unique device ID of phone, for example, the IMEI for
7655 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7656 *
7657 * <p>Requires Permission:
7658 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7659 */
7660 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007661 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007662 try {
7663 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7664 } catch (SecurityException se) {
7665 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7666 throw new SecurityException("Package " + callingPackage + " does not belong to "
7667 + Binder.getCallingUid());
7668 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007669 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007670 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007671 return null;
7672 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007673 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007674 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007675 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007676 return null;
7677 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007678
7679 final long identity = Binder.clearCallingIdentity();
7680 try {
7681 return phone.getDeviceId();
7682 } finally {
7683 Binder.restoreCallingIdentity(identity);
7684 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007685 }
7686
Ping Sunc67b7c22016-03-02 19:16:45 +08007687 /**
7688 * {@hide}
7689 * Returns the IMS Registration Status on a particular subid
7690 *
7691 * @param subId
7692 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007693 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007694 Phone phone = getPhone(subId);
7695 if (phone != null) {
7696 return phone.isImsRegistered();
7697 } else {
7698 return false;
7699 }
7700 }
7701
Santos Cordon7a1885b2015-02-03 11:15:19 -08007702 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007703 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007704 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007705 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007706 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007707 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7708 }
7709 final long identity = Binder.clearCallingIdentity();
7710 try {
7711 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7712 } finally {
7713 Binder.restoreCallingIdentity(identity);
7714 }
7715 }
7716
7717 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007718 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007719 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007720 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007721 mApp,
7722 subscriptionId,
7723 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007724 final long identity = Binder.clearCallingIdentity();
7725 try {
7726 Phone phone = getPhone(subscriptionId);
7727 if (phone == null) {
7728 return null;
7729 }
7730 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7731 } finally {
7732 Binder.restoreCallingIdentity(identity);
7733 }
7734 }
7735
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007736 /**
7737 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007738 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007739 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007740 final long identity = Binder.clearCallingIdentity();
7741 try {
7742 Phone phone = getPhone(subId);
7743 if (phone != null) {
7744 return phone.isWifiCallingEnabled();
7745 } else {
7746 return false;
7747 }
7748 } finally {
7749 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007750 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007751 }
7752
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007753 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007754 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007755 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007756 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007757 final long identity = Binder.clearCallingIdentity();
7758 try {
7759 Phone phone = getPhone(subId);
7760 if (phone != null) {
7761 return phone.isVideoEnabled();
7762 } else {
7763 return false;
7764 }
7765 } finally {
7766 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007767 }
7768 }
7769
7770 /**
7771 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7772 * defined in {@link ImsRegistrationImplBase}.
7773 */
7774 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007775 final long identity = Binder.clearCallingIdentity();
7776 try {
7777 Phone phone = getPhone(subId);
7778 if (phone != null) {
7779 return phone.getImsRegistrationTech();
7780 } else {
7781 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7782 }
7783 } finally {
7784 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007785 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007786 }
7787
Stuart Scott8eef64f2015-04-08 15:13:54 -07007788 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007789 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007790 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007791 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7792 return;
7793 }
Kai Shif70f46f2021-03-03 13:59:46 -08007794 Phone defaultPhone = getDefaultPhone();
7795 if (defaultPhone != null) {
7796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7797 mApp, getDefaultPhone().getSubId(), "factoryReset");
7798 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007799 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007800
Svet Ganovcc087f82015-05-12 20:35:54 -07007801 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007802 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7803 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007804 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007805 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007806 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007807 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007808 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007809 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007810 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007811 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007812 // There has been issues when Sms raw table somehow stores orphan
7813 // fragments. They lead to garbled message when new fragments come
7814 // in and combined with those stale ones. In case this happens again,
7815 // user can reset all network settings which will clean up this table.
7816 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007817 // Clean up IMS settings as well here.
7818 int slotId = getSlotIndex(subId);
7819 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7820 ImsManager.getInstance(mApp, slotId).factoryReset();
7821 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007822
Kai Shif70f46f2021-03-03 13:59:46 -08007823 if (defaultPhone == null) {
7824 return;
7825 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007826 // Erase modem config if erase modem on network setting is enabled.
7827 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7828 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7829 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007830 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007831 }
Kai Shif70f46f2021-03-03 13:59:46 -08007832
7833 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007834 } finally {
7835 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007836 }
7837 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007838
SongFerngWangfd89b102021-05-27 22:44:54 +08007839 @VisibleForTesting
7840 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7841 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7842 return;
7843 }
7844 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7845 RILConstants.PREFERRED_NETWORK_MODE);
7846 SubscriptionManager.setSubscriptionProperty(subId,
7847 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7848 "user=" + defaultNetworkType);
7849 phone.loadAllowedNetworksFromSubscriptionDatabase();
7850 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7851 defaultNetworkType, null);
7852 }
7853
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007854 private void cleanUpSmsRawTable(Context context) {
7855 ContentResolver resolver = context.getContentResolver();
7856 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7857 resolver.delete(uri, null, null);
7858 }
7859
Narayan Kamath1c496c22015-04-16 14:40:19 +01007860 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007861 public String getSimLocaleForSubscriber(int subId) {
7862 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7863 final Phone phone = getPhone(subId);
7864 if (phone == null) {
7865 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007866 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007867 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007868 final long identity = Binder.clearCallingIdentity();
7869 try {
Jack Yu285100e2022-12-02 22:48:35 -08007870 SubscriptionInfo info;
7871 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7872 info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId,
7873 phone.getContext().getOpPackageName(),
7874 phone.getContext().getAttributionTag());
7875 if (info == null) {
7876 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7877 return null;
7878 }
7879 } else {
7880 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
7881 phone.getContext().getOpPackageName(),
7882 phone.getContext().getAttributionTag());
7883 if (info == null) {
7884 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7885 return null;
7886 }
chen xu6291c472019-02-04 12:55:53 -08007887 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007888 // Try and fetch the locale from the carrier properties or from the SIM language
7889 // preferences (EF-PL and EF-LI)...
7890 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007891 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007892 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7893 if (localeFromDefaultSim != null) {
7894 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7895 if (DBG) log("Using locale from subId: " + subId + " locale: "
7896 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08007897 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007898 } else {
7899 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007900 }
7901 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007902
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007903 // The SIM language preferences only store a language (e.g. fr = French), not an
7904 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7905 // the SIM and carrier preferences does not include a country we add the country
7906 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007907 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007908 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007909 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08007910 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007911 }
7912
7913 if (DBG) log("No locale found - returning null");
7914 return null;
7915 } finally {
7916 Binder.restoreCallingIdentity(identity);
7917 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007918 }
7919
tom hsu0b59d292022-09-29 23:49:21 +08007920 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08007921 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08007922 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08007923 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08007924 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08007925 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
7926 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08007927 Locale.forLanguageTag(localeTag).getCountry())) {
7928 return localeTag;
7929 }
7930 }
7931 return inputLocale.toLanguageTag();
7932 }
7933
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007934 /**
7935 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7936 */
7937 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08007938 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7939 return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList(
7940 mApp.getOpPackageName(), mApp.getAttributionTag());
7941 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007942 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007943 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007944 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007945
Gary Jian3aa9a762022-01-24 16:41:19 +08007946 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7947 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007948
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007949 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007950 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7951 * representing the state of the modem.
7952 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007953 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7954 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007955 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007956 */
7957 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007958 public void requestModemActivityInfo(ResultReceiver result) {
7959 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007960 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007961
7962 final long identity = Binder.clearCallingIdentity();
7963 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007964 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007965 } finally {
7966 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007967 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007968 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007969
Siddharth Rayb8114062018-06-17 15:02:38 -07007970 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7971 // less than total activity duration.
7972 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7973 if (info == null) {
7974 return false;
7975 }
7976 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007977 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7978 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7979
Siddharth Rayb8114062018-06-17 15:02:38 -07007980 return (info.isValid()
7981 && (info.getSleepTimeMillis() <= activityDurationMs)
7982 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007983 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007984 && (totalTxTimeMs <= activityDurationMs));
7985 }
7986
Gary Jian3aa9a762022-01-24 16:41:19 +08007987 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7988 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7989 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7990 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7991
7992 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7993 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7994 }
7995
7996 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7997 mLastModemActivityInfo.setReceiveTimeMillis(
7998 rat,
7999 freq,
8000 info.getReceiveTimeMillis(rat, freq)
8001 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8002 }
8003
8004 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8005 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8006 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8007 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8008
8009 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8010 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8011 }
8012 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8013 mLastModemActivityInfo.setReceiveTimeMillis(
8014 rat,
8015 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8016 }
8017
8018 /**
8019 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8020 * @param info recent ModemActivityInfo
8021 */
8022 private void mergeModemActivityInfo(ModemActivityInfo info) {
8023 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008024 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008025 boolean matched;
8026 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8027 matched = false;
8028 int rat = info.getSpecificInfoRat(i);
8029 int freq = info.getSpecificInfoFrequencyRange(i);
8030 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8031 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8032 //if it already exists
8033 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8034 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8035 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8036 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8037 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8038 updateLastModemActivityInfo(info, rat, freq);
8039 matched = true;
8040 }
8041 } else {
8042 updateLastModemActivityInfo(info, rat);
8043 matched = true;
8044 }
8045 }
8046 }
8047
8048 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008049 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008050 new ActivityStatsTechSpecificInfo(
8051 rat,
8052 freq,
8053 info.getTransmitTimeMillis(rat, freq),
8054 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008055 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008056 }
8057 }
8058 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8059 mLastModemActivitySpecificInfo =
8060 new ActivityStatsTechSpecificInfo[merged.size()];
8061 merged.toArray(mLastModemActivitySpecificInfo);
8062
8063 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8064 mLastModemActivityInfo.setSleepTimeMillis(
8065 info.getSleepTimeMillis()
8066 + mLastModemActivityInfo.getSleepTimeMillis());
8067 mLastModemActivityInfo.setIdleTimeMillis(
8068 info.getIdleTimeMillis()
8069 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008070
8071 mLastModemActivityInfo =
8072 new ModemActivityInfo(
8073 mLastModemActivityInfo.getTimestampMillis(),
8074 mLastModemActivityInfo.getSleepTimeMillis(),
8075 mLastModemActivityInfo.getIdleTimeMillis(),
8076 mLastModemActivitySpecificInfo);
8077 }
8078
8079 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8080 ActivityStatsTechSpecificInfo[] info) {
8081 int infoSize = info.length;
8082 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8083 for (int i = 0; i < infoSize; i++) {
8084 ret[i] = new ActivityStatsTechSpecificInfo(
8085 info[i].getRat(), info[i].getFrequencyRange(),
8086 info[i].getTransmitTimeMillis(),
8087 (int) info[i].getReceiveTimeMillis());
8088 }
8089 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008090 }
8091
Jack Yu85bd38a2015-11-09 11:34:32 -08008092 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008093 * Returns the service state information on specified subscription.
8094 */
8095 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008096 public ServiceState getServiceStateForSubscriber(int subId,
8097 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8098 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008099 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008100 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008101 return null;
8102 }
8103
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008104 boolean hasFinePermission = false;
8105 boolean hasCoarsePermission = false;
8106 if (!renounceFineLocationAccess) {
8107 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8108 LocationAccessPolicy.checkLocationPermission(mApp,
8109 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8110 .setCallingPackage(callingPackage)
8111 .setCallingFeatureId(callingFeatureId)
8112 .setCallingPid(Binder.getCallingPid())
8113 .setCallingUid(Binder.getCallingUid())
8114 .setMethod("getServiceStateForSubscriber")
8115 .setLogAsInfo(true)
8116 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8117 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8118 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8119 .build());
8120 hasFinePermission =
8121 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8122 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008123
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008124 if (!renounceCoarseLocationAccess) {
8125 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8126 LocationAccessPolicy.checkLocationPermission(mApp,
8127 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8128 .setCallingPackage(callingPackage)
8129 .setCallingFeatureId(callingFeatureId)
8130 .setCallingPid(Binder.getCallingPid())
8131 .setCallingUid(Binder.getCallingUid())
8132 .setMethod("getServiceStateForSubscriber")
8133 .setLogAsInfo(true)
8134 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8135 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8136 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8137 .build());
8138 hasCoarsePermission =
8139 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8140 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008141
Jack Yu479f40e2020-10-27 21:29:25 -07008142 final Phone phone = getPhone(subId);
8143 if (phone == null) {
8144 return null;
8145 }
8146
Jordan Liu0f2bc442020-11-18 16:47:37 -08008147 final long identity = Binder.clearCallingIdentity();
8148
Jack Yu479f40e2020-10-27 21:29:25 -07008149 boolean isCallingPackageDataService = phone.getDataServicePackages()
8150 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008151 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008152 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008153 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8154 SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance()
8155 .getSubscriptionInfoInternal(subId);
8156 if (subInfo == null || !subInfo.isActive()) {
8157 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8158 + "subId=" + subId);
8159 return null;
8160 }
8161 } else {
8162 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8163 callingFeatureId)) {
8164 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8165 + "subId=" + subId);
8166 return null;
8167 }
Jordan Liuc437b192020-08-17 10:59:12 -07008168 }
8169
Hall Liuf19c44f2018-11-27 14:38:17 -08008170 ServiceState ss = phone.getServiceState();
8171
8172 // Scrub out the location info in ServiceState depending on what level of access
8173 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008174 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008175 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8176 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008177 } finally {
8178 Binder.restoreCallingIdentity(identity);
8179 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008180 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008181
8182 /**
8183 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8184 *
8185 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8186 * voicemail ringtone.
8187 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8188 * PhoneAccount.
8189 */
8190 @Override
8191 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008192 final long identity = Binder.clearCallingIdentity();
8193 try {
8194 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8195 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008196 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008197 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008198
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008199 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8200 } finally {
8201 Binder.restoreCallingIdentity(identity);
8202 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008203 }
8204
8205 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008206 * Sets the per-account voicemail ringtone.
8207 *
8208 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8209 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8210 *
8211 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8212 * voicemail ringtone.
8213 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8214 * PhoneAccount.
8215 */
8216 @Override
8217 public void setVoicemailRingtoneUri(String callingPackage,
8218 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008219 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008220 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008221 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8222 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008223 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8224 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8225 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008226 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008227
8228 final long identity = Binder.clearCallingIdentity();
8229 try {
8230 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8231 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008232 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008233 }
8234 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8235 } finally {
8236 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008237 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008238 }
8239
8240 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008241 * Returns whether vibration is set for voicemail notification in Phone settings.
8242 *
8243 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8244 * voicemail vibration setting.
8245 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8246 */
8247 @Override
8248 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008249 final long identity = Binder.clearCallingIdentity();
8250 try {
8251 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8252 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008253 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008254 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008255
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008256 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8257 } finally {
8258 Binder.restoreCallingIdentity(identity);
8259 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008260 }
8261
Youhan Wange64578a2016-05-02 15:32:42 -07008262 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008263 * Sets the per-account voicemail vibration.
8264 *
8265 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8266 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8267 *
8268 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8269 * voicemail vibration setting.
8270 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8271 * specific PhoneAccount.
8272 */
8273 @Override
8274 public void setVoicemailVibrationEnabled(String callingPackage,
8275 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008276 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008277 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008278 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8279 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008280 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8281 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8282 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008283 }
8284
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008285 final long identity = Binder.clearCallingIdentity();
8286 try {
8287 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8288 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008289 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008290 }
8291 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8292 } finally {
8293 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008294 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008295 }
8296
8297 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008298 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8299 *
8300 * @throws SecurityException if the caller does not have the required permission
8301 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008302 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008303 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008304 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008305 }
8306
8307 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008308 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8309 * permission.
8310 *
8311 * @throws SecurityException if the caller does not have the required permission
8312 */
8313 private void enforceSendSmsPermission() {
8314 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8315 }
8316
8317 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008318 * Make sure either called from same process as self (phone) or IPC caller has interact across
8319 * users permission.
8320 *
8321 * @throws SecurityException if the caller does not have the required permission
8322 */
8323 private void enforceInteractAcrossUsersPermission(String message) {
8324 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8325 }
8326
8327 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008328 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008329 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008330 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008331 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008332 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008333 final long identity = Binder.clearCallingIdentity();
8334 try {
8335 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008336 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008337 if (componentName == null) {
8338 throw new SecurityException(
8339 "Caller not current active visual voicemail package[null]");
8340 }
8341 String vvmPackage = componentName.getPackageName();
8342 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008343 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008344 }
8345 } finally {
8346 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008347 }
8348 }
8349
8350 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008351 * Return the application ID for the app type.
8352 *
8353 * @param subId the subscription ID that this request applies to.
8354 * @param appType the uicc app type.
8355 * @return Application ID for specificied app type, or null if no uicc.
8356 */
8357 @Override
8358 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008359 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008360 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008361
8362 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008363 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008364 if (phone == null) {
8365 return null;
8366 }
8367 String aid = null;
8368 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008369 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008370 .getApplicationByType(appType).getAid();
8371 } catch (Exception e) {
8372 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8373 }
8374 return aid;
8375 } finally {
8376 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008377 }
Youhan Wange64578a2016-05-02 15:32:42 -07008378 }
8379
Youhan Wang4001d252016-05-11 10:29:41 -07008380 /**
8381 * Return the Electronic Serial Number.
8382 *
8383 * @param subId the subscription ID that this request applies to.
8384 * @return ESN or null if error.
8385 */
8386 @Override
8387 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008388 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008389 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008390
8391 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008392 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008393 if (phone == null) {
8394 return null;
8395 }
8396 String esn = null;
8397 try {
8398 esn = phone.getEsn();
8399 } catch (Exception e) {
8400 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8401 }
8402 return esn;
8403 } finally {
8404 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008405 }
Youhan Wang4001d252016-05-11 10:29:41 -07008406 }
8407
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008408 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008409 * Return the Preferred Roaming List Version.
8410 *
8411 * @param subId the subscription ID that this request applies to.
8412 * @return PRLVersion or null if error.
8413 */
8414 @Override
8415 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008416 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008417 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008418
8419 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008420 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008421 if (phone == null) {
8422 return null;
8423 }
8424 String cdmaPrlVersion = null;
8425 try {
8426 cdmaPrlVersion = phone.getCdmaPrlVersion();
8427 } catch (Exception e) {
8428 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8429 }
8430 return cdmaPrlVersion;
8431 } finally {
8432 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008433 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008434 }
8435
8436 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008437 * Get snapshot of Telephony histograms
8438 * @return List of Telephony histograms
8439 * @hide
8440 */
8441 @Override
8442 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8444 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008445
8446 final long identity = Binder.clearCallingIdentity();
8447 try {
8448 return RIL.getTelephonyRILTimingHistograms();
8449 } finally {
8450 Binder.restoreCallingIdentity(identity);
8451 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008452 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008453
8454 /**
8455 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008456 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8457 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008458 * Require system privileges. In the future we may add this to carrier APIs.
8459 *
Michele Berionne482f8202018-11-27 18:57:59 -08008460 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008461 */
8462 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008463 @TelephonyManager.SetCarrierRestrictionResult
8464 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008465 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008466 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008467
Michele Berionne482f8202018-11-27 18:57:59 -08008468 if (carrierRestrictionRules == null) {
8469 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008470 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008472 final long identity = Binder.clearCallingIdentity();
8473 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008474 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008475 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008476 } finally {
8477 Binder.restoreCallingIdentity(identity);
8478 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008479 }
8480
8481 /**
8482 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008483 * Get the allowed carrier list and the excluded carrier list, including the priority between
8484 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008485 * Require system privileges. In the future we may add this to carrier APIs.
8486 *
Michele Berionne482f8202018-11-27 18:57:59 -08008487 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008488 */
8489 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008490 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008491 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008492 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008493
8494 final long identity = Binder.clearCallingIdentity();
8495 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008496 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8497 if (response instanceof CarrierRestrictionRules) {
8498 return (CarrierRestrictionRules) response;
8499 }
8500 // Response is an Exception of some kind,
8501 // which is signalled to the user as a NULL retval
8502 return null;
8503 } catch (Exception e) {
8504 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8505 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008506 } finally {
8507 Binder.restoreCallingIdentity(identity);
8508 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008509 }
8510
fionaxu59545b42016-05-25 15:53:37 -07008511 /**
fionaxu59545b42016-05-25 15:53:37 -07008512 * Action set from carrier signalling broadcast receivers to enable/disable radio
8513 * @param subId the subscription ID that this action applies to.
8514 * @param enabled control enable or disable radio.
8515 * {@hide}
8516 */
8517 @Override
8518 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8519 enforceModifyPermission();
8520 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008521
8522 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008523 if (phone == null) {
8524 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8525 return;
8526 }
8527 try {
8528 phone.carrierActionSetRadioEnabled(enabled);
8529 } catch (Exception e) {
8530 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008531 } finally {
8532 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008533 }
8534 }
8535
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008536 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008537 * Enable or disable Voice over NR (VoNR)
8538 * @param subId the subscription ID that this action applies to.
8539 * @param enabled enable or disable VoNR.
8540 * @return operation result.
8541 */
8542 @Override
8543 public int setVoNrEnabled(int subId, boolean enabled) {
8544 enforceModifyPermission();
8545 final Phone phone = getPhone(subId);
8546
8547 final long identity = Binder.clearCallingIdentity();
8548 if (phone == null) {
8549 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8550 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8551 }
8552
8553 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8554 try {
8555 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8556 workSource);
8557 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008558
8559 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8560 if (DBG) {
8561 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8562 }
8563 SubscriptionManager.setSubscriptionProperty(
8564 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8565 (enabled ? "1" : "0"));
8566 }
8567
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008568 return result;
8569 } finally {
8570 Binder.restoreCallingIdentity(identity);
8571 }
8572 }
8573
8574 /**
8575 * Is voice over NR enabled
8576 * @return true if VoNR is enabled else false
8577 */
8578 @Override
8579 public boolean isVoNrEnabled(int subId) {
8580 enforceReadPrivilegedPermission("isVoNrEnabled");
8581 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8582 final long identity = Binder.clearCallingIdentity();
8583 try {
8584 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8585 null, subId, workSource);
8586 if (DBG) log("isVoNrEnabled: " + isEnabled);
8587 return isEnabled;
8588 } finally {
8589 Binder.restoreCallingIdentity(identity);
8590 }
8591 }
8592
8593 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008594 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8595 * network status based on which carrier apps could apply actions accordingly,
8596 * enable/disable default url handler for example.
8597 *
8598 * @param subId the subscription ID that this action applies to.
8599 * @param report control start/stop reporting the default network status.
8600 * {@hide}
8601 */
8602 @Override
8603 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8604 enforceModifyPermission();
8605 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008606
8607 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008608 if (phone == null) {
8609 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8610 return;
8611 }
8612 try {
8613 phone.carrierActionReportDefaultNetworkStatus(report);
8614 } catch (Exception e) {
8615 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008616 } finally {
8617 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008618 }
8619 }
8620
8621 /**
fionaxud9622282017-07-17 17:51:30 -07008622 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8623 * @param subId the subscription ID that this action applies to.
8624 * {@hide}
8625 */
8626 @Override
8627 public void carrierActionResetAll(int subId) {
8628 enforceModifyPermission();
8629 final Phone phone = getPhone(subId);
8630 if (phone == null) {
8631 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8632 return;
8633 }
8634 try {
8635 phone.carrierActionResetAll();
8636 } catch (Exception e) {
8637 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8638 }
8639 }
8640
8641 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008642 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8643 * bug report is being generated.
8644 */
8645 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008646 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008647 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8648 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008649 writer.println("Permission Denial: can't dump Phone from pid="
8650 + Binder.getCallingPid()
8651 + ", uid=" + Binder.getCallingUid()
8652 + "without permission "
8653 + android.Manifest.permission.DUMP);
8654 return;
8655 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008656 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008657 }
Jack Yueb89b242016-06-22 13:27:47 -07008658
Brad Ebingerdac2f002018-04-03 15:17:52 -07008659 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008660 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8661 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8662 @NonNull String[] args) {
8663 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8664 this, in.getFileDescriptor(), out.getFileDescriptor(),
8665 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008666 }
8667
Jack Yueb89b242016-06-22 13:27:47 -07008668 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008669 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008670 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008671 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008672 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008673 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008674 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008675 */
8676 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008677 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008678 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008679 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8680 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8681 try {
8682 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008683 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008684 } catch (SecurityException se) {
8685 enforceModifyPermission();
8686 }
8687 } else {
8688 enforceModifyPermission();
8689 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008690
8691 final long identity = Binder.clearCallingIdentity();
8692 try {
8693 Phone phone = getPhone(subId);
8694 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008695 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8696 phone.carrierActionSetMeteredApnsEnabled(enabled);
8697 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008698 phone.getDataSettingsManager().setDataEnabled(
8699 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008700 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008701 }
8702 } finally {
8703 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008704 }
8705 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008706
8707 /**
8708 * Get Client request stats
8709 * @return List of Client Request Stats
8710 * @hide
8711 */
8712 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008713 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8714 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008715 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008716 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008717 return null;
8718 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008719 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008720
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008721 final long identity = Binder.clearCallingIdentity();
8722 try {
8723 if (phone != null) {
8724 return phone.getClientRequestStats();
8725 }
8726
8727 return null;
8728 } finally {
8729 Binder.restoreCallingIdentity(identity);
8730 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008731 }
8732
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008733 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008734 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008735 if (uid == Process.ROOT_UID && packageName == null) {
8736 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8737 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8738 // exception. ROOT_UID seems not to have a valid package name returned by
8739 // PackageManager, so just fake it here to avoid issues when running telephony shell
8740 // commands that plumb through the RIL as root, like so:
8741 // $ adb root
8742 // $ adb shell cmd phone ...
8743 packageName = "root";
8744 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008745 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008746 }
Jack Yueb4124c2017-02-16 15:32:43 -08008747
8748 /**
Grace Chen70990072017-03-24 17:21:30 -07008749 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008750 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008751 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008752 * @param state State of SIM (power down, power up, pass through)
8753 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8754 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8755 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008756 *
8757 **/
8758 @Override
Grace Chen70990072017-03-24 17:21:30 -07008759 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008760 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008761 Phone phone = PhoneFactory.getPhone(slotIndex);
8762
vagdeviaf9a5b92018-08-15 16:01:53 -07008763 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008765 final long identity = Binder.clearCallingIdentity();
8766 try {
8767 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008768 phone.setSimPowerState(state, null, workSource);
8769 }
8770 } finally {
8771 Binder.restoreCallingIdentity(identity);
8772 }
8773 }
8774
8775 /**
8776 * Set SIM card power state.
8777 *
8778 * @param slotIndex SIM slot id.
8779 * @param state State of SIM (power down, power up, pass through)
8780 * @param callback callback to trigger after success or failure
8781 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8782 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8783 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8784 *
8785 **/
8786 @Override
8787 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8788 IIntegerConsumer callback) {
8789 enforceModifyPermission();
8790 Phone phone = PhoneFactory.getPhone(slotIndex);
8791
8792 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8793
8794 final long identity = Binder.clearCallingIdentity();
8795 try {
8796 if (phone != null) {
8797 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8798 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008799 }
8800 } finally {
8801 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008802 }
8803 }
Shuo Qiandd210312017-04-12 22:11:33 +00008804
Tyler Gunn65d45c22017-06-05 11:22:26 -07008805 private boolean isUssdApiAllowed(int subId) {
8806 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008807 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008808 if (configManager == null) {
8809 return false;
8810 }
8811 PersistableBundle pb = configManager.getConfigForSubId(subId);
8812 if (pb == null) {
8813 return false;
8814 }
8815 return pb.getBoolean(
8816 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8817 }
8818
Shuo Qiandd210312017-04-12 22:11:33 +00008819 /**
8820 * Check if phone is in emergency callback mode
8821 * @return true if phone is in emergency callback mode
8822 * @param subId sub id
8823 */
goneil9c5f4872017-12-05 14:07:56 -08008824 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008825 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008826 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008827 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008828
8829 final long identity = Binder.clearCallingIdentity();
8830 try {
8831 if (phone != null) {
8832 return phone.isInEcm();
8833 } else {
8834 return false;
8835 }
8836 } finally {
8837 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008838 }
8839 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008840
8841 /**
8842 * Get the current signal strength information for the given subscription.
8843 * Because this information is not updated when the device is in a low power state
8844 * it should not be relied-upon to be current.
8845 * @param subId Subscription index
8846 * @return the most recent cached signal strength info from the modem
8847 */
8848 @Override
8849 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008850 final long identity = Binder.clearCallingIdentity();
8851 try {
8852 Phone p = getPhone(subId);
8853 if (p == null) {
8854 return null;
8855 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008856
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008857 return p.getSignalStrength();
8858 } finally {
8859 Binder.restoreCallingIdentity(identity);
8860 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008861 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008862
Pengquan Meng77b7f132018-08-22 14:49:57 -07008863 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008864 * Get the current modem radio state for the given slot.
8865 * @param slotIndex slot index.
8866 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008867 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008868 * @return the current radio power state from the modem
8869 */
8870 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008871 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008872 Phone phone = PhoneFactory.getPhone(slotIndex);
8873 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008874 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8875 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008876 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8877 }
8878
8879 final long identity = Binder.clearCallingIdentity();
8880 try {
8881 return phone.getRadioPowerState();
8882 } finally {
8883 Binder.restoreCallingIdentity(identity);
8884 }
8885 }
8886 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8887 }
8888
8889 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008890 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8891 *
8892 * <p>Requires one of the following permissions:
8893 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008894 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008895 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8896 * privileges.
8897 *
8898 * @param subId subscription id
8899 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8900 * {@code false}.
8901 */
8902 @Override
8903 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008904 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008905 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008906 try {
8907 mApp.enforceCallingOrSelfPermission(
8908 android.Manifest.permission.ACCESS_NETWORK_STATE,
8909 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008910 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008911 mApp.enforceCallingOrSelfPermission(
8912 permission.READ_BASIC_PHONE_STATE, functionName);
8913 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008914 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008915 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008916 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008917 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008918
Pengquan Menga1bb6272018-09-06 09:59:22 -07008919 boolean isEnabled = false;
8920 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008921 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008922 Phone phone = getPhone(subId);
8923 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008924 } finally {
8925 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008926 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008927 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008928 }
8929
8930
8931 /**
8932 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8933 *
8934 * <p> Requires permission:
8935 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8936 * privileges.
8937 *
8938 * @param subId subscription id
8939 * @param isEnabled {@code true} means enable, {@code false} means disable.
8940 */
8941 @Override
8942 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008943 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8944 mApp, subId, "setDataRoamingEnabled");
8945
Pengquan Menga1bb6272018-09-06 09:59:22 -07008946 final long identity = Binder.clearCallingIdentity();
8947 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008948 Phone phone = getPhone(subId);
8949 if (phone != null) {
8950 phone.setDataRoamingEnabled(isEnabled);
8951 }
8952 } finally {
8953 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008954 }
8955 }
8956
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008957 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008958 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008959 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008960 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008961 mApp, subId, "isManualNetworkSelectionAllowed");
8962
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008963 boolean isAllowed = true;
8964 final long identity = Binder.clearCallingIdentity();
8965 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008966 Phone phone = getPhone(subId);
8967 if (phone != null) {
8968 isAllowed = phone.isCspPlmnEnabled();
8969 }
8970 } finally {
8971 Binder.restoreCallingIdentity(identity);
8972 }
8973 return isAllowed;
8974 }
8975
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008976 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8977 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008978 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008979 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008980 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008981 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8982 if (phone == null) {
8983 return false;
8984 }
8985 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8986 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8987 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008988 }
8989
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008990 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008991 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008992 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008993 mApp.getSystemService(AppOpsManager.class)
8994 .checkPackage(Binder.getCallingUid(), callingPackage);
8995
Jordan Liu1e142fc2019-04-22 15:10:43 -07008996 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008997 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008998 try {
8999 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009000 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009001 } catch (SecurityException e) {
9002 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9003 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009004 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08009005 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009006 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009007 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009008 }
sandeepjsb6c87872021-09-27 15:34:44 +00009009 // checking compatibility, if calling app's target SDK is T and beyond.
9010 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9011 Binder.getCallingUid())) {
9012 isIccIdAccessRestricted = true;
9013 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009014 final long identity = Binder.clearCallingIdentity();
9015 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009016 UiccController uiccController = UiccController.getInstance();
9017 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009018 if (hasReadPermission) {
9019 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009020 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009021
9022 // Remove private info if the caller doesn't have access
9023 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9024 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009025 //setting the value after compatibility check
9026 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009027 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9028 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009029 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009030 if (card == null) {
9031 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009032 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009033 continue;
9034 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009035 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9036 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009037 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009038 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009039 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009040 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9041 for (UiccPortInfo portInfo : portInfos) {
9042 UiccPort port = uiccController.getUiccPortForSlot(
9043 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9044 if (port == null) {
9045 // assume no access if port is null
9046 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9047 continue;
9048 }
9049 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9050 uiccPortInfos.add(portInfo);
9051 } else {
9052 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9053 }
9054 }
9055 filteredInfos.add(new UiccCardInfo(
9056 cardInfo.isEuicc(),
9057 cardInfo.getCardId(),
9058 null,
9059 cardInfo.getPhysicalSlotIndex(),
9060 cardInfo.isRemovable(),
9061 cardInfo.isMultipleEnabledProfilesSupported(),
9062 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009063 }
9064 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009065 } finally {
9066 Binder.restoreCallingIdentity(identity);
9067 }
9068 }
9069
sandeepjsb6c87872021-09-27 15:34:44 +00009070 /**
9071 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9072 * generally private and require carrier privileges to view.
9073 *
9074 * @hide
9075 */
9076 @NonNull
9077 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9078 List<UiccPortInfo> portinfo = new ArrayList<>();
9079 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9080 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9081 }
9082 return new UiccCardInfo(
9083 cardInfo.isEuicc(),
9084 cardInfo.getCardId(),
9085 null,
9086 cardInfo.getPhysicalSlotIndex(),
9087 cardInfo.isRemovable(),
9088 cardInfo.isMultipleEnabledProfilesSupported(),
9089 portinfo
9090 );
9091 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009092
sandeepjsb6c87872021-09-27 15:34:44 +00009093 /**
9094 * @hide
9095 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9096 * These values are generally private and require carrier privileges to view.
9097 */
9098 @NonNull
9099 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9100 return new UiccPortInfo(
9101 UiccPortInfo.ICCID_REDACTED,
9102 portInfo.getPortIndex(),
9103 portInfo.getLogicalSlotIndex(),
9104 portInfo.isActive()
9105 );
9106 }
9107 @Override
9108 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009109 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009110 mApp.getSystemService(AppOpsManager.class)
9111 .checkPackage(Binder.getCallingUid(), callingPackage);
9112
sandeepjsb6c87872021-09-27 15:34:44 +00009113 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009114
Aman Guptaf3c90b32022-03-17 04:54:16 +00009115 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9116 // we are reading iccId which is PII data.
9117 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009118
9119 // checking compatibility, if calling app's target SDK is T and beyond.
9120 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9121 Binder.getCallingUid())) {
9122 isLogicalSlotAccessRestricted = true;
9123 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009124 final long identity = Binder.clearCallingIdentity();
9125 try {
9126 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009127 if (slots == null || slots.length == 0) {
9128 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009129 return null;
9130 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009131 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9132 for (int i = 0; i < slots.length; i++) {
9133 UiccSlot slot = slots[i];
9134 if (slot == null) {
9135 continue;
9136 }
9137
Jordan Liu7be7e652019-05-06 18:55:02 +00009138 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009139 UiccCard card = slot.getUiccCard();
9140 if (card != null) {
9141 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009142 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009143 cardId = slot.getEid();
9144 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009145 // If cardId is null, use iccId of default port as cardId.
9146 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009147 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009148 }
9149
Jordan Liu857451f2019-05-09 16:35:35 -07009150 if (cardId != null) {
9151 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9152 // if cardId is an EID, it's all digits so this is fine
9153 cardId = IccUtils.stripTrailingFs(cardId);
9154 }
9155
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009156 int cardState = 0;
9157 switch (slot.getCardState()) {
9158 case CARDSTATE_ABSENT:
9159 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9160 break;
9161 case CARDSTATE_PRESENT:
9162 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9163 break;
9164 case CARDSTATE_ERROR:
9165 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9166 break;
9167 case CARDSTATE_RESTRICTED:
9168 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9169 break;
9170 default:
9171 break;
9172
9173 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009174 List<UiccPortInfo> portInfos = new ArrayList<>();
9175 int[] portIndexes = slot.getPortList();
9176 for (int portIdx : portIndexes) {
9177 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009178 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009179 portInfos.add(new UiccPortInfo(iccId, portIdx,
9180 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009181 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009182 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009183 slot.isEuicc(),
9184 cardId,
9185 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009186 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009187 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009188 //setting the value after compatibility check
9189 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009190 }
9191 return infos;
9192 } finally {
9193 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009194 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009195 }
9196
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009197 /* Returns null if doesn't have read permission or carrier privilege access. */
9198 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9199 boolean hasReadPermission) {
9200 String iccId = slot.getIccId(portIndex);
9201 if (hasReadPermission) { // if has read permission
9202 return iccId;
9203 } else {
9204 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9205 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9206 // if no read permission, checking carrier privilege access
9207 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9208 return iccId;
9209 }
9210 }
9211 }
9212 // No read permission or carrier privilege access.
9213 return UiccPortInfo.ICCID_REDACTED;
9214 }
9215
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009216 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009217 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009218 public boolean switchSlots(int[] physicalSlots) {
9219 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009220
9221 final long identity = Binder.clearCallingIdentity();
9222 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009223 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9224 for (int i = 0; i < physicalSlots.length; i++) {
9225 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9226 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9227 physicalSlots[i], i));
9228 }
9229 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009230 } finally {
9231 Binder.restoreCallingIdentity(identity);
9232 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009233 }
Jack Yu4c988042018-02-27 15:30:01 -08009234
9235 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009236 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9237 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9238 enforceModifyPermission();
9239
9240 final long identity = Binder.clearCallingIdentity();
9241 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009242 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009243 } finally {
9244 Binder.restoreCallingIdentity(identity);
9245 }
9246 }
9247
9248 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009249 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009250 final long identity = Binder.clearCallingIdentity();
9251 try {
9252 return UiccController.getInstance().getCardIdForDefaultEuicc();
9253 } finally {
9254 Binder.restoreCallingIdentity(identity);
9255 }
9256 }
9257
Pengquan Meng85728fb2018-03-12 16:31:21 -07009258 /**
goneil47ffb6e2018-04-06 15:40:58 -07009259 * A test API to reload the UICC profile.
9260 *
9261 * <p>Requires that the calling app has permission
9262 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9263 * @hide
9264 */
9265 @Override
9266 public void refreshUiccProfile(int subId) {
9267 enforceModifyPermission();
9268
9269 final long identity = Binder.clearCallingIdentity();
9270 try {
9271 Phone phone = getPhone(subId);
9272 if (phone == null) {
9273 return;
9274 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009275 UiccPort uiccPort = phone.getUiccPort();
9276 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009277 return;
9278 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009279 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009280 if (uiccProfile == null) {
9281 return;
9282 }
9283 uiccProfile.refresh();
9284 } finally {
9285 Binder.restoreCallingIdentity(identity);
9286 }
9287 }
9288
9289 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009290 * Returns false if the mobile data is disabled by default, otherwise return true.
9291 */
9292 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009293 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009294 }
9295
9296 /**
9297 * Returns true if the data roaming is enabled by default, i.e the system property
9298 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9299 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9300 */
9301 private boolean getDefaultDataRoamingEnabled(int subId) {
9302 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009303 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009304 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009305 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9306 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9307 return isDataRoamingEnabled;
9308 }
9309
9310 /**
9311 * Returns the default network type for the given {@code subId}, if the default network type is
9312 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9313 */
9314 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009315 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009316 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009317 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9318 return list.get(phoneId);
9319 }
9320 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009321 }
fionaxua13278b2018-03-21 00:08:13 -07009322
9323 @Override
9324 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009325 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009326 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009327
9328 final long identity = Binder.clearCallingIdentity();
9329 try {
9330 final Phone phone = getPhone(subId);
9331 if (phone == null) {
9332 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9333 return;
9334 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009335 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9336 if (cpt != null) {
9337 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9338 }
9339 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009340 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9341 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009342 if (carrierPrivilegeRules == null) {
9343 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9344 } else {
9345 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009347 } finally {
9348 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009349 }
fionaxua13278b2018-03-21 00:08:13 -07009350 }
9351
9352 @Override
9353 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009354 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009355
9356 final long identity = Binder.clearCallingIdentity();
9357 try {
9358 final Phone phone = getPhone(subId);
9359 if (phone == null) {
9360 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9361 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9362 }
9363 return phone.getCarrierIdListVersion();
9364 } finally {
9365 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009366 }
fionaxua13278b2018-03-21 00:08:13 -07009367 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009368
9369 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009370 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9371 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009372 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009373 mApp, subId, callingPackage, callingFeatureId,
9374 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009375 return -1;
9376 }
9377
9378 final long identity = Binder.clearCallingIdentity();
9379 try {
9380 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9381 } finally {
9382 Binder.restoreCallingIdentity(identity);
9383 }
9384 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009385
9386 @Override
9387 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009388 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009389 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009390 mApp, subId, "getCdmaRoamingMode");
9391
9392 final long identity = Binder.clearCallingIdentity();
9393 try {
9394 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9395 } finally {
9396 Binder.restoreCallingIdentity(identity);
9397 }
9398 }
9399
9400 @Override
9401 public boolean setCdmaRoamingMode(int subId, int mode) {
9402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9403 mApp, subId, "setCdmaRoamingMode");
9404
9405 final long identity = Binder.clearCallingIdentity();
9406 try {
9407 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9408 } finally {
9409 Binder.restoreCallingIdentity(identity);
9410 }
9411 }
9412
9413 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009414 public int getCdmaSubscriptionMode(int subId) {
9415 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009416 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009417 mApp, subId, "getCdmaSubscriptionMode");
9418
9419 final long identity = Binder.clearCallingIdentity();
9420 try {
9421 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9422 } finally {
9423 Binder.restoreCallingIdentity(identity);
9424 }
9425 }
9426
9427 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009428 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9429 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9430 mApp, subId, "setCdmaSubscriptionMode");
9431
9432 final long identity = Binder.clearCallingIdentity();
9433 try {
9434 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9435 } finally {
9436 Binder.restoreCallingIdentity(identity);
9437 }
9438 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009439
sqianc5eccab2018-10-19 18:46:41 -07009440 @Override
sqian8c685422019-02-22 15:55:18 -08009441 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009442 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009443 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009444 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9445 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009446 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9447 }
9448 final long identity = Binder.clearCallingIdentity();
9449 try {
sqian854d44b2018-12-12 16:48:18 -08009450 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9451 for (Phone phone: PhoneFactory.getPhones()) {
9452 if (phone.getEmergencyNumberTracker() != null
9453 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9454 emergencyNumberListInternal.put(
9455 phone.getSubId(),
9456 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9457 }
sqian11b7a0e2018-12-05 18:48:28 -08009458 }
sqian854d44b2018-12-12 16:48:18 -08009459 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009460 } finally {
9461 Binder.restoreCallingIdentity(identity);
9462 }
sqianc5eccab2018-10-19 18:46:41 -07009463 }
9464
9465 @Override
sqian8c685422019-02-22 15:55:18 -08009466 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009467 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009468 if (!exactMatch) {
9469 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009470 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009471 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009472 }
9473 final long identity = Binder.clearCallingIdentity();
9474 try {
sqian854d44b2018-12-12 16:48:18 -08009475 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009476 //Note: we ignore passed in param exactMatch. We can remove it once
9477 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009478 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009479 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009480 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009481 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009482 }
sqian11b7a0e2018-12-05 18:48:28 -08009483 }
9484 return false;
9485 } finally {
9486 Binder.restoreCallingIdentity(identity);
9487 }
9488 }
9489
sqianf4ca7ed2019-01-15 18:32:07 -08009490 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009491 * Start emergency callback mode for GsmCdmaPhone for testing.
9492 */
9493 @Override
9494 public void startEmergencyCallbackMode() {
9495 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9496 "startEmergencyCallbackMode");
9497 enforceModifyPermission();
9498 final long identity = Binder.clearCallingIdentity();
9499 try {
9500 for (Phone phone : PhoneFactory.getPhones()) {
9501 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9502 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9503 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9504 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9505 gsmCdmaPhone.obtainMessage(
9506 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9507 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9508 }
9509 }
9510 } finally {
9511 Binder.restoreCallingIdentity(identity);
9512 }
9513 }
9514
9515 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009516 * Update emergency number list for test mode.
9517 */
9518 @Override
9519 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9520 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9521 "updateEmergencyNumberListTestMode");
9522
9523 final long identity = Binder.clearCallingIdentity();
9524 try {
9525 for (Phone phone: PhoneFactory.getPhones()) {
9526 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9527 if (tracker != null) {
9528 tracker.executeEmergencyNumberTestModeCommand(action, num);
9529 }
9530 }
9531 } finally {
9532 Binder.restoreCallingIdentity(identity);
9533 }
9534 }
9535
9536 /**
9537 * Get the full emergency number list for test mode.
9538 */
9539 @Override
9540 public List<String> getEmergencyNumberListTestMode() {
9541 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9542 "getEmergencyNumberListTestMode");
9543
9544 final long identity = Binder.clearCallingIdentity();
9545 try {
9546 Set<String> emergencyNumbers = new HashSet<>();
9547 for (Phone phone: PhoneFactory.getPhones()) {
9548 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9549 if (tracker != null) {
9550 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9551 emergencyNumbers.add(num.getNumber());
9552 }
9553 }
9554 }
9555 return new ArrayList<>(emergencyNumbers);
9556 } finally {
9557 Binder.restoreCallingIdentity(identity);
9558 }
9559 }
9560
chen xud6b45bd2018-10-30 22:27:10 -07009561 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009562 public int getEmergencyNumberDbVersion(int subId) {
9563 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9564
9565 final long identity = Binder.clearCallingIdentity();
9566 try {
9567 final Phone phone = getPhone(subId);
9568 if (phone == null) {
9569 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9570 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9571 }
9572 return phone.getEmergencyNumberDbVersion();
9573 } finally {
9574 Binder.restoreCallingIdentity(identity);
9575 }
9576 }
9577
9578 @Override
9579 public void notifyOtaEmergencyNumberDbInstalled() {
9580 enforceModifyPermission();
9581
9582 final long identity = Binder.clearCallingIdentity();
9583 try {
9584 for (Phone phone: PhoneFactory.getPhones()) {
9585 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9586 if (tracker != null) {
9587 tracker.updateOtaEmergencyNumberDatabase();
9588 }
9589 }
9590 } finally {
9591 Binder.restoreCallingIdentity(identity);
9592 }
9593 }
9594
9595 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009596 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009597 enforceActiveEmergencySessionPermission();
9598
9599 final long identity = Binder.clearCallingIdentity();
9600 try {
9601 for (Phone phone: PhoneFactory.getPhones()) {
9602 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9603 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009604 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9605 }
9606 }
9607 } finally {
9608 Binder.restoreCallingIdentity(identity);
9609 }
9610 }
9611
9612 @Override
9613 public void resetOtaEmergencyNumberDbFilePath() {
9614 enforceActiveEmergencySessionPermission();
9615
9616 final long identity = Binder.clearCallingIdentity();
9617 try {
9618 for (Phone phone: PhoneFactory.getPhones()) {
9619 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9620 if (tracker != null) {
9621 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009622 }
9623 }
9624 } finally {
9625 Binder.restoreCallingIdentity(identity);
9626 }
9627 }
9628
9629 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009630 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9631 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9632 Phone phone = getPhone(subId);
9633 if (phone == null) {
9634 return null;
9635 }
9636 final long identity = Binder.clearCallingIdentity();
9637 try {
9638 UiccProfile profile = UiccController.getInstance()
9639 .getUiccProfileForPhone(phone.getPhoneId());
9640 if (profile != null) {
9641 return profile.getCertsFromCarrierPrivilegeAccessRules();
9642 }
9643 } finally {
9644 Binder.restoreCallingIdentity(identity);
9645 }
9646 return null;
9647 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009648
9649 /**
9650 * Enable or disable a modem stack.
9651 */
9652 @Override
9653 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9654 enforceModifyPermission();
9655
9656 final long identity = Binder.clearCallingIdentity();
9657 try {
9658 Phone phone = PhoneFactory.getPhone(slotIndex);
9659 if (phone == null) {
9660 return false;
9661 } else {
9662 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9663 }
9664 } finally {
9665 Binder.restoreCallingIdentity(identity);
9666 }
9667 }
Michelecea4cf22018-12-21 15:00:11 -08009668
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009669 /**
9670 * Whether a modem stack is enabled or not.
9671 */
9672 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009673 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9674 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009675 Phone phone = PhoneFactory.getPhone(slotIndex);
9676 if (phone == null) return false;
9677
9678 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009679 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9680 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009681 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9682 }
9683
9684 final long identity = Binder.clearCallingIdentity();
9685 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009686 try {
9687 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9688 } catch (NoSuchElementException ex) {
9689 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9690 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009691 } finally {
9692 Binder.restoreCallingIdentity(identity);
9693 }
9694 }
9695
Michelecea4cf22018-12-21 15:00:11 -08009696 @Override
Michele0ea7d782019-03-19 14:58:42 -07009697 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009698 enforceModifyPermission();
9699
9700 final long identity = Binder.clearCallingIdentity();
9701 try {
9702 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009703 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009704 .commit();
9705 } finally {
9706 Binder.restoreCallingIdentity(identity);
9707 }
9708 }
9709
9710 @Override
Michele0ea7d782019-03-19 14:58:42 -07009711 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009712 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009713 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009714 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9715 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009716 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009717 }
Michelecea4cf22018-12-21 15:00:11 -08009718
9719 final long identity = Binder.clearCallingIdentity();
9720 try {
Michele0ea7d782019-03-19 14:58:42 -07009721 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009722 } finally {
9723 Binder.restoreCallingIdentity(identity);
9724 }
9725 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009726
Michele0ea7d782019-03-19 14:58:42 -07009727 @TelephonyManager.IsMultiSimSupportedResult
9728 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009729 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9730 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9731 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009732 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9733 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009734 }
9735 // Check if the hardware supports multisim functionality. If usage of multisim is not
9736 // supported by the modem, indicate that it is restricted.
9737 PhoneCapability staticCapability =
9738 mPhoneConfigurationManager.getStaticPhoneCapability();
9739 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009740 loge("isMultiSimSupportedInternal: no static configuration available");
9741 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009742 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009743 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009744 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9745 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009746 }
9747 // Check if support of multiple SIMs is restricted by carrier
9748 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009749 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009750 }
9751
Michele0ea7d782019-03-19 14:58:42 -07009752 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009753 }
9754
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009755 /**
9756 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009757 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9758 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9759 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009760 * @param numOfSims number of active sims we want to switch to
9761 */
9762 @Override
9763 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009764 if (numOfSims == 1) {
9765 enforceModifyPermission();
9766 } else {
9767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9768 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9769 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009770 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009771
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009772 try {
Michele30b57b22019-03-01 12:01:14 -08009773 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009774 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009775 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9776 return;
9777 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009778 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9779 } finally {
9780 Binder.restoreCallingIdentity(identity);
9781 }
9782 }
9783
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009784 @Override
9785 public boolean isApplicationOnUicc(int subId, int appType) {
9786 enforceReadPrivilegedPermission("isApplicationOnUicc");
9787 Phone phone = getPhone(subId);
9788 if (phone == null) {
9789 return false;
9790 }
9791 final long identity = Binder.clearCallingIdentity();
9792 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009793 UiccPort uiccPort = phone.getUiccPort();
9794 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009795 return false;
9796 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009797 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009798 if (uiccProfile == null) {
9799 return false;
9800 }
9801 if (TelephonyManager.APPTYPE_SIM <= appType
9802 && appType <= TelephonyManager.APPTYPE_ISIM) {
9803 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9804 }
9805 return false;
9806 } finally {
9807 Binder.restoreCallingIdentity(identity);
9808 }
9809 }
9810
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009811 /**
chen xub4baa772019-04-03 10:23:41 -07009812 * Get whether making changes to modem configurations will trigger reboot.
9813 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009814 */
9815 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009816 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9817 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009818 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009819 mApp, subId, callingPackage, callingFeatureId,
9820 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009821 return false;
9822 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009823 final long identity = Binder.clearCallingIdentity();
9824 try {
9825 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9826 } finally {
9827 Binder.restoreCallingIdentity(identity);
9828 }
9829 }
9830
Nathan Harold29f5f052019-02-15 13:41:57 -08009831 private void updateModemStateMetrics() {
9832 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9833 // TODO: check the state for each modem if the api is ready.
9834 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9835 }
9836
Pengquan Meng3889a572019-01-23 11:16:29 -08009837 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009838 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009839 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009840 // Verify that the callingPackage belongs to the calling UID
9841 mApp.getSystemService(AppOpsManager.class)
9842 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009843 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009844 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009845 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009846 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9847 if (slotInfos != null) {
9848 for (int i = 0; i < slotInfos.length; i++) {
9849 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9850 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9851 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9852 portInfo.getLogicalSlotIndex()));
9853 }
9854 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009855 }
9856 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009857 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009858 } finally {
9859 Binder.restoreCallingIdentity(identity);
9860 }
9861 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009862
9863 /**
9864 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +08009865 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -08009866 */
jimsunf9ec1622022-09-13 21:18:43 +08009867 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -08009868 @Override
9869 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +08009870 return getHalVersion(HAL_SERVICE_RADIO);
9871 }
9872
9873 /**
9874 * Get the HAL Version of a specific service
9875 */
9876 @Override
9877 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -08009878 Phone phone = getDefaultPhone();
9879 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +08009880 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -08009881 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9882 return hv.major * 100 + hv.minor;
9883 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009884
9885 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009886 * Get the current calling package name.
9887 * @return the current calling package name
9888 */
9889 @Override
9890 public String getCurrentPackageName() {
9891 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9892 }
9893
9894 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009895 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9896 * corresponding network requests on a subId.
9897 *
9898 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009899 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009900 * 2) APN is un-metered for this subscription, or
9901 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009902 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009903 *
9904 * @return whether data is allowed for a apn type.
9905 *
9906 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009907 */
9908 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009909 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009910 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9911 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009912
9913 // Now that all security checks passes, perform the operation as ourselves.
9914 final long identity = Binder.clearCallingIdentity();
9915 try {
9916 Phone phone = getPhone(subId);
9917 if (phone == null) return false;
9918
Jack Yu27422a52022-03-21 10:38:05 -07009919 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009920 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -07009921 isMetered = phone.getDataNetworkController().getDataConfigManager()
9922 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9923 phone.getServiceState().getDataRoaming());
9924 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009925 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009926 } finally {
9927 Binder.restoreCallingIdentity(identity);
9928 }
9929 }
9930
9931 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009932 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009933 enforceReadPrivilegedPermission("isApnMetered");
9934
9935 // Now that all security checks passes, perform the operation as ourselves.
9936 final long identity = Binder.clearCallingIdentity();
9937 try {
9938 Phone phone = getPhone(subId);
9939 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -07009940 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9941 DataUtils.apnTypeToNetworkCapability(apnType),
9942 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009943 } finally {
9944 Binder.restoreCallingIdentity(identity);
9945 }
9946 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009947
9948 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009949 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9950 int subscriptionId, IBooleanConsumer resultCallback) {
9951 enforceModifyPermission();
9952 long token = Binder.clearCallingIdentity();
9953 try {
9954 Phone phone = getPhone(subscriptionId);
9955 if (phone == null) {
9956 try {
9957 if (resultCallback != null) {
9958 resultCallback.accept(false);
9959 }
9960 } catch (RemoteException e) {
9961 // ignore
9962 }
9963 return;
9964 }
9965 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9966 Pair.create(specifiers, (x) -> {
9967 try {
9968 if (resultCallback != null) {
9969 resultCallback.accept(x);
9970 }
9971 } catch (RemoteException e) {
9972 // ignore
9973 }
9974 });
9975 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9976 } finally {
9977 Binder.restoreCallingIdentity(token);
9978 }
9979 }
9980
9981 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009982 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9983 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009984 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009985 mApp, subId, "getSystemSelectionChannels");
9986 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9987 final long identity = Binder.clearCallingIdentity();
9988 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009989 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9990 if (result instanceof IllegalStateException) {
9991 throw (IllegalStateException) result;
9992 }
9993 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009994 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9995 return specifiers;
9996 } finally {
9997 Binder.restoreCallingIdentity(identity);
9998 }
9999 }
10000
10001 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010002 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010003 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010004 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010005 }
10006
10007 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010008 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10009 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010010 if (callingPackage == null) {
10011 callingPackage = getCurrentPackageName();
10012 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010013 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10014 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010015 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10016 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010017 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10018 }
10019 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10020 Intent intent = new Intent();
10021 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10022 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10023 // Bring up choose default SMS subscription dialog right now
10024 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10025 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10026 mApp.startActivity(intent);
10027 }
chen xud5ca2d52019-05-28 15:20:57 -070010028
10029 @Override
10030 public String getMmsUAProfUrl(int subId) {
10031 //TODO investigate if this API should require proper permission check in R b/133791609
10032 final long identity = Binder.clearCallingIdentity();
10033 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010034 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10035 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10036 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10037 return carrierUAProfUrl;
10038 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010039 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10040 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010041 } finally {
10042 Binder.restoreCallingIdentity(identity);
10043 }
10044 }
10045
10046 @Override
10047 public String getMmsUserAgent(int subId) {
10048 //TODO investigate if this API should require proper permission check in R b/133791609
10049 final long identity = Binder.clearCallingIdentity();
10050 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010051 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10052 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10053 if (!TextUtils.isEmpty(carrierUserAgent)) {
10054 return carrierUserAgent;
10055 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010056 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10057 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010058 } finally {
10059 Binder.restoreCallingIdentity(identity);
10060 }
10061 }
Jack Yub07d4972019-05-28 16:12:25 -070010062
10063 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010064 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10065 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010066
Jack Yub07d4972019-05-28 16:12:25 -070010067 final long identity = Binder.clearCallingIdentity();
10068 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010069 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010070 if (phone == null) return false;
10071
Ling Maf188d502022-09-16 15:22:36 -070010072 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010073 } finally {
10074 Binder.restoreCallingIdentity(identity);
10075 }
10076 }
10077
10078 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010079 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010080 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010081 enforceModifyPermission();
10082
changbettyd5c246e2019-12-24 15:40:37 +080010083 final long identity = Binder.clearCallingIdentity();
10084 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010085 Phone phone = getPhone(subscriptionId);
10086 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010087
Ling Maf188d502022-09-16 15:22:36 -070010088 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010089 } finally {
10090 Binder.restoreCallingIdentity(identity);
10091 }
10092 }
10093
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010094 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010095 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010096 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10097 * otherwise.
10098 */
10099 @Override
10100 public void setCepEnabled(boolean isCepEnabled) {
10101 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10102
10103 final long identity = Binder.clearCallingIdentity();
10104 try {
10105 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10106 for (Phone phone : PhoneFactory.getPhones()) {
10107 Phone defaultPhone = phone.getImsPhone();
10108 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10109 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10110 ImsPhoneCallTracker imsPhoneCallTracker =
10111 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10112 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10113 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10114 + imsPhone.getMsisdn());
10115 }
10116 }
10117 } finally {
10118 Binder.restoreCallingIdentity(identity);
10119 }
10120 }
allenwtsu46dcc572020-01-08 18:24:03 +080010121
10122 /**
10123 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10124 *
10125 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10126 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10127 * before being read.
10128 */
10129 @Override
10130 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10131 isCompressed) {
10132 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10133 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010134 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10135 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10136 }
10137 if (!isImsAvailableOnDevice()) {
10138 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10139 "IMS not available on device.");
10140 }
10141
10142 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010143 try {
Hui Wang761a6682020-10-31 05:12:53 +000010144 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10145 } finally {
10146 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010147 }
10148 }
zoey chene02881a2019-12-30 16:11:23 +080010149
10150 @Override
10151 public boolean isIccLockEnabled(int subId) {
10152 enforceReadPrivilegedPermission("isIccLockEnabled");
10153
10154 // Now that all security checks passes, perform the operation as ourselves.
10155 final long identity = Binder.clearCallingIdentity();
10156 try {
10157 Phone phone = getPhone(subId);
10158 if (phone != null && phone.getIccCard() != null) {
10159 return phone.getIccCard().getIccLockEnabled();
10160 } else {
10161 return false;
10162 }
10163 } finally {
10164 Binder.restoreCallingIdentity(identity);
10165 }
10166 }
10167
10168 /**
10169 * Set the ICC pin lock enabled or disabled.
10170 *
10171 * @return an integer representing the status of IccLock enabled or disabled in the following
10172 * three cases:
10173 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10174 * successfully.
10175 * - Positive number and zero for remaining password attempts.
10176 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10177 *
10178 */
10179 @Override
10180 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10181 enforceModifyPermission();
10182
10183 Phone phone = getPhone(subId);
10184 if (phone == null) {
10185 return 0;
10186 }
10187 // Now that all security checks passes, perform the operation as ourselves.
10188 final long identity = Binder.clearCallingIdentity();
10189 try {
10190 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10191 new Pair<Boolean, String>(enabled, password), phone, null);
10192 return attemptsRemaining;
10193
10194 } catch (Exception e) {
10195 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10196 } finally {
10197 Binder.restoreCallingIdentity(identity);
10198 }
10199 return 0;
10200 }
10201
10202 /**
10203 * Change the ICC password used in ICC pin lock.
10204 *
10205 * @return an integer representing the status of IccLock changed in the following three cases:
10206 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10207 * - Positive number and zero for remaining password attempts.
10208 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10209 *
10210 */
10211 @Override
10212 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10213 enforceModifyPermission();
10214
10215 Phone phone = getPhone(subId);
10216 if (phone == null) {
10217 return 0;
10218 }
10219 // Now that all security checks passes, perform the operation as ourselves.
10220 final long identity = Binder.clearCallingIdentity();
10221 try {
10222 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10223 new Pair<String, String>(oldPassword, newPassword), phone, null);
10224 return attemptsRemaining;
10225
10226 } catch (Exception e) {
10227 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10228 } finally {
10229 Binder.restoreCallingIdentity(identity);
10230 }
10231 return 0;
10232 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010233
10234 /**
10235 * Request for receiving user activity notification
10236 */
10237 @Override
10238 public void requestUserActivityNotification() {
10239 if (!mNotifyUserActivity.get()
10240 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10241 mNotifyUserActivity.set(true);
10242 }
10243 }
10244
10245 /**
10246 * Called when userActivity is signalled in the power manager.
10247 * This is safe to call from any thread, with any window manager locks held or not.
10248 */
10249 @Override
10250 public void userActivity() {
10251 // ***************************************
10252 // * Inherited from PhoneWindowManager *
10253 // ***************************************
10254 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10255 // WITH ITS LOCKS HELD.
10256 //
10257 // This code must be VERY careful about the locks
10258 // it acquires.
10259 // In fact, the current code acquires way too many,
10260 // and probably has lurking deadlocks.
10261
10262 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10263 throw new SecurityException("Only the OS may call notifyUserActivity()");
10264 }
10265
10266 if (mNotifyUserActivity.getAndSet(false)) {
10267 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10268 USER_ACTIVITY_NOTIFICATION_DELAY);
10269 }
10270 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010271
10272 @Override
10273 public boolean canConnectTo5GInDsdsMode() {
10274 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10275 }
Jack Yud10cdd42020-09-28 20:28:01 -070010276
10277 @Override
10278 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10279 String callingFeatureId) {
10280 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10281 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10282 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10283 }
10284
10285 Phone phone = getPhone(subId);
10286 if (phone == null) {
10287 throw new RuntimeException("phone is not available");
10288 }
10289 // Now that all security checks passes, perform the operation as ourselves.
10290 final long identity = Binder.clearCallingIdentity();
10291 try {
10292 return phone.getEquivalentHomePlmns();
10293 } finally {
10294 Binder.restoreCallingIdentity(identity);
10295 }
10296 }
Daniel Bright59e67312020-11-13 11:49:37 -080010297
10298 @Override
10299 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010300 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10301 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010302 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010303 if (radioInterfaceCapabilities == null) {
10304 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010305 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010306 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010307 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010308
Hui Wang641e81c2020-10-12 12:14:23 -070010309 @Override
10310 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10311 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010312 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10313 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10314 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10315 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10316 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010317 if (DBG) {
10318 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10319 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10320 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10321 }
10322
10323 if (!SubscriptionManager.isValidSubscriptionId(subId)
10324 || appType < TelephonyManager.APPTYPE_UNKNOWN
10325 || appType > TelephonyManager.APPTYPE_ISIM
10326 || nafUrl == null || securityProtocol == null || callback == null) {
10327 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10328 if (callback != null) {
10329 try {
10330 callback.onAuthenticationFailure(
10331 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10332 } catch (RemoteException exception) {
10333 log("Fail to notify onAuthenticationFailure due to " + exception);
10334 }
10335 return;
10336 }
10337 }
10338
10339 final long token = Binder.clearCallingIdentity();
10340 try {
10341 getGbaManager(subId).bootstrapAuthenticationRequest(
10342 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10343 forceBootStrapping, callback));
10344 } finally {
10345 Binder.restoreCallingIdentity(token);
10346 }
10347 }
10348
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010349 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010350 * Attempts to set the radio power state for all phones for thermal reason.
10351 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010352 * requested radio power state will actually be set. See {@link
10353 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10354 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010355 * @param enable {@code true} if trying to turn radio on.
10356 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10357 * false}.
10358 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010359 private boolean setRadioPowerForThermal(boolean enable) {
10360 boolean isPhoneAvailable = false;
10361 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10362 Phone phone = PhoneFactory.getPhone(i);
10363 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010364 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010365 isPhoneAvailable = true;
10366 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010367 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010368
10369 // return true if successfully informed the phone object about the thermal radio power
10370 // request.
10371 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010372 }
10373
10374 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010375 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010376 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10377 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10378 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10379 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10380 throw new IllegalArgumentException("modem does not support data throttling");
10381 }
10382
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010383 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10384 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010385 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010386 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10387 }
10388
Sarah Chinecc78c42022-03-31 21:16:48 -070010389 setDataEnabledForReason(
10390 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010391
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010392 if (isDataThrottlingSupported) {
10393 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010394 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010395 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10396 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10397 } else if (thermalMitigationResult
10398 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010399 log("Modem likely does not support data throttling on secondary carrier. Data " +
10400 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10401 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010402 }
10403 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010404 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010405
10406 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010407 }
10408
Jack Nudelman644b91a2021-03-12 14:09:48 -080010409 private static List<String> getThermalMitigationAllowlist(Context context) {
10410 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10411 for (String pckg : context.getResources()
10412 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10413 sThermalMitigationAllowlistedPackages.add(pckg);
10414 }
10415 }
10416
10417 return sThermalMitigationAllowlistedPackages;
10418 }
10419
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010420 private boolean isAnyPhoneInEmergencyState() {
10421 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10422 if (tm.isInEmergencyCall()) {
10423 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10424 return true;
10425 }
10426 for (Phone phone : PhoneFactory.getPhones()) {
10427 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10428 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10429 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10430 + phone.isInEcm());
10431 return true;
10432 }
10433 }
10434
10435 return false;
10436 }
10437
Jack Nudelman644b91a2021-03-12 14:09:48 -080010438 /**
10439 * Used by shell commands to add an authorized package name for thermal mitigation.
10440 * @param packageName name of package to be allowlisted
10441 * @param context
10442 */
10443 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10444 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10445 sThermalMitigationAllowlistedPackages.add(packageName);
10446 }
10447
10448 /**
10449 * Used by shell commands to remove an authorized package name for thermal mitigation.
10450 * @param packageName name of package to remove from allowlist
10451 * @param context
10452 */
10453 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10454 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10455 sThermalMitigationAllowlistedPackages.remove(packageName);
10456 }
10457
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010458 /**
10459 * Thermal mitigation request to control functionalities at modem.
10460 *
10461 * @param subId the id of the subscription.
10462 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010463 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010464 *
10465 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10466 */
10467 @Override
10468 @ThermalMitigationResult
10469 public int sendThermalMitigationRequest(
10470 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010471 ThermalMitigationRequest thermalMitigationRequest,
10472 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010473 enforceModifyPermission();
10474
Jack Nudelman644b91a2021-03-12 14:09:48 -080010475 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10476 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10477 .contains(callingPackage)) {
10478 throw new SecurityException("Calling package must be configured in the device config. "
10479 + "calling package: " + callingPackage);
10480 }
10481
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010482 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10483 final long identity = Binder.clearCallingIdentity();
10484
10485 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10486 try {
10487 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10488 switch (thermalMitigationAction) {
10489 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10490 thermalMitigationResult =
10491 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010492 thermalMitigationRequest.getDataThrottlingRequest(),
10493 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010494 break;
10495 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10496 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10497 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10498 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10499 }
10500
10501 // Ensure that radio is on. If not able to power on due to phone being
10502 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010503 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010504 thermalMitigationResult =
10505 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10506 break;
10507 }
10508
10509 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010510 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010511 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10512 break;
10513 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10514 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10515 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10516 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10517 }
10518
10519 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10520 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010521 Phone phone = getPhone(subId);
10522 if (phone == null) {
10523 thermalMitigationResult =
10524 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10525 break;
10526 }
10527
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010528 TelephonyConnectionService service =
10529 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010530 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010531 Log.e(LOG_TAG, "An emergency call is pending");
10532 thermalMitigationResult =
10533 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10534 break;
10535 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010536 thermalMitigationResult =
10537 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10538 break;
10539 }
10540 } else {
10541 thermalMitigationResult =
10542 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10543 break;
10544 }
10545
10546 // Turn radio off. If not able to power off due to phone being unavailable,
10547 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010548 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010549 thermalMitigationResult =
10550 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10551 break;
10552 }
10553 thermalMitigationResult =
10554 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10555 break;
10556 default:
10557 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10558 + "not exist. Requested action: " + thermalMitigationAction);
10559 }
10560 } catch (IllegalArgumentException e) {
10561 throw e;
10562 } catch (Exception e) {
10563 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10564 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10565 } finally {
10566 Binder.restoreCallingIdentity(identity);
10567 }
10568
10569 if (DBG) {
10570 log("thermalMitigationRequest returning with thermalMitigationResult: "
10571 + thermalMitigationResult);
10572 }
10573
10574 return thermalMitigationResult;
10575 }
Hui Wang641e81c2020-10-12 12:14:23 -070010576
10577 /**
10578 * Set the GbaService Package Name that Telephony will bind to.
10579 *
10580 * @param subId The sim that the GbaService is associated with.
10581 * @param packageName The name of the package to be replaced with.
10582 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10583 */
10584 @Override
10585 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10586 enforceModifyPermission();
10587
10588 final long identity = Binder.clearCallingIdentity();
10589 try {
10590 return getGbaManager(subId).overrideServicePackage(packageName);
10591 } finally {
10592 Binder.restoreCallingIdentity(identity);
10593 }
10594 }
10595
10596 /**
10597 * Return the package name of the currently bound GbaService.
10598 *
10599 * @param subId The sim that the GbaService is associated with.
10600 * @return the package name of the GbaService configuration, null if GBA is not supported.
10601 */
10602 @Override
10603 public String getBoundGbaService(int subId) {
10604 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10605
10606 final long identity = Binder.clearCallingIdentity();
10607 try {
10608 return getGbaManager(subId).getServicePackage();
10609 } finally {
10610 Binder.restoreCallingIdentity(identity);
10611 }
10612 }
10613
10614 /**
10615 * Set the release time for telephony to unbind GbaService.
10616 *
10617 * @param subId The sim that the GbaService is associated with.
10618 * @param interval The release time to unbind GbaService by millisecond.
10619 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10620 */
10621 @Override
10622 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10623 enforceModifyPermission();
10624
10625 final long identity = Binder.clearCallingIdentity();
10626 try {
10627 return getGbaManager(subId).overrideReleaseTime(interval);
10628 } finally {
10629 Binder.restoreCallingIdentity(identity);
10630 }
10631 }
10632
10633 /**
10634 * Return the release time for telephony to unbind GbaService.
10635 *
10636 * @param subId The sim that the GbaService is associated with.
10637 * @return The release time to unbind GbaService by millisecond.
10638 */
10639 @Override
10640 public int getGbaReleaseTime(int subId) {
10641 enforceReadPrivilegedPermission("getGbaReleaseTime");
10642
10643 final long identity = Binder.clearCallingIdentity();
10644 try {
10645 return getGbaManager(subId).getReleaseTime();
10646 } finally {
10647 Binder.restoreCallingIdentity(identity);
10648 }
10649 }
10650
10651 private GbaManager getGbaManager(int subId) {
10652 GbaManager instance = GbaManager.getInstance(subId);
10653 if (instance == null) {
10654 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10655 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10656 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10657 }
10658 return instance;
10659 }
Hui Wang761a6682020-10-31 05:12:53 +000010660
10661 /**
10662 * indicate whether the device and the carrier can support
10663 * RCS VoLTE single registration.
10664 */
10665 @Override
10666 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010667 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10668 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10669 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10670 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010671
10672 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10673 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10674 }
10675
10676 final long identity = Binder.clearCallingIdentity();
10677 try {
10678 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10679 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010680 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10681 if (isCapable != null) {
10682 return isCapable;
10683 }
Hui Wang761a6682020-10-31 05:12:53 +000010684 }
Hui Wang67af90e2021-06-04 16:57:15 -070010685 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10686 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010687 } finally {
10688 Binder.restoreCallingIdentity(identity);
10689 }
10690 }
10691
10692 /**
10693 * Register RCS provisioning callback.
10694 */
10695 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010696 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010697 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010698 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010699 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010700 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10701 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010702
10703 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10704 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10705 }
10706 if (!isImsAvailableOnDevice()) {
10707 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10708 "IMS not available on device.");
10709 }
10710
10711 final long identity = Binder.clearCallingIdentity();
10712 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010713 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010714 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010715 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10716 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010717 }
Hui Wang761a6682020-10-31 05:12:53 +000010718 } finally {
10719 Binder.restoreCallingIdentity(identity);
10720 }
10721 }
10722
10723 /**
10724 * Unregister RCS provisioning callback.
10725 */
10726 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010727 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010728 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010729 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010730 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010731 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10732 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010733
10734 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10735 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10736 }
10737 if (!isImsAvailableOnDevice()) {
10738 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10739 "IMS not available on device.");
10740 }
10741
10742 final long identity = Binder.clearCallingIdentity();
10743 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010744 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010745 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010746 } finally {
10747 Binder.restoreCallingIdentity(identity);
10748 }
10749 }
10750
10751 /**
10752 * trigger RCS reconfiguration.
10753 */
10754 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010755 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10756 "triggerRcsReconfiguration",
10757 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010758
10759 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10760 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10761 }
10762 if (!isImsAvailableOnDevice()) {
10763 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10764 "IMS not available on device.");
10765 }
10766
10767 final long identity = Binder.clearCallingIdentity();
10768 try {
10769 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10770 } finally {
10771 Binder.restoreCallingIdentity(identity);
10772 }
10773 }
10774
10775 /**
10776 * Provide the client configuration parameters of the RCS application.
10777 */
10778 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010779 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10780 "setRcsClientConfiguration",
10781 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010782
10783 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10784 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10785 }
10786 if (!isImsAvailableOnDevice()) {
10787 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10788 "IMS not available on device.");
10789 }
10790
10791 final long identity = Binder.clearCallingIdentity();
10792
10793 try {
10794 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10795 if (configBinder == null) {
10796 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010797 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10798 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010799 } else {
10800 configBinder.setRcsClientConfiguration(rcc);
10801 }
joonhunshin3e154242021-09-17 06:33:39 +000010802
10803 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10804 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010805 } catch (RemoteException e) {
10806 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010807 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10808 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010809 } finally {
10810 Binder.restoreCallingIdentity(identity);
10811 }
10812 }
10813
10814 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010815 * Enables or disables the test mode for RCS VoLTE single registration.
10816 */
10817 @Override
10818 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10819 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10820 "setRcsSingleRegistrationTestModeEnabled");
10821
10822 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10823 }
10824
10825 /**
10826 * Gets the test mode for RCS VoLTE single registration.
10827 */
10828 @Override
10829 public boolean getRcsSingleRegistrationTestModeEnabled() {
10830 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10831 "getRcsSingleRegistrationTestModeEnabled");
10832
10833 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10834 }
10835
10836 /**
Hui Wang761a6682020-10-31 05:12:53 +000010837 * Overrides the config of RCS VoLTE single registration enabled for the device.
10838 */
10839 @Override
10840 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10841 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10842 "setDeviceSingleRegistrationEnabledOverride");
10843 enforceModifyPermission();
10844
10845 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10846 : Boolean.parseBoolean(enabledStr);
10847 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010848 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010849 }
10850
10851 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010852 * Sends a device to device communication message. Only usable via shell.
10853 * @param message message to send.
10854 * @param value message value.
10855 */
10856 @Override
10857 public void sendDeviceToDeviceMessage(int message, int value) {
10858 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010859 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010860 enforceModifyPermission();
10861
10862 final long identity = Binder.clearCallingIdentity();
10863 try {
10864 TelephonyConnectionService service =
10865 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10866 if (service == null) {
10867 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10868 return;
10869 }
10870 service.sendTestDeviceToDeviceMessage(message, value);
10871 } finally {
10872 Binder.restoreCallingIdentity(identity);
10873 }
10874 }
10875
Tyler Gunnbabbda02021-02-10 11:05:02 -080010876 /**
10877 * Sets the specified device to device transport active.
10878 * @param transport The transport to set active.
10879 */
10880 @Override
10881 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10882 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10883 "setActiveDeviceToDeviceTransport");
10884 enforceModifyPermission();
10885
10886 final long identity = Binder.clearCallingIdentity();
10887 try {
10888 TelephonyConnectionService service =
10889 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10890 if (service == null) {
10891 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10892 return;
10893 }
10894 service.setActiveDeviceToDeviceTransport(transport);
10895 } finally {
10896 Binder.restoreCallingIdentity(identity);
10897 }
10898 }
Tyler Gunn92479152021-01-20 16:30:10 -080010899
Tyler Gunnd4339262021-05-03 14:46:49 -070010900 @Override
10901 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10902 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10903 "setDeviceToDeviceForceEnabled");
10904
10905 final long identity = Binder.clearCallingIdentity();
10906 try {
10907 Arrays.stream(PhoneFactory.getPhones()).forEach(
10908 p -> {
10909 Phone thePhone = p.getImsPhone();
10910 if (thePhone != null && thePhone instanceof ImsPhone) {
10911 ImsPhone imsPhone = (ImsPhone) thePhone;
10912 CallTracker tracker = imsPhone.getCallTracker();
10913 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10914 ImsPhoneCallTracker imsPhoneCallTracker =
10915 (ImsPhoneCallTracker) tracker;
10916 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10917 }
10918 }
10919 }
10920 );
10921 } finally {
10922 Binder.restoreCallingIdentity(identity);
10923 }
10924 }
10925
Tyler Gunn92479152021-01-20 16:30:10 -080010926 /**
Hui Wang761a6682020-10-31 05:12:53 +000010927 * Gets the config of RCS VoLTE single registration enabled for the device.
10928 */
10929 @Override
10930 public boolean getDeviceSingleRegistrationEnabled() {
10931 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10932 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10933 }
10934
10935 /**
10936 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10937 */
10938 @Override
10939 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10940 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10941 "setCarrierSingleRegistrationEnabledOverride");
10942 enforceModifyPermission();
10943
10944 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10945 : Boolean.parseBoolean(enabledStr);
10946 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10947 subId, enabled);
10948 }
10949
10950 /**
10951 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10952 */
10953 @Override
10954 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10955 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10956 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10957 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010958
10959 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010960 * Overrides the ims feature validation result
10961 */
10962 @Override
10963 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10964 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10965 "setImsFeatureValidationOverride");
10966
10967 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10968 : Boolean.parseBoolean(enabledStr);
10969 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10970 subId, enabled);
10971 }
10972
10973 /**
10974 * Gets the ims feature validation override value
10975 */
10976 @Override
10977 public boolean getImsFeatureValidationOverride(int subId) {
10978 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10979 "getImsFeatureValidationOverride");
10980 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10981 }
10982
10983 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010984 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10985 * their mobile plan.
10986 */
10987 @Override
10988 public String getMobileProvisioningUrl() {
10989 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10990 final long identity = Binder.clearCallingIdentity();
10991 try {
10992 return getDefaultPhone().getMobileProvisioningUrl();
10993 } finally {
10994 Binder.restoreCallingIdentity(identity);
10995 }
10996 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010997
James.cf Linbcdf8b32021-01-14 16:44:13 +080010998 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010999 * Get the EAB contact from the EAB database.
11000 */
11001 @Override
11002 public String getContactFromEab(String contact) {
11003 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11004 enforceModifyPermission();
11005 final long identity = Binder.clearCallingIdentity();
11006 try {
11007 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11008 } finally {
11009 Binder.restoreCallingIdentity(identity);
11010 }
11011 }
11012
11013 /**
Calvin Pana1434322021-07-01 19:27:01 +080011014 * Get the EAB capability from the EAB database.
11015 */
11016 @Override
11017 public String getCapabilityFromEab(String contact) {
11018 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11019 enforceModifyPermission();
11020 final long identity = Binder.clearCallingIdentity();
11021 try {
11022 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11023 } finally {
11024 Binder.restoreCallingIdentity(identity);
11025 }
11026 }
11027
11028 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011029 * Remove the EAB contacts from the EAB database.
11030 */
11031 @Override
11032 public int removeContactFromEab(int subId, String contacts) {
11033 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11034 enforceModifyPermission();
11035 final long identity = Binder.clearCallingIdentity();
11036 try {
11037 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11038 } finally {
11039 Binder.restoreCallingIdentity(identity);
11040 }
11041 }
11042
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011043 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011044 public boolean getDeviceUceEnabled() {
11045 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11046 final long identity = Binder.clearCallingIdentity();
11047 try {
11048 return mApp.getDeviceUceEnabled();
11049 } finally {
11050 Binder.restoreCallingIdentity(identity);
11051 }
11052 }
11053
11054 @Override
11055 public void setDeviceUceEnabled(boolean isEnabled) {
11056 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11057 final long identity = Binder.clearCallingIdentity();
11058 try {
11059 mApp.setDeviceUceEnabled(isEnabled);
11060 } finally {
11061 Binder.restoreCallingIdentity(identity);
11062 }
11063 }
11064
Brad Ebinger14d467f2021-02-12 06:18:28 +000011065 /**
11066 * Add new feature tags to 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 addUceRegistrationOverrideShell(int subId,
11072 List<String> featureTags) {
11073 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11074 "addUceRegistrationOverrideShell");
11075 final long identity = Binder.clearCallingIdentity();
11076 try {
11077 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11078 new ArraySet<>(featureTags));
11079 } catch (ImsException e) {
11080 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11081 } finally {
11082 Binder.restoreCallingIdentity(identity);
11083 }
11084 }
11085
11086 /**
11087 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11088 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11089 */
11090 // Used for SHELL command only right now.
11091 @Override
11092 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11093 List<String> featureTags) {
11094 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11095 "removeUceRegistrationOverrideShell");
11096 final long identity = Binder.clearCallingIdentity();
11097 try {
11098 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11099 new ArraySet<>(featureTags));
11100 } catch (ImsException e) {
11101 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11102 } finally {
11103 Binder.restoreCallingIdentity(identity);
11104 }
11105 }
11106
11107 /**
11108 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11109 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11110 */
11111 // Used for SHELL command only right now.
11112 @Override
11113 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11114 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11115 "clearUceRegistrationOverrideShell");
11116 final long identity = Binder.clearCallingIdentity();
11117 try {
11118 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11119 } catch (ImsException e) {
11120 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11121 } finally {
11122 Binder.restoreCallingIdentity(identity);
11123 }
11124 }
11125
11126 /**
11127 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11128 */
11129 // Used for SHELL command only right now.
11130 @Override
11131 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11132 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11133 "getLatestRcsContactUceCapabilityShell");
11134 final long identity = Binder.clearCallingIdentity();
11135 try {
11136 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11137 } catch (ImsException e) {
11138 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11139 } finally {
11140 Binder.restoreCallingIdentity(identity);
11141 }
11142 }
11143
11144 /**
11145 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11146 * device does not have an active PUBLISH.
11147 */
11148 // Used for SHELL command only right now.
11149 @Override
11150 public String getLastUcePidfXmlShell(int subId) {
11151 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11152 final long identity = Binder.clearCallingIdentity();
11153 try {
11154 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11155 } catch (ImsException e) {
11156 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11157 } finally {
11158 Binder.restoreCallingIdentity(identity);
11159 }
11160 }
11161
James.cf Line8713a42021-04-29 16:04:26 +080011162 /**
11163 * Remove UCE requests cannot be sent to the network status.
11164 */
11165 // Used for SHELL command only right now.
11166 @Override
11167 public boolean removeUceRequestDisallowedStatus(int subId) {
11168 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11169 final long identity = Binder.clearCallingIdentity();
11170 try {
11171 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11172 } catch (ImsException e) {
11173 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11174 } finally {
11175 Binder.restoreCallingIdentity(identity);
11176 }
11177 }
11178
James.cf Lin18bb9002021-05-25 01:37:38 +080011179 /**
11180 * Remove UCE requests cannot be sent to the network status.
11181 */
11182 // Used for SHELL command only.
11183 @Override
11184 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11185 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11186 final long identity = Binder.clearCallingIdentity();
11187 try {
11188 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11189 } catch (ImsException e) {
11190 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11191 } finally {
11192 Binder.restoreCallingIdentity(identity);
11193 }
11194 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011195
James.cf Lin4b784aa2021-01-31 03:25:15 +080011196 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011197 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11198 String callingPackage) {
11199 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11200 mApp, subId, "setSignalStrengthUpdateRequest");
11201
11202 final int callingUid = Binder.getCallingUid();
11203 // Verify that tha callingPackage belongs to the calling UID
11204 mApp.getSystemService(AppOpsManager.class)
11205 .checkPackage(callingUid, callingPackage);
11206
Rambo Wang3607f502021-02-01 21:51:40 -080011207 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011208
11209 final long identity = Binder.clearCallingIdentity();
11210 try {
11211 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11212 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11213
11214 if (result instanceof IllegalStateException) {
11215 throw (IllegalStateException) result;
11216 }
11217 } finally {
11218 Binder.restoreCallingIdentity(identity);
11219 }
11220 }
11221
11222 @Override
11223 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11224 String callingPackage) {
11225 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11226 mApp, subId, "clearSignalStrengthUpdateRequest");
11227
11228 final int callingUid = Binder.getCallingUid();
11229 // Verify that tha callingPackage belongs to the calling UID
11230 mApp.getSystemService(AppOpsManager.class)
11231 .checkPackage(callingUid, callingPackage);
11232
11233 final long identity = Binder.clearCallingIdentity();
11234 try {
11235 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11236 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11237
11238 if (result instanceof IllegalStateException) {
11239 throw (IllegalStateException) result;
11240 }
11241 } finally {
11242 Binder.restoreCallingIdentity(identity);
11243 }
11244 }
11245
Rambo Wang3607f502021-02-01 21:51:40 -080011246 private static void validateSignalStrengthUpdateRequest(Context context,
11247 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011248 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11249 // phone/system process do not have further restriction on request
11250 return;
11251 }
11252
11253 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011254 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011255 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011256 context.enforceCallingOrSelfPermission(
11257 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11258 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011259 }
11260
11261 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11262 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11263 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11264 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11265 || info.isEnabled()) {
11266 throw new IllegalArgumentException(
11267 "Only system can set hide fields in SignalThresholdInfo");
11268 }
11269
11270 // Thresholds length for each RAN need in range. This has been validated in
11271 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11272 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11273 final int[] thresholds = info.getThresholds();
11274 Objects.requireNonNull(thresholds);
11275 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11276 || thresholds.length
11277 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11278 throw new IllegalArgumentException(
11279 "thresholds length is out of range: " + thresholds.length);
11280 }
11281 }
11282 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011283
11284 /**
11285 * Gets the current phone capability.
11286 *
11287 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11288 * @return the PhoneCapability which describes the data connection capability of modem.
11289 * It's used to evaluate possible phone config change, for example from single
11290 * SIM device to multi-SIM device.
11291 */
11292 @Override
11293 public PhoneCapability getPhoneCapability() {
11294 enforceReadPrivilegedPermission("getPhoneCapability");
11295 final long identity = Binder.clearCallingIdentity();
11296 try {
11297 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11298 } finally {
11299 Binder.restoreCallingIdentity(identity);
11300 }
11301 }
Michele Berionne5e411512020-11-13 02:36:59 +000011302
11303 /**
11304 * Prepare TelephonyManager for an unattended reboot. The reboot is
11305 * required to be done shortly after the API is invoked.
11306 */
11307 @Override
11308 @TelephonyManager.PrepareUnattendedRebootResult
11309 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011310 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011311 enforceRebootPermission();
11312
11313 final long identity = Binder.clearCallingIdentity();
11314 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011315 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011316 } finally {
11317 Binder.restoreCallingIdentity(identity);
11318 }
11319 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011320
11321 /**
11322 * Request to get the current slicing configuration including URSP rules and
11323 * NSSAIs (configured, allowed and rejected).
11324 *
11325 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11326 */
11327 @Override
11328 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011329 TelephonyPermissions
11330 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11331 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011332
11333 final long identity = Binder.clearCallingIdentity();
11334 try {
11335 Phone phone = getDefaultPhone();
11336 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11337 } finally {
11338 Binder.restoreCallingIdentity(identity);
11339 }
11340 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011341
11342 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011343 * Check whether the given premium capability is available for purchase from the carrier.
11344 *
11345 * @param capability The premium capability to check.
11346 * @param subId The subId to check the premium capability for.
11347 *
11348 * @return Whether the given premium capability is available to purchase.
11349 */
11350 @Override
11351 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11352 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11353 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11354 log("Premium capability "
11355 + TelephonyManager.convertPremiumCapabilityToString(capability)
11356 + " is not available for purchase due to missing permissions.");
11357 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11358 + "permission READ_BASIC_PHONE_STATE.");
11359 }
11360
11361 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011362 if (phone == null) {
11363 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11364 return false;
11365 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011366 final long identity = Binder.clearCallingIdentity();
11367 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011368 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011369 .isPremiumCapabilityAvailableForPurchase(capability);
11370 } finally {
11371 Binder.restoreCallingIdentity(identity);
11372 }
11373 }
11374
11375 /**
11376 * Purchase the given premium capability from the carrier.
11377 *
11378 * @param capability The premium capability to purchase.
11379 * @param callback The result of the purchase request.
11380 * @param subId The subId to purchase the premium capability for.
11381 */
11382 @Override
11383 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11384 log("purchasePremiumCapability: capability="
11385 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11386 + getCurrentPackageName());
11387
11388 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11389 mApp, "purchasePremiumCapability")) {
11390 log("purchasePremiumCapability "
11391 + TelephonyManager.convertPremiumCapabilityToString(capability)
11392 + " failed due to missing permissions.");
11393 throw new SecurityException("purchasePremiumCapability requires permission "
11394 + "READ_BASIC_PHONE_STATE.");
11395 }
11396
11397 Phone phone = getPhone(subId);
Sarah Chin71b3a852022-09-28 15:54:19 -070011398 String appName;
11399 try {
11400 appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager()
11401 .getApplicationInfo(getCurrentPackageName(), 0)).toString();
11402 } catch (PackageManager.NameNotFoundException e) {
11403 appName = "An application";
11404 }
11405 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
11406 new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011407 }
11408
11409 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011410 * Register an IMS connection state callback
11411 */
11412 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011413 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11414 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011415 if (feature == ImsFeature.FEATURE_MMTEL) {
11416 // ImsMmTelManager
11417 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11418 TelephonyPermissions
11419 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11420 mApp, subId, "registerImsStateCallback");
11421 } else if (feature == ImsFeature.FEATURE_RCS) {
11422 // ImsRcsManager or SipDelegateManager
11423 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11424 Binder.getCallingUid(), "registerImsStateCallback",
11425 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11426 Manifest.permission.READ_PRECISE_PHONE_STATE,
11427 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11428 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11429 }
11430
11431 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11432 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11433 "IMS not available on device.");
11434 }
11435
11436 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11437 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11438 }
11439
11440 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11441 if (controller == null) {
11442 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11443 "IMS not available on device.");
11444 }
11445
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011446 if (callingPackage == null) {
11447 callingPackage = getCurrentPackageName();
11448 }
11449
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011450 final long token = Binder.clearCallingIdentity();
11451 try {
11452 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011453 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011454 } catch (ImsException e) {
11455 throw new ServiceSpecificException(e.getCode());
11456 } finally {
11457 Binder.restoreCallingIdentity(token);
11458 }
11459 }
11460
11461 /**
11462 * Unregister an IMS connection state callback
11463 */
11464 @Override
11465 public void unregisterImsStateCallback(IImsStateCallback cb) {
11466 final long token = Binder.clearCallingIdentity();
11467 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11468 if (controller == null) {
11469 return;
11470 }
11471 try {
11472 controller.unregisterImsStateCallback(cb);
11473 } finally {
11474 Binder.restoreCallingIdentity(token);
11475 }
11476 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011477
11478 /**
11479 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11480 *
11481 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11482 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11483 * SecurityException.
11484 * If there is current registered network this value will be same as the registered cell
11485 * identity. If the device goes out of service the previous cell identity is cached and
11486 * will be returned. If the cache age of the Cell identity is more than 24 hours
11487 * it will be cleared and null will be returned.
11488 *
11489 */
11490 @Override
11491 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11492 String callingFeatureId) {
11493 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11494 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11495 LocationAccessPolicy.checkLocationPermission(mApp,
11496 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11497 .setCallingPackage(callingPackage)
11498 .setCallingFeatureId(callingFeatureId)
11499 .setCallingPid(Binder.getCallingPid())
11500 .setCallingUid(Binder.getCallingUid())
11501 .setMethod("getLastKnownCellIdentity")
11502 .setLogAsInfo(true)
11503 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11504 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11505 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11506 .build());
11507
11508 boolean hasFinePermission =
11509 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11510 if (!hasFinePermission
11511 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11512 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011513 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011514 }
11515
11516 final long identity = Binder.clearCallingIdentity();
11517 try {
11518 Phone phone = getPhone(subId);
11519 if (phone == null) return null;
11520 ServiceStateTracker sst = phone.getServiceStateTracker();
11521 if (sst == null) return null;
11522 return sst.getLastKnownCellIdentity();
11523 } finally {
11524 Binder.restoreCallingIdentity(identity);
11525 }
11526 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011527
jimsun3b9ccac2021-10-26 15:01:23 +080011528 /**
11529 * Sets the modem service class Name that Telephony will bind to.
11530 *
11531 * @param serviceName The class name of the modem service.
11532 * @return true if the operation is succeed, otherwise false.
11533 */
11534 public boolean setModemService(String serviceName) {
11535 Log.d(LOG_TAG, "setModemService - " + serviceName);
11536 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11537 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11538 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11539 "setModemService");
11540 return mPhoneConfigurationManager.setModemService(serviceName);
11541 }
11542
11543 /**
11544 * Return the class name of the currently bounded modem service.
11545 *
11546 * @return the class name of the modem service.
11547 */
11548 public String getModemService() {
11549 String result;
11550 Log.d(LOG_TAG, "getModemService");
11551 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11552 TelephonyPermissions
11553 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11554 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11555 "getModemService");
11556 result = mPhoneConfigurationManager.getModemService();
11557 Log.d(LOG_TAG, "result = " + result);
11558 return result;
11559 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011560
11561 @Override
11562 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11563 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11564 mApp.enforceCallingOrSelfPermission(
11565 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11566 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11567
11568 final long identity = Binder.clearCallingIdentity();
11569 try {
11570 Phone phone = getPhone(subId);
11571 if (phone == null) return;
11572 phone.setVoiceServiceStateOverride(hasService);
11573 } finally {
11574 Binder.restoreCallingIdentity(identity);
11575 }
11576 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011577
11578 /**
11579 * set removable eSIM as default eUICC.
11580 *
11581 * @hide
11582 */
11583 @Override
11584 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11585 enforceModifyPermission();
11586 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11587
11588 final long identity = Binder.clearCallingIdentity();
11589 try {
11590 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11591 } finally {
11592 Binder.restoreCallingIdentity(identity);
11593 }
11594 }
11595
11596 /**
11597 * Returns whether the removable eSIM is default eUICC or not.
11598 *
11599 * @hide
11600 */
11601 @Override
11602 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11603 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11604 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11605
11606 final long identity = Binder.clearCallingIdentity();
11607 try {
11608 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11609 } finally {
11610 Binder.restoreCallingIdentity(identity);
11611 }
11612 }
11613
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011614 /**
11615 * Get the component name of the default app to direct respond-via-message intent for the
11616 * user associated with this subscription, update the cache if there is no respond-via-message
11617 * application currently configured for this user.
11618 * @return component name of the app and class to direct Respond Via Message intent to, or
11619 * {@code null} if the functionality is not supported.
11620 * @hide
11621 */
11622 @Override
11623 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11624 boolean updateIfNeeded) {
11625 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011626
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011627 Context context = getPhone(subId).getContext();
11628 UserHandle userHandle = null;
11629 final long identity = Binder.clearCallingIdentity();
11630 try {
11631 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11632 } finally {
11633 Binder.restoreCallingIdentity(identity);
11634 }
11635 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11636 updateIfNeeded, userHandle);
11637 }
11638}