blob: 170d86d50ce97ac19d0330678d3d4138b11c0f2a [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
jimsunf9ec1622022-09-13 21:18:43 +080020import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Hall Liud892bec2018-11-30 14:51:45 -080021
Shuo Qianccbaf742021-02-22 18:32:21 -080022import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
23import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070024import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070025import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000026import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070027
Brad Ebinger34c09a52021-02-17 23:23:21 +000028import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080029import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080030import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070031import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000032import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080034import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070035import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000036import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080037import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000038import android.compat.annotation.ChangeId;
39import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070040import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070041import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.content.Context;
43import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070044import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070045import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070046import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.net.Uri;
48import android.os.AsyncResult;
49import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080050import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.os.Bundle;
52import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070053import android.os.IBinder;
tom hsu0b59d292022-09-29 23:49:21 +080054import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.Looper;
56import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070057import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080058import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070059import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070060import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080061import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080062import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070063import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070064import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080065import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070067import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070068import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070069import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070070import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080071import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070072import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090073import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080074import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080075import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070076import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080077import android.telephony.AccessNetworkConstants;
78import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070079import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070080import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080081import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070082import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080083import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070084import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080085import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070086import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080087import android.telephony.CellIdentityCdma;
88import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070090import android.telephony.CellInfoGsm;
91import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070092import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080093import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070094import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070095import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070096import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080097import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070098import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080099import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700100import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800101import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800102import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700103import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800104import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700105import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800106import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800107import android.telephony.SignalStrengthUpdateRequest;
108import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800109import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800110import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800111import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700112import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700113import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800114import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800115import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800116import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000117import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000118import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000119import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700120import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700121import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800122import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800123import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700124import android.telephony.gba.GbaAuthRequest;
125import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700126import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800127import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000128import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000129import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700130import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000131import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700132import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800133import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700134import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800135import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700136import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000137import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700138import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800139import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800140import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800142import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700143import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800145import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800146
Andrew Lee312e8172014-10-23 17:01:36 -0700147import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800148import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800149import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800150import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800151import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700152import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700153import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700154import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800155import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800156import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700157import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700158import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800159import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700160import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800161import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800162import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800163import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700164import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000165import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700166import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800167import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700168import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800169import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800170import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700171import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700172import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700173import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700175import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800176import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700177import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700178import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700179import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700180import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800181import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800182import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700183import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000184import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700185import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700186import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800187import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800188import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800189import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700190import com.android.internal.telephony.data.DataUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800191import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700192import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800193import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700194import com.android.internal.telephony.imsphone.ImsPhone;
195import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000196import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800197import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700198import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700199import com.android.internal.telephony.uicc.IccIoResult;
200import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800201import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700202import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800203import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700204import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000205import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800206import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000207import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800208import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000209import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700210import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700211import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800212import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800213import com.android.phone.callcomposer.CallComposerPictureManager;
214import com.android.phone.callcomposer.CallComposerPictureTransfer;
215import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700216import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700217import com.android.phone.slice.SlicePurchaseController;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700218import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800219import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700220import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700221import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800222import com.android.services.telephony.TelecomAccountRegistry;
223import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800224import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800225
Hall Liu82694d52020-12-11 18:22:04 -0800226import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700227import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800228import java.io.IOException;
229import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700230import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700231import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800232import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000233import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800234import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800235import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800236import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800237import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100238import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800239import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700240import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800241import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800242import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700243import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800244import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800245import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800246import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700247
248/**
249 * Implementation of the ITelephony interface.
250 */
Santos Cordon117fee72014-05-16 17:56:12 -0700251public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700252 private static final String LOG_TAG = "PhoneInterfaceManager";
253 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
254 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800255 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700256
257 // Message codes used with mMainThreadHandler
258 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700259 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
260 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700261 private static final int CMD_OPEN_CHANNEL = 9;
262 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
263 private static final int CMD_CLOSE_CHANNEL = 11;
264 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800265 private static final int CMD_NV_READ_ITEM = 13;
266 private static final int EVENT_NV_READ_ITEM_DONE = 14;
267 private static final int CMD_NV_WRITE_ITEM = 15;
268 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
269 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
270 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700271 private static final int CMD_RESET_MODEM_CONFIG = 19;
272 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800273 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
274 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800275 private static final int CMD_SEND_ENVELOPE = 25;
276 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000277 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
278 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700279 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
280 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
281 private static final int CMD_EXCHANGE_SIM_IO = 31;
282 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800283 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
284 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700285 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
286 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700287 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
288 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700289 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
290 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
291 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
292 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700293 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
294 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
295 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
296 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700297 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800298 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
299 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000300 private static final int CMD_SWITCH_SLOTS = 50;
301 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700302 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
303 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
304 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
305 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
306 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
307 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
308 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
309 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700310 private static final int CMD_GET_ALL_CELL_INFO = 60;
311 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
312 private static final int CMD_GET_CELL_LOCATION = 62;
313 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700314 private static final int CMD_MODEM_REBOOT = 64;
315 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700316 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
317 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800318 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
319 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700320 private static final int CMD_GET_MODEM_STATUS = 70;
321 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700322 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
323 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700324 private static final int CMD_ERASE_MODEM_CONFIG = 74;
325 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800326 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
327 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
328 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
329 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800330 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
331 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800332 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800333 private static final int CMD_GET_CALL_FORWARDING = 83;
334 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
335 private static final int CMD_SET_CALL_FORWARDING = 85;
336 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
337 private static final int CMD_GET_CALL_WAITING = 87;
338 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
339 private static final int CMD_SET_CALL_WAITING = 89;
340 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700341 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
342 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
343 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
344 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700345 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
346 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800347 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
348 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800349 private static final int CMD_SET_DATA_THROTTLING = 99;
350 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800351 private static final int CMD_SET_SIM_POWER = 101;
352 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800353 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
354 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
355 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
356 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800357 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
358 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000359 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800360 private static final int CMD_GET_SLICING_CONFIG = 110;
361 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800362 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700363 private static final int CMD_ENABLE_VONR = 113;
364 private static final int EVENT_ENABLE_VONR_DONE = 114;
365 private static final int CMD_IS_VONR_ENABLED = 115;
366 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700367 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
368 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800370 // Parameters of select command.
371 private static final int SELECT_COMMAND = 0xA4;
372 private static final int SELECT_P1 = 0x04;
373 private static final int SELECT_P2 = 0;
374 private static final int SELECT_P3 = 0x10;
375
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376 /** The singleton instance. */
377 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800378 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379
Wink Saville3ab207e2014-11-20 13:07:20 -0800380 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800381 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800382 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700383 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800384 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700385 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800386 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800387 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800388 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700389 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800390 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Gil Cukierman6dac5eb2022-09-19 16:09:04 +0000391 private final Telephony2gUpdater mTelephony2gUpdater;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700392
Peter Wangdafb9ac2020-01-15 14:13:38 -0800393 /** User Activity */
394 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800395 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
396
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700397 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
398
Derek Tan97ebb422014-09-05 16:55:38 -0700399 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
400 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800401 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800402 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700403
Michelecea4cf22018-12-21 15:00:11 -0800404 // String to store multi SIM allowed
405 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
406
Derek Tan740e1672017-06-27 14:56:27 -0700407 // The AID of ISD-R.
408 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
409
yinxub1bed742017-04-17 11:45:04 -0700410 private NetworkScanRequestTracker mNetworkScanRequestTracker;
411
David Kelly5e06a7f2018-03-12 14:10:59 +0000412 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
413 private static final int MANUFACTURER_CODE_LENGTH = 8;
414
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800415 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800416 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800417
Sarah Chin2ec39f62022-08-31 17:03:26 -0700418 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
419 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
420
Derek Tan89e89d42014-07-08 17:00:10 -0700421 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700422 * Experiment flag to enable erase modem config on reset network, default value is false
423 */
424 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
425 "reset_network_erase_modem_config_enabled";
426
Rambo Wang0f050d82021-02-12 11:43:36 -0800427 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800428
sandeepjsb6c87872021-09-27 15:34:44 +0000429 /**
430 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
431 * one ICCID active at the same time.
432 * Apps should use below API signatures if targeting SDK is T and beyond.
433 *
434 * @hide
435 */
436 @ChangeId
437 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
438 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800439
Naina Nallurid63128d2019-09-17 14:10:30 -0700440 /**
Chen Xu540470b2021-12-14 17:15:47 -0800441 * Apps targeting on Android T and beyond will get exception whenever icc close channel
442 * operation fails.
443 */
444 @ChangeId
445 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
446 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
447
448 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700449 * A request object to use for transmitting data to an ICC.
450 */
451 private static final class IccAPDUArgument {
452 public int channel, cla, command, p1, p2, p3;
453 public String data;
454
455 public IccAPDUArgument(int channel, int cla, int command,
456 int p1, int p2, int p3, String data) {
457 this.channel = channel;
458 this.cla = cla;
459 this.command = command;
460 this.p1 = p1;
461 this.p2 = p2;
462 this.p3 = p3;
463 this.data = data;
464 }
465 }
466
467 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700468 * A request object to use for transmitting data to an ICC.
469 */
470 private static final class ManualNetworkSelectionArgument {
471 public OperatorInfo operatorInfo;
472 public boolean persistSelection;
473
474 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
475 this.operatorInfo = operatorInfo;
476 this.persistSelection = persistSelection;
477 }
478 }
479
Sarah Chin71b3a852022-09-28 15:54:19 -0700480 private static final class PurchasePremiumCapabilityArgument {
481 public @TelephonyManager.PremiumCapability int capability;
482 public @NonNull String appName;
483 public @NonNull IIntegerConsumer callback;
484
485 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
486 @NonNull String appName, @NonNull IIntegerConsumer callback) {
487 this.capability = capability;
488 this.appName = appName;
489 this.callback = callback;
490 }
491 }
492
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700493 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700494 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
495 * request after sending. The main thread will notify the request when it is complete.
496 */
497 private static final class MainThreadRequest {
498 /** The argument to use for the request */
499 public Object argument;
500 /** The result of the request that is run on the main thread */
501 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800502 // The subscriber id that this request applies to. Defaults to
503 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
504 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700505
Nathan Harold92bed182018-10-12 18:16:49 -0700506 // In cases where subId is unavailable, the caller needs to specify the phone.
507 public Phone phone;
508
vagdeviaf9a5b92018-08-15 16:01:53 -0700509 public WorkSource workSource;
510
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700511 public MainThreadRequest(Object argument) {
512 this.argument = argument;
513 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800514
Nathan Harold92bed182018-10-12 18:16:49 -0700515 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
516 this.argument = argument;
517 if (phone != null) {
518 this.phone = phone;
519 }
520 this.workSource = workSource;
521 }
522
vagdeviaf9a5b92018-08-15 16:01:53 -0700523 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800524 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800525 if (subId != null) {
526 this.subId = subId;
527 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700528 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800529 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700530 }
531
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800532 private static final class IncomingThirdPartyCallArgs {
533 public final ComponentName component;
534 public final String callId;
535 public final String callerDisplayName;
536
537 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
538 String callerDisplayName) {
539 this.component = component;
540 this.callId = callId;
541 this.callerDisplayName = callerDisplayName;
542 }
543 }
544
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545 /**
546 * A handler that processes messages on the main thread in the phone process. Since many
547 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
548 * inbound binder threads to the main thread in the phone process. The Binder thread
549 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
550 * on, which will be notified when the operation completes and will contain the result of the
551 * request.
552 *
553 * <p>If a MainThreadRequest object is provided in the msg.obj field,
554 * note that request.result must be set to something non-null for the calling thread to
555 * unblock.
556 */
557 private final class MainThreadHandler extends Handler {
558 @Override
559 public void handleMessage(Message msg) {
560 MainThreadRequest request;
561 Message onCompleted;
562 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000563 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800565 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700566
567 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700568 case CMD_HANDLE_USSD_REQUEST: {
569 request = (MainThreadRequest) msg.obj;
570 final Phone phone = getPhoneFromRequest(request);
571 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800572 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700573 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700574
Pengquan Menga1bb6272018-09-06 09:59:22 -0700575 if (!isUssdApiAllowed(request.subId)) {
576 // Carrier does not support use of this API, return failure.
577 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
578 UssdResponse response = new UssdResponse(ussdRequest, null);
579 Bundle returnData = new Bundle();
580 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
581 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700582
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 request.result = true;
584 notifyRequester(request);
585 return;
586 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700587
Pengquan Menga1bb6272018-09-06 09:59:22 -0700588 try {
589 request.result = phone != null
590 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
591 } catch (CallStateException cse) {
592 request.result = false;
593 }
594 // Wake up the requesting thread
595 notifyRequester(request);
596 break;
pkanwar32d516d2016-10-14 19:37:38 -0700597 }
598
Yorke Lee716f67e2015-06-17 15:39:16 -0700599 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700600 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700601 final Phone phone = getPhoneFromRequest(request);
602 request.result = phone != null ?
603 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
604 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700605 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700606 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700607 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700608 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700609
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000613 uiccPort = getUiccPortFromRequest(request);
614 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700615 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800616 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700618 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700619 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800620 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000621 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800622 iccArgument.channel, iccArgument.cla, iccArgument.command,
623 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
624 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700625 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 break;
627
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700628 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 ar = (AsyncResult) msg.obj;
630 request = (MainThreadRequest) ar.userObj;
631 if (ar.exception == null && ar.result != null) {
632 request.result = ar.result;
633 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800634 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 if (ar.result == null) {
636 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800637 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800639 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 } else {
641 loge("iccTransmitApduLogicalChannel: Unknown exception");
642 }
643 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700644 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 break;
646
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700647 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
648 request = (MainThreadRequest) msg.obj;
649 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000650 uiccPort = getUiccPortFromRequest(request);
651 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700652 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800653 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700655 } else {
656 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800657 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000658 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800659 iccArgument.cla, iccArgument.command, iccArgument.p1,
660 iccArgument.p2,
661 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700662 }
663 break;
664
665 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
666 ar = (AsyncResult) msg.obj;
667 request = (MainThreadRequest) ar.userObj;
668 if (ar.exception == null && ar.result != null) {
669 request.result = ar.result;
670 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800671 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700672 if (ar.result == null) {
673 loge("iccTransmitApduBasicChannel: Empty response");
674 } else if (ar.exception instanceof CommandException) {
675 loge("iccTransmitApduBasicChannel: CommandException: " +
676 ar.exception);
677 } else {
678 loge("iccTransmitApduBasicChannel: Unknown exception");
679 }
680 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700681 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700682 break;
683
684 case CMD_EXCHANGE_SIM_IO:
685 request = (MainThreadRequest) msg.obj;
686 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000687 uiccPort = getUiccPortFromRequest(request);
688 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700689 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800690 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700691 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700692 } else {
693 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
694 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000695 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700696 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
697 iccArgument.data, onCompleted);
698 }
699 break;
700
701 case EVENT_EXCHANGE_SIM_IO_DONE:
702 ar = (AsyncResult) msg.obj;
703 request = (MainThreadRequest) ar.userObj;
704 if (ar.exception == null && ar.result != null) {
705 request.result = ar.result;
706 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800707 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700709 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700710 break;
711
Derek Tan4d5e5c12014-02-04 11:54:58 -0800712 case CMD_SEND_ENVELOPE:
713 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000714 uiccPort = getUiccPortFromRequest(request);
715 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700716 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800717 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700718 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700719 } else {
720 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800721 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700722 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800723 break;
724
725 case EVENT_SEND_ENVELOPE_DONE:
726 ar = (AsyncResult) msg.obj;
727 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700728 if (ar.exception == null && ar.result != null) {
729 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800730 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800731 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700732 if (ar.result == null) {
733 loge("sendEnvelopeWithStatus: Empty response");
734 } else if (ar.exception instanceof CommandException) {
735 loge("sendEnvelopeWithStatus: CommandException: " +
736 ar.exception);
737 } else {
738 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
739 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800740 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700741 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800742 break;
743
Shishir Agrawal566b7612013-10-28 14:41:00 -0700744 case CMD_OPEN_CHANNEL:
745 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000746 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800747 IccLogicalChannelRequest openChannelRequest =
748 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000749 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700750 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800751 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800752 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700753 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700754 } else {
755 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800756 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
757 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700758 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700759 break;
760
761 case EVENT_OPEN_CHANNEL_DONE:
762 ar = (AsyncResult) msg.obj;
763 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700764 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700765 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700766 int[] result = (int[]) ar.result;
767 int channelId = result[0];
768 byte[] selectResponse = null;
769 if (result.length > 1) {
770 selectResponse = new byte[result.length - 1];
771 for (int i = 1; i < result.length; ++i) {
772 selectResponse[i - 1] = (byte) result[i];
773 }
774 }
775 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800776 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800777
778 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700779 if (uiccPort == null) {
780 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
781 } else {
782 IccLogicalChannelRequest channelRequest =
783 (IccLogicalChannelRequest) request.argument;
784 channelRequest.channel = channelId;
785 uiccPort.onLogicalChannelOpened(channelRequest);
786 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700787 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700788 if (ar.result == null) {
789 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700790 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700791 if (ar.exception != null) {
792 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
793 }
794
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700795 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700796 if (ar.exception instanceof CommandException) {
797 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800798 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700799 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700800 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700801 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700802 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700803 }
804 }
805 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800806 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700807 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700808 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700809 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700810 break;
811
812 case CMD_CLOSE_CHANNEL:
813 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000814 uiccPort = getUiccPortFromRequest(request);
815 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700816 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800817 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800818 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800819 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700820 } else {
821 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000822 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700823 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700824 break;
825
826 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800827 ar = (AsyncResult) msg.obj;
828 request = (MainThreadRequest) ar.userObj;
829 if (ar.exception == null) {
830 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800831 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700832 if (uiccPort == null) {
833 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
834 } else {
835 final int channelId = (Integer) request.argument;
836 uiccPort.onLogicalChannelClosed(channelId);
837 }
Chen Xu540470b2021-12-14 17:15:47 -0800838 } else {
839 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800840 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800841 if (ar.exception instanceof CommandException) {
842 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
843 CommandException.Error error =
844 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800845 if (error == CommandException.Error.INVALID_ARGUMENTS) {
846 // should only throw exceptions from the binder threads.
847 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800848 "iccCloseLogicalChannel: invalid argument ");
849 }
850 } else {
851 loge("iccCloseLogicalChannel: Unknown exception");
852 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800853 request.result = (exception != null) ? exception :
854 new IllegalStateException(
855 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800856 }
857 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800858 break;
859
860 case CMD_NV_READ_ITEM:
861 request = (MainThreadRequest) msg.obj;
862 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800863 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
864 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800865 break;
866
867 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700868 ar = (AsyncResult) msg.obj;
869 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800870 if (ar.exception == null && ar.result != null) {
871 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700872 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800873 request.result = "";
874 if (ar.result == null) {
875 loge("nvReadItem: Empty response");
876 } else if (ar.exception instanceof CommandException) {
877 loge("nvReadItem: CommandException: " +
878 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700879 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800880 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700881 }
882 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700883 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700884 break;
885
Jake Hambye994d462014-02-03 13:10:13 -0800886 case CMD_NV_WRITE_ITEM:
887 request = (MainThreadRequest) msg.obj;
888 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
889 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800890 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700891 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800892 break;
893
894 case EVENT_NV_WRITE_ITEM_DONE:
895 handleNullReturnEvent(msg, "nvWriteItem");
896 break;
897
898 case CMD_NV_WRITE_CDMA_PRL:
899 request = (MainThreadRequest) msg.obj;
900 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800901 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800902 break;
903
904 case EVENT_NV_WRITE_CDMA_PRL_DONE:
905 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
906 break;
907
chen xu6dac5ab2018-10-26 17:39:23 -0700908 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800909 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700910 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800911 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800912 break;
913
chen xu6dac5ab2018-10-26 17:39:23 -0700914 case EVENT_RESET_MODEM_CONFIG_DONE:
915 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800916 break;
917
Sooraj Sasindran37444802020-08-11 10:40:43 -0700918 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
919 request = (MainThreadRequest) msg.obj;
920 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
921 request);
922 Phone phone = getPhoneFromRequest(request);
923 if (phone != null) {
924 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
925 } else {
926 loge("isNRDualConnectivityEnabled: No phone object");
927 request.result = false;
928 notifyRequester(request);
929 }
930 break;
931 }
932
933 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
934 ar = (AsyncResult) msg.obj;
935 request = (MainThreadRequest) ar.userObj;
936 if (ar.exception == null && ar.result != null) {
937 request.result = ar.result;
938 } else {
939 // request.result must be set to something non-null
940 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700941 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700942 request.result = ar.result;
943 } else {
944 request.result = false;
945 }
946 if (ar.result == null) {
947 loge("isNRDualConnectivityEnabled: Empty response");
948 } else if (ar.exception instanceof CommandException) {
949 loge("isNRDualConnectivityEnabled: CommandException: "
950 + ar.exception);
951 } else {
952 loge("isNRDualConnectivityEnabled: Unknown exception");
953 }
954 }
955 notifyRequester(request);
956 break;
957
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700958 case CMD_IS_VONR_ENABLED: {
959 request = (MainThreadRequest) msg.obj;
960 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
961 request);
962 Phone phone = getPhoneFromRequest(request);
963 if (phone != null) {
964 phone.isVoNrEnabled(onCompleted, request.workSource);
965 } else {
966 loge("isVoNrEnabled: No phone object");
967 request.result = false;
968 notifyRequester(request);
969 }
970 break;
971 }
972
973 case EVENT_IS_VONR_ENABLED_DONE:
974 ar = (AsyncResult) msg.obj;
975 request = (MainThreadRequest) ar.userObj;
976 if (ar.exception == null && ar.result != null) {
977 request.result = ar.result;
978 } else {
979 // request.result must be set to something non-null
980 // for the calling thread to unblock
981 if (ar.result != null) {
982 request.result = ar.result;
983 } else {
984 request.result = false;
985 }
986 if (ar.result == null) {
987 loge("isVoNrEnabled: Empty response");
988 } else if (ar.exception instanceof CommandException) {
989 loge("isVoNrEnabled: CommandException: "
990 + ar.exception);
991 } else {
992 loge("isVoNrEnabled: Unknown exception");
993 }
994 }
995 notifyRequester(request);
996 break;
997
Sooraj Sasindran37444802020-08-11 10:40:43 -0700998 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
999 request = (MainThreadRequest) msg.obj;
1000 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1001 Phone phone = getPhoneFromRequest(request);
1002 if (phone != null) {
1003 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1004 request.workSource);
1005 } else {
1006 loge("enableNrDualConnectivity: No phone object");
1007 request.result =
1008 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1009 notifyRequester(request);
1010 }
1011 break;
1012 }
1013
1014 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1015 ar = (AsyncResult) msg.obj;
1016 request = (MainThreadRequest) ar.userObj;
1017 if (ar.exception == null) {
1018 request.result =
1019 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1020 } else {
1021 request.result =
1022 TelephonyManager
1023 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1024 if (ar.exception instanceof CommandException) {
1025 CommandException.Error error =
1026 ((CommandException) (ar.exception)).getCommandError();
1027 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1028 request.result =
1029 TelephonyManager
1030 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001031 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1032 request.result =
1033 TelephonyManager
1034 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001035 }
1036 loge("enableNrDualConnectivity" + ": CommandException: "
1037 + ar.exception);
1038 } else {
1039 loge("enableNrDualConnectivity" + ": Unknown exception");
1040 }
1041 }
1042 notifyRequester(request);
1043 break;
1044 }
1045
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001046 case CMD_ENABLE_VONR: {
1047 request = (MainThreadRequest) msg.obj;
1048 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1049 Phone phone = getPhoneFromRequest(request);
1050 if (phone != null) {
1051 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1052 request.workSource);
1053 } else {
1054 loge("setVoNrEnabled: No phone object");
1055 request.result =
1056 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1057 notifyRequester(request);
1058 }
1059 break;
1060 }
1061
1062 case EVENT_ENABLE_VONR_DONE: {
1063 ar = (AsyncResult) msg.obj;
1064 request = (MainThreadRequest) ar.userObj;
1065 if (ar.exception == null) {
1066 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1067 } else {
1068 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1069 if (ar.exception instanceof CommandException) {
1070 CommandException.Error error =
1071 ((CommandException) (ar.exception)).getCommandError();
1072 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1073 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1074 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1075 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1076 } else {
1077 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1078 }
1079 loge("setVoNrEnabled" + ": CommandException: "
1080 + ar.exception);
1081 } else {
1082 loge("setVoNrEnabled" + ": Unknown exception");
1083 }
1084 }
1085 notifyRequester(request);
1086 break;
1087 }
1088
SongFerngWang3ef3e072020-12-21 16:41:52 +08001089 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001090 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001091 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1092 request);
1093 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001094 break;
1095
SongFerngWang3ef3e072020-12-21 16:41:52 +08001096 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001097 ar = (AsyncResult) msg.obj;
1098 request = (MainThreadRequest) ar.userObj;
1099 if (ar.exception == null && ar.result != null) {
1100 request.result = ar.result; // Integer
1101 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301102 // request.result must be set to something non-null
1103 // for the calling thread to unblock
1104 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001105 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001106 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001107 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001108 loge("getAllowedNetworkTypesBitmask: CommandException: "
1109 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001110 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001111 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001112 }
1113 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001114 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001115 break;
1116
SongFerngWang3ef3e072020-12-21 16:41:52 +08001117 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001118 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001119 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1120 request);
1121 Pair<Integer, Long> reasonWithNetworkTypes =
1122 (Pair<Integer, Long>) request.argument;
1123 getPhoneFromRequest(request).setAllowedNetworkTypes(
1124 reasonWithNetworkTypes.first,
1125 reasonWithNetworkTypes.second,
1126 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001127 break;
1128
SongFerngWang3ef3e072020-12-21 16:41:52 +08001129 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1130 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001131 break;
1132
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001133 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1134 request = (MainThreadRequest)msg.obj;
1135 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001136 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001137 break;
1138
1139 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1140 ar = (AsyncResult)msg.obj;
1141 request = (MainThreadRequest)ar.userObj;
1142 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001143 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001144 break;
1145
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001146 case CMD_SET_VOICEMAIL_NUMBER:
1147 request = (MainThreadRequest) msg.obj;
1148 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1149 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001150 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1151 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001152 break;
1153
1154 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1155 handleNullReturnEvent(msg, "setVoicemailNumber");
1156 break;
1157
Stuart Scott54788802015-03-30 13:18:01 -07001158 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1159 request = (MainThreadRequest) msg.obj;
1160 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1161 request);
1162 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1163 break;
1164
1165 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1166 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1167 break;
1168
Shishir Agrawal302c8692015-06-19 13:49:39 -07001169 case CMD_PERFORM_NETWORK_SCAN:
1170 request = (MainThreadRequest) msg.obj;
1171 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1172 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1173 break;
1174
Hall Liu27d24262020-09-18 19:04:59 -07001175 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001176 request = (MainThreadRequest) msg.obj;
1177 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001178 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1179 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1180 request.argument;
1181 int callForwardingReason = args.first;
1182 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001183 break;
Hall Liu27d24262020-09-18 19:04:59 -07001184 }
1185 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001186 ar = (AsyncResult) msg.obj;
1187 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001188 TelephonyManager.CallForwardingInfoCallback callback =
1189 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1190 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001191 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001192 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001193 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1194 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1195 // Service Class is a bit mask per 3gpp 27.007. Search for
1196 // any service for voice call.
1197 if ((callForwardInfo.serviceClass
1198 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001199 callForwardingInfo = new CallForwardingInfo(
1200 callForwardInfo.status
1201 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001202 callForwardInfo.reason,
1203 callForwardInfo.number,
1204 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001205 break;
1206 }
1207 }
1208 // Didn't find a call forward info for voice call.
1209 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001210 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1211 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001212 }
Hall Liu27d24262020-09-18 19:04:59 -07001213 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001214 } else {
1215 if (ar.result == null) {
1216 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1217 }
1218 if (ar.exception != null) {
1219 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1220 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001221 int errorCode = TelephonyManager
1222 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001223 if (ar.exception instanceof CommandException) {
1224 CommandException.Error error =
1225 ((CommandException) (ar.exception)).getCommandError();
1226 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001227 errorCode = TelephonyManager
1228 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001229 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001230 errorCode = TelephonyManager
1231 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001232 }
1233 }
Hall Liu27d24262020-09-18 19:04:59 -07001234 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001235 }
Shuo Qian4a594052020-01-23 11:59:30 -08001236 break;
Hall Liu27d24262020-09-18 19:04:59 -07001237 }
Shuo Qian4a594052020-01-23 11:59:30 -08001238
Hall Liu27d24262020-09-18 19:04:59 -07001239 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001240 request = (MainThreadRequest) msg.obj;
1241 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001242 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001243 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001244 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1245 request.argument).first;
1246 request.phone.setCallForwardingOption(
1247 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001248 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001249 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001250 callForwardingInfoToSet.getReason(),
1251 callForwardingInfoToSet.getNumber(),
1252 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1253 break;
Hall Liu27d24262020-09-18 19:04:59 -07001254 }
Shuo Qian4a594052020-01-23 11:59:30 -08001255
Hall Liu27d24262020-09-18 19:04:59 -07001256 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001257 ar = (AsyncResult) msg.obj;
1258 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001259 Consumer<Integer> callback =
1260 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1261 request.argument).second;
1262 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001263 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001264 int errorCode = TelephonyManager.CallForwardingInfoCallback
1265 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001266 if (ar.exception instanceof CommandException) {
1267 CommandException.Error error =
1268 ((CommandException) (ar.exception)).getCommandError();
1269 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001270 errorCode = TelephonyManager.CallForwardingInfoCallback
1271 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001272 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001273 errorCode = TelephonyManager.CallForwardingInfoCallback
1274 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001275 }
1276 }
1277 callback.accept(errorCode);
1278 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001279 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001280 }
Shuo Qian4a594052020-01-23 11:59:30 -08001281 break;
Hall Liu27d24262020-09-18 19:04:59 -07001282 }
Shuo Qian4a594052020-01-23 11:59:30 -08001283
Hall Liu27d24262020-09-18 19:04:59 -07001284 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001285 request = (MainThreadRequest) msg.obj;
1286 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1287 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1288 break;
Hall Liu27d24262020-09-18 19:04:59 -07001289 }
Shuo Qian4a594052020-01-23 11:59:30 -08001290
Hall Liu27d24262020-09-18 19:04:59 -07001291 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001292 ar = (AsyncResult) msg.obj;
1293 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001294 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001295 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001296 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001297 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001298 // Service Class is a bit mask per 3gpp 27.007.
1299 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001300 if (callForwardResults.length > 1
1301 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001302 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001303 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001304 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1305 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001306 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001307 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001308 }
1309 } else {
1310 if (ar.result == null) {
1311 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1312 }
1313 if (ar.exception != null) {
1314 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1315 }
1316 if (ar.exception instanceof CommandException) {
1317 CommandException.Error error =
1318 ((CommandException) (ar.exception)).getCommandError();
1319 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001320 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001321 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001322 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1323 callWaitingStatus =
1324 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001325 }
1326 }
1327 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001328 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001329 break;
Hall Liu27d24262020-09-18 19:04:59 -07001330 }
Shuo Qian4a594052020-01-23 11:59:30 -08001331
Hall Liu27d24262020-09-18 19:04:59 -07001332 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001333 request = (MainThreadRequest) msg.obj;
1334 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001335 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1336 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001337 break;
Hall Liu27d24262020-09-18 19:04:59 -07001338 }
Shuo Qian4a594052020-01-23 11:59:30 -08001339
Hall Liu27d24262020-09-18 19:04:59 -07001340 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001341 ar = (AsyncResult) msg.obj;
1342 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001343 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1344 Consumer<Integer> callback =
1345 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1346 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001347 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001348 if (ar.exception instanceof CommandException) {
1349 CommandException.Error error =
1350 ((CommandException) (ar.exception)).getCommandError();
1351 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1352 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001353 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1354 callback.accept(
1355 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001356 } else {
1357 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1358 }
1359 } else {
1360 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1361 }
1362 } else {
1363 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1364 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001365 }
Shuo Qian4a594052020-01-23 11:59:30 -08001366 break;
Hall Liu27d24262020-09-18 19:04:59 -07001367 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001368 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1369 ar = (AsyncResult) msg.obj;
1370 request = (MainThreadRequest) ar.userObj;
1371 CellNetworkScanResult cellScanResult;
1372 if (ar.exception == null && ar.result != null) {
1373 cellScanResult = new CellNetworkScanResult(
1374 CellNetworkScanResult.STATUS_SUCCESS,
1375 (List<OperatorInfo>) ar.result);
1376 } else {
1377 if (ar.result == null) {
1378 loge("getCellNetworkScanResults: Empty response");
1379 }
1380 if (ar.exception != null) {
1381 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1382 }
1383 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1384 if (ar.exception instanceof CommandException) {
1385 CommandException.Error error =
1386 ((CommandException) (ar.exception)).getCommandError();
1387 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1388 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1389 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1390 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1391 }
1392 }
1393 cellScanResult = new CellNetworkScanResult(errorCode, null);
1394 }
1395 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001396 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001397 break;
1398
1399 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1400 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001401 ManualNetworkSelectionArgument selArg =
1402 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001403 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1404 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001405 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1406 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001407 break;
1408
1409 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001410 ar = (AsyncResult) msg.obj;
1411 request = (MainThreadRequest) ar.userObj;
1412 if (ar.exception == null) {
1413 request.result = true;
1414 } else {
1415 request.result = false;
1416 loge("setNetworkSelectionModeManual " + ar.exception);
1417 }
1418 notifyRequester(request);
1419 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001420 break;
1421
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001422 case CMD_GET_MODEM_ACTIVITY_INFO:
1423 request = (MainThreadRequest) msg.obj;
1424 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001425 if (defaultPhone != null) {
1426 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001427 } else {
1428 ResultReceiver result = (ResultReceiver) request.argument;
1429 Bundle bundle = new Bundle();
1430 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001431 new ModemActivityInfo(0, 0, 0,
1432 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001433 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001434 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001435 break;
1436
Hall Liud0f208c2020-10-14 16:54:44 -07001437 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001438 ar = (AsyncResult) msg.obj;
1439 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001440 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001441 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001442 if (mLastModemActivityInfo == null) {
1443 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1444 mLastModemActivitySpecificInfo[0] =
1445 new ActivityStatsTechSpecificInfo(
1446 0,
1447 0,
1448 new int[ModemActivityInfo.getNumTxPowerLevels()],
1449 0);
1450 mLastModemActivityInfo =
1451 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1452 }
1453
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001454 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001455 // Update the last modem activity info and the result of the request.
1456 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1457 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001458 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001459 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001460 mLastModemActivityInfo =
1461 new ModemActivityInfo(
1462 mLastModemActivityInfo.getTimestampMillis(),
1463 mLastModemActivityInfo.getSleepTimeMillis(),
1464 mLastModemActivityInfo.getIdleTimeMillis(),
1465 mLastModemActivitySpecificInfo);
1466
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001467 } else {
1468 if (ar.result == null) {
1469 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001470 error = TelephonyManager.ModemActivityInfoException
1471 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001472 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001473 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001474 error = TelephonyManager.ModemActivityInfoException
1475 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001476 } else {
1477 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001478 error = TelephonyManager.ModemActivityInfoException
1479 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001480 }
1481 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001482 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001483 if (mLastModemActivityInfo != null) {
1484 bundle.putParcelable(
1485 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1486 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001487 } else {
1488 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1489 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001490 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001491 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001492 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001493 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001494
Meng Wang1a7c35a2016-05-05 20:56:15 -07001495 case CMD_SET_ALLOWED_CARRIERS:
1496 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001497 CarrierRestrictionRules argument =
1498 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001499 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001500 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001501 break;
1502
1503 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1504 ar = (AsyncResult) msg.obj;
1505 request = (MainThreadRequest) ar.userObj;
1506 if (ar.exception == null && ar.result != null) {
1507 request.result = ar.result;
1508 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001509 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1510 if (ar.exception instanceof CommandException) {
1511 loge("setAllowedCarriers: CommandException: " + ar.exception);
1512 CommandException.Error error =
1513 ((CommandException) (ar.exception)).getCommandError();
1514 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1515 request.result =
1516 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1517 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001518 } else {
1519 loge("setAllowedCarriers: Unknown exception");
1520 }
1521 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001522 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001523 break;
1524
1525 case CMD_GET_ALLOWED_CARRIERS:
1526 request = (MainThreadRequest) msg.obj;
1527 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001528 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001529 break;
1530
1531 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1532 ar = (AsyncResult) msg.obj;
1533 request = (MainThreadRequest) ar.userObj;
1534 if (ar.exception == null && ar.result != null) {
1535 request.result = ar.result;
1536 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001537 request.result = new IllegalStateException(
1538 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001539 if (ar.result == null) {
1540 loge("getAllowedCarriers: Empty response");
1541 } else if (ar.exception instanceof CommandException) {
1542 loge("getAllowedCarriers: CommandException: " +
1543 ar.exception);
1544 } else {
1545 loge("getAllowedCarriers: Unknown exception");
1546 }
1547 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001548 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001549 break;
1550
Nathan Haroldb3014052017-01-25 15:57:32 -08001551 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1552 ar = (AsyncResult) msg.obj;
1553 request = (MainThreadRequest) ar.userObj;
1554 if (ar.exception == null && ar.result != null) {
1555 request.result = ar.result;
1556 } else {
1557 request.result = new IllegalArgumentException(
1558 "Failed to retrieve Forbidden Plmns");
1559 if (ar.result == null) {
1560 loge("getForbiddenPlmns: Empty response");
1561 } else {
1562 loge("getForbiddenPlmns: Unknown exception");
1563 }
1564 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001565 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001566 break;
1567
1568 case CMD_GET_FORBIDDEN_PLMNS:
1569 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001570 uiccPort = getUiccPortFromRequest(request);
1571 if (uiccPort == null) {
1572 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001573 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001574 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001575 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001576 break;
1577 }
1578 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001579 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001580 if (uiccApp == null) {
1581 loge("getForbiddenPlmns() no app with specified type -- "
1582 + appType);
1583 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001584 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001585 break;
1586 } else {
1587 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1588 + " specified type -- " + appType);
1589 }
1590 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1591 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1592 onCompleted);
1593 break;
1594
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001595 case CMD_SWITCH_SLOTS:
1596 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001597 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001598 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001599 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001600 break;
1601
1602 case EVENT_SWITCH_SLOTS_DONE:
1603 ar = (AsyncResult) msg.obj;
1604 request = (MainThreadRequest) ar.userObj;
1605 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001606 notifyRequester(request);
1607 break;
1608 case CMD_GET_NETWORK_SELECTION_MODE:
1609 request = (MainThreadRequest) msg.obj;
1610 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1611 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1612 break;
1613
1614 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1615 ar = (AsyncResult) msg.obj;
1616 request = (MainThreadRequest) ar.userObj;
1617 if (ar.exception != null) {
1618 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1619 } else {
1620 int mode = ((int[]) ar.result)[0];
1621 if (mode == 0) {
1622 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1623 } else {
1624 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1625 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001626 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001627 notifyRequester(request);
1628 break;
1629 case CMD_GET_CDMA_ROAMING_MODE:
1630 request = (MainThreadRequest) msg.obj;
1631 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1632 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1633 break;
1634 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1635 ar = (AsyncResult) msg.obj;
1636 request = (MainThreadRequest) ar.userObj;
1637 if (ar.exception != null) {
1638 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1639 } else {
1640 request.result = ((int[]) ar.result)[0];
1641 }
1642 notifyRequester(request);
1643 break;
1644 case CMD_SET_CDMA_ROAMING_MODE:
1645 request = (MainThreadRequest) msg.obj;
1646 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1647 int mode = (int) request.argument;
1648 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1649 break;
1650 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1651 ar = (AsyncResult) msg.obj;
1652 request = (MainThreadRequest) ar.userObj;
1653 request.result = ar.exception == null;
1654 notifyRequester(request);
1655 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001656 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1657 request = (MainThreadRequest) msg.obj;
1658 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1659 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1660 break;
1661 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1662 ar = (AsyncResult) msg.obj;
1663 request = (MainThreadRequest) ar.userObj;
1664 if (ar.exception != null) {
1665 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1666 } else {
1667 request.result = ((int[]) ar.result)[0];
1668 }
1669 notifyRequester(request);
1670 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001671 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1672 request = (MainThreadRequest) msg.obj;
1673 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1674 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001675 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1676 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001677 break;
1678 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1679 ar = (AsyncResult) msg.obj;
1680 request = (MainThreadRequest) ar.userObj;
1681 request.result = ar.exception == null;
1682 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001683 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001684 case CMD_GET_ALL_CELL_INFO:
1685 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001686 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001687 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001688 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001689 case EVENT_GET_ALL_CELL_INFO_DONE:
1690 ar = (AsyncResult) msg.obj;
1691 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001692 // If a timeout occurs, the response will be null
1693 request.result = (ar.exception == null && ar.result != null)
1694 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001695 synchronized (request) {
1696 request.notifyAll();
1697 }
1698 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001699 case CMD_REQUEST_CELL_INFO_UPDATE:
1700 request = (MainThreadRequest) msg.obj;
1701 request.phone.requestCellInfoUpdate(request.workSource,
1702 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1703 break;
1704 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1705 ar = (AsyncResult) msg.obj;
1706 request = (MainThreadRequest) ar.userObj;
1707 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1708 try {
1709 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001710 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001711 cb.onError(
1712 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1713 ar.exception.getClass().getName(),
1714 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001715 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001716 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001717 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001718 } else {
1719 // use the result as returned
1720 cb.onCellInfo((List<CellInfo>) ar.result);
1721 }
1722 } catch (RemoteException re) {
1723 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1724 }
1725 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001726 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001727 request = (MainThreadRequest) msg.obj;
1728 WorkSource ws = (WorkSource) request.argument;
1729 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001730 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001731 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001732 }
1733 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001734 ar = (AsyncResult) msg.obj;
1735 request = (MainThreadRequest) ar.userObj;
1736 if (ar.exception == null) {
1737 request.result = ar.result;
1738 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001739 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001740 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001741 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001742 }
1743
1744 synchronized (request) {
1745 request.notifyAll();
1746 }
1747 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001748 }
chen xu6dac5ab2018-10-26 17:39:23 -07001749 case CMD_MODEM_REBOOT:
1750 request = (MainThreadRequest) msg.obj;
1751 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001752 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001753 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001754 case EVENT_CMD_MODEM_REBOOT_DONE:
1755 handleNullReturnEvent(msg, "rebootModem");
1756 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001757 case CMD_REQUEST_ENABLE_MODEM:
1758 request = (MainThreadRequest) msg.obj;
1759 boolean enable = (boolean) request.argument;
1760 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001761 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001762 PhoneConfigurationManager.getInstance()
1763 .enablePhone(request.phone, enable, onCompleted);
1764 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001765 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001766 ar = (AsyncResult) msg.obj;
1767 request = (MainThreadRequest) ar.userObj;
1768 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001769 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001770 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001771 if ((boolean) request.result) {
1772 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1773 updateModemStateMetrics();
1774 } else {
1775 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1776 + ar.exception);
1777 }
1778 notifyRequester(request);
1779 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001780 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001781 case CMD_GET_MODEM_STATUS:
1782 request = (MainThreadRequest) msg.obj;
1783 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1784 PhoneConfigurationManager.getInstance()
1785 .getPhoneStatusFromModem(request.phone, onCompleted);
1786 break;
1787 case EVENT_GET_MODEM_STATUS_DONE:
1788 ar = (AsyncResult) msg.obj;
1789 request = (MainThreadRequest) ar.userObj;
1790 int id = request.phone.getPhoneId();
1791 if (ar.exception == null && ar.result != null) {
1792 request.result = ar.result;
1793 //update the cache as modem status has changed
1794 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1795 (boolean) request.result);
1796 } else {
1797 // Return true if modem status cannot be retrieved. For most cases,
1798 // modem status is on. And for older version modems, GET_MODEM_STATUS
1799 // and disable modem are not supported. Modem is always on.
1800 // TODO: this should be fixed in R to support a third
1801 // status UNKNOWN b/131631629
1802 request.result = true;
1803 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1804 + ar.exception);
1805 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001806 notifyRequester(request);
1807 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001808 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1809 request = (MainThreadRequest) msg.obj;
1810 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1811 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1812 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1813 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1814 break;
1815 }
1816 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1817 ar = (AsyncResult) msg.obj;
1818 request = (MainThreadRequest) ar.userObj;
1819 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1820 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1821 args.second.accept(ar.exception == null);
1822 notifyRequester(request);
1823 break;
1824 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001825 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1826 request = (MainThreadRequest) msg.obj;
1827 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1828 Phone phone = getPhoneFromRequest(request);
1829 if (phone != null) {
1830 phone.getSystemSelectionChannels(onCompleted);
1831 } else {
1832 loge("getSystemSelectionChannels: No phone object");
1833 request.result = new ArrayList<RadioAccessSpecifier>();
1834 notifyRequester(request);
1835 }
1836 break;
1837 }
1838 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1839 ar = (AsyncResult) msg.obj;
1840 request = (MainThreadRequest) ar.userObj;
1841 if (ar.exception == null && ar.result != null) {
1842 request.result = ar.result;
1843 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001844 request.result = new IllegalStateException(
1845 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001846 if (ar.result == null) {
1847 loge("getSystemSelectionChannels: Empty response");
1848 } else {
1849 loge("getSystemSelectionChannels: Unknown exception");
1850 }
1851 }
1852 notifyRequester(request);
1853 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001854 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1855 ar = (AsyncResult) msg.obj;
1856 request = (MainThreadRequest) ar.userObj;
1857 if (ar.exception == null && ar.result != null) {
1858 request.result = ar.result;
1859 } else {
1860 request.result = -1;
1861 loge("Failed to set Forbidden Plmns");
1862 if (ar.result == null) {
1863 loge("setForbidenPlmns: Empty response");
1864 } else if (ar.exception != null) {
1865 loge("setForbiddenPlmns: Exception: " + ar.exception);
1866 request.result = -1;
1867 } else {
1868 loge("setForbiddenPlmns: Unknown exception");
1869 }
1870 }
1871 notifyRequester(request);
1872 break;
1873 case CMD_SET_FORBIDDEN_PLMNS:
1874 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001875 uiccPort = getUiccPortFromRequest(request);
1876 if (uiccPort == null) {
1877 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001878 request.result = -1;
1879 notifyRequester(request);
1880 break;
1881 }
1882 Pair<Integer, List<String>> setFplmnsArgs =
1883 (Pair<Integer, List<String>>) request.argument;
1884 appType = setFplmnsArgs.first;
1885 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001886 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001887 if (uiccApp == null) {
1888 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1889 request.result = -1;
1890 loge("Failed to get UICC App");
1891 notifyRequester(request);
1892 } else {
1893 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1894 ((SIMRecords) uiccApp.getIccRecords())
1895 .setForbiddenPlmns(onCompleted, fplmns);
1896 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001897 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001898 case CMD_ERASE_MODEM_CONFIG:
1899 request = (MainThreadRequest) msg.obj;
1900 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1901 defaultPhone.eraseModemConfig(onCompleted);
1902 break;
1903 case EVENT_ERASE_MODEM_CONFIG_DONE:
1904 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001905 break;
zoey chene02881a2019-12-30 16:11:23 +08001906
Kai Shif70f46f2021-03-03 13:59:46 -08001907 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1908 request = (MainThreadRequest) msg.obj;
1909 request.result = defaultPhone.eraseDataInSharedPreferences();
1910 notifyRequester(request);
1911 break;
1912
zoey chene02881a2019-12-30 16:11:23 +08001913 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1914 request = (MainThreadRequest) msg.obj;
1915 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1916 Pair<String, String> changed = (Pair<String, String>) request.argument;
1917 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1918 changed.first, changed.second, onCompleted);
1919 break;
1920 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1921 ar = (AsyncResult) msg.obj;
1922 request = (MainThreadRequest) ar.userObj;
1923 if (ar.exception == null) {
1924 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001925 // If the operation is successful, update the PIN storage
1926 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1927 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001928 UiccController.getInstance().getPinStorage()
1929 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001930 } else {
1931 request.result = msg.arg1;
1932 }
1933 notifyRequester(request);
1934 break;
1935
Michele Berionne5e411512020-11-13 02:36:59 +00001936 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001937 request = (MainThreadRequest) msg.obj;
1938 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1939 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1940 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1941 enabled.first, enabled.second, onCompleted);
1942 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001943 }
zoey chene02881a2019-12-30 16:11:23 +08001944 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1945 ar = (AsyncResult) msg.obj;
1946 request = (MainThreadRequest) ar.userObj;
1947 if (ar.exception == null) {
1948 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001949 // If the operation is successful, update the PIN storage
1950 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1951 int phoneId = getPhoneFromRequest(request).getPhoneId();
1952 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001953 UiccController.getInstance().getPinStorage()
1954 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001955 } else {
1956 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1957 }
zoey chene02881a2019-12-30 16:11:23 +08001958 } else {
1959 request.result = msg.arg1;
1960 }
Michele Berionne5e411512020-11-13 02:36:59 +00001961
1962
zoey chene02881a2019-12-30 16:11:23 +08001963 notifyRequester(request);
1964 break;
1965
Peter Wangdafb9ac2020-01-15 14:13:38 -08001966 case MSG_NOTIFY_USER_ACTIVITY:
1967 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001968 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001969 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1970 getDefaultPhone().getContext().sendBroadcastAsUser(
1971 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1972 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001973
1974 case CMD_SET_DATA_THROTTLING: {
1975 request = (MainThreadRequest) msg.obj;
1976 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1977 DataThrottlingRequest dataThrottlingRequest =
1978 (DataThrottlingRequest) request.argument;
1979 Phone phone = getPhoneFromRequest(request);
1980 if (phone != null) {
1981 phone.setDataThrottling(onCompleted,
1982 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1983 dataThrottlingRequest.getCompletionDurationMillis());
1984 } else {
1985 loge("setDataThrottling: No phone object");
1986 request.result =
1987 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1988 notifyRequester(request);
1989 }
1990
1991 break;
1992 }
1993 case EVENT_SET_DATA_THROTTLING_DONE:
1994 ar = (AsyncResult) msg.obj;
1995 request = (MainThreadRequest) ar.userObj;
1996
1997 if (ar.exception == null) {
1998 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1999 } else if (ar.exception instanceof CommandException) {
2000 loge("setDataThrottling: CommandException: " + ar.exception);
2001 CommandException.Error error =
2002 ((CommandException) (ar.exception)).getCommandError();
2003
2004 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2005 request.result = TelephonyManager
2006 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2007 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2008 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002009 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2010 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002011 } else {
2012 request.result =
2013 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2014 }
2015 } else {
2016 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2017 }
2018 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2019 notifyRequester(request);
2020 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002021
2022 case CMD_SET_SIM_POWER: {
2023 request = (MainThreadRequest) msg.obj;
2024 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2025 request = (MainThreadRequest) msg.obj;
2026 int stateToSet =
2027 ((Pair<Integer, IIntegerConsumer>)
2028 request.argument).first;
2029 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2030 break;
2031 }
2032 case EVENT_SET_SIM_POWER_DONE: {
2033 ar = (AsyncResult) msg.obj;
2034 request = (MainThreadRequest) ar.userObj;
2035 IIntegerConsumer callback =
2036 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2037 if (ar.exception != null) {
2038 loge("setSimPower exception: " + ar.exception);
2039 int errorCode = TelephonyManager.CallForwardingInfoCallback
2040 .RESULT_ERROR_UNKNOWN;
2041 if (ar.exception instanceof CommandException) {
2042 CommandException.Error error =
2043 ((CommandException) (ar.exception)).getCommandError();
2044 if (error == CommandException.Error.SIM_ERR) {
2045 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2046 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2047 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2048 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2049 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2050 } else {
2051 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2052 }
2053 }
2054 try {
2055 callback.accept(errorCode);
2056 } catch (RemoteException e) {
2057 // Ignore if the remote process is no longer available to call back.
2058 Log.w(LOG_TAG, "setSimPower: callback not available.");
2059 }
2060 } else {
2061 try {
2062 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2063 } catch (RemoteException e) {
2064 // Ignore if the remote process is no longer available to call back.
2065 Log.w(LOG_TAG, "setSimPower: callback not available.");
2066 }
2067 }
2068 break;
2069 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002070 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2071 request = (MainThreadRequest) msg.obj;
2072
2073 final Phone phone = getPhoneFromRequest(request);
2074 if (phone == null || phone.getServiceStateTracker() == null) {
2075 request.result = new IllegalStateException("Phone or SST is null");
2076 notifyRequester(request);
2077 break;
2078 }
2079
2080 Pair<Integer, SignalStrengthUpdateRequest> pair =
2081 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2082 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2083 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002084 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002085 request.subId, pair.first /*callingUid*/,
2086 pair.second /*request*/, onCompleted);
2087 break;
2088 }
2089 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2090 ar = (AsyncResult) msg.obj;
2091 request = (MainThreadRequest) ar.userObj;
2092 // request.result will be the exception of ar if present, true otherwise.
2093 // Be cautious not to leave result null which will wait() forever
2094 request.result = ar.exception != null ? ar.exception : true;
2095 notifyRequester(request);
2096 break;
2097 }
2098 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2099 request = (MainThreadRequest) msg.obj;
2100
2101 Phone phone = getPhoneFromRequest(request);
2102 if (phone == null || phone.getServiceStateTracker() == null) {
2103 request.result = new IllegalStateException("Phone or SST is null");
2104 notifyRequester(request);
2105 break;
2106 }
2107
2108 Pair<Integer, SignalStrengthUpdateRequest> pair =
2109 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2110 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2111 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002112 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002113 request.subId, pair.first /*callingUid*/,
2114 pair.second /*request*/, onCompleted);
2115 break;
2116 }
2117 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2118 ar = (AsyncResult) msg.obj;
2119 request = (MainThreadRequest) ar.userObj;
2120 request.result = ar.exception != null ? ar.exception : true;
2121 notifyRequester(request);
2122 break;
2123 }
Jordan Liu109698e2020-11-24 14:50:34 -08002124
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002125 case CMD_GET_SLICING_CONFIG: {
2126 request = (MainThreadRequest) msg.obj;
2127 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2128 request.phone.getSlicingConfig(onCompleted);
2129 break;
2130 }
2131 case EVENT_GET_SLICING_CONFIG_DONE: {
2132 ar = (AsyncResult) msg.obj;
2133 request = (MainThreadRequest) ar.userObj;
2134 ResultReceiver result = (ResultReceiver) request.argument;
2135
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002136 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002137 Bundle bundle = new Bundle();
2138 int resultCode = 0;
2139 if (ar.exception != null) {
2140 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2141 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002142 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002143 } else if (ar.result == null) {
2144 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002145 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002146 } else {
2147 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002148 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2149 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002150 }
2151
2152 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002153 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002154 }
2155 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2156 result.send(resultCode, bundle);
2157 notifyRequester(request);
2158 break;
2159 }
2160
Sarah Chin71b3a852022-09-28 15:54:19 -07002161 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002162 request = (MainThreadRequest) msg.obj;
2163 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002164 PurchasePremiumCapabilityArgument arg =
2165 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002166 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chin71b3a852022-09-28 15:54:19 -07002167 arg.capability, arg.appName, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002168 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002169 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002170
Sarah Chin71b3a852022-09-28 15:54:19 -07002171 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002172 ar = (AsyncResult) msg.obj;
2173 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002174 PurchasePremiumCapabilityArgument arg =
2175 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002176 try {
2177 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002178 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002179 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002180 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002181 + ", result= "
2182 + TelephonyManager.convertPurchaseResultToString(result));
2183 } catch (RemoteException e) {
2184 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002185 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002186 + " failed: " + e;
2187 if (DBG) log(logStr);
2188 AnomalyReporter.reportAnomaly(
2189 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2190 }
2191 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002192 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002193
Michele Berionne5e411512020-11-13 02:36:59 +00002194 case CMD_PREPARE_UNATTENDED_REBOOT:
2195 request = (MainThreadRequest) msg.obj;
2196 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002197 UiccController.getInstance().getPinStorage()
2198 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002199 notifyRequester(request);
2200 break;
2201
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002202 default:
2203 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2204 break;
2205 }
2206 }
Jake Hambye994d462014-02-03 13:10:13 -08002207
Pengquan Menga1bb6272018-09-06 09:59:22 -07002208 private void notifyRequester(MainThreadRequest request) {
2209 synchronized (request) {
2210 request.notifyAll();
2211 }
2212 }
2213
Jake Hambye994d462014-02-03 13:10:13 -08002214 private void handleNullReturnEvent(Message msg, String command) {
2215 AsyncResult ar = (AsyncResult) msg.obj;
2216 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2217 if (ar.exception == null) {
2218 request.result = true;
2219 } else {
2220 request.result = false;
2221 if (ar.exception instanceof CommandException) {
2222 loge(command + ": CommandException: " + ar.exception);
2223 } else {
2224 loge(command + ": Unknown exception");
2225 }
2226 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002227 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002228 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002229 }
2230
2231 /**
2232 * Posts the specified command to be executed on the main thread,
2233 * waits for the request to complete, and returns the result.
2234 * @see #sendRequestAsync
2235 */
2236 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002237 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2238 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002239 }
2240
2241 /**
2242 * Posts the specified command to be executed on the main thread,
2243 * waits for the request to complete, and returns the result.
2244 * @see #sendRequestAsync
2245 */
2246 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2247 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002248 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002249 }
2250
2251 /**
2252 * Posts the specified command to be executed on the main thread,
2253 * waits for the request to complete, and returns the result.
2254 * @see #sendRequestAsync
2255 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002256 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002257 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2258 }
2259
2260 /**
2261 * Posts the specified command to be executed on the main thread,
2262 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2263 * if not timeout or null otherwise.
2264 * @see #sendRequestAsync
2265 */
2266 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2267 long timeoutInMs) {
2268 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002269 }
2270
2271 /**
2272 * Posts the specified command to be executed on the main thread,
2273 * waits for the request to complete, and returns the result.
2274 * @see #sendRequestAsync
2275 */
Nathan Harold92bed182018-10-12 18:16:49 -07002276 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002277 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002278 }
2279
2280 /**
2281 * Posts the specified command to be executed on the main thread,
2282 * waits for the request to complete, and returns the result.
2283 * @see #sendRequestAsync
2284 */
2285 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002286 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2287 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002288 }
2289
2290 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002291 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2292 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2293 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002294 * @see #sendRequestAsync
2295 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002296 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2297 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2299 throw new RuntimeException("This method will deadlock if called from the main thread.");
2300 }
2301
Nathan Harold92bed182018-10-12 18:16:49 -07002302 MainThreadRequest request = null;
2303 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2304 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2305 } else if (phone != null) {
2306 request = new MainThreadRequest(argument, phone, workSource);
2307 } else {
2308 request = new MainThreadRequest(argument, subId, workSource);
2309 }
2310
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 Message msg = mMainThreadHandler.obtainMessage(command, request);
2312 msg.sendToTarget();
2313
Rambo Wang0f050d82021-02-12 11:43:36 -08002314
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002315 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002316 if (timeoutInMs >= 0) {
2317 // Wait for at least timeoutInMs before returning null request result
2318 long now = SystemClock.elapsedRealtime();
2319 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002320 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002321 try {
2322 request.wait(deadline - now);
2323 } catch (InterruptedException e) {
2324 // Do nothing, go back and check if request is completed or timeout
2325 } finally {
2326 now = SystemClock.elapsedRealtime();
2327 }
2328 }
2329 } else {
2330 // Wait for the request to complete
2331 while (request.result == null) {
2332 try {
2333 request.wait();
2334 } catch (InterruptedException e) {
2335 // Do nothing, go back and wait until the request is complete
2336 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002337 }
2338 }
2339 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002340 if (request.result == null) {
2341 Log.wtf(LOG_TAG,
2342 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2343 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002344 return request.result;
2345 }
2346
2347 /**
2348 * Asynchronous ("fire and forget") version of sendRequest():
2349 * Posts the specified command to be executed on the main thread, and
2350 * returns immediately.
2351 * @see #sendRequest
2352 */
2353 private void sendRequestAsync(int command) {
2354 mMainThreadHandler.sendEmptyMessage(command);
2355 }
2356
2357 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002358 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002359 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002360 */
2361 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002362 sendRequestAsync(command, argument, null, null);
2363 }
2364
2365 /**
2366 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2367 * @see {@link #sendRequest(int,Object)}
2368 */
2369 private void sendRequestAsync(
2370 int command, Object argument, Phone phone, WorkSource workSource) {
2371 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002372 Message msg = mMainThreadHandler.obtainMessage(command, request);
2373 msg.sendToTarget();
2374 }
2375
2376 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002377 * Initialize the singleton PhoneInterfaceManager instance.
2378 * This is only done once, at startup, from PhoneApp.onCreate().
2379 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002380 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002381 synchronized (PhoneInterfaceManager.class) {
2382 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002383 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002384 } else {
2385 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2386 }
2387 return sInstance;
2388 }
2389 }
2390
2391 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002392 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002395 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002396 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002397 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002398 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002400 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002401 mTelephonySharedPreferences =
2402 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002403 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002404 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002405 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002406 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002407 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002408 mTelephony2gUpdater = new Telephony2gUpdater(
2409 Executors.newSingleThreadExecutor(), mApp);
2410 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002411 publish();
2412 }
2413
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002414 private Phone getDefaultPhone() {
2415 Phone thePhone = getPhone(getDefaultSubscription());
2416 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2417 }
2418
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 private void publish() {
2420 if (DBG) log("publish: " + this);
2421
Peter Wangc035ce42020-01-08 21:00:22 -08002422 TelephonyFrameworkInitializer
2423 .getTelephonyServiceManager()
2424 .getTelephonyServiceRegisterer()
2425 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002426 }
2427
Stuart Scott584921c2015-01-15 17:10:34 -08002428 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002429 if (request.phone != null) {
2430 return request.phone;
2431 } else {
2432 return getPhoneFromSubId(request.subId);
2433 }
2434 }
2435
2436 private Phone getPhoneFromSubId(int subId) {
2437 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2438 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002439 }
2440
Rambo Wange53e07d2022-05-10 13:01:13 -07002441 @Nullable
2442 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002443 Phone phone = getPhoneFromRequest(request);
2444 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002445 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002446 }
2447
Wink Saville36469e72014-06-11 15:17:00 -07002448 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002449 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002450 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002451 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452
Kai Shif70f46f2021-03-03 13:59:46 -08002453 private void sendEraseModemConfig(@NonNull Phone phone) {
2454 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2455 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2456 }
2457
2458 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2459 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2460 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002461 }
2462
Peter Wang44b186e2020-01-13 23:33:09 -08002463 private boolean isImsAvailableOnDevice() {
2464 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2465 if (pm == null) {
2466 // For some reason package manger is not available.. This will fail internally anyway,
2467 // so do not throw error and allow.
2468 return true;
2469 }
2470 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2471 }
2472
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002473 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002474 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002475 }
2476
Wink Savilleb564aae2014-10-23 10:18:09 -07002477 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 if (DBG) log("dial: " + number);
2479 // No permission check needed here: This is just a wrapper around the
2480 // ACTION_DIAL intent, which is available to any app since it puts up
2481 // the UI before it does anything.
2482
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002483 final long identity = Binder.clearCallingIdentity();
2484 try {
2485 String url = createTelUrl(number);
2486 if (url == null) {
2487 return;
2488 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002490 // PENDING: should we just silently fail if phone is offhook or ringing?
2491 PhoneConstants.State state = mCM.getState(subId);
2492 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2493 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2494 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2495 mApp.startActivity(intent);
2496 }
2497 } finally {
2498 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002499 }
2500 }
2501
2502 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002503 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002504 }
2505
Wink Savilleb564aae2014-10-23 10:18:09 -07002506 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002507 if (DBG) log("call: " + number);
2508
2509 // This is just a wrapper around the ACTION_CALL intent, but we still
2510 // need to do a permission check since we're calling startActivity()
2511 // from the context of the phone app.
2512 enforceCallPermission();
2513
Jordan Liu1617b712019-07-10 15:06:26 -07002514 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 != AppOpsManager.MODE_ALLOWED) {
2516 return;
2517 }
2518
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519 final long identity = Binder.clearCallingIdentity();
2520 try {
2521 String url = createTelUrl(number);
2522 if (url == null) {
2523 return;
2524 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002525
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002526 boolean isValid = false;
2527 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2528 if (slist != null) {
2529 for (SubscriptionInfo subInfoRecord : slist) {
2530 if (subInfoRecord.getSubscriptionId() == subId) {
2531 isValid = true;
2532 break;
2533 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002534 }
Wink Saville08874612014-08-31 19:19:58 -07002535 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002536 if (!isValid) {
2537 return;
2538 }
Wink Saville08874612014-08-31 19:19:58 -07002539
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002540 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2541 intent.putExtra(SUBSCRIPTION_KEY, subId);
2542 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2543 mApp.startActivity(intent);
2544 } finally {
2545 Binder.restoreCallingIdentity(identity);
2546 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002547 }
2548
Wink Savilleb564aae2014-10-23 10:18:09 -07002549 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002550 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002551 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2552 }
2553
Wink Savilleb564aae2014-10-23 10:18:09 -07002554 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002555 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, 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 int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002560 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002561
2562 final long identity = Binder.clearCallingIdentity();
2563 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002564 Phone phone = getPhone(subId);
2565 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002566 checkSimPin.start();
2567 return checkSimPin.unlockSim(null, pin);
2568 } finally {
2569 Binder.restoreCallingIdentity(identity);
2570 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002571 }
2572
Wink Savilleb564aae2014-10-23 10:18:09 -07002573 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002574 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002575
2576 final long identity = Binder.clearCallingIdentity();
2577 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002578 Phone phone = getPhone(subId);
2579 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002580 checkSimPuk.start();
2581 return checkSimPuk.unlockSim(puk, pin);
2582 } finally {
2583 Binder.restoreCallingIdentity(identity);
2584 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002585 }
2586
2587 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002588 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002589 * a synchronous one.
2590 */
2591 private static class UnlockSim extends Thread {
2592
2593 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002594 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002595
2596 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002597 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2598 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002599
2600 // For replies from SimCard interface
2601 private Handler mHandler;
2602
2603 // For async handler to identify request type
2604 private static final int SUPPLY_PIN_COMPLETE = 100;
2605
Michele Berionne5e411512020-11-13 02:36:59 +00002606 UnlockSim(int phoneId, IccCard simCard) {
2607 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608 mSimCard = simCard;
2609 }
2610
2611 @Override
2612 public void run() {
2613 Looper.prepare();
2614 synchronized (UnlockSim.this) {
2615 mHandler = new Handler() {
2616 @Override
2617 public void handleMessage(Message msg) {
2618 AsyncResult ar = (AsyncResult) msg.obj;
2619 switch (msg.what) {
2620 case SUPPLY_PIN_COMPLETE:
2621 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2622 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002623 mRetryCount = msg.arg1;
2624 if (ar.exception != null) {
2625 if (ar.exception instanceof CommandException &&
2626 ((CommandException)(ar.exception)).getCommandError()
2627 == CommandException.Error.PASSWORD_INCORRECT) {
2628 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002629 } //When UiccCardApp dispose,handle message and return exception
2630 else if (ar.exception instanceof CommandException &&
2631 ((CommandException) (ar.exception)).getCommandError()
2632 == CommandException.Error.ABORTED) {
2633 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002634 } else {
2635 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2636 }
2637 } else {
2638 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2639 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002640 mDone = true;
2641 UnlockSim.this.notifyAll();
2642 }
2643 break;
2644 }
2645 }
2646 };
2647 UnlockSim.this.notifyAll();
2648 }
2649 Looper.loop();
2650 }
2651
2652 /*
2653 * Use PIN or PUK to unlock SIM card
2654 *
2655 * If PUK is null, unlock SIM card with PIN
2656 *
2657 * If PUK is not null, unlock SIM card with PUK and set PIN code
2658 */
Wink Saville9de0f752013-10-22 19:04:03 -07002659 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002660
2661 while (mHandler == null) {
2662 try {
2663 wait();
2664 } catch (InterruptedException e) {
2665 Thread.currentThread().interrupt();
2666 }
2667 }
2668 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2669
2670 if (puk == null) {
2671 mSimCard.supplyPin(pin, callback);
2672 } else {
2673 mSimCard.supplyPuk(puk, pin, callback);
2674 }
2675
2676 while (!mDone) {
2677 try {
2678 Log.d(LOG_TAG, "wait for done");
2679 wait();
2680 } catch (InterruptedException e) {
2681 // Restore the interrupted status
2682 Thread.currentThread().interrupt();
2683 }
2684 }
2685 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002686 int[] resultArray = new int[2];
2687 resultArray[0] = mResult;
2688 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002689
2690 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002691 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002692 }
2693
Wink Saville9de0f752013-10-22 19:04:03 -07002694 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 }
2696 }
2697
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002698 /**
2699 * This method has been removed due to privacy and stability concerns.
2700 */
2701 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002702 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002703 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2704 return;
Wink Saville36469e72014-06-11 15:17:00 -07002705 }
2706
Nathan Harold1f889d82020-06-04 17:05:26 -07002707 @Override
2708 public void updateServiceLocationWithPackageName(String callingPackage) {
2709 mApp.getSystemService(AppOpsManager.class)
2710 .checkPackage(Binder.getCallingUid(), callingPackage);
2711
Nathan Haroldf096d982020-11-18 17:18:06 -08002712 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002713 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2714 // Callers targeting S have no business invoking this method.
2715 return;
2716 }
2717
2718 LocationAccessPolicy.LocationPermissionResult locationResult =
2719 LocationAccessPolicy.checkLocationPermission(mApp,
2720 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2721 .setCallingPackage(callingPackage)
2722 .setCallingFeatureId(null)
2723 .setCallingPid(Binder.getCallingPid())
2724 .setCallingUid(Binder.getCallingUid())
2725 .setMethod("updateServiceLocation")
2726 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2727 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2728 .build());
2729 // Apps that lack location permission have no business calling this method;
2730 // however, because no permission was declared in the public API, denials must
2731 // all be "soft".
2732 switch (locationResult) {
2733 case DENIED_HARD: /* fall through */
2734 case DENIED_SOFT:
2735 return;
2736 }
2737
2738 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 final long identity = Binder.clearCallingIdentity();
2740 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002741 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002742 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002743 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002744 }
2745 } finally {
2746 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002747 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002748 }
2749
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002750 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002751 @Override
2752 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002753 return isRadioOnWithFeature(callingPackage, null);
2754 }
2755
2756
2757 @Override
2758 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2759 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2760 callingFeatureId);
2761 }
2762
2763 @Deprecated
2764 @Override
2765 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2766 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002767 }
2768
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002769 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002770 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2771 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002772 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002773 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002774 return false;
2775 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002776
2777 final long identity = Binder.clearCallingIdentity();
2778 try {
2779 return isRadioOnForSubscriber(subId);
2780 } finally {
2781 Binder.restoreCallingIdentity(identity);
2782 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002783 }
2784
2785 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 final long identity = Binder.clearCallingIdentity();
2787 try {
2788 final Phone phone = getPhone(subId);
2789 if (phone != null) {
2790 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2791 } else {
2792 return false;
2793 }
2794 } finally {
2795 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002796 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002797 }
2798
2799 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002800 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002801 }
Wink Saville36469e72014-06-11 15:17:00 -07002802
Wink Savilleb564aae2014-10-23 10:18:09 -07002803 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002804 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002805
2806 final long identity = Binder.clearCallingIdentity();
2807 try {
2808 final Phone phone = getPhone(subId);
2809 if (phone != null) {
2810 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2811 }
2812 } finally {
2813 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002814 }
Wink Saville36469e72014-06-11 15:17:00 -07002815 }
2816
2817 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002818 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002819 }
2820
Wink Savilleb564aae2014-10-23 10:18:09 -07002821 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002822 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002823
2824 final long identity = Binder.clearCallingIdentity();
2825 try {
2826 final Phone phone = getPhone(subId);
2827 if (phone == null) {
2828 return false;
2829 }
2830 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2831 toggleRadioOnOffForSubscriber(subId);
2832 }
2833 return true;
2834 } finally {
2835 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002836 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002837 }
Wink Saville36469e72014-06-11 15:17:00 -07002838
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002839 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002840 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002841 /*
2842 * If any of the Radios are available, it will need to be
2843 * shutdown. So return true if any Radio is available.
2844 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002845 final long identity = Binder.clearCallingIdentity();
2846 try {
2847 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2848 Phone phone = PhoneFactory.getPhone(i);
2849 if (phone != null && phone.isRadioAvailable()) return true;
2850 }
2851 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2852 return false;
2853 } finally {
2854 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002855 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002856 }
2857
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002859 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002860 enforceModifyPermission();
2861
2862 final long identity = Binder.clearCallingIdentity();
2863 try {
2864 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2865 logv("Shutting down Phone " + i);
2866 shutdownRadioUsingPhoneId(i);
2867 }
2868 } finally {
2869 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002870 }
2871 }
2872
2873 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002874 Phone phone = PhoneFactory.getPhone(phoneId);
2875 if (phone != null && phone.isRadioAvailable()) {
2876 phone.shutdownRadio();
2877 }
2878 }
2879
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002880 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002881 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882
2883 final long identity = Binder.clearCallingIdentity();
2884 try {
2885 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2886 if (defaultPhone != null) {
2887 defaultPhone.setRadioPower(turnOn);
2888 return true;
2889 } else {
2890 loge("There's no default phone.");
2891 return false;
2892 }
2893 } finally {
2894 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002895 }
Wink Saville36469e72014-06-11 15:17:00 -07002896 }
2897
Wink Savilleb564aae2014-10-23 10:18:09 -07002898 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002899 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002900
2901 final long identity = Binder.clearCallingIdentity();
2902 try {
2903 final Phone phone = getPhone(subId);
2904 if (phone != null) {
2905 phone.setRadioPower(turnOn);
2906 return true;
2907 } else {
2908 return false;
2909 }
2910 } finally {
2911 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002912 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002913 }
2914
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002915 /**
2916 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2917 * no reason to power it off. When any of the voters want to power it off, it will be turned
2918 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2919 * powering it off, and these radio off votes will be cleared.
2920 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
2921 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
2922 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
2923 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
2924 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
2925 * check its vote.
2926 *
2927 * @param subId The subscription ID.
2928 * @param reason The reason for powering off radio.
2929 * @return true on success and false on failure.
2930 */
2931 public boolean requestRadioPowerOffForReason(int subId,
2932 @TelephonyManager.RadioPowerReason int reason) {
2933 enforceModifyPermission();
2934
2935 final long identity = Binder.clearCallingIdentity();
2936 try {
2937 final Phone phone = getPhone(subId);
2938 if (phone != null) {
2939 phone.setRadioPowerForReason(false, reason);
2940 return true;
2941 } else {
2942 return false;
2943 }
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
2946 }
2947 }
2948
2949 /**
2950 * Remove the vote on powering off the radio for a reason, as requested by
2951 * {@link requestRadioPowerOffForReason}.
2952 *
2953 * @param subId The subscription ID.
2954 * @param reason The reason for powering off radio.
2955 * @return true on success and false on failure.
2956 */
2957 public boolean clearRadioPowerOffForReason(int subId,
2958 @TelephonyManager.RadioPowerReason int reason) {
2959 enforceModifyPermission();
2960
2961 final long identity = Binder.clearCallingIdentity();
2962 try {
2963 final Phone phone = getPhone(subId);
2964 if (phone != null) {
2965 phone.setRadioPowerForReason(true, reason);
2966 return true;
2967 } else {
2968 return false;
2969 }
2970 } finally {
2971 Binder.restoreCallingIdentity(identity);
2972 }
2973 }
2974
2975 /**
2976 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
2977 *
2978 * @param subId The subscription ID.
2979 * @param callingPackage The package making the call.
2980 * @param callingFeatureId The feature in the package.
2981 * @return List of reasons for powering off radio.
2982 */
2983 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
2984 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
2985
2986 final long identity = Binder.clearCallingIdentity();
2987 List result = new ArrayList();
2988 try {
2989 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
2990 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
2991 return result;
2992 }
2993
2994 final Phone phone = getPhone(subId);
2995 if (phone != null) {
2996 result.addAll(phone.getRadioPowerOffReasons());
2997 }
2998 } finally {
2999 Binder.restoreCallingIdentity(identity);
3000 }
3001 return result;
3002 }
3003
Wink Saville36469e72014-06-11 15:17:00 -07003004 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003005 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003006 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003007 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003008
3009 final long identity = Binder.clearCallingIdentity();
3010 try {
3011 int subId = mSubscriptionController.getDefaultDataSubId();
3012 final Phone phone = getPhone(subId);
3013 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003014 phone.getDataSettingsManager().setDataEnabled(
3015 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003016 return true;
3017 } else {
3018 return false;
3019 }
3020 } finally {
3021 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003022 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003023 }
3024
Wink Saville36469e72014-06-11 15:17:00 -07003025 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003026 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003027 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003028 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003029
3030 final long identity = Binder.clearCallingIdentity();
3031 try {
3032 int subId = mSubscriptionController.getDefaultDataSubId();
3033 final Phone phone = getPhone(subId);
3034 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003035 phone.getDataSettingsManager().setDataEnabled(
3036 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003037 return true;
3038 } else {
3039 return false;
3040 }
3041 } finally {
3042 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003043 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003044 }
3045
Sanket Padawe356d7632015-06-22 14:03:32 -07003046 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003047 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003048 final long identity = Binder.clearCallingIdentity();
3049 try {
3050 final Phone phone = getPhone(subId);
3051 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003052 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003053 } else {
3054 return false;
3055 }
3056 } finally {
3057 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003058 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003059 }
3060
3061 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003062 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003063 }
3064
pkanwarae03a6b2016-11-06 20:37:09 -08003065 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003066 enforceCallPermission();
3067
3068 final long identity = Binder.clearCallingIdentity();
3069 try {
3070 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3071 return;
3072 }
3073 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3074 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3075 } finally {
3076 Binder.restoreCallingIdentity(identity);
3077 }
pkanwar32d516d2016-10-14 19:37:38 -07003078 };
3079
Wink Savilleb564aae2014-10-23 10:18:09 -07003080 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003081 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003082
3083 final long identity = Binder.clearCallingIdentity();
3084 try {
3085 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3086 return false;
3087 }
3088 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3089 } finally {
3090 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003091 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003092 }
3093
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003094 /**
3095 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3096 * tag on getCallState Binder call.
3097 */
3098 @Deprecated
3099 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003100 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003101 if (CompatChanges.isChangeEnabled(
3102 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3103 Binder.getCallingUid())) {
3104 // Do not allow this API to be called on API version 31+, it should only be
3105 // called on old apps using this Binder call directly.
3106 throw new SecurityException("This method can only be used for applications "
3107 + "targeting API version 30 or less.");
3108 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003109 final long identity = Binder.clearCallingIdentity();
3110 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003111 Phone phone = getPhone(getDefaultSubscription());
3112 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3113 PhoneConstantConversions.convertCallState(phone.getState());
3114 } finally {
3115 Binder.restoreCallingIdentity(identity);
3116 }
3117 }
3118
3119 @Override
3120 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3121 if (CompatChanges.isChangeEnabled(
3122 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3123 Binder.getCallingUid())) {
3124 // Check READ_PHONE_STATE for API version 31+
3125 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3126 featureId, "getCallStateForSubscription")) {
3127 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3128 + "targeting API level 31+.");
3129 }
3130 }
3131 final long identity = Binder.clearCallingIdentity();
3132 try {
3133 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003134 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3135 PhoneConstantConversions.convertCallState(phone.getState());
3136 } finally {
3137 Binder.restoreCallingIdentity(identity);
3138 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003139 }
3140
Sanket Padawe356d7632015-06-22 14:03:32 -07003141 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003142 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003143 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
3144 }
3145
3146 @Override
3147 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003148 final long identity = Binder.clearCallingIdentity();
3149 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003150 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003151 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003152 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003153 } else {
3154 return PhoneConstantConversions.convertDataState(
3155 PhoneConstants.DataState.DISCONNECTED);
3156 }
3157 } finally {
3158 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003159 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003160 }
3161
Sanket Padawe356d7632015-06-22 14:03:32 -07003162 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003163 public @DataActivityType int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003164 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3165 }
3166
3167 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003168 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003169 final long identity = Binder.clearCallingIdentity();
3170 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003171 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003172 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003173 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003174 } else {
3175 return TelephonyManager.DATA_ACTIVITY_NONE;
3176 }
3177 } finally {
3178 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003179 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003180 }
3181
3182 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003183 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003184 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003185 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003186
3187 LocationAccessPolicy.LocationPermissionResult locationResult =
3188 LocationAccessPolicy.checkLocationPermission(mApp,
3189 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3190 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003191 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003192 .setCallingPid(Binder.getCallingPid())
3193 .setCallingUid(Binder.getCallingUid())
3194 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003195 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003196 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3197 .build());
3198 switch (locationResult) {
3199 case DENIED_HARD:
3200 throw new SecurityException("Not allowed to access cell location");
3201 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003202 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3203 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003204 }
3205
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003206 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003207 final long identity = Binder.clearCallingIdentity();
3208 try {
3209 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003210 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003211 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212 } finally {
3213 Binder.restoreCallingIdentity(identity);
3214 }
Svetoslav64fad262015-04-14 14:35:21 -07003215 }
3216
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003217 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003218 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003219 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3220 // registered cell info, so return a NULL country instead.
3221 final long identity = Binder.clearCallingIdentity();
3222 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003223 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3224 // Get default phone in this case.
3225 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3226 }
Jack Yue84aa0e2022-11-17 22:47:32 -08003227 final int subId = mSubscriptionController.getSubId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003228 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003229 if (phone == null) return "";
3230 ServiceStateTracker sst = phone.getServiceStateTracker();
3231 if (sst == null) return "";
3232 LocaleTracker lt = sst.getLocaleTracker();
3233 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003234 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003235 } finally {
3236 Binder.restoreCallingIdentity(identity);
3237 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003238 }
3239
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003240 /**
3241 * This method was removed due to potential issues caused by performing partial
3242 * updates of service state, and lack of a credible use case.
3243 *
3244 * This has the ability to break the telephony implementation by disabling notification of
3245 * changes in device connectivity. DO NOT USE THIS!
3246 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003247 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003248 public void enableLocationUpdates() {
3249 mApp.enforceCallingOrSelfPermission(
3250 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003251 }
3252
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003253 /**
3254 * This method was removed due to potential issues caused by performing partial
3255 * updates of service state, and lack of a credible use case.
3256 *
3257 * This has the ability to break the telephony implementation by disabling notification of
3258 * changes in device connectivity. DO NOT USE THIS!
3259 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003260 @Override
3261 public void disableLocationUpdates() {
3262 mApp.enforceCallingOrSelfPermission(
3263 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003264 }
3265
3266 @Override
3267 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003268 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3269 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003270 try {
3271 mApp.getSystemService(AppOpsManager.class)
3272 .checkPackage(Binder.getCallingUid(), callingPackage);
3273 } catch (SecurityException e) {
3274 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3275 throw e;
3276 }
3277
Nathan Haroldf096d982020-11-18 17:18:06 -08003278 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003279 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3280 throw new SecurityException(
3281 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3282 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003283
Jordan Liu1617b712019-07-10 15:06:26 -07003284 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003285 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3286 return null;
3287 }
Svetoslav64fad262015-04-14 14:35:21 -07003288
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003289 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003290
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003291 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003292 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003293
Nathan Haroldf180aac2018-06-01 18:43:55 -07003294 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3295 for (CellInfo ci : info) {
3296 if (ci instanceof CellInfoGsm) {
3297 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3298 } else if (ci instanceof CellInfoWcdma) {
3299 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003301 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003302 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003303 }
3304
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003305 private List<CellInfo> getCachedCellInfo() {
3306 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3307 for (Phone phone : PhoneFactory.getPhones()) {
3308 List<CellInfo> info = phone.getAllCellInfo();
3309 if (info != null) cellInfos.addAll(info);
3310 }
3311 return cellInfos;
3312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003313
3314 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003315 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003316 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003317 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003318
3319 LocationAccessPolicy.LocationPermissionResult locationResult =
3320 LocationAccessPolicy.checkLocationPermission(mApp,
3321 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3322 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003323 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003324 .setCallingPid(Binder.getCallingPid())
3325 .setCallingUid(Binder.getCallingUid())
3326 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003327 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003328 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3329 .build());
3330 switch (locationResult) {
3331 case DENIED_HARD:
3332 throw new SecurityException("Not allowed to access cell info");
3333 case DENIED_SOFT:
3334 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003335 }
3336
Nathan Haroldf096d982020-11-18 17:18:06 -08003337 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003338 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3339 return getCachedCellInfo();
3340 }
3341
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003342 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003343 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003344 final long identity = Binder.clearCallingIdentity();
3345 try {
3346 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3347 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003348 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003349 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003350 if (info != null) cellInfos.addAll(info);
3351 }
3352 return cellInfos;
3353 } finally {
3354 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003355 }
3356 }
3357
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003358 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003359 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3360 String callingFeatureId) {
3361 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3362 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003363 }
3364
3365 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003366 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3367 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003368 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003369 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003370 }
3371
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003372 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3373 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003374 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003375 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003376
3377 LocationAccessPolicy.LocationPermissionResult locationResult =
3378 LocationAccessPolicy.checkLocationPermission(mApp,
3379 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3380 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003381 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003382 .setCallingPid(Binder.getCallingPid())
3383 .setCallingUid(Binder.getCallingUid())
3384 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003385 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3386 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003387 .build());
3388 switch (locationResult) {
3389 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003390 if (TelephonyPermissions
3391 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003392 // Safetynet logging for b/154934934
3393 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3394 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003395 throw new SecurityException("Not allowed to access cell info");
3396 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003397 if (TelephonyPermissions
3398 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003399 // Safetynet logging for b/154934934
3400 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3401 }
Nathan Harold5320c422019-05-09 10:26:08 -07003402 try {
3403 cb.onCellInfo(new ArrayList<CellInfo>());
3404 } catch (RemoteException re) {
3405 // Drop without consequences
3406 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003407 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003408 }
3409
Nathan Harolda939a962019-05-09 10:13:47 -07003410
3411 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003412 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3413
3414 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3415 }
3416
3417 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003418 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003419 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003420 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003421
3422 final long identity = Binder.clearCallingIdentity();
3423 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003424 Phone phone = getPhone(subId);
3425 if (phone == null) {
3426 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3427 } else {
3428 phone.setCellInfoListRate(rateInMillis, workSource);
3429 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003430 } finally {
3431 Binder.restoreCallingIdentity(identity);
3432 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003433 }
3434
Shishir Agrawala9f32182016-04-12 12:00:16 -07003435 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003436 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003437 Phone phone = PhoneFactory.getPhone(slotIndex);
3438 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003439 return null;
3440 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003441 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003442 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003443 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003444 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003445 return null;
3446 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003447
3448 final long identity = Binder.clearCallingIdentity();
3449 try {
3450 return phone.getImei();
3451 } finally {
3452 Binder.restoreCallingIdentity(identity);
3453 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003454 }
3455
3456 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003457 public String getTypeAllocationCodeForSlot(int slotIndex) {
3458 Phone phone = PhoneFactory.getPhone(slotIndex);
3459 String tac = null;
3460 if (phone != null) {
3461 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003462 try {
3463 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3464 } catch (IndexOutOfBoundsException e) {
3465 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3466 return null;
3467 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003468 }
3469 return tac;
3470 }
3471
3472 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003473 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003474 try {
3475 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3476 } catch (SecurityException se) {
3477 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3478 throw new SecurityException("Package " + callingPackage + " does not belong to "
3479 + Binder.getCallingUid());
3480 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003481 Phone phone = PhoneFactory.getPhone(slotIndex);
3482 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003483 return null;
3484 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003485
Jeff Davidson913390f2018-02-23 17:11:49 -08003486 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003487 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003488 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003489 return null;
3490 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003491
3492 final long identity = Binder.clearCallingIdentity();
3493 try {
3494 return phone.getMeid();
3495 } finally {
3496 Binder.restoreCallingIdentity(identity);
3497 }
Jack Yu2af8d712017-03-15 17:14:14 -07003498 }
3499
3500 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003501 public String getManufacturerCodeForSlot(int slotIndex) {
3502 Phone phone = PhoneFactory.getPhone(slotIndex);
3503 String manufacturerCode = null;
3504 if (phone != null) {
3505 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003506 try {
3507 manufacturerCode =
3508 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3509 } catch (IndexOutOfBoundsException e) {
3510 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3511 return null;
3512 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003513 }
3514 return manufacturerCode;
3515 }
3516
3517 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003518 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3519 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003520 Phone phone = PhoneFactory.getPhone(slotIndex);
3521 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003522 return null;
3523 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003524 int subId = phone.getSubId();
3525 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003526 mApp, subId, callingPackage, callingFeatureId,
3527 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003528 return null;
3529 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003530
3531 final long identity = Binder.clearCallingIdentity();
3532 try {
3533 return phone.getDeviceSvn();
3534 } finally {
3535 Binder.restoreCallingIdentity(identity);
3536 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003537 }
3538
fionaxu43304da2017-11-27 22:51:16 -08003539 @Override
3540 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003541 final long identity = Binder.clearCallingIdentity();
3542 try {
3543 final Phone phone = getPhone(subId);
3544 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3545 } finally {
3546 Binder.restoreCallingIdentity(identity);
3547 }
fionaxu43304da2017-11-27 22:51:16 -08003548 }
3549
3550 @Override
3551 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003552 final long identity = Binder.clearCallingIdentity();
3553 try {
3554 final Phone phone = getPhone(subId);
3555 return phone == null ? null : phone.getCarrierName();
3556 } finally {
3557 Binder.restoreCallingIdentity(identity);
3558 }
fionaxu43304da2017-11-27 22:51:16 -08003559 }
3560
calvinpanffe225e2018-11-01 19:43:06 +08003561 @Override
chen xu0026ca62019-03-06 15:28:50 -08003562 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003563 final long identity = Binder.clearCallingIdentity();
3564 try {
3565 final Phone phone = getPhone(subId);
3566 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003567 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003568 } finally {
3569 Binder.restoreCallingIdentity(identity);
3570 }
3571 }
3572
3573 @Override
chen xu0026ca62019-03-06 15:28:50 -08003574 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003575 final long identity = Binder.clearCallingIdentity();
3576 try {
3577 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003578 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003579 } finally {
3580 Binder.restoreCallingIdentity(identity);
3581 }
3582 }
3583
chen xu651eec72018-11-11 19:03:44 -08003584 @Override
chen xu864e11c2018-12-06 22:10:03 -08003585 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3586 if (!isSubscriptionMccMnc) {
3587 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3588 }
chen xu651eec72018-11-11 19:03:44 -08003589 final Phone phone = PhoneFactory.getPhone(slotIndex);
3590 if (phone == null) {
3591 return TelephonyManager.UNKNOWN_CARRIER_ID;
3592 }
3593 final long identity = Binder.clearCallingIdentity();
3594 try {
3595 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3596 } finally {
3597 Binder.restoreCallingIdentity(identity);
3598 }
3599 }
3600
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003601 //
3602 // Internal helper methods.
3603 //
3604
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003605 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003606 * Make sure the caller is the calling package itself
3607 *
3608 * @throws SecurityException if the caller is not the calling package
3609 */
3610 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3611 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003612 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3613 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003614 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003615 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003616 } catch (PackageManager.NameNotFoundException e) {
3617 // packageUid is -1
3618 }
3619 if (packageUid != callingUid) {
3620 throw new SecurityException(message + ": Package " + callingPackage
3621 + " does not belong to " + callingUid);
3622 }
3623 }
3624
3625 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003626 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3627 *
3628 * @throws SecurityException if the caller does not have the required permission
3629 */
3630 private void enforceModifyPermission() {
3631 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3632 }
3633
Shuo Qian3b6ee772019-11-13 17:43:31 -08003634 private void enforceActiveEmergencySessionPermission() {
3635 mApp.enforceCallingOrSelfPermission(
3636 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3637 }
3638
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003639 /**
3640 * Make sure the caller has the CALL_PHONE permission.
3641 *
3642 * @throws SecurityException if the caller does not have the required permission
3643 */
3644 private void enforceCallPermission() {
3645 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3646 }
3647
paulhu5a773602019-08-23 19:17:33 +08003648 private void enforceSettingsPermission() {
3649 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003650 }
3651
Michele Berionne5e411512020-11-13 02:36:59 +00003652 private void enforceRebootPermission() {
3653 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3654 }
3655
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003656 private String createTelUrl(String number) {
3657 if (TextUtils.isEmpty(number)) {
3658 return null;
3659 }
3660
Jake Hambye994d462014-02-03 13:10:13 -08003661 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003662 }
3663
Ihab Awadf9e92732013-12-05 18:02:52 -08003664 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003665 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3666 }
3667
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003668 private static void logv(String msg) {
3669 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3670 }
3671
Ihab Awadf9e92732013-12-05 18:02:52 -08003672 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003673 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3674 }
3675
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003676 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003677 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003678 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003679 }
3680
Sanket Padawe356d7632015-06-22 14:03:32 -07003681 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003682 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003683 final long identity = Binder.clearCallingIdentity();
3684 try {
3685 final Phone phone = PhoneFactory.getPhone(slotIndex);
3686 if (phone == null) {
3687 return PhoneConstants.PHONE_TYPE_NONE;
3688 } else {
3689 return phone.getPhoneType();
3690 }
3691 } finally {
3692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003694 }
3695
3696 /**
3697 * Returns the CDMA ERI icon index to display
3698 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003699 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003700 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3701 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3702 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003703 }
3704
Sanket Padawe356d7632015-06-22 14:03:32 -07003705 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003706 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3707 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003708 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003709 mApp, subId, callingPackage, callingFeatureId,
3710 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003711 return -1;
3712 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003713
3714 final long identity = Binder.clearCallingIdentity();
3715 try {
3716 final Phone phone = getPhone(subId);
3717 if (phone != null) {
3718 return phone.getCdmaEriIconIndex();
3719 } else {
3720 return -1;
3721 }
3722 } finally {
3723 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003724 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003725 }
3726
3727 /**
3728 * Returns the CDMA ERI icon mode,
3729 * 0 - ON
3730 * 1 - FLASHING
3731 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003732 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003733 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3734 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3735 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003736 }
3737
Sanket Padawe356d7632015-06-22 14:03:32 -07003738 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003739 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3740 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003741 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003742 mApp, subId, callingPackage, callingFeatureId,
3743 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003744 return -1;
3745 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003746
3747 final long identity = Binder.clearCallingIdentity();
3748 try {
3749 final Phone phone = getPhone(subId);
3750 if (phone != null) {
3751 return phone.getCdmaEriIconMode();
3752 } else {
3753 return -1;
3754 }
3755 } finally {
3756 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003757 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003758 }
3759
3760 /**
3761 * Returns the CDMA ERI text,
3762 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003763 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003764 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3765 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3766 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003767 }
3768
Sanket Padawe356d7632015-06-22 14:03:32 -07003769 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003770 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3771 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003772 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003773 mApp, subId, callingPackage, callingFeatureId,
3774 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003775 return null;
3776 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003777
3778 final long identity = Binder.clearCallingIdentity();
3779 try {
3780 final Phone phone = getPhone(subId);
3781 if (phone != null) {
3782 return phone.getCdmaEriText();
3783 } else {
3784 return null;
3785 }
3786 } finally {
3787 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003788 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003789 }
3790
3791 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003792 * Returns the CDMA MDN.
3793 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003794 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003795 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3797 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003798
3799 final long identity = Binder.clearCallingIdentity();
3800 try {
3801 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003802 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003803 return phone.getLine1Number();
3804 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003805 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003806 return null;
3807 }
3808 } finally {
3809 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003810 }
3811 }
3812
3813 /**
3814 * Returns the CDMA MIN.
3815 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003816 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003817 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003818 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3819 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003820
3821 final long identity = Binder.clearCallingIdentity();
3822 try {
3823 final Phone phone = getPhone(subId);
3824 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3825 return phone.getCdmaMin();
3826 } else {
3827 return null;
3828 }
3829 } finally {
3830 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003831 }
3832 }
3833
Hall Liud892bec2018-11-30 14:51:45 -08003834 @Override
3835 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3836 INumberVerificationCallback callback, String callingPackage) {
3837 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3838 != PERMISSION_GRANTED) {
3839 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3840 }
3841 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3842
3843 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3844 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003845 throw new SecurityException("Calling package must be configured in the device config: "
3846 + "calling package: " + callingPackage
3847 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003848 }
3849
3850 if (range == null) {
3851 throw new NullPointerException("Range must be non-null");
3852 }
3853
3854 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003855 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003856
3857 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3858 }
3859
Junda Liuca05d5d2014-08-14 22:36:34 -07003860 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003861 * Returns true if CDMA provisioning needs to run.
3862 */
3863 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003864 final long identity = Binder.clearCallingIdentity();
3865 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003866 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003867 } finally {
3868 Binder.restoreCallingIdentity(identity);
3869 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003870 }
3871
3872 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003873 * Sets the voice mail number of a given subId.
3874 */
3875 @Override
3876 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003877 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3878 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003879
3880 final long identity = Binder.clearCallingIdentity();
3881 try {
3882 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3883 new Pair<String, String>(alphaTag, number), new Integer(subId));
3884 return success;
3885 } finally {
3886 Binder.restoreCallingIdentity(identity);
3887 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003888 }
3889
Ta-wei Yen87c49842016-05-13 21:19:52 -07003890 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003891 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3892 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003893 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3894 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003895 if (!TextUtils.equals(callingPackage, systemDialer)) {
3896 throw new SecurityException("caller must be system dialer");
3897 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003898
3899 final long identity = Binder.clearCallingIdentity();
3900 try {
3901 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3902 if (phoneAccountHandle == null) {
3903 return null;
3904 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003905 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003906 } finally {
3907 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003908 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003909 }
3910
3911 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003912 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3913 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003914 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003915 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003916 mApp, subId, callingPackage, callingFeatureId,
3917 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003918 return null;
3919 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003920
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003921 final long identity = Binder.clearCallingIdentity();
3922 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003923 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003924 } finally {
3925 Binder.restoreCallingIdentity(identity);
3926 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003927 }
3928
3929 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003930 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3931 VisualVoicemailSmsFilterSettings settings) {
3932 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003933
3934 final long identity = Binder.clearCallingIdentity();
3935 try {
3936 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003937 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003938 } finally {
3939 Binder.restoreCallingIdentity(identity);
3940 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003941 }
3942
3943 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003944 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3945 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003946
3947 final long identity = Binder.clearCallingIdentity();
3948 try {
3949 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003950 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003951 } finally {
3952 Binder.restoreCallingIdentity(identity);
3953 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003954 }
3955
3956 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003957 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3958 String callingPackage, int subId) {
3959 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003960
3961 final long identity = Binder.clearCallingIdentity();
3962 try {
3963 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003964 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003965 } finally {
3966 Binder.restoreCallingIdentity(identity);
3967 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003968 }
3969
3970 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003971 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003972 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003973
3974 final long identity = Binder.clearCallingIdentity();
3975 try {
3976 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003977 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003978 } finally {
3979 Binder.restoreCallingIdentity(identity);
3980 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003981 }
3982
3983 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003984 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3985 String callingAttributionTag, int subId, String number, int port, String text,
3986 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003987 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003988 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003989 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003990 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003991 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3992 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003993 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003994
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003995 /**
fionaxu0152e512016-11-14 13:36:14 -08003996 * Sets the voice activation state of a given subId.
3997 */
3998 @Override
3999 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4001 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004002
4003 final long identity = Binder.clearCallingIdentity();
4004 try {
4005 final Phone phone = getPhone(subId);
4006 if (phone != null) {
4007 phone.setVoiceActivationState(activationState);
4008 } else {
4009 loge("setVoiceActivationState fails with invalid subId: " + subId);
4010 }
4011 } finally {
4012 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004013 }
4014 }
4015
4016 /**
4017 * Sets the data activation state of a given subId.
4018 */
4019 @Override
4020 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4022 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004023
4024 final long identity = Binder.clearCallingIdentity();
4025 try {
4026 final Phone phone = getPhone(subId);
4027 if (phone != null) {
4028 phone.setDataActivationState(activationState);
4029 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004030 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004031 }
4032 } finally {
4033 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004034 }
4035 }
4036
4037 /**
4038 * Returns the voice activation state of a given subId.
4039 */
4040 @Override
4041 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004042 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004043
fionaxu0152e512016-11-14 13:36:14 -08004044 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004045 final long identity = Binder.clearCallingIdentity();
4046 try {
4047 if (phone != null) {
4048 return phone.getVoiceActivationState();
4049 } else {
4050 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4051 }
4052 } finally {
4053 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004054 }
4055 }
4056
4057 /**
4058 * Returns the data activation state of a given subId.
4059 */
4060 @Override
4061 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004062 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004063
fionaxu0152e512016-11-14 13:36:14 -08004064 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004065 final long identity = Binder.clearCallingIdentity();
4066 try {
4067 if (phone != null) {
4068 return phone.getDataActivationState();
4069 } else {
4070 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4071 }
4072 } finally {
4073 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004074 }
4075 }
4076
4077 /**
Wink Saville36469e72014-06-11 15:17:00 -07004078 * Returns the unread count of voicemails for a subId
4079 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004080 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004081 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4082 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004083 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004084 mApp, subId, callingPackage, callingFeatureId,
4085 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004086 return 0;
4087 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004088 final long identity = Binder.clearCallingIdentity();
4089 try {
4090 final Phone phone = getPhone(subId);
4091 if (phone != null) {
4092 return phone.getVoiceMessageCount();
4093 } else {
4094 return 0;
4095 }
4096 } finally {
4097 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004098 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004099 }
4100
4101 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004102 * returns true, if the device is in a state where both voice and data
4103 * are supported simultaneously. This can change based on location or network condition.
4104 */
4105 @Override
4106 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004107 final long identity = Binder.clearCallingIdentity();
4108 try {
4109 final Phone phone = getPhone(subId);
4110 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4111 } finally {
4112 Binder.restoreCallingIdentity(identity);
4113 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004114 }
4115
4116 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004117 * Send the dialer code if called from the current default dialer or the caller has
4118 * carrier privilege.
4119 * @param inputCode The dialer code to send
4120 */
4121 @Override
4122 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004123 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004124 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004125 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4126 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004127 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004128 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004129 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004130 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004131
4132 final long identity = Binder.clearCallingIdentity();
4133 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004134 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004135 } finally {
4136 Binder.restoreCallingIdentity(identity);
4137 }
fionaxu235cc5e2017-03-06 22:25:57 -08004138 }
4139
Pengquan Menga1bb6272018-09-06 09:59:22 -07004140 @Override
4141 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004142 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004143 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004144 mApp, subId, "getNetworkSelectionMode");
4145 final long identity = Binder.clearCallingIdentity();
4146 try {
4147 if (!isActiveSubscription(subId)) {
4148 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4149 }
4150 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4151 } finally {
4152 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004153 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004154 }
4155
Brad Ebinger35c841c2018-10-01 10:40:55 -07004156 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004157 public boolean isInEmergencySmsMode() {
4158 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4159 final long identity = Binder.clearCallingIdentity();
4160 try {
4161 for (Phone phone : PhoneFactory.getPhones()) {
4162 if (phone.isInEmergencySmsMode()) {
4163 return true;
4164 }
4165 }
4166 } finally {
4167 Binder.restoreCallingIdentity(identity);
4168 }
4169 return false;
4170 }
4171
shilu366312e2019-12-17 09:28:10 -08004172 /**
4173 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4174 * @param subId The subscription to use to check the configuration.
4175 * @param c The callback that will be used to send the result.
4176 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004177 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004178 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4179 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004180 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004181 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004182
4183 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4184 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4185 "IMS not available on device.");
4186 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004187 final long token = Binder.clearCallingIdentity();
4188 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004189 int slotId = getSlotIndexOrException(subId);
4190 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004191
4192 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4193 if (controller != null) {
4194 ImsManager imsManager = controller.getImsManager(subId);
4195 if (imsManager != null) {
4196 imsManager.addRegistrationCallbackForSubscription(c, subId);
4197 } else {
4198 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4199 }
4200 } else {
4201 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4202 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004203 } catch (ImsException e) {
4204 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004205 } finally {
4206 Binder.restoreCallingIdentity(token);
4207 }
4208 }
4209
shilu366312e2019-12-17 09:28:10 -08004210 /**
4211 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4212 * @param subId The subscription to use to check the configuration.
4213 * @param c The callback that will be used to send the result.
4214 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004215 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004216 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004217 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004218 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004219 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4220 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4221 }
Meng Wangafbc5852019-09-19 17:37:13 -07004222 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004223
Meng Wangafbc5852019-09-19 17:37:13 -07004224 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004225 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4226 if (controller != null) {
4227 ImsManager imsManager = controller.getImsManager(subId);
4228 if (imsManager != null) {
4229 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4230 } else {
4231 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4232 + "is inactive, ignoring unregister.");
4233 // If the ImsManager is not valid, just return, since the callback
4234 // will already have been removed internally.
4235 }
4236 }
Meng Wangafbc5852019-09-19 17:37:13 -07004237 } finally {
4238 Binder.restoreCallingIdentity(token);
4239 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004240 }
4241
Brad Ebingera34a6c22019-10-22 17:36:18 -07004242 /**
4243 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4244 */
4245 @Override
4246 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4247 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4248 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4249 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4250 "IMS not available on device.");
4251 }
4252 final long token = Binder.clearCallingIdentity();
4253 try {
4254 Phone phone = getPhone(subId);
4255 if (phone == null) {
4256 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4257 + subId + "'");
4258 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4259 }
4260 phone.getImsRegistrationState(regState -> {
4261 try {
4262 consumer.accept((regState == null)
4263 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4264 } catch (RemoteException e) {
4265 // Ignore if the remote process is no longer available to call back.
4266 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4267 }
4268 });
4269 } finally {
4270 Binder.restoreCallingIdentity(token);
4271 }
4272 }
4273
4274 /**
4275 * Get the transport type for the IMS service registration state.
4276 */
4277 @Override
4278 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004279 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004280 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004281 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4282 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4283 "IMS not available on device.");
4284 }
4285 final long token = Binder.clearCallingIdentity();
4286 try {
4287 Phone phone = getPhone(subId);
4288 if (phone == null) {
4289 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4290 + subId + "'");
4291 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4292 }
4293 phone.getImsRegistrationTech(regTech -> {
4294 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4295 int regTechConverted = (regTech == null)
4296 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4297 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4298 regTechConverted);
4299 try {
4300 consumer.accept(regTechConverted);
4301 } catch (RemoteException e) {
4302 // Ignore if the remote process is no longer available to call back.
4303 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4304 }
4305 });
4306 } finally {
4307 Binder.restoreCallingIdentity(token);
4308 }
4309 }
4310
shilu366312e2019-12-17 09:28:10 -08004311 /**
4312 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4313 * @param subId The subscription to use to check the configuration.
4314 * @param c The callback that will be used to send the result.
4315 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004316 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004317 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4318 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004319 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004320 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004321 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4322 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4323 "IMS not available on device.");
4324 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004325 final long token = Binder.clearCallingIdentity();
4326 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004327 int slotId = getSlotIndexOrException(subId);
4328 verifyImsMmTelConfiguredOrThrow(slotId);
4329 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004330 } catch (ImsException e) {
4331 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004332 } finally {
4333 Binder.restoreCallingIdentity(token);
4334 }
4335 }
4336
shilu366312e2019-12-17 09:28:10 -08004337 /**
4338 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4339 * @param subId The subscription to use to check the configuration.
4340 * @param c The callback that will be used to send the result.
4341 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004342 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004343 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004344 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004345 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004346 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4347 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4348 }
Meng Wangafbc5852019-09-19 17:37:13 -07004349
4350 final long token = Binder.clearCallingIdentity();
4351 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004352 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004353 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004354 } catch (ImsException e) {
4355 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4356 + "is inactive, ignoring unregister.");
4357 // If the subscription is no longer active, just return, since the callback
4358 // will already have been removed internally.
4359 } finally {
4360 Binder.restoreCallingIdentity(token);
4361 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004362 }
4363
4364 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004365 public boolean isCapable(int subId, int capability, int regTech) {
4366 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004367 final long token = Binder.clearCallingIdentity();
4368 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004369 int slotId = getSlotIndexOrException(subId);
4370 verifyImsMmTelConfiguredOrThrow(slotId);
4371 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4372 } catch (com.android.ims.ImsException e) {
4373 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4374 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004375 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004376 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4377 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004378 } finally {
4379 Binder.restoreCallingIdentity(token);
4380 }
4381 }
4382
4383 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004384 public boolean isAvailable(int subId, int capability, int regTech) {
4385 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004386 final long token = Binder.clearCallingIdentity();
4387 try {
4388 Phone phone = getPhone(subId);
4389 if (phone == null) return false;
4390 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004391 } catch (com.android.ims.ImsException e) {
4392 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4393 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004394 } finally {
4395 Binder.restoreCallingIdentity(token);
4396 }
4397 }
4398
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004399 /**
4400 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4401 * subscription.
4402 * @param subId The subscription to use to check the configuration.
4403 * @param callback The callback that will be used to send the result.
4404 * @param capability The MmTelFeature capability that will be used to send the result.
4405 * @param transportType The transport type of the MmTelFeature capability.
4406 */
4407 @Override
4408 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4409 int transportType) {
4410 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004411 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4412 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4413 "IMS not available on device.");
4414 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004415 final long token = Binder.clearCallingIdentity();
4416 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004417 int slotId = getSlotIndex(subId);
4418 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4419 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4420 + subId + "'");
4421 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4422 }
4423 verifyImsMmTelConfiguredOrThrow(slotId);
4424 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4425 transportType, aBoolean -> {
4426 try {
4427 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4428 } catch (RemoteException e) {
4429 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4430 + "running. Ignore");
4431 }
4432 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004433 } catch (ImsException e) {
4434 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004435 } finally {
4436 Binder.restoreCallingIdentity(token);
4437 }
4438 }
4439
shilu366312e2019-12-17 09:28:10 -08004440 /**
4441 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4442 * @param subId The subscription to use to check the configuration.
4443 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004444 @Override
4445 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004446 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004447 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004448
Brad Ebinger35c841c2018-10-01 10:40:55 -07004449 final long token = Binder.clearCallingIdentity();
4450 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004451 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004452 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004453 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004454 } catch (ImsException e) {
4455 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004456 } finally {
4457 Binder.restoreCallingIdentity(token);
4458 }
4459 }
4460
4461 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004462 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004463 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004464 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004465 final long identity = Binder.clearCallingIdentity();
4466 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004467 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004468 // This setting doesn't require an active ImsService connection, so do not verify. The
4469 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004470 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004471 } catch (ImsException e) {
4472 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004473 } finally {
4474 Binder.restoreCallingIdentity(identity);
4475 }
4476 }
4477
shilu366312e2019-12-17 09:28:10 -08004478 /**
4479 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4480 * @param subId The subscription to use to check the configuration.
4481 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004482 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004483 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004484 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004485 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004486 final long identity = Binder.clearCallingIdentity();
4487 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004488 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004489 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004490 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004491 } catch (ImsException e) {
4492 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004493 } finally {
4494 Binder.restoreCallingIdentity(identity);
4495 }
4496 }
4497
4498 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004499 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004500 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004501 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004502 final long identity = Binder.clearCallingIdentity();
4503 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004504 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004505 // This setting doesn't require an active ImsService connection, so do not verify. The
4506 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004507 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004508 } catch (ImsException e) {
4509 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004510 } finally {
4511 Binder.restoreCallingIdentity(identity);
4512 }
4513 }
4514
shilu366312e2019-12-17 09:28:10 -08004515 /**
4516 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4517 * @param subId The subscription to use to check the configuration.
4518 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004519 @Override
4520 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004521 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004522 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004523 final long identity = Binder.clearCallingIdentity();
4524 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004525 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004526 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004527 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004528 } catch (ImsException e) {
4529 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004530 } finally {
4531 Binder.restoreCallingIdentity(identity);
4532 }
4533 }
4534
4535 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004536 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004537 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004538 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004539 final long identity = Binder.clearCallingIdentity();
4540 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004541 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004542 // This setting doesn't require an active ImsService connection, so do not verify. The
4543 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004544 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004545 } catch (ImsException e) {
4546 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004547 } finally {
4548 Binder.restoreCallingIdentity(identity);
4549 }
4550 }
4551
shilu366312e2019-12-17 09:28:10 -08004552 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004553 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4554 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4555 * @param subId The subscription to use to check the configuration.
4556 */
4557 @Override
4558 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004559 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004560 mApp, subId, "isCrossSimCallingEnabledByUser");
4561 final long identity = Binder.clearCallingIdentity();
4562 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004563 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004564 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004565 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004566 } catch (ImsException e) {
4567 throw new ServiceSpecificException(e.getCode());
4568 } finally {
4569 Binder.restoreCallingIdentity(identity);
4570 }
4571 }
4572
4573 /**
4574 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4575 * Requires MODIFY_PHONE_STATE permission.
4576 * @param subId The subscription to use to check the configuration.
4577 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4578 * false otherwise
4579 */
4580 @Override
4581 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4582 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4583 "setCrossSimCallingEnabled");
4584 final long identity = Binder.clearCallingIdentity();
4585 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004586 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004587 // This setting doesn't require an active ImsService connection, so do not verify. The
4588 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004589 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004590 } catch (ImsException e) {
4591 throw new ServiceSpecificException(e.getCode());
4592 } finally {
4593 Binder.restoreCallingIdentity(identity);
4594 }
4595 }
4596
4597 /**
shilu366312e2019-12-17 09:28:10 -08004598 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4599 * @param subId The subscription to use to check the configuration.
4600 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004601 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004602
Brad Ebinger35c841c2018-10-01 10:40:55 -07004603 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004604 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004605 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004606 final long identity = Binder.clearCallingIdentity();
4607 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004608 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004609 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004610 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004611 } catch (ImsException e) {
4612 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004613 } finally {
4614 Binder.restoreCallingIdentity(identity);
4615 }
4616 }
4617
4618 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004619 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004621 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004622 final long identity = Binder.clearCallingIdentity();
4623 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004624 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004625 // This setting doesn't require an active ImsService connection, so do not verify. The
4626 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004627 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004628 } catch (ImsException e) {
4629 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004630 } finally {
4631 Binder.restoreCallingIdentity(identity);
4632 }
4633 }
4634
4635 @Override
4636 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4638 "setVoWiFiNonPersistent");
4639 final long identity = Binder.clearCallingIdentity();
4640 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004641 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004642 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004643 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004644 } catch (ImsException e) {
4645 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004646 } finally {
4647 Binder.restoreCallingIdentity(identity);
4648 }
4649 }
4650
shilu366312e2019-12-17 09:28:10 -08004651 /**
4652 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4653 * @param subId The subscription to use to check the configuration.
4654 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004655 @Override
4656 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004657 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004658 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004659 final long identity = Binder.clearCallingIdentity();
4660 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004661 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004662 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004663 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004664 } catch (ImsException e) {
4665 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004666 } finally {
4667 Binder.restoreCallingIdentity(identity);
4668 }
4669 }
4670
4671 @Override
4672 public void setVoWiFiModeSetting(int subId, int mode) {
4673 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4674 "setVoWiFiModeSetting");
4675 final long identity = Binder.clearCallingIdentity();
4676 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004677 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004678 // This setting doesn't require an active ImsService connection, so do not verify. The
4679 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004680 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004681 } catch (ImsException e) {
4682 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004683 } finally {
4684 Binder.restoreCallingIdentity(identity);
4685 }
4686 }
4687
4688 @Override
4689 public int getVoWiFiRoamingModeSetting(int subId) {
4690 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4691 final long identity = Binder.clearCallingIdentity();
4692 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004693 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004694 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004695 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004696 } catch (ImsException e) {
4697 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004698 } finally {
4699 Binder.restoreCallingIdentity(identity);
4700 }
4701 }
4702
4703 @Override
4704 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4705 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4706 "setVoWiFiRoamingModeSetting");
4707 final long identity = Binder.clearCallingIdentity();
4708 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004709 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004710 // This setting doesn't require an active ImsService connection, so do not verify. The
4711 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004712 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004713 } catch (ImsException e) {
4714 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004715 } finally {
4716 Binder.restoreCallingIdentity(identity);
4717 }
4718 }
4719
4720 @Override
4721 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4722 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4723 "setRttCapabilityEnabled");
4724 final long identity = Binder.clearCallingIdentity();
4725 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004726 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004727 // This setting doesn't require an active ImsService connection, so do not verify. The
4728 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004729 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004730 } catch (ImsException e) {
4731 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004732 } finally {
4733 Binder.restoreCallingIdentity(identity);
4734 }
4735 }
4736
shilu366312e2019-12-17 09:28:10 -08004737 /**
4738 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4739 * @param subId The subscription to use to check the configuration.
4740 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004741 @Override
4742 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004743 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004744 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004745 final long identity = Binder.clearCallingIdentity();
4746 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004747 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004748 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004749 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004750 } catch (ImsException e) {
4751 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004752 } finally {
4753 Binder.restoreCallingIdentity(identity);
4754 }
4755 }
4756
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004757 @Override
4758 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4759 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004760
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004761 final long identity = Binder.clearCallingIdentity();
4762 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004763 if (!isImsAvailableOnDevice()) {
4764 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4765 "IMS not available on device.");
4766 }
4767 int slotId = getSlotIndexOrException(subId);
4768 verifyImsMmTelConfiguredOrThrow(slotId);
4769 ImsManager.getInstance(mApp, slotId)
4770 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004771 } catch (ImsException e) {
4772 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004773 } finally {
4774 Binder.restoreCallingIdentity(identity);
4775 }
4776 }
4777
4778 @Override
4779 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4780 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004781
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004782 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004783 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4784 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4785 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004786 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004787 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004788 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004789 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004790 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4791 + "is inactive, ignoring unregister.");
4792 // If the subscription is no longer active, just return, since the callback will already
4793 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004794 } finally {
4795 Binder.restoreCallingIdentity(identity);
4796 }
4797 }
4798
joonhunshincffb7fc2021-11-28 07:32:01 +00004799 @Override
4800 public void registerFeatureProvisioningChangedCallback(int subId,
4801 IFeatureProvisioningCallback callback) {
4802 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4803 mApp, subId, "registerFeatureProvisioningChangedCallback");
4804
4805 final long identity = Binder.clearCallingIdentity();
4806 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4807 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4808 }
4809
joonhunshin91bc1952022-04-29 08:47:15 +00004810 try {
4811 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4812 if (controller == null) {
4813 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4814 "Device does not support IMS");
4815 }
4816 controller.addFeatureProvisioningChangedCallback(subId, callback);
4817 } finally {
4818 Binder.restoreCallingIdentity(identity);
4819 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004820 }
4821
4822 @Override
4823 public void unregisterFeatureProvisioningChangedCallback(int subId,
4824 IFeatureProvisioningCallback callback) {
4825 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4826 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4827
4828 final long identity = Binder.clearCallingIdentity();
4829 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4830 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4831 }
4832
joonhunshin91bc1952022-04-29 08:47:15 +00004833 try {
4834 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4835 if (controller == null) {
4836 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4837 return;
4838 }
4839 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4840 } finally {
4841 Binder.restoreCallingIdentity(identity);
4842 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004843 }
allenwtsu99c623b2020-01-03 18:24:23 +08004844
4845 private void checkModifyPhoneStatePermission(int subId, String message) {
4846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4847 message);
4848 }
4849
allenwtsu99c623b2020-01-03 18:24:23 +08004850 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004851 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004852 boolean isProvisioned) {
4853 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4854
4855 final long identity = Binder.clearCallingIdentity();
4856 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004857 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4858 if (controller == null) {
4859 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4860 return;
4861 }
4862 controller.setRcsProvisioningStatusForCapability(
4863 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004864 } finally {
4865 Binder.restoreCallingIdentity(identity);
4866 }
allenwtsu99c623b2020-01-03 18:24:23 +08004867 }
4868
4869
4870 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004871 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4872 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4873 mApp, subId, "getRcsProvisioningStatusForCapability");
4874
allenwtsu99c623b2020-01-03 18:24:23 +08004875 final long identity = Binder.clearCallingIdentity();
4876 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004877 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4878 if (controller == null) {
4879 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4880
4881 // device does not support IMS, this method will return true always.
4882 return true;
4883 }
4884 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004885 } finally {
4886 Binder.restoreCallingIdentity(identity);
4887 }
4888 }
4889
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004890 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004891 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4892 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004893 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004894
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004895 final long identity = Binder.clearCallingIdentity();
4896 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004897 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4898 if (controller == null) {
4899 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4900 return;
4901 }
4902 controller.setImsProvisioningStatusForCapability(
4903 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004904 } finally {
4905 Binder.restoreCallingIdentity(identity);
4906 }
4907 }
4908
4909 @Override
4910 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004911 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4912 mApp, subId, "getProvisioningStatusForCapability");
4913
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004914 final long identity = Binder.clearCallingIdentity();
4915 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004916 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4917 if (controller == null) {
4918 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004919
joonhunshin91bc1952022-04-29 08:47:15 +00004920 // device does not support IMS, this method will return true always.
4921 return true;
4922 }
4923 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004924 } finally {
4925 Binder.restoreCallingIdentity(identity);
4926 }
4927 }
4928
4929 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004930 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4931 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4932 mApp, subId, "isProvisioningRequiredForCapability");
4933
4934 final long identity = Binder.clearCallingIdentity();
4935 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004936 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4937 if (controller == null) {
4938 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4939
4940 // device does not support IMS, this method will return false
4941 return false;
4942 }
4943 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004944 } finally {
4945 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004946 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004947 }
4948
4949 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004950 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4951 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4952 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004953
joonhunshincffb7fc2021-11-28 07:32:01 +00004954 final long identity = Binder.clearCallingIdentity();
4955 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004956 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4957 if (controller == null) {
4958 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4959
4960 // device does not support IMS, this method will return false
4961 return false;
4962 }
4963 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004964 } finally {
4965 Binder.restoreCallingIdentity(identity);
4966 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004967 }
4968
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004969 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004970 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004971 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4972 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4973 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004974 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4975 mApp, subId, "getImsProvisioningInt");
4976
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004977 final long identity = Binder.clearCallingIdentity();
4978 try {
4979 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004980 int slotId = getSlotIndex(subId);
4981 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4982 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4983 + subId + "' for key:" + key);
4984 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4985 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004986
joonhunshin91bc1952022-04-29 08:47:15 +00004987 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4988 if (controller == null) {
4989 loge("getImsProvisioningInt: Device does not support IMS");
4990
4991 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4992 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4993 }
4994 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004995 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4996 return retVal;
4997 }
4998
calvinpanb5a34062021-02-08 19:59:36 +08004999 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005000 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005001 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5002 + subId + "' for key:" + key);
5003 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005004 } finally {
5005 Binder.restoreCallingIdentity(identity);
5006 }
5007 }
5008
5009 @Override
5010 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005011 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5012 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5013 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005014 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5015 mApp, subId, "getImsProvisioningString");
5016
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005017 final long identity = Binder.clearCallingIdentity();
5018 try {
5019 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005020 int slotId = getSlotIndex(subId);
5021 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5022 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5023 + subId + "' for key:" + key);
5024 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5025 }
calvinpanb5a34062021-02-08 19:59:36 +08005026 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005027 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005028 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5029 + subId + "' for key:" + key);
5030 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005031 } finally {
5032 Binder.restoreCallingIdentity(identity);
5033 }
5034 }
5035
5036 @Override
5037 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005038 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5039 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5040 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5042 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005043
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005044 final long identity = Binder.clearCallingIdentity();
5045 try {
5046 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005047 int slotId = getSlotIndex(subId);
5048 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5049 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5050 + subId + "' for key:" + key);
5051 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5052 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005053
joonhunshin91bc1952022-04-29 08:47:15 +00005054 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5055 if (controller == null) {
5056 loge("setImsProvisioningInt: Device does not support IMS");
5057
5058 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5059 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5060 }
5061 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005062 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5063 return retVal;
5064 }
5065
calvinpanb5a34062021-02-08 19:59:36 +08005066 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5067 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005068 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005069 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005070 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005071 } finally {
5072 Binder.restoreCallingIdentity(identity);
5073 }
5074 }
5075
5076 @Override
5077 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005078 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5079 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5080 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5082 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005083 final long identity = Binder.clearCallingIdentity();
5084 try {
5085 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005086 int slotId = getSlotIndex(subId);
5087 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5088 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5089 + subId + "' for key:" + key);
5090 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5091 }
calvinpanb5a34062021-02-08 19:59:36 +08005092 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5093 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005094 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005095 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005096 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005097 } finally {
5098 Binder.restoreCallingIdentity(identity);
5099 }
5100 }
5101
Brad Ebinger919631e2021-06-02 17:46:35 -07005102 /**
5103 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5104 * for the given slot ID or no ImsResolver instance has been created.
5105 * @param slotId The slot ID that the IMS service is created for.
5106 * @throws ImsException If there is no ImsService configured for this slot.
5107 */
5108 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5109 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5110 ImsFeature.FEATURE_MMTEL)) {
5111 throw new ImsException("This subscription does not support MMTEL over IMS",
5112 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5113 }
5114 }
5115
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005116 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005117 int slotId = SubscriptionManager.getSlotIndex(subId);
5118 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005119 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5120 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005121 }
5122 return slotId;
5123 }
5124
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005125 private int getSlotIndex(int subId) {
5126 int slotId = SubscriptionManager.getSlotIndex(subId);
5127 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5128 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5129 }
5130 return slotId;
5131 }
5132
Wink Saville36469e72014-06-11 15:17:00 -07005133 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005134 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005135 */
5136 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005137 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5138 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005139 try {
5140 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5141 } catch (SecurityException se) {
5142 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5143 throw new SecurityException("Package " + callingPackage + " does not belong to "
5144 + Binder.getCallingUid());
5145 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005146 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005147 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005148 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005149 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005150 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005151 mApp, subId, callingPackage, callingFeatureId,
5152 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005153 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5154 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005155
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005156 final long identity = Binder.clearCallingIdentity();
5157 try {
5158 final Phone phone = getPhone(subId);
5159 if (phone != null) {
5160 return phone.getServiceState().getDataNetworkType();
5161 } else {
5162 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5163 }
5164 } finally {
5165 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005166 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005167 }
5168
5169 /**
5170 * Returns the data network type
5171 */
5172 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005173 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005174 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5175 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005176 }
5177
5178 /**
5179 * Returns the data network type for a subId
5180 */
5181 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005182 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5183 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005184 String functionName = "getDataNetworkTypeForSubscriber";
5185 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5186 mApp, functionName)) {
5187 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5188 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5189 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5190 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005191 }
5192
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005193 final long identity = Binder.clearCallingIdentity();
5194 try {
5195 final Phone phone = getPhone(subId);
5196 if (phone != null) {
5197 return phone.getServiceState().getDataNetworkType();
5198 } else {
5199 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5200 }
5201 } finally {
5202 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005203 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005204 }
5205
5206 /**
Wink Saville36469e72014-06-11 15:17:00 -07005207 * Returns the Voice network type for a subId
5208 */
5209 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005210 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5211 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005212 String functionName = "getVoiceNetworkTypeForSubscriber";
5213 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5214 mApp, functionName)) {
5215 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5216 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5217 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5218 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005219 }
5220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005221 final long identity = Binder.clearCallingIdentity();
5222 try {
5223 final Phone phone = getPhone(subId);
5224 if (phone != null) {
5225 return phone.getServiceState().getVoiceNetworkType();
5226 } else {
5227 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5228 }
5229 } finally {
5230 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005231 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005232 }
5233
5234 /**
5235 * @return true if a ICC card is present
5236 */
5237 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005238 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005239 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5240 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005241 }
5242
5243 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005244 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005245 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005246 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005247 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005248 final long identity = Binder.clearCallingIdentity();
5249 try {
5250 final Phone phone = PhoneFactory.getPhone(slotIndex);
5251 if (phone != null) {
5252 return phone.getIccCard().hasIccCard();
5253 } else {
5254 return false;
5255 }
5256 } finally {
5257 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005259 }
5260
5261 /**
5262 * Return if the current radio is LTE on CDMA. This
5263 * is a tri-state return value as for a period of time
5264 * the mode may be unknown.
5265 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005266 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005267 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005268 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005269 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005270 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005271 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5272 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5273 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005274 }
5275
Sanket Padawe356d7632015-06-22 14:03:32 -07005276 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005277 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5278 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005279 try {
5280 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5281 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005282 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5283 }
5284
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005285 final long identity = Binder.clearCallingIdentity();
5286 try {
5287 final Phone phone = getPhone(subId);
5288 if (phone == null) {
5289 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5290 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005291 return TelephonyProperties.lte_on_cdma_device()
5292 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005293 }
5294 } finally {
5295 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005296 }
Wink Saville36469e72014-06-11 15:17:00 -07005297 }
5298
Wink Saville36469e72014-06-11 15:17:00 -07005299 /**
5300 * {@hide}
5301 * Returns Default subId, 0 in the case of single standby.
5302 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005303 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005304 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005305 }
5306
Shishir Agrawala9f32182016-04-12 12:00:16 -07005307 private int getSlotForDefaultSubscription() {
5308 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5309 }
5310
Wink Savilleb564aae2014-10-23 10:18:09 -07005311 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005312 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005313 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005314
Pengquan Menge92a50d2018-09-21 15:54:48 -07005315 private boolean isActiveSubscription(int subId) {
5316 return mSubscriptionController.isActiveSubId(subId);
5317 }
5318
Ihab Awadf2177b72013-11-25 13:33:23 -08005319 /**
5320 * @see android.telephony.TelephonyManager.WifiCallingChoices
5321 */
5322 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005323 final long identity = Binder.clearCallingIdentity();
5324 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005325 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5327 getWhenToMakeWifiCallsDefaultPreference());
5328 } finally {
5329 Binder.restoreCallingIdentity(identity);
5330 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005331 }
5332
5333 /**
5334 * @see android.telephony.TelephonyManager.WifiCallingChoices
5335 */
5336 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005337 final long identity = Binder.clearCallingIdentity();
5338 try {
5339 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005340 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005341 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5342 } finally {
5343 Binder.restoreCallingIdentity(identity);
5344 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005345 }
5346
Sailesh Nepald1e68152013-12-12 19:08:02 -08005347 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005348 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005349 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005350 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005351
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005352 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5353 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5354 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005355 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005356 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5357 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005358 }
5359 return PhoneFactory.getPhone(phoneId);
5360 }
5361
Shishir Agrawal566b7612013-10-28 14:41:00 -07005362 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005363 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005364 @NonNull IccLogicalChannelRequest request) {
5365 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5366 /*message=*/ "iccOpenLogicalChannel");
5367
5368 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5369 // Verify that the callingPackage in the request belongs to the calling UID
5370 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5371
5372 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005373 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005374
Rambo Wanga1782702021-11-10 20:15:19 -08005375 private Phone getPhoneFromValidIccLogicalChannelRequest(
5376 @NonNull IccLogicalChannelRequest request, String message) {
5377 Phone phone;
5378 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5380 mApp, request.subId, message);
5381 phone = getPhoneFromSubId(request.subId);
5382 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5383 enforceModifyPermission();
5384 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5385 } else {
5386 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005387 }
Rambo Wanga1782702021-11-10 20:15:19 -08005388 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005389 }
5390
5391 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005392 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393 final long identity = Binder.clearCallingIdentity();
5394 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005395 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005397 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5398 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005399 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5400 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005401 loge("The calling package is not allowed to access ISD-R.");
5402 throw new SecurityException(
5403 "The calling package is not allowed to access ISD-R.");
5404 }
Derek Tan740e1672017-06-27 14:56:27 -07005405 }
Derek Tan740e1672017-06-27 14:56:27 -07005406
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005407 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005408 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5409 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 return response;
5411 } finally {
5412 Binder.restoreCallingIdentity(identity);
5413 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005414 }
5415
5416 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005417 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5418 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5419 /*message=*/"iccCloseLogicalChannel");
5420
5421 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5422
5423 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005424 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005425
Rambo Wanga1782702021-11-10 20:15:19 -08005426 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5427 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005428 // before this feature is enabled, this API should only return false if
5429 // the operation fails instead of throwing runtime exception for
5430 // backward-compatibility.
5431 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5432 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005433 final long identity = Binder.clearCallingIdentity();
5434 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005435 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005436 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005437 }
Chen Xue9d737e2022-01-01 23:41:31 -08005438 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005439 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005440 Boolean success = false;
5441 if (result instanceof RuntimeException) {
5442 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005443 if (shouldThrowExceptionOnFailure) {
5444 throw (RuntimeException) result;
5445 } else {
5446 return false;
5447 }
Chen Xue9d737e2022-01-01 23:41:31 -08005448 } else if (result instanceof Boolean) {
5449 success = (Boolean) result;
5450 } else {
5451 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5452 }
Rambo Wanga1782702021-11-10 20:15:19 -08005453 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005454 return success;
5455 } finally {
5456 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005457 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005458 }
5459
5460 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005461 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005462 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005463 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5464 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005465 if (DBG) {
5466 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5467 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5468 + p3 + " data=" + data);
5469 }
5470 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5471 command, p1, p2, p3, data);
5472 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005473
Jordan Liu4c733742019-02-28 12:03:40 -08005474 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005475 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5476 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005477 enforceModifyPermission();
5478 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005479 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5480 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5481 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005482 }
5483 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005484 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5485 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005486 }
5487
5488 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5489 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005490 final long identity = Binder.clearCallingIdentity();
5491 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005492 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005493 return "";
5494 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005495
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005496 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005497 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5498 null /* workSource */);
5499 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005500
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005501 // Append the returned status code to the end of the response payload.
5502 String s = Integer.toHexString(
5503 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5504 if (response.payload != null) {
5505 s = IccUtils.bytesToHexString(response.payload) + s;
5506 }
5507 return s;
5508 } finally {
5509 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005510 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005511 }
Jake Hambye994d462014-02-03 13:10:13 -08005512
Evan Charltonc66da362014-05-16 14:06:40 -07005513 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005514 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5515 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005516 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5517 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005518 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005519 if (DBG) {
5520 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5521 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5522 }
5523 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5524 cla, command, p1, p2, p3, data);
5525 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005526
Jordan Liu4c733742019-02-28 12:03:40 -08005527 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005528 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5529 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005530 enforceModifyPermission();
5531 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5532 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005533 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5534 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5535 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005536 }
5537
5538 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005539 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5540 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005541 }
5542
5543 // open APDU basic channel assuming the caller has sufficient permissions
5544 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5545 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005546 final long identity = Binder.clearCallingIdentity();
5547 try {
5548 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5549 && TextUtils.equals(ISDR_AID, data)) {
5550 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005551 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5552 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005553 if (bestComponent == null
5554 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5555 loge("The calling package is not allowed to select ISD-R.");
5556 throw new SecurityException(
5557 "The calling package is not allowed to select ISD-R.");
5558 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005559 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005560
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005561 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005562 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5563 null /* workSource */);
5564 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005565
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005566 // Append the returned status code to the end of the response payload.
5567 String s = Integer.toHexString(
5568 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5569 if (response.payload != null) {
5570 s = IccUtils.bytesToHexString(response.payload) + s;
5571 }
5572 return s;
5573 } finally {
5574 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005575 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005576 }
5577
5578 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005579 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005580 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005581 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5582 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005583
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005584 final long identity = Binder.clearCallingIdentity();
5585 try {
5586 if (DBG) {
5587 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5588 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5589 }
5590
5591 IccIoResult response =
5592 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5593 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5594 subId);
5595
5596 if (DBG) {
5597 log("Exchange SIM_IO [R]" + response);
5598 }
5599
5600 byte[] result = null;
5601 int length = 2;
5602 if (response.payload != null) {
5603 length = 2 + response.payload.length;
5604 result = new byte[length];
5605 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5606 } else {
5607 result = new byte[length];
5608 }
5609
5610 result[length - 1] = (byte) response.sw2;
5611 result[length - 2] = (byte) response.sw1;
5612 return result;
5613 } finally {
5614 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005615 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005616 }
5617
Nathan Haroldb3014052017-01-25 15:57:32 -08005618 /**
5619 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5620 * on a particular subscription
5621 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005622 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5623 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005624 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005625 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005626 return null;
5627 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005628
5629 final long identity = Binder.clearCallingIdentity();
5630 try {
5631 if (appType != TelephonyManager.APPTYPE_USIM
5632 && appType != TelephonyManager.APPTYPE_SIM) {
5633 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5634 return null;
5635 }
5636 Object response = sendRequest(
5637 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5638 if (response instanceof String[]) {
5639 return (String[]) response;
5640 }
yincheng zhao2737e882019-09-06 17:06:54 -07005641 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005643 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005644 } finally {
5645 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005646 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005647 }
5648
yincheng zhao2737e882019-09-06 17:06:54 -07005649 /**
5650 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5651 * subscription.
5652 *
5653 * @param subId the id of the subscription.
5654 * @param appType the uicc app type, must be USIM or SIM.
5655 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5656 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005657 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005658 * @return number of fplmns that is successfully written to the SIM.
5659 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005660 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5661 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5663 mApp, subId, "setForbiddenPlmns");
5664
yincheng zhao2737e882019-09-06 17:06:54 -07005665 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5666 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5667 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5668 }
5669 if (fplmns == null) {
5670 throw new IllegalArgumentException("Fplmn List provided is null");
5671 }
5672 for (String fplmn : fplmns) {
5673 if (!CellIdentity.isValidPlmn(fplmn)) {
5674 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5675 }
5676 }
5677 final long identity = Binder.clearCallingIdentity();
5678 try {
5679 Object response = sendRequest(
5680 CMD_SET_FORBIDDEN_PLMNS,
5681 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5682 subId);
5683 return (int) response;
5684 } finally {
5685 Binder.restoreCallingIdentity(identity);
5686 }
5687 }
5688
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005689 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005690 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005691 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5692 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 final long identity = Binder.clearCallingIdentity();
5695 try {
5696 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5697 if (response.payload == null) {
5698 return "";
5699 }
Evan Charltonc66da362014-05-16 14:06:40 -07005700
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005701 // Append the returned status code to the end of the response payload.
5702 String s = Integer.toHexString(
5703 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5704 s = IccUtils.bytesToHexString(response.payload) + s;
5705 return s;
5706 } finally {
5707 Binder.restoreCallingIdentity(identity);
5708 }
Evan Charltonc66da362014-05-16 14:06:40 -07005709 }
5710
Jake Hambye994d462014-02-03 13:10:13 -08005711 /**
5712 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5713 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5714 *
5715 * @param itemID the ID of the item to read
5716 * @return the NV item as a String, or null on error.
5717 */
5718 @Override
5719 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005720 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005721 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5722 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005723
5724 final long identity = Binder.clearCallingIdentity();
5725 try {
5726 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005727 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005728 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5729 return value;
5730 } finally {
5731 Binder.restoreCallingIdentity(identity);
5732 }
Jake Hambye994d462014-02-03 13:10:13 -08005733 }
5734
5735 /**
5736 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5737 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5738 *
5739 * @param itemID the ID of the item to read
5740 * @param itemValue the value to write, as a String
5741 * @return true on success; false on any failure
5742 */
5743 @Override
5744 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005745 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005746 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5747 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005748
5749 final long identity = Binder.clearCallingIdentity();
5750 try {
5751 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5752 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005753 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5755 return success;
5756 } finally {
5757 Binder.restoreCallingIdentity(identity);
5758 }
Jake Hambye994d462014-02-03 13:10:13 -08005759 }
5760
5761 /**
5762 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5763 * Used for device configuration by some CDMA operators.
5764 *
5765 * @param preferredRoamingList byte array containing the new PRL
5766 * @return true on success; false on any failure
5767 */
5768 @Override
5769 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5771 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005772
5773 final long identity = Binder.clearCallingIdentity();
5774 try {
5775 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5776 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5777 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5778 return success;
5779 } finally {
5780 Binder.restoreCallingIdentity(identity);
5781 }
Jake Hambye994d462014-02-03 13:10:13 -08005782 }
5783
5784 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005785 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005786 * Used for device configuration by some CDMA operators.
5787 *
chen xu6dac5ab2018-10-26 17:39:23 -07005788 * @param slotIndex - device slot.
5789 *
Jake Hambye994d462014-02-03 13:10:13 -08005790 * @return true on success; false on any failure
5791 */
5792 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005793 public boolean resetModemConfig(int slotIndex) {
5794 Phone phone = PhoneFactory.getPhone(slotIndex);
5795 if (phone != null) {
5796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5797 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005798
chen xu6dac5ab2018-10-26 17:39:23 -07005799 final long identity = Binder.clearCallingIdentity();
5800 try {
5801 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5802 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5803 return success;
5804 } finally {
5805 Binder.restoreCallingIdentity(identity);
5806 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005807 }
chen xu6dac5ab2018-10-26 17:39:23 -07005808 return false;
5809 }
5810
5811 /**
5812 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5813 *
5814 * @param slotIndex - device slot.
5815 *
5816 * @return true on success; false on any failure
5817 */
5818 @Override
5819 public boolean rebootModem(int slotIndex) {
5820 Phone phone = PhoneFactory.getPhone(slotIndex);
5821 if (phone != null) {
5822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5823 mApp, phone.getSubId(), "rebootModem");
5824
5825 final long identity = Binder.clearCallingIdentity();
5826 try {
5827 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5828 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5829 return success;
5830 } finally {
5831 Binder.restoreCallingIdentity(identity);
5832 }
5833 }
5834 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005835 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005836
Brad Ebinger51f743a2017-01-23 13:50:20 -08005837 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005838 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5839 * {@link #disableIms(int)}.
5840 * @param slotIndex device slot.
5841 */
5842 public void resetIms(int slotIndex) {
5843 enforceModifyPermission();
5844
5845 final long identity = Binder.clearCallingIdentity();
5846 try {
5847 if (mImsResolver == null) {
5848 // may happen if the does not support IMS.
5849 return;
5850 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00005851 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005852 } finally {
5853 Binder.restoreCallingIdentity(identity);
5854 }
5855 }
5856
5857 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005858 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5859 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005860 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005861 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005862 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005863
5864 final long identity = Binder.clearCallingIdentity();
5865 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005866 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005867 // may happen if the device does not support IMS.
5868 return;
5869 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005870 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005871 } finally {
5872 Binder.restoreCallingIdentity(identity);
5873 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005874 }
5875
5876 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005877 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5878 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005879 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005880 public void disableIms(int slotId) {
5881 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882
5883 final long identity = Binder.clearCallingIdentity();
5884 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005885 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005886 // may happen if the device does not support IMS.
5887 return;
5888 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005889 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005890 } finally {
5891 Binder.restoreCallingIdentity(identity);
5892 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005893 }
5894
5895 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005896 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5897 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005898 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005899 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005900 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005901 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005902
5903 final long identity = Binder.clearCallingIdentity();
5904 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005905 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005906 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5907 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005908 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005909 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005910 } finally {
5911 Binder.restoreCallingIdentity(identity);
5912 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005913 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005914 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005915 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5916 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005917 @Override
5918 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005919 enforceModifyPermission();
5920
5921 final long identity = Binder.clearCallingIdentity();
5922 try {
5923 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005924 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005925 } finally {
5926 Binder.restoreCallingIdentity(identity);
5927 }
5928 }
5929
5930 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005931 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005932 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005933 */
5934 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5935 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005936
5937 final long identity = Binder.clearCallingIdentity();
5938 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005939 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005940 // may happen if the device does not support IMS.
5941 return null;
5942 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005943 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005944 } finally {
5945 Binder.restoreCallingIdentity(identity);
5946 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005947 }
5948
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005949 /**
5950 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005951 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005952 */
5953 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5954 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005955
5956 final long identity = Binder.clearCallingIdentity();
5957 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005958 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005959 // may happen if the device does not support IMS.
5960 return null;
5961 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005962 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005963 } finally {
5964 Binder.restoreCallingIdentity(identity);
5965 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005966 }
5967
Brad Ebinger884c07b2018-02-15 16:17:40 -08005968 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005969 * Sets the ImsService Package Name that Telephony will bind to.
5970 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005971 * @param slotIndex the slot ID that the ImsService should bind for.
5972 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005973 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005974 * @param featureTypes An integer array of feature types associated with a packageName.
5975 * @param packageName The name of the package that the current configuration will be replaced
5976 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005977 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005978 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005979 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5980 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08005981 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08005983 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005984
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985 final long identity = Binder.clearCallingIdentity();
5986 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005987 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005988 // may happen if the device does not support IMS.
5989 return false;
5990 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005991 Map<Integer, String> featureConfig = new HashMap<>();
5992 for (int featureType : featureTypes) {
5993 featureConfig.put(featureType, packageName);
5994 }
5995 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5996 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997 } finally {
5998 Binder.restoreCallingIdentity(identity);
5999 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006000 }
6001
6002 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006003 * Clears any carrier ImsService overrides for the slot index specified that were previously
6004 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6005 *
6006 * This should only be used for testing.
6007 *
6008 * @param slotIndex the slot ID that the ImsService should bind for.
6009 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6010 */
6011 @Override
6012 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006013 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6014 "clearCarrierImsServiceOverride");
6015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006016 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006017
6018 final long identity = Binder.clearCallingIdentity();
6019 try {
6020 if (mImsResolver == null) {
6021 // may happen if the device does not support IMS.
6022 return false;
6023 }
6024 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6025 } finally {
6026 Binder.restoreCallingIdentity(identity);
6027 }
6028 }
6029
6030 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006031 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006032 *
6033 * @param slotId The slot that the ImsService is associated with.
6034 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6035 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006036 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006037 * @return the package name of the ImsService configuration.
6038 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006039 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6040 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006041 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006042 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6043 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006044
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006045 final long identity = Binder.clearCallingIdentity();
6046 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006047 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006048 // may happen if the device does not support IMS.
6049 return "";
6050 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006051 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006052 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6053 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006054 } finally {
6055 Binder.restoreCallingIdentity(identity);
6056 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006057 }
6058
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006059 /**
6060 * Get the MmTelFeature state associated with the requested subscription id.
6061 * @param subId The subscription that the MmTelFeature is associated with.
6062 * @param callback A callback with an integer containing the
6063 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6064 */
6065 @Override
6066 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6067 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006068 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6069 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6070 "IMS not available on device.");
6071 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006072 final long token = Binder.clearCallingIdentity();
6073 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006074 int slotId = getSlotIndex(subId);
6075 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6076 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6077 + subId + "'");
6078 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6079 }
6080 verifyImsMmTelConfiguredOrThrow(slotId);
6081 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6082 try {
6083 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6084 } catch (RemoteException e) {
6085 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6086 + "Ignore");
6087 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006088 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006089 } catch (ImsException e) {
6090 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006091 } finally {
6092 Binder.restoreCallingIdentity(token);
6093 }
6094 }
6095
Daniel Brightbb5840b2021-01-12 15:48:18 -08006096 /**
6097 * Sets the ims registration state on all valid {@link Phone}s.
6098 */
6099 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006100 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006101
6102 final long identity = Binder.clearCallingIdentity();
6103 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006104 // NOTE: Before S, this method only set the default phone.
6105 for (final Phone phone : PhoneFactory.getPhones()) {
6106 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6107 phone.setImsRegistrationState(registered);
6108 }
6109 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006110 } finally {
6111 Binder.restoreCallingIdentity(identity);
6112 }
Wink Saville36469e72014-06-11 15:17:00 -07006113 }
6114
6115 /**
Stuart Scott54788802015-03-30 13:18:01 -07006116 * Set the network selection mode to automatic.
6117 *
6118 */
6119 @Override
6120 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6122 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006123
6124 final long identity = Binder.clearCallingIdentity();
6125 try {
shilufc958392020-01-20 11:36:01 -08006126 if (!isActiveSubscription(subId)) {
6127 return;
6128 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006129 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006130 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6131 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132 } finally {
6133 Binder.restoreCallingIdentity(identity);
6134 }
Stuart Scott54788802015-03-30 13:18:01 -07006135 }
6136
Jack Yud10cdd42020-09-28 20:28:01 -07006137 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006138 * Ask the radio to connect to the input network and change selection mode to manual.
6139 *
6140 * @param subId the id of the subscription.
6141 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6142 * the operator to attach to.
6143 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6144 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6145 * normal network selection next time.
6146 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006147 */
6148 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006149 public boolean setNetworkSelectionModeManual(
6150 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6152 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006153
6154 if (!isActiveSubscription(subId)) {
6155 return false;
6156 }
6157
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158 final long identity = Binder.clearCallingIdentity();
6159 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006160 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006161 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006162 if (DBG) {
6163 log("setNetworkSelectionModeManual: subId: " + subId
6164 + " operator: " + operatorInfo);
6165 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006166 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6167 } finally {
6168 Binder.restoreCallingIdentity(identity);
6169 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006170 }
shilu84f6e8b2019-12-19 13:58:01 -08006171 /**
6172 * Get the manual network selection
6173 *
6174 * @param subId the id of the subscription.
6175 *
6176 * @return the previously saved user selected PLMN
6177 */
6178 @Override
6179 public String getManualNetworkSelectionPlmn(int subId) {
6180 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006181 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006182 mApp, subId, "getManualNetworkSelectionPlmn");
6183
6184 final long identity = Binder.clearCallingIdentity();
6185 try {
6186 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006187 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006188 }
6189
6190 final Phone phone = getPhone(subId);
6191 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006192 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006193 }
6194 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6195 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6196 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6197 } finally {
6198 Binder.restoreCallingIdentity(identity);
6199 }
6200 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006201
6202 /**
6203 * Scans for available networks.
6204 */
6205 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006206 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6207 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6209 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006210 LocationAccessPolicy.LocationPermissionResult locationResult =
6211 LocationAccessPolicy.checkLocationPermission(mApp,
6212 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6213 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006214 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006215 .setCallingPid(Binder.getCallingPid())
6216 .setCallingUid(Binder.getCallingUid())
6217 .setMethod("getCellNetworkScanResults")
6218 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006219 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6220 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006221 .build());
6222 switch (locationResult) {
6223 case DENIED_HARD:
6224 throw new SecurityException("Not allowed to access scan results -- location");
6225 case DENIED_SOFT:
6226 return null;
6227 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006228
Pengquan Menga1bb6272018-09-06 09:59:22 -07006229 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006230 try {
6231 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006232 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006233 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006234 } finally {
6235 Binder.restoreCallingIdentity(identity);
6236 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006237 }
6238
6239 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006240 * Get the call forwarding info, given the call forwarding reason.
6241 */
6242 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006243 public void getCallForwarding(int subId, int callForwardingReason,
6244 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006245 enforceReadPrivilegedPermission("getCallForwarding");
6246 long identity = Binder.clearCallingIdentity();
6247 try {
6248 if (DBG) {
6249 log("getCallForwarding: subId " + subId
6250 + " callForwardingReason" + callForwardingReason);
6251 }
Hall Liu27d24262020-09-18 19:04:59 -07006252
6253 Phone phone = getPhone(subId);
6254 if (phone == null) {
6255 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006256 callback.onError(
6257 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006258 } catch (RemoteException e) {
6259 // ignore
6260 }
6261 return;
6262 }
6263
6264 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6265 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6266 @Override
6267 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6268 try {
6269 callback.onCallForwardingInfoAvailable(info);
6270 } catch (RemoteException e) {
6271 // ignore
6272 }
6273 }
6274
6275 @Override
6276 public void onError(int error) {
6277 try {
6278 callback.onError(error);
6279 } catch (RemoteException e) {
6280 // ignore
6281 }
6282 }
6283 });
6284 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006285 } finally {
6286 Binder.restoreCallingIdentity(identity);
6287 }
6288 }
6289
6290 /**
6291 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6292 * reason, the number to forward, and the timeout before the forwarding is attempted.
6293 */
6294 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006295 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6296 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006297 enforceModifyPermission();
6298 long identity = Binder.clearCallingIdentity();
6299 try {
6300 if (DBG) {
6301 log("setCallForwarding: subId " + subId
6302 + " callForwardingInfo" + callForwardingInfo);
6303 }
Hall Liu27d24262020-09-18 19:04:59 -07006304
6305 Phone phone = getPhone(subId);
6306 if (phone == null) {
6307 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006308 callback.accept(
6309 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006310 } catch (RemoteException e) {
6311 // ignore
6312 }
6313 return;
6314 }
6315
6316 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6317 FunctionalUtils.ignoreRemoteException(callback::accept));
6318
6319 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006320 } finally {
6321 Binder.restoreCallingIdentity(identity);
6322 }
6323 }
6324
6325 /**
Hall Liu27d24262020-09-18 19:04:59 -07006326 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006327 */
6328 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006329 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006330 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006331 long identity = Binder.clearCallingIdentity();
6332 try {
Hall Liu27d24262020-09-18 19:04:59 -07006333 Phone phone = getPhone(subId);
6334 if (phone == null) {
6335 try {
6336 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6337 } catch (RemoteException e) {
6338 // ignore
6339 }
6340 return;
6341 }
SongFerngWang0e767992021-03-31 22:08:45 +08006342 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6343 PersistableBundle c = configManager.getConfigForSubId(subId);
6344 boolean requireUssd = c.getBoolean(
6345 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006346
Shuo Qian4a594052020-01-23 11:59:30 -08006347 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006348 if (requireUssd) {
6349 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6350 getSubscriptionCarrierId(subId));
6351 String newUssdCommand = "";
6352 try {
6353 newUssdCommand = carrierXmlParser.getFeature(
6354 CarrierXmlParser.FEATURE_CALL_WAITING)
6355 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6356 } catch (NullPointerException e) {
6357 loge("Failed to generate USSD number" + e);
6358 }
6359 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6360 mMainThreadHandler, callback, carrierXmlParser,
6361 CarrierXmlParser.SsEntry.SSAction.QUERY);
6362 final String ussdCommand = newUssdCommand;
6363 Executors.newSingleThreadExecutor().execute(() -> {
6364 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6365 });
6366 } else {
6367 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6368 callback::accept);
6369 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6370 }
Shuo Qian4a594052020-01-23 11:59:30 -08006371 } finally {
6372 Binder.restoreCallingIdentity(identity);
6373 }
6374 }
6375
6376 /**
Hall Liu27d24262020-09-18 19:04:59 -07006377 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006378 */
6379 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006380 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006381 enforceModifyPermission();
6382 long identity = Binder.clearCallingIdentity();
6383 try {
Hall Liu27d24262020-09-18 19:04:59 -07006384 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6385
6386 Phone phone = getPhone(subId);
6387 if (phone == null) {
6388 try {
6389 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6390 } catch (RemoteException e) {
6391 // ignore
6392 }
6393 return;
6394 }
6395
SongFerngWang0e767992021-03-31 22:08:45 +08006396 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6397 PersistableBundle c = configManager.getConfigForSubId(subId);
6398 boolean requireUssd = c.getBoolean(
6399 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006400
SongFerngWang0e767992021-03-31 22:08:45 +08006401 if (DBG) log("getCallWaitingStatus: subId " + subId);
6402 if (requireUssd) {
6403 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6404 getSubscriptionCarrierId(subId));
6405 CarrierXmlParser.SsEntry.SSAction ssAction =
6406 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6407 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6408 String newUssdCommand = "";
6409 try {
6410 newUssdCommand = carrierXmlParser.getFeature(
6411 CarrierXmlParser.FEATURE_CALL_WAITING)
6412 .makeCommand(ssAction, null);
6413 } catch (NullPointerException e) {
6414 loge("Failed to generate USSD number" + e);
6415 }
6416 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6417 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6418 final String ussdCommand = newUssdCommand;
6419 Executors.newSingleThreadExecutor().execute(() -> {
6420 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6421 });
6422 } else {
6423 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6424 FunctionalUtils.ignoreRemoteException(callback::accept));
6425
6426 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6427 }
Shuo Qian4a594052020-01-23 11:59:30 -08006428 } finally {
6429 Binder.restoreCallingIdentity(identity);
6430 }
6431 }
6432
6433 /**
yinxub1bed742017-04-17 11:45:04 -07006434 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006435 *
yinxub1bed742017-04-17 11:45:04 -07006436 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006437 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6438 * location related information which will be sent if the caller already possess
6439 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006440 * @param request contains the radio access networks with bands/channels to scan
6441 * @param messenger callback messenger for scan results or errors
6442 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006443 * @return the id of the requested scan which can be used to stop the scan.
6444 */
6445 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006446 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6447 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006448 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006449 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6450 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006451 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006452 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6453 if (!renounceFineLocationAccess) {
6454 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6455 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6456 .setCallingPackage(callingPackage)
6457 .setCallingFeatureId(callingFeatureId)
6458 .setCallingPid(Binder.getCallingPid())
6459 .setCallingUid(Binder.getCallingUid())
6460 .setMethod("requestNetworkScan")
6461 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6462 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6463 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6464 .build());
6465 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006466 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006467 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6468 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006469 if (e != null) {
6470 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6471 throw e;
6472 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006473 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006474 return TelephonyScanManager.INVALID_SCAN_ID;
6475 }
6476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006477 }
Hall Liu912dfd32019-04-25 14:02:26 -07006478 int callingUid = Binder.getCallingUid();
6479 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006480 final long identity = Binder.clearCallingIdentity();
6481 try {
6482 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006483 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006484 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006485 } finally {
6486 Binder.restoreCallingIdentity(identity);
6487 }
yinxu504e1392017-04-12 16:03:22 -07006488 }
6489
Hall Liub2ac8ef2019-02-28 15:56:23 -08006490 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006491 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006492 boolean hasCarrierPriv;
6493 final long identity = Binder.clearCallingIdentity();
6494 try {
6495 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6496 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6497 } finally {
6498 Binder.restoreCallingIdentity(identity);
6499 }
Hall Liu558027f2019-05-15 19:14:05 -07006500 boolean hasNetworkScanPermission =
6501 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6502 == PERMISSION_GRANTED;
6503
6504 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6505 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6506 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006507 }
6508
6509 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6510 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006511 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6512 return new SecurityException("Specific channels must not be"
6513 + " scanned without location access.");
6514 }
6515 }
6516 }
6517
Hall Liub2ac8ef2019-02-28 15:56:23 -08006518 return null;
6519 }
6520
yinxu504e1392017-04-12 16:03:22 -07006521 /**
6522 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006523 *
6524 * @param subId id of the subscription
6525 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006526 */
6527 @Override
6528 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6530 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006531
Hall Liu912dfd32019-04-25 14:02:26 -07006532 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006533 final long identity = Binder.clearCallingIdentity();
6534 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006535 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006536 } finally {
6537 Binder.restoreCallingIdentity(identity);
6538 }
yinxu504e1392017-04-12 16:03:22 -07006539 }
6540
6541 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006542 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006543 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006544 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006545 */
6546 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006547 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006548 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006549 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006550 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006551
6552 final long identity = Binder.clearCallingIdentity();
6553 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006554 if (DBG) log("getAllowedNetworkTypesBitmask");
6555 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6556 int networkTypesBitmask = (result != null ? result[0] : -1);
6557 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6558 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006559 } finally {
6560 Binder.restoreCallingIdentity(identity);
6561 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006562 }
6563
6564 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006565 * Get the allowed network types for certain reason.
6566 *
6567 * @param subId the id of the subscription.
6568 * @param reason the reason the allowed network type change is taking place
6569 * @return the allowed network types.
6570 */
6571 @Override
6572 public long getAllowedNetworkTypesForReason(int subId,
6573 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006574 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006575 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006576 final long identity = Binder.clearCallingIdentity();
6577 try {
6578 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6579 } finally {
6580 Binder.restoreCallingIdentity(identity);
6581 }
6582 }
6583
6584 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006585 * Enable/Disable E-UTRA-NR Dual Connectivity
6586 * @param subId subscription id of the sim card
6587 * @param nrDualConnectivityState expected NR dual connectivity state
6588 * This can be passed following states
6589 * <ol>
6590 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6591 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6592 * <li>Disable NR dual connectivity and force secondary cell to be released
6593 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6594 * </ol>
6595 * @return operation result.
6596 */
6597 @Override
6598 public int setNrDualConnectivityState(int subId,
6599 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6600 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6601 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006602 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006603 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6604 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6605 }
6606
Sooraj Sasindran37444802020-08-11 10:40:43 -07006607 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6608 final long identity = Binder.clearCallingIdentity();
6609 try {
6610 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6611 nrDualConnectivityState, subId,
6612 workSource);
6613 if (DBG) log("enableNRDualConnectivity result: " + result);
6614 return result;
6615 } finally {
6616 Binder.restoreCallingIdentity(identity);
6617 }
6618 }
6619
6620 /**
6621 * Is E-UTRA-NR Dual Connectivity enabled
6622 * @return true if dual connectivity is enabled else false
6623 */
6624 @Override
6625 public boolean isNrDualConnectivityEnabled(int subId) {
6626 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006627 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006628 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006629 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006630 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6631 return false;
6632 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006633 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6634 final long identity = Binder.clearCallingIdentity();
6635 try {
6636 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6637 null, subId, workSource);
6638 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6639 return isEnabled;
6640 } finally {
6641 Binder.restoreCallingIdentity(identity);
6642 }
6643 }
6644
6645 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006646 * Set the allowed network types of the device and
6647 * provide the reason triggering the allowed network change.
6648 *
6649 * @param subId the id of the subscription.
6650 * @param reason the reason the allowed network type change is taking place
6651 * @param allowedNetworkTypes the allowed network types.
6652 * @return true on success; false on any failure.
6653 */
6654 @Override
6655 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006656 @TelephonyManager.AllowedNetworkTypesReason int reason,
6657 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006658 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6659 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006660 // If the caller only has carrier privileges, then they should not be able to override
6661 // any network types which were set for security reasons.
6662 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6663 != PERMISSION_GRANTED
6664 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6665 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6666 throw new SecurityException(
6667 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6668 + " reason "
6669 + reason);
6670 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006671 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006672 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6673 return false;
6674 }
6675 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6676 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006677 return false;
6678 }
6679
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006680 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6681 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6682
6683
6684 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6685 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6686 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006687 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006688
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006689 final long identity = Binder.clearCallingIdentity();
6690 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006691 Boolean success = (Boolean) sendRequest(
6692 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6693 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6694
6695 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6696 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006697 } finally {
6698 Binder.restoreCallingIdentity(identity);
6699 }
6700 }
6701
6702 /**
Miaoa84611c2019-03-15 09:21:10 +08006703 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006704 *
Miaoa84611c2019-03-15 09:21:10 +08006705 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006706 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006707 * @hide
6708 */
6709 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006710 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006711 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006712 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006713 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006714 try {
Miaoa84611c2019-03-15 09:21:10 +08006715 if (phone != null) {
6716 return phone.hasMatchedTetherApnSetting();
6717 } else {
6718 return false;
6719 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006720 } finally {
6721 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006722 }
Junda Liu475951f2014-11-07 16:45:03 -08006723 }
6724
6725 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006726 * Get the user enabled state of Mobile Data.
6727 *
6728 * TODO: remove and use isUserDataEnabled.
6729 * This can't be removed now because some vendor codes
6730 * calls through ITelephony directly while they should
6731 * use TelephonyManager.
6732 *
6733 * @return true on enabled
6734 */
6735 @Override
6736 public boolean getDataEnabled(int subId) {
6737 return isUserDataEnabled(subId);
6738 }
6739
6740 /**
6741 * Get whether mobile data is enabled per user setting.
6742 *
6743 * There are other factors deciding whether mobile data is actually enabled, but they are
6744 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006745 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006746 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6747 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006748 *
6749 * @return {@code true} if data is enabled else {@code false}
6750 */
6751 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006752 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006753 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006754 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006755 try {
6756 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6757 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006758 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006759 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6760 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006761 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006762 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006763 mApp, subId, functionName);
6764
Robert Greenwalt646120a2014-05-23 11:54:03 -07006765 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006766
6767 final long identity = Binder.clearCallingIdentity();
6768 try {
6769 int phoneId = mSubscriptionController.getPhoneId(subId);
6770 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6771 Phone phone = PhoneFactory.getPhone(phoneId);
6772 if (phone != null) {
6773 boolean retVal = phone.isUserDataEnabled();
6774 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6775 return retVal;
6776 } else {
6777 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6778 return false;
6779 }
6780 } finally {
6781 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006782 }
6783 }
6784
6785 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006786 * Checks if the device is capable of mobile data by considering whether whether the
6787 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6788 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006789 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006790 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006791 */
6792 @Override
6793 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006794 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006795 try {
6796 try {
6797 mApp.enforceCallingOrSelfPermission(
6798 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006799 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006800 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006801 try {
6802 mApp.enforceCallingOrSelfPermission(
6803 android.Manifest.permission.READ_PHONE_STATE,
6804 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006805 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006806 mApp.enforceCallingOrSelfPermission(
6807 permission.READ_BASIC_PHONE_STATE, functionName);
6808 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006809 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006810 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006811 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006812 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006813
6814 final long identity = Binder.clearCallingIdentity();
6815 try {
6816 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006817 Phone phone = PhoneFactory.getPhone(phoneId);
6818 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006819 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006820 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006821 return retVal;
6822 } else {
6823 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6824 return false;
6825 }
6826 } finally {
6827 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006828 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006829 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006830
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006831 /**
6832 * Check if data is enabled for a specific reason
6833 * @param subId Subscription index
6834 * @param reason the reason the data enable change is taking place
6835 * @return {@code true} if the overall data is enabled; {@code false} if not.
6836 */
6837 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006838 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006839 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006840 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006841 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006842 try {
6843 mApp.enforceCallingOrSelfPermission(
6844 android.Manifest.permission.ACCESS_NETWORK_STATE,
6845 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006846 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006847 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6848 functionName);
6849 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006850 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006851 try {
6852 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006853 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006854 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006856 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006857 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006858 }
6859
6860
6861 final long identity = Binder.clearCallingIdentity();
6862 try {
6863 int phoneId = mSubscriptionController.getPhoneId(subId);
6864 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006865 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006866 + " reason=" + reason);
6867 }
6868 Phone phone = PhoneFactory.getPhone(phoneId);
6869 if (phone != null) {
6870 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006871 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006872 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006873 return retVal;
6874 } else {
6875 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006876 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006877 + subId + " retVal=false");
6878 }
6879 return false;
6880 }
6881 } finally {
6882 Binder.restoreCallingIdentity(identity);
6883 }
6884 }
6885
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006886 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006887 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006888 // No permission needed; this only lets the caller inspect their own status.
6889 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006890 }
Junda Liu29340342014-07-10 15:23:27 -07006891
6892 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006893 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006894 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006895 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6896 }
6897
6898 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6899 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006900 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006901 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006902 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6903 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006904 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6905 if (cpt == null) {
6906 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006907 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6908 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006909 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006910 }
6911
6912 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006913 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006914 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006915 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006916 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006917 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006918 Phone phone = getPhone(subId);
6919 if (phone == null) {
6920 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6921 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6922 }
6923 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6924 if (cpt == null) {
6925 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006926 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6927 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006928 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006929 }
6930
6931 @Override
6932 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006933 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006934 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6935 }
6936
6937 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006938 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006939 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006940 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006941 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006942 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6943 Phone phone = PhoneFactory.getPhone(phoneId);
6944 if (phone == null) {
6945 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006946 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006947 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6948 if (cpt == null) {
6949 continue;
6950 }
6951 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006952 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6953 break;
6954 }
6955 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006956 return result;
Junda Liu29340342014-07-10 15:23:27 -07006957 }
Derek Tan89e89d42014-07-08 17:00:10 -07006958
6959 @Override
Junda Liue64de782015-04-16 17:19:16 -07006960 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006961 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006962 Phone phone = PhoneFactory.getPhone(phoneId);
6963 if (phone == null) {
6964 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006965 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006966 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6967 if (cpt == null) {
6968 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006969 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006970 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006971 }
6972
Amith Yamasani6e118872016-02-19 12:53:51 -08006973 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006974 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006975 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006976 Phone phone = PhoneFactory.getPhone(phoneId);
6977 if (phone == null) {
6978 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006979 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006980 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6981 if (cpt == null) {
6982 return Collections.emptyList();
6983 }
6984 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006985 }
6986
chen xuf7e9fe82019-05-09 19:31:02 -07006987 @Override
6988 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006989 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006990 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006991 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006992 try {
6993 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6994 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6995 }
6996 } finally {
6997 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006998 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006999 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007000 }
7001
Rambo Wang6812ffb2022-03-15 16:54:17 -07007002 @Override
7003 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7004 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7005
7006 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7007 if (phone == null) {
7008 return null;
7009 }
7010 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7011 if (cpt == null) {
7012 return null;
7013 }
7014 return cpt.getCarrierServicePackageName();
7015 }
7016
Wink Savilleb564aae2014-10-23 10:18:09 -07007017 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007018 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007019 UiccPort port = phone == null ? null : phone.getUiccPort();
7020 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007021 return null;
7022 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007023 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007024 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007025 return null;
7026 }
7027 return iccId;
7028 }
7029
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007030 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007031 public void setCallComposerStatus(int subId, int status) {
7032 enforceModifyPermission();
7033
7034 final long identity = Binder.clearCallingIdentity();
7035 try {
7036 Phone phone = getPhone(subId);
7037 if (phone != null) {
7038 Phone defaultPhone = phone.getImsPhone();
7039 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7040 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7041 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007042 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7043 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007044 }
7045 }
Shuo Qian284ae752020-12-22 19:10:14 -08007046 } catch (ImsException e) {
7047 throw new ServiceSpecificException(e.getCode());
7048 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007049 Binder.restoreCallingIdentity(identity);
7050 }
7051 }
7052
7053 @Override
7054 public int getCallComposerStatus(int subId) {
7055 enforceReadPrivilegedPermission("getCallComposerStatus");
7056
7057 final long identity = Binder.clearCallingIdentity();
7058 try {
7059 Phone phone = getPhone(subId);
7060 if (phone != null) {
7061 Phone defaultPhone = phone.getImsPhone();
7062 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7063 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7064 return imsPhone.getCallComposerStatus();
7065 }
7066 }
7067 } finally {
7068 Binder.restoreCallingIdentity(identity);
7069 }
7070 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7071 }
7072
7073 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007074 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7075 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007076 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007077 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007078
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079 final long identity = Binder.clearCallingIdentity();
7080 try {
7081 final String iccId = getIccId(subId);
7082 final Phone phone = getPhone(subId);
7083 if (phone == null) {
7084 return false;
7085 }
7086 final String subscriberId = phone.getSubscriberId();
7087
7088 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007089 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007090 + subscriberId + " to " + number);
7091 }
7092
7093 if (TextUtils.isEmpty(iccId)) {
7094 return false;
7095 }
7096
7097 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7098
7099 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7100 if (alphaTag == null) {
7101 editor.remove(alphaTagPrefKey);
7102 } else {
7103 editor.putString(alphaTagPrefKey, alphaTag);
7104 }
7105
7106 // Record both the line number and IMSI for this ICCID, since we need to
7107 // track all merged IMSIs based on line number
7108 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7109 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7110 if (number == null) {
7111 editor.remove(numberPrefKey);
7112 editor.remove(subscriberPrefKey);
7113 } else {
7114 editor.putString(numberPrefKey, number);
7115 editor.putString(subscriberPrefKey, subscriberId);
7116 }
7117
7118 editor.commit();
7119 return true;
7120 } finally {
7121 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007122 }
Derek Tan7226c842014-07-02 17:42:23 -07007123 }
7124
7125 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007126 public String getLine1NumberForDisplay(int subId, String callingPackage,
7127 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007128 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007129 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007130 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007131 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007132 return null;
7133 }
Derek Tan97ebb422014-09-05 16:55:38 -07007134
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007135 final long identity = Binder.clearCallingIdentity();
7136 try {
7137 String iccId = getIccId(subId);
7138 if (iccId != null) {
7139 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7140 if (DBG_MERGE) {
7141 log("getLine1NumberForDisplay returning "
7142 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7143 }
7144 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007145 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007146 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7147 return null;
7148 } finally {
7149 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007150 }
Derek Tan7226c842014-07-02 17:42:23 -07007151 }
7152
7153 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007154 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7155 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007156 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007157 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007158 return null;
7159 }
Derek Tan97ebb422014-09-05 16:55:38 -07007160
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007161 final long identity = Binder.clearCallingIdentity();
7162 try {
7163 String iccId = getIccId(subId);
7164 if (iccId != null) {
7165 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7166 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7167 }
7168 return null;
7169 } finally {
7170 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007171 }
Derek Tan7226c842014-07-02 17:42:23 -07007172 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007173
7174 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007175 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7176 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007177 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7178 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007179 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007180 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007181 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007182 return null;
7183 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007184
Jordan Liub49b04b2019-05-06 14:45:15 -07007185 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7186 // the process, where TelephonyManager was instantiated.
7187 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007188 final long identity = Binder.clearCallingIdentity();
7189 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007190 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007191 final TelephonyManager tele = TelephonyManager.from(context);
7192 final SubscriptionManager sub = SubscriptionManager.from(context);
7193
7194 // Figure out what subscribers are currently active
7195 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007196
Jordan Liub49b04b2019-05-06 14:45:15 -07007197 // Only consider subs which match the current subId
7198 // This logic can be simplified. See b/131189269 for progress.
7199 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007200 activeSubscriberIds.add(tele.getSubscriberId(subId));
7201 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007202
7203 // First pass, find a number override for an active subscriber
7204 String mergeNumber = null;
7205 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7206 for (String key : prefs.keySet()) {
7207 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7208 final String subscriberId = (String) prefs.get(key);
7209 if (activeSubscriberIds.contains(subscriberId)) {
7210 final String iccId = key.substring(
7211 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7212 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7213 mergeNumber = (String) prefs.get(numberKey);
7214 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007215 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007216 + " for active subscriber " + subscriberId);
7217 }
7218 if (!TextUtils.isEmpty(mergeNumber)) {
7219 break;
7220 }
7221 }
7222 }
7223 }
7224
7225 // Shortcut when no active merged subscribers
7226 if (TextUtils.isEmpty(mergeNumber)) {
7227 return null;
7228 }
7229
7230 // Second pass, find all subscribers under that line override
7231 final ArraySet<String> result = new ArraySet<>();
7232 for (String key : prefs.keySet()) {
7233 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7234 final String number = (String) prefs.get(key);
7235 if (mergeNumber.equals(number)) {
7236 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7237 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7238 final String subscriberId = (String) prefs.get(subscriberKey);
7239 if (!TextUtils.isEmpty(subscriberId)) {
7240 result.add(subscriberId);
7241 }
7242 }
7243 }
7244 }
7245
7246 final String[] resultArray = result.toArray(new String[result.size()]);
7247 Arrays.sort(resultArray);
7248 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007249 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007250 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7251 }
7252 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007253 } finally {
7254 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007255 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007256 }
7257
7258 @Override
zoey chen38003472019-12-13 17:16:31 +08007259 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7260 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007261
7262 final long identity = Binder.clearCallingIdentity();
7263 try {
7264 final TelephonyManager telephonyManager = mApp.getSystemService(
7265 TelephonyManager.class);
7266 String subscriberId = telephonyManager.getSubscriberId(subId);
7267 if (subscriberId == null) {
7268 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007269 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007270 + subId);
7271 }
7272 return null;
7273 }
7274
7275 final SubscriptionInfo info = SubscriptionController.getInstance()
7276 .getSubscriptionInfo(subId);
7277 final ParcelUuid groupUuid = info.getGroupUuid();
7278 // If it doesn't belong to any group, return just subscriberId of itself.
7279 if (groupUuid == null) {
7280 return new String[]{subscriberId};
7281 }
7282
7283 // Get all subscriberIds from the group.
7284 final List<String> mergedSubscriberIds = new ArrayList<>();
7285 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007286 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007287 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007288 for (SubscriptionInfo subInfo : groupInfos) {
7289 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7290 if (subscriberId != null) {
7291 mergedSubscriberIds.add(subscriberId);
7292 }
7293 }
7294
7295 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7296 } finally {
7297 Binder.restoreCallingIdentity(identity);
7298
7299 }
7300 }
7301
7302 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007303 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007304 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007305 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007306
7307 final long identity = Binder.clearCallingIdentity();
7308 try {
7309 final Phone phone = getPhone(subId);
7310 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7311 } finally {
7312 Binder.restoreCallingIdentity(identity);
7313 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007314 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007315
7316 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007317 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007318 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7319 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007320 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7321 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007322
7323 final long identity = Binder.clearCallingIdentity();
7324 try {
7325 final Phone phone = getPhone(subId);
7326 if (phone == null) {
7327 return false;
7328 }
7329 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7330 cdmaNonRoamingList);
7331 } finally {
7332 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007333 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007334 }
7335
7336 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007337 @Deprecated
7338 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7339 enforceModifyPermission();
7340
7341 int returnValue = 0;
7342 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007343 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007344 if(result.exception == null) {
7345 if (result.result != null) {
7346 byte[] responseData = (byte[])(result.result);
7347 if(responseData.length > oemResp.length) {
7348 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7349 responseData.length + "bytes. Buffer Size is " +
7350 oemResp.length + "bytes.");
7351 }
7352 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7353 returnValue = responseData.length;
7354 }
7355 } else {
7356 CommandException ex = (CommandException) result.exception;
7357 returnValue = ex.getCommandError().ordinal();
7358 if(returnValue > 0) returnValue *= -1;
7359 }
7360 } catch (RuntimeException e) {
7361 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7362 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7363 if(returnValue > 0) returnValue *= -1;
7364 }
7365
7366 return returnValue;
7367 }
7368
7369 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007370 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007371 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007372 try {
7373 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007374 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007375 mApp, phone.getSubId(), "getRadioAccessFamily");
7376 } catch (SecurityException e) {
7377 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7378 throw e;
7379 }
chen xub97461a2018-10-26 14:17:57 -07007380 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007381 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007382 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007383 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007384 final long identity = Binder.clearCallingIdentity();
7385 try {
chen xub97461a2018-10-26 14:17:57 -07007386 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007387 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007388 mApp, phone.getSubId(), "getRadioAccessFamily");
7389 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007390 } finally {
7391 Binder.restoreCallingIdentity(identity);
7392 }
chen xub97461a2018-10-26 14:17:57 -07007393 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007394 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007395
7396 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007397 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007398 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007399 try {
7400 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7401 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007402 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007403 }
7404 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007405 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007406 }
7407 RoleManager rm = mApp.getSystemService(RoleManager.class);
7408 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7409 if (!dialerRoleHolders.contains(callingPackage)) {
7410 throw new SecurityException("App must be the dialer role holder to"
7411 + " upload a call composer pic");
7412 }
7413
7414 Executors.newSingleThreadExecutor().execute(() -> {
7415 ByteArrayOutputStream output = new ByteArrayOutputStream(
7416 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7417 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7418 boolean readUntilEnd = false;
7419 int totalBytesRead = 0;
7420 byte[] buffer = new byte[16 * 1024];
7421 while (true) {
7422 int numRead;
7423 try {
7424 numRead = input.read(buffer);
7425 } catch (IOException e) {
7426 try {
7427 fd.checkError();
7428 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7429 null);
7430 } catch (IOException e1) {
7431 // This means that the other side closed explicitly with an error. If this
7432 // happens, log and ignore.
7433 loge("Remote end of call composer picture pipe closed: " + e1);
7434 }
7435 break;
7436 }
7437 if (numRead == -1) {
7438 readUntilEnd = true;
7439 break;
7440 }
7441 totalBytesRead += numRead;
7442 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7443 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7444 try {
7445 input.close();
7446 } catch (IOException e) {
7447 // ignore
7448 }
7449 break;
7450 }
7451 output.write(buffer, 0, numRead);
7452 }
7453 // Generally, the remote end will close the file descriptors. The only case where we
7454 // close is above, where the picture size is too big.
7455
7456 try {
7457 fd.checkError();
7458 } catch (IOException e) {
7459 loge("Remote end for call composer closed with an error: " + e);
7460 return;
7461 }
7462
Hall Liuaa4211e2021-01-20 15:43:39 -08007463 if (!readUntilEnd) {
7464 loge("Did not finish reading entire image; aborting");
7465 return;
7466 }
Hall Liu82694d52020-12-11 18:22:04 -08007467
Hall Liuaa4211e2021-01-20 15:43:39 -08007468 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7469 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7470 new CallComposerPictureTransfer.Factory() {},
7471 imageData,
7472 (result) -> {
7473 if (result.first != null) {
7474 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7475 Bundle outputResult = new Bundle();
7476 outputResult.putParcelable(
7477 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7478 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7479 outputResult);
7480 } else {
7481 callback.send(result.second, null);
7482 }
7483 }
7484 );
Hall Liu82694d52020-12-11 18:22:04 -08007485 });
7486 }
7487
7488 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007489 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007490 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007491 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007492
7493 final long identity = Binder.clearCallingIdentity();
7494 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007495 ImsManager.getInstance(defaultPhone.getContext(),
7496 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007497 } finally {
7498 Binder.restoreCallingIdentity(identity);
7499 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007500 }
7501
7502 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007503 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007504 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007505 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7506 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007507 return false;
7508 }
Svet Ganovb320e182015-04-16 12:30:10 -07007509
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007510 final long identity = Binder.clearCallingIdentity();
7511 try {
7512 // Check the user preference and the system-level IMS setting. Even if the user has
7513 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7514 // In the long run, we may instead need to check if there exists a connection service
7515 // which can support video calling.
7516 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007517 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007518 return imsManager.isVtEnabledByPlatform()
7519 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7520 && imsManager.isVtEnabledByUser();
7521 } finally {
7522 Binder.restoreCallingIdentity(identity);
7523 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007524 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007525
Andrew Leea1239f22015-03-02 17:44:07 -08007526 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007527 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7528 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007529 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007530 mApp, subId, callingPackage, callingFeatureId,
7531 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 return false;
7533 }
7534
7535 final long identity = Binder.clearCallingIdentity();
7536 try {
7537 CarrierConfigManager configManager =
7538 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007539 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007540 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7541 } finally {
7542 Binder.restoreCallingIdentity(identity);
7543 }
Andrew Leea1239f22015-03-02 17:44:07 -08007544 }
7545
7546 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007547 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007548 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007549 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007550 return false;
7551 }
7552
7553 final long identity = Binder.clearCallingIdentity();
7554 try {
7555 CarrierConfigManager configManager =
7556 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007557 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007558 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7559 } finally {
7560 Binder.restoreCallingIdentity(identity);
7561 }
Andrew Leea1239f22015-03-02 17:44:07 -08007562 }
7563
Andrew Lee9431b832015-03-09 18:46:45 -07007564 @Override
7565 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007566 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007567 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007568 }
7569
7570 @Override
7571 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007572 final long identity = Binder.clearCallingIdentity();
7573 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007574 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007575 } finally {
7576 Binder.restoreCallingIdentity(identity);
7577 }
Andrew Lee9431b832015-03-09 18:46:45 -07007578 }
7579
Hall Liuf6668912018-10-31 17:05:23 -07007580 /**
7581 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7582 * support for the feature and device firmware support.
7583 *
7584 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7585 */
7586 @Override
7587 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007588 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007589 final Phone phone = getPhone(subscriptionId);
7590 if (phone == null) {
7591 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7592 return false;
7593 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007594 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007595 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007596 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7597 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007598 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007599 return isCarrierSupported && isDeviceSupported;
7600 } finally {
7601 Binder.restoreCallingIdentity(identity);
7602 }
Hall Liu98187582018-01-22 19:15:32 -08007603 }
7604
Hall Liuf6668912018-10-31 17:05:23 -07007605 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007606 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7607 * RTT setting, will return true if the device and carrier both support RTT.
7608 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007609 */
7610 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007611 final long identity = Binder.clearCallingIdentity();
7612 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007613 boolean isRttSupported = isRttSupported(subscriptionId);
7614 boolean isUserRttSettingOn = Settings.Secure.getInt(
7615 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7616 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7617 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7618 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007619 } finally {
7620 Binder.restoreCallingIdentity(identity);
7621 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007622 }
7623
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007624 @Deprecated
7625 @Override
7626 public String getDeviceId(String callingPackage) {
7627 return getDeviceIdWithFeature(callingPackage, null);
7628 }
7629
Sanket Padawe7310cc72015-01-14 09:53:20 -08007630 /**
7631 * Returns the unique device ID of phone, for example, the IMEI for
7632 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7633 *
7634 * <p>Requires Permission:
7635 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7636 */
7637 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007638 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007639 try {
7640 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7641 } catch (SecurityException se) {
7642 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7643 throw new SecurityException("Package " + callingPackage + " does not belong to "
7644 + Binder.getCallingUid());
7645 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007646 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007647 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007648 return null;
7649 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007650 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007651 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007652 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007653 return null;
7654 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007655
7656 final long identity = Binder.clearCallingIdentity();
7657 try {
7658 return phone.getDeviceId();
7659 } finally {
7660 Binder.restoreCallingIdentity(identity);
7661 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007662 }
7663
Ping Sunc67b7c22016-03-02 19:16:45 +08007664 /**
7665 * {@hide}
7666 * Returns the IMS Registration Status on a particular subid
7667 *
7668 * @param subId
7669 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007670 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007671 Phone phone = getPhone(subId);
7672 if (phone != null) {
7673 return phone.isImsRegistered();
7674 } else {
7675 return false;
7676 }
7677 }
7678
Santos Cordon7a1885b2015-02-03 11:15:19 -08007679 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007680 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007681 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007682 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007683 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007684 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7685 }
7686 final long identity = Binder.clearCallingIdentity();
7687 try {
7688 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7689 } finally {
7690 Binder.restoreCallingIdentity(identity);
7691 }
7692 }
7693
7694 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007695 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007696 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007697 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007698 mApp,
7699 subscriptionId,
7700 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007701 final long identity = Binder.clearCallingIdentity();
7702 try {
7703 Phone phone = getPhone(subscriptionId);
7704 if (phone == null) {
7705 return null;
7706 }
7707 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7708 } finally {
7709 Binder.restoreCallingIdentity(identity);
7710 }
7711 }
7712
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007713 /**
7714 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007715 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007716 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007717 final long identity = Binder.clearCallingIdentity();
7718 try {
7719 Phone phone = getPhone(subId);
7720 if (phone != null) {
7721 return phone.isWifiCallingEnabled();
7722 } else {
7723 return false;
7724 }
7725 } finally {
7726 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007727 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007728 }
7729
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007730 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007731 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007732 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007733 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007734 final long identity = Binder.clearCallingIdentity();
7735 try {
7736 Phone phone = getPhone(subId);
7737 if (phone != null) {
7738 return phone.isVideoEnabled();
7739 } else {
7740 return false;
7741 }
7742 } finally {
7743 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007744 }
7745 }
7746
7747 /**
7748 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7749 * defined in {@link ImsRegistrationImplBase}.
7750 */
7751 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007752 final long identity = Binder.clearCallingIdentity();
7753 try {
7754 Phone phone = getPhone(subId);
7755 if (phone != null) {
7756 return phone.getImsRegistrationTech();
7757 } else {
7758 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7759 }
7760 } finally {
7761 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007762 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007763 }
7764
Stuart Scott8eef64f2015-04-08 15:13:54 -07007765 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007766 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007767 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007768 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7769 return;
7770 }
Kai Shif70f46f2021-03-03 13:59:46 -08007771 Phone defaultPhone = getDefaultPhone();
7772 if (defaultPhone != null) {
7773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7774 mApp, getDefaultPhone().getSubId(), "factoryReset");
7775 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007776 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007777
Svet Ganovcc087f82015-05-12 20:35:54 -07007778 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007779 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7780 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007781 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007782 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007783 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007784 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007785 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007786 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007787 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007788 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007789 // There has been issues when Sms raw table somehow stores orphan
7790 // fragments. They lead to garbled message when new fragments come
7791 // in and combined with those stale ones. In case this happens again,
7792 // user can reset all network settings which will clean up this table.
7793 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007794 // Clean up IMS settings as well here.
7795 int slotId = getSlotIndex(subId);
7796 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7797 ImsManager.getInstance(mApp, slotId).factoryReset();
7798 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007799
Kai Shif70f46f2021-03-03 13:59:46 -08007800 if (defaultPhone == null) {
7801 return;
7802 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007803 // Erase modem config if erase modem on network setting is enabled.
7804 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7805 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7806 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007807 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007808 }
Kai Shif70f46f2021-03-03 13:59:46 -08007809
7810 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007811 } finally {
7812 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007813 }
7814 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007815
SongFerngWangfd89b102021-05-27 22:44:54 +08007816 @VisibleForTesting
7817 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7818 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7819 return;
7820 }
7821 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7822 RILConstants.PREFERRED_NETWORK_MODE);
7823 SubscriptionManager.setSubscriptionProperty(subId,
7824 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7825 "user=" + defaultNetworkType);
7826 phone.loadAllowedNetworksFromSubscriptionDatabase();
7827 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7828 defaultNetworkType, null);
7829 }
7830
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007831 private void cleanUpSmsRawTable(Context context) {
7832 ContentResolver resolver = context.getContentResolver();
7833 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7834 resolver.delete(uri, null, null);
7835 }
7836
Narayan Kamath1c496c22015-04-16 14:40:19 +01007837 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007838 public String getSimLocaleForSubscriber(int subId) {
7839 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7840 final Phone phone = getPhone(subId);
7841 if (phone == null) {
7842 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007843 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007844 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007845 final long identity = Binder.clearCallingIdentity();
7846 try {
chen xu5d3637b2019-01-21 23:31:38 -08007847 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007848 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007849 if (info == null) {
7850 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7851 return null;
7852 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007853 // Try and fetch the locale from the carrier properties or from the SIM language
7854 // preferences (EF-PL and EF-LI)...
7855 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007856 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007857 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7858 if (localeFromDefaultSim != null) {
7859 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7860 if (DBG) log("Using locale from subId: " + subId + " locale: "
7861 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08007862 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007863 } else {
7864 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007865 }
7866 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007867
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007868 // The SIM language preferences only store a language (e.g. fr = French), not an
7869 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7870 // the SIM and carrier preferences does not include a country we add the country
7871 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007872 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007873 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007874 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08007875 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007876 }
7877
7878 if (DBG) log("No locale found - returning null");
7879 return null;
7880 } finally {
7881 Binder.restoreCallingIdentity(identity);
7882 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007883 }
7884
tom hsu0b59d292022-09-29 23:49:21 +08007885 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08007886 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08007887 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08007888 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08007889 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08007890 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
7891 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08007892 Locale.forLanguageTag(localeTag).getCountry())) {
7893 return localeTag;
7894 }
7895 }
7896 return inputLocale.toLanguageTag();
7897 }
7898
Narayan Kamath1c496c22015-04-16 14:40:19 +01007899 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007900 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007901 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007902 }
7903
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007904 /**
7905 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7906 */
7907 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007908 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007909 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007910 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007911
Gary Jian3aa9a762022-01-24 16:41:19 +08007912 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7913 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007914
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007915 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007916 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7917 * representing the state of the modem.
7918 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007919 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7920 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007921 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007922 */
7923 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007924 public void requestModemActivityInfo(ResultReceiver result) {
7925 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007926 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007927
7928 final long identity = Binder.clearCallingIdentity();
7929 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007930 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007931 } finally {
7932 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007933 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007934 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007935
Siddharth Rayb8114062018-06-17 15:02:38 -07007936 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7937 // less than total activity duration.
7938 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7939 if (info == null) {
7940 return false;
7941 }
7942 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007943 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7944 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7945
Siddharth Rayb8114062018-06-17 15:02:38 -07007946 return (info.isValid()
7947 && (info.getSleepTimeMillis() <= activityDurationMs)
7948 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007949 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007950 && (totalTxTimeMs <= activityDurationMs));
7951 }
7952
Gary Jian3aa9a762022-01-24 16:41:19 +08007953 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7954 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7955 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7956 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7957
7958 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7959 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7960 }
7961
7962 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7963 mLastModemActivityInfo.setReceiveTimeMillis(
7964 rat,
7965 freq,
7966 info.getReceiveTimeMillis(rat, freq)
7967 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7968 }
7969
7970 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7971 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7972 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7973 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7974
7975 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7976 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7977 }
7978 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7979 mLastModemActivityInfo.setReceiveTimeMillis(
7980 rat,
7981 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7982 }
7983
7984 /**
7985 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7986 * @param info recent ModemActivityInfo
7987 */
7988 private void mergeModemActivityInfo(ModemActivityInfo info) {
7989 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7990 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7991 boolean matched;
7992 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7993 matched = false;
7994 int rat = info.getSpecificInfoRat(i);
7995 int freq = info.getSpecificInfoFrequencyRange(i);
7996 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7997 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7998 //if it already exists
7999 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8000 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8001 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8002 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8003 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8004 updateLastModemActivityInfo(info, rat, freq);
8005 matched = true;
8006 }
8007 } else {
8008 updateLastModemActivityInfo(info, rat);
8009 matched = true;
8010 }
8011 }
8012 }
8013
8014 if (!matched) {
8015 mDeltaSpecificInfo =
8016 new ActivityStatsTechSpecificInfo(
8017 rat,
8018 freq,
8019 info.getTransmitTimeMillis(rat, freq),
8020 (int) info.getReceiveTimeMillis(rat, freq));
8021 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
8022 }
8023 }
8024 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8025 mLastModemActivitySpecificInfo =
8026 new ActivityStatsTechSpecificInfo[merged.size()];
8027 merged.toArray(mLastModemActivitySpecificInfo);
8028
8029 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8030 mLastModemActivityInfo.setSleepTimeMillis(
8031 info.getSleepTimeMillis()
8032 + mLastModemActivityInfo.getSleepTimeMillis());
8033 mLastModemActivityInfo.setIdleTimeMillis(
8034 info.getIdleTimeMillis()
8035 + mLastModemActivityInfo.getIdleTimeMillis());
8036 }
8037
Jack Yu85bd38a2015-11-09 11:34:32 -08008038 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008039 * Returns the service state information on specified subscription.
8040 */
8041 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008042 public ServiceState getServiceStateForSubscriber(int subId,
8043 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8044 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008045 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008046 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008047 return null;
8048 }
8049
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008050 boolean hasFinePermission = false;
8051 boolean hasCoarsePermission = false;
8052 if (!renounceFineLocationAccess) {
8053 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8054 LocationAccessPolicy.checkLocationPermission(mApp,
8055 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8056 .setCallingPackage(callingPackage)
8057 .setCallingFeatureId(callingFeatureId)
8058 .setCallingPid(Binder.getCallingPid())
8059 .setCallingUid(Binder.getCallingUid())
8060 .setMethod("getServiceStateForSubscriber")
8061 .setLogAsInfo(true)
8062 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8063 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8064 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8065 .build());
8066 hasFinePermission =
8067 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8068 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008069
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008070 if (!renounceCoarseLocationAccess) {
8071 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8072 LocationAccessPolicy.checkLocationPermission(mApp,
8073 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8074 .setCallingPackage(callingPackage)
8075 .setCallingFeatureId(callingFeatureId)
8076 .setCallingPid(Binder.getCallingPid())
8077 .setCallingUid(Binder.getCallingUid())
8078 .setMethod("getServiceStateForSubscriber")
8079 .setLogAsInfo(true)
8080 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8081 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8082 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8083 .build());
8084 hasCoarsePermission =
8085 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8086 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008087
Jack Yu479f40e2020-10-27 21:29:25 -07008088 final Phone phone = getPhone(subId);
8089 if (phone == null) {
8090 return null;
8091 }
8092
Jordan Liu0f2bc442020-11-18 16:47:37 -08008093 final long identity = Binder.clearCallingIdentity();
8094
Jack Yu479f40e2020-10-27 21:29:25 -07008095 boolean isCallingPackageDataService = phone.getDataServicePackages()
8096 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008097 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008098 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
8099 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
8100 Rlog.d(LOG_TAG,
8101 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
8102 return null;
8103 }
8104
Hall Liuf19c44f2018-11-27 14:38:17 -08008105 ServiceState ss = phone.getServiceState();
8106
8107 // Scrub out the location info in ServiceState depending on what level of access
8108 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008109 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008110 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8111 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008112 } finally {
8113 Binder.restoreCallingIdentity(identity);
8114 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008115 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008116
8117 /**
8118 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8119 *
8120 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8121 * voicemail ringtone.
8122 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8123 * PhoneAccount.
8124 */
8125 @Override
8126 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008127 final long identity = Binder.clearCallingIdentity();
8128 try {
8129 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8130 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008131 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008132 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008133
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008134 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8135 } finally {
8136 Binder.restoreCallingIdentity(identity);
8137 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008138 }
8139
8140 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008141 * Sets the per-account voicemail ringtone.
8142 *
8143 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8144 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8145 *
8146 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8147 * voicemail ringtone.
8148 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8149 * PhoneAccount.
8150 */
8151 @Override
8152 public void setVoicemailRingtoneUri(String callingPackage,
8153 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008154 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008155 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008156 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8157 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008158 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8159 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8160 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008161 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008162
8163 final long identity = Binder.clearCallingIdentity();
8164 try {
8165 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8166 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008167 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008168 }
8169 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8170 } finally {
8171 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008172 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008173 }
8174
8175 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008176 * Returns whether vibration is set for voicemail notification in Phone settings.
8177 *
8178 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8179 * voicemail vibration setting.
8180 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8181 */
8182 @Override
8183 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008184 final long identity = Binder.clearCallingIdentity();
8185 try {
8186 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8187 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008188 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008189 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008190
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008191 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8192 } finally {
8193 Binder.restoreCallingIdentity(identity);
8194 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008195 }
8196
Youhan Wange64578a2016-05-02 15:32:42 -07008197 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008198 * Sets the per-account voicemail vibration.
8199 *
8200 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8201 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8202 *
8203 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8204 * voicemail vibration setting.
8205 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8206 * specific PhoneAccount.
8207 */
8208 @Override
8209 public void setVoicemailVibrationEnabled(String callingPackage,
8210 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008211 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008212 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008213 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8214 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008215 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8216 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8217 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008218 }
8219
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008220 final long identity = Binder.clearCallingIdentity();
8221 try {
8222 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8223 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008224 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008225 }
8226 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8227 } finally {
8228 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008229 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008230 }
8231
8232 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008233 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8234 *
8235 * @throws SecurityException if the caller does not have the required permission
8236 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008237 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008238 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008239 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008240 }
8241
8242 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008243 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8244 * permission.
8245 *
8246 * @throws SecurityException if the caller does not have the required permission
8247 */
8248 private void enforceSendSmsPermission() {
8249 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8250 }
8251
8252 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008253 * Make sure either called from same process as self (phone) or IPC caller has interact across
8254 * users permission.
8255 *
8256 * @throws SecurityException if the caller does not have the required permission
8257 */
8258 private void enforceInteractAcrossUsersPermission(String message) {
8259 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8260 }
8261
8262 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008263 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008264 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008265 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008266 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008267 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008268 final long identity = Binder.clearCallingIdentity();
8269 try {
8270 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008271 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008272 if (componentName == null) {
8273 throw new SecurityException(
8274 "Caller not current active visual voicemail package[null]");
8275 }
8276 String vvmPackage = componentName.getPackageName();
8277 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008278 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008279 }
8280 } finally {
8281 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008282 }
8283 }
8284
8285 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008286 * Return the application ID for the app type.
8287 *
8288 * @param subId the subscription ID that this request applies to.
8289 * @param appType the uicc app type.
8290 * @return Application ID for specificied app type, or null if no uicc.
8291 */
8292 @Override
8293 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008294 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008295 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008296
8297 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008298 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008299 if (phone == null) {
8300 return null;
8301 }
8302 String aid = null;
8303 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008304 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008305 .getApplicationByType(appType).getAid();
8306 } catch (Exception e) {
8307 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8308 }
8309 return aid;
8310 } finally {
8311 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008312 }
Youhan Wange64578a2016-05-02 15:32:42 -07008313 }
8314
Youhan Wang4001d252016-05-11 10:29:41 -07008315 /**
8316 * Return the Electronic Serial Number.
8317 *
8318 * @param subId the subscription ID that this request applies to.
8319 * @return ESN or null if error.
8320 */
8321 @Override
8322 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008323 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008324 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008325
8326 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008327 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008328 if (phone == null) {
8329 return null;
8330 }
8331 String esn = null;
8332 try {
8333 esn = phone.getEsn();
8334 } catch (Exception e) {
8335 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8336 }
8337 return esn;
8338 } finally {
8339 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008340 }
Youhan Wang4001d252016-05-11 10:29:41 -07008341 }
8342
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008343 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008344 * Return the Preferred Roaming List Version.
8345 *
8346 * @param subId the subscription ID that this request applies to.
8347 * @return PRLVersion or null if error.
8348 */
8349 @Override
8350 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008351 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008352 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008353
8354 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008355 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008356 if (phone == null) {
8357 return null;
8358 }
8359 String cdmaPrlVersion = null;
8360 try {
8361 cdmaPrlVersion = phone.getCdmaPrlVersion();
8362 } catch (Exception e) {
8363 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8364 }
8365 return cdmaPrlVersion;
8366 } finally {
8367 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008368 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008369 }
8370
8371 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008372 * Get snapshot of Telephony histograms
8373 * @return List of Telephony histograms
8374 * @hide
8375 */
8376 @Override
8377 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8379 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008380
8381 final long identity = Binder.clearCallingIdentity();
8382 try {
8383 return RIL.getTelephonyRILTimingHistograms();
8384 } finally {
8385 Binder.restoreCallingIdentity(identity);
8386 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008387 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008388
8389 /**
8390 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008391 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8392 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008393 * Require system privileges. In the future we may add this to carrier APIs.
8394 *
Michele Berionne482f8202018-11-27 18:57:59 -08008395 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008396 */
8397 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008398 @TelephonyManager.SetCarrierRestrictionResult
8399 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008400 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008401 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008402
Michele Berionne482f8202018-11-27 18:57:59 -08008403 if (carrierRestrictionRules == null) {
8404 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008405 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008406
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008407 final long identity = Binder.clearCallingIdentity();
8408 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008409 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008410 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008411 } finally {
8412 Binder.restoreCallingIdentity(identity);
8413 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008414 }
8415
8416 /**
8417 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008418 * Get the allowed carrier list and the excluded carrier list, including the priority between
8419 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008420 * Require system privileges. In the future we may add this to carrier APIs.
8421 *
Michele Berionne482f8202018-11-27 18:57:59 -08008422 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008423 */
8424 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008425 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008426 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008427 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008428
8429 final long identity = Binder.clearCallingIdentity();
8430 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008431 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8432 if (response instanceof CarrierRestrictionRules) {
8433 return (CarrierRestrictionRules) response;
8434 }
8435 // Response is an Exception of some kind,
8436 // which is signalled to the user as a NULL retval
8437 return null;
8438 } catch (Exception e) {
8439 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8440 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008441 } finally {
8442 Binder.restoreCallingIdentity(identity);
8443 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008444 }
8445
fionaxu59545b42016-05-25 15:53:37 -07008446 /**
fionaxu59545b42016-05-25 15:53:37 -07008447 * Action set from carrier signalling broadcast receivers to enable/disable radio
8448 * @param subId the subscription ID that this action applies to.
8449 * @param enabled control enable or disable radio.
8450 * {@hide}
8451 */
8452 @Override
8453 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8454 enforceModifyPermission();
8455 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008456
8457 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008458 if (phone == null) {
8459 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8460 return;
8461 }
8462 try {
8463 phone.carrierActionSetRadioEnabled(enabled);
8464 } catch (Exception e) {
8465 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008466 } finally {
8467 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008468 }
8469 }
8470
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008471 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008472 * Enable or disable Voice over NR (VoNR)
8473 * @param subId the subscription ID that this action applies to.
8474 * @param enabled enable or disable VoNR.
8475 * @return operation result.
8476 */
8477 @Override
8478 public int setVoNrEnabled(int subId, boolean enabled) {
8479 enforceModifyPermission();
8480 final Phone phone = getPhone(subId);
8481
8482 final long identity = Binder.clearCallingIdentity();
8483 if (phone == null) {
8484 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8485 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8486 }
8487
8488 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8489 try {
8490 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8491 workSource);
8492 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008493
8494 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8495 if (DBG) {
8496 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8497 }
8498 SubscriptionManager.setSubscriptionProperty(
8499 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8500 (enabled ? "1" : "0"));
8501 }
8502
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008503 return result;
8504 } finally {
8505 Binder.restoreCallingIdentity(identity);
8506 }
8507 }
8508
8509 /**
8510 * Is voice over NR enabled
8511 * @return true if VoNR is enabled else false
8512 */
8513 @Override
8514 public boolean isVoNrEnabled(int subId) {
8515 enforceReadPrivilegedPermission("isVoNrEnabled");
8516 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8517 final long identity = Binder.clearCallingIdentity();
8518 try {
8519 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8520 null, subId, workSource);
8521 if (DBG) log("isVoNrEnabled: " + isEnabled);
8522 return isEnabled;
8523 } finally {
8524 Binder.restoreCallingIdentity(identity);
8525 }
8526 }
8527
8528 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008529 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8530 * network status based on which carrier apps could apply actions accordingly,
8531 * enable/disable default url handler for example.
8532 *
8533 * @param subId the subscription ID that this action applies to.
8534 * @param report control start/stop reporting the default network status.
8535 * {@hide}
8536 */
8537 @Override
8538 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8539 enforceModifyPermission();
8540 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008541
8542 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008543 if (phone == null) {
8544 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8545 return;
8546 }
8547 try {
8548 phone.carrierActionReportDefaultNetworkStatus(report);
8549 } catch (Exception e) {
8550 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008551 } finally {
8552 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008553 }
8554 }
8555
8556 /**
fionaxud9622282017-07-17 17:51:30 -07008557 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8558 * @param subId the subscription ID that this action applies to.
8559 * {@hide}
8560 */
8561 @Override
8562 public void carrierActionResetAll(int subId) {
8563 enforceModifyPermission();
8564 final Phone phone = getPhone(subId);
8565 if (phone == null) {
8566 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8567 return;
8568 }
8569 try {
8570 phone.carrierActionResetAll();
8571 } catch (Exception e) {
8572 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8573 }
8574 }
8575
8576 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008577 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8578 * bug report is being generated.
8579 */
8580 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008581 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008582 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8583 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008584 writer.println("Permission Denial: can't dump Phone from pid="
8585 + Binder.getCallingPid()
8586 + ", uid=" + Binder.getCallingUid()
8587 + "without permission "
8588 + android.Manifest.permission.DUMP);
8589 return;
8590 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008591 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008592 }
Jack Yueb89b242016-06-22 13:27:47 -07008593
Brad Ebingerdac2f002018-04-03 15:17:52 -07008594 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008595 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8596 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8597 @NonNull String[] args) {
8598 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8599 this, in.getFileDescriptor(), out.getFileDescriptor(),
8600 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008601 }
8602
Jack Yueb89b242016-06-22 13:27:47 -07008603 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008604 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008605 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008606 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008607 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008608 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008609 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008610 */
8611 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008612 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008613 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008614 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8615 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8616 try {
8617 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008618 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008619 } catch (SecurityException se) {
8620 enforceModifyPermission();
8621 }
8622 } else {
8623 enforceModifyPermission();
8624 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008625
8626 final long identity = Binder.clearCallingIdentity();
8627 try {
8628 Phone phone = getPhone(subId);
8629 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008630 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8631 phone.carrierActionSetMeteredApnsEnabled(enabled);
8632 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008633 phone.getDataSettingsManager().setDataEnabled(
8634 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008635 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008636 }
8637 } finally {
8638 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008639 }
8640 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008641
8642 /**
8643 * Get Client request stats
8644 * @return List of Client Request Stats
8645 * @hide
8646 */
8647 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008648 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8649 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008650 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008651 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008652 return null;
8653 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008654 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008655
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008656 final long identity = Binder.clearCallingIdentity();
8657 try {
8658 if (phone != null) {
8659 return phone.getClientRequestStats();
8660 }
8661
8662 return null;
8663 } finally {
8664 Binder.restoreCallingIdentity(identity);
8665 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008666 }
8667
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008668 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008669 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008670 if (uid == Process.ROOT_UID && packageName == null) {
8671 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8672 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8673 // exception. ROOT_UID seems not to have a valid package name returned by
8674 // PackageManager, so just fake it here to avoid issues when running telephony shell
8675 // commands that plumb through the RIL as root, like so:
8676 // $ adb root
8677 // $ adb shell cmd phone ...
8678 packageName = "root";
8679 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008680 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008681 }
Jack Yueb4124c2017-02-16 15:32:43 -08008682
8683 /**
Grace Chen70990072017-03-24 17:21:30 -07008684 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008685 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008686 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008687 * @param state State of SIM (power down, power up, pass through)
8688 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8689 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8690 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008691 *
8692 **/
8693 @Override
Grace Chen70990072017-03-24 17:21:30 -07008694 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008695 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008696 Phone phone = PhoneFactory.getPhone(slotIndex);
8697
vagdeviaf9a5b92018-08-15 16:01:53 -07008698 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8699
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008700 final long identity = Binder.clearCallingIdentity();
8701 try {
8702 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008703 phone.setSimPowerState(state, null, workSource);
8704 }
8705 } finally {
8706 Binder.restoreCallingIdentity(identity);
8707 }
8708 }
8709
8710 /**
8711 * Set SIM card power state.
8712 *
8713 * @param slotIndex SIM slot id.
8714 * @param state State of SIM (power down, power up, pass through)
8715 * @param callback callback to trigger after success or failure
8716 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8717 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8718 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8719 *
8720 **/
8721 @Override
8722 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8723 IIntegerConsumer callback) {
8724 enforceModifyPermission();
8725 Phone phone = PhoneFactory.getPhone(slotIndex);
8726
8727 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8728
8729 final long identity = Binder.clearCallingIdentity();
8730 try {
8731 if (phone != null) {
8732 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8733 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008734 }
8735 } finally {
8736 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008737 }
8738 }
Shuo Qiandd210312017-04-12 22:11:33 +00008739
Tyler Gunn65d45c22017-06-05 11:22:26 -07008740 private boolean isUssdApiAllowed(int subId) {
8741 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008742 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008743 if (configManager == null) {
8744 return false;
8745 }
8746 PersistableBundle pb = configManager.getConfigForSubId(subId);
8747 if (pb == null) {
8748 return false;
8749 }
8750 return pb.getBoolean(
8751 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8752 }
8753
Shuo Qiandd210312017-04-12 22:11:33 +00008754 /**
8755 * Check if phone is in emergency callback mode
8756 * @return true if phone is in emergency callback mode
8757 * @param subId sub id
8758 */
goneil9c5f4872017-12-05 14:07:56 -08008759 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008760 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008761 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008762 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008763
8764 final long identity = Binder.clearCallingIdentity();
8765 try {
8766 if (phone != null) {
8767 return phone.isInEcm();
8768 } else {
8769 return false;
8770 }
8771 } finally {
8772 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008773 }
8774 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008775
8776 /**
8777 * Get the current signal strength information for the given subscription.
8778 * Because this information is not updated when the device is in a low power state
8779 * it should not be relied-upon to be current.
8780 * @param subId Subscription index
8781 * @return the most recent cached signal strength info from the modem
8782 */
8783 @Override
8784 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008785 final long identity = Binder.clearCallingIdentity();
8786 try {
8787 Phone p = getPhone(subId);
8788 if (p == null) {
8789 return null;
8790 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008791
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008792 return p.getSignalStrength();
8793 } finally {
8794 Binder.restoreCallingIdentity(identity);
8795 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008796 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008797
Pengquan Meng77b7f132018-08-22 14:49:57 -07008798 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008799 * Get the current modem radio state for the given slot.
8800 * @param slotIndex slot index.
8801 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008802 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008803 * @return the current radio power state from the modem
8804 */
8805 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008806 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008807 Phone phone = PhoneFactory.getPhone(slotIndex);
8808 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008809 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8810 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008811 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8812 }
8813
8814 final long identity = Binder.clearCallingIdentity();
8815 try {
8816 return phone.getRadioPowerState();
8817 } finally {
8818 Binder.restoreCallingIdentity(identity);
8819 }
8820 }
8821 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8822 }
8823
8824 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008825 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8826 *
8827 * <p>Requires one of the following permissions:
8828 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008829 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008830 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8831 * privileges.
8832 *
8833 * @param subId subscription id
8834 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8835 * {@code false}.
8836 */
8837 @Override
8838 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008839 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008840 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008841 try {
8842 mApp.enforceCallingOrSelfPermission(
8843 android.Manifest.permission.ACCESS_NETWORK_STATE,
8844 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008845 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008846 mApp.enforceCallingOrSelfPermission(
8847 permission.READ_BASIC_PHONE_STATE, functionName);
8848 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008849 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008850 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008851 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008852 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008853
Pengquan Menga1bb6272018-09-06 09:59:22 -07008854 boolean isEnabled = false;
8855 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008856 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008857 Phone phone = getPhone(subId);
8858 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008859 } finally {
8860 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008861 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008862 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008863 }
8864
8865
8866 /**
8867 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8868 *
8869 * <p> Requires permission:
8870 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8871 * privileges.
8872 *
8873 * @param subId subscription id
8874 * @param isEnabled {@code true} means enable, {@code false} means disable.
8875 */
8876 @Override
8877 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8879 mApp, subId, "setDataRoamingEnabled");
8880
Pengquan Menga1bb6272018-09-06 09:59:22 -07008881 final long identity = Binder.clearCallingIdentity();
8882 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008883 Phone phone = getPhone(subId);
8884 if (phone != null) {
8885 phone.setDataRoamingEnabled(isEnabled);
8886 }
8887 } finally {
8888 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008889 }
8890 }
8891
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008892 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008893 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008894 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008895 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008896 mApp, subId, "isManualNetworkSelectionAllowed");
8897
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008898 boolean isAllowed = true;
8899 final long identity = Binder.clearCallingIdentity();
8900 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008901 Phone phone = getPhone(subId);
8902 if (phone != null) {
8903 isAllowed = phone.isCspPlmnEnabled();
8904 }
8905 } finally {
8906 Binder.restoreCallingIdentity(identity);
8907 }
8908 return isAllowed;
8909 }
8910
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008911 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8912 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008913 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008914 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008915 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008916 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8917 if (phone == null) {
8918 return false;
8919 }
8920 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8921 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8922 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008923 }
8924
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008925 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008926 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008927 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008928 mApp.getSystemService(AppOpsManager.class)
8929 .checkPackage(Binder.getCallingUid(), callingPackage);
8930
Jordan Liu1e142fc2019-04-22 15:10:43 -07008931 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008932 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008933 try {
8934 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008935 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008936 } catch (SecurityException e) {
8937 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8938 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008939 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008940 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008941 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008942 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008943 }
sandeepjsb6c87872021-09-27 15:34:44 +00008944 // checking compatibility, if calling app's target SDK is T and beyond.
8945 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8946 Binder.getCallingUid())) {
8947 isIccIdAccessRestricted = true;
8948 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008949 final long identity = Binder.clearCallingIdentity();
8950 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008951 UiccController uiccController = UiccController.getInstance();
8952 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008953 if (hasReadPermission) {
8954 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008955 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008956
8957 // Remove private info if the caller doesn't have access
8958 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8959 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008960 //setting the value after compatibility check
8961 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008962 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8963 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008964 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008965 if (card == null) {
8966 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008967 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008968 continue;
8969 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008970 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8971 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008972 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008973 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008974 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008975 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8976 for (UiccPortInfo portInfo : portInfos) {
8977 UiccPort port = uiccController.getUiccPortForSlot(
8978 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8979 if (port == null) {
8980 // assume no access if port is null
8981 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8982 continue;
8983 }
8984 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8985 uiccPortInfos.add(portInfo);
8986 } else {
8987 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8988 }
8989 }
8990 filteredInfos.add(new UiccCardInfo(
8991 cardInfo.isEuicc(),
8992 cardInfo.getCardId(),
8993 null,
8994 cardInfo.getPhysicalSlotIndex(),
8995 cardInfo.isRemovable(),
8996 cardInfo.isMultipleEnabledProfilesSupported(),
8997 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008998 }
8999 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009000 } finally {
9001 Binder.restoreCallingIdentity(identity);
9002 }
9003 }
9004
sandeepjsb6c87872021-09-27 15:34:44 +00009005 /**
9006 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9007 * generally private and require carrier privileges to view.
9008 *
9009 * @hide
9010 */
9011 @NonNull
9012 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9013 List<UiccPortInfo> portinfo = new ArrayList<>();
9014 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9015 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9016 }
9017 return new UiccCardInfo(
9018 cardInfo.isEuicc(),
9019 cardInfo.getCardId(),
9020 null,
9021 cardInfo.getPhysicalSlotIndex(),
9022 cardInfo.isRemovable(),
9023 cardInfo.isMultipleEnabledProfilesSupported(),
9024 portinfo
9025 );
9026 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009027
sandeepjsb6c87872021-09-27 15:34:44 +00009028 /**
9029 * @hide
9030 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9031 * These values are generally private and require carrier privileges to view.
9032 */
9033 @NonNull
9034 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9035 return new UiccPortInfo(
9036 UiccPortInfo.ICCID_REDACTED,
9037 portInfo.getPortIndex(),
9038 portInfo.getLogicalSlotIndex(),
9039 portInfo.isActive()
9040 );
9041 }
9042 @Override
9043 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009044 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009045 mApp.getSystemService(AppOpsManager.class)
9046 .checkPackage(Binder.getCallingUid(), callingPackage);
9047
sandeepjsb6c87872021-09-27 15:34:44 +00009048 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009049
Aman Guptaf3c90b32022-03-17 04:54:16 +00009050 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9051 // we are reading iccId which is PII data.
9052 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009053
9054 // checking compatibility, if calling app's target SDK is T and beyond.
9055 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9056 Binder.getCallingUid())) {
9057 isLogicalSlotAccessRestricted = true;
9058 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009059 final long identity = Binder.clearCallingIdentity();
9060 try {
9061 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009062 if (slots == null || slots.length == 0) {
9063 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009064 return null;
9065 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009066 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9067 for (int i = 0; i < slots.length; i++) {
9068 UiccSlot slot = slots[i];
9069 if (slot == null) {
9070 continue;
9071 }
9072
Jordan Liu7be7e652019-05-06 18:55:02 +00009073 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009074 UiccCard card = slot.getUiccCard();
9075 if (card != null) {
9076 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009077 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009078 cardId = slot.getEid();
9079 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009080 // If cardId is null, use iccId of default port as cardId.
9081 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009082 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009083 }
9084
Jordan Liu857451f2019-05-09 16:35:35 -07009085 if (cardId != null) {
9086 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9087 // if cardId is an EID, it's all digits so this is fine
9088 cardId = IccUtils.stripTrailingFs(cardId);
9089 }
9090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009091 int cardState = 0;
9092 switch (slot.getCardState()) {
9093 case CARDSTATE_ABSENT:
9094 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9095 break;
9096 case CARDSTATE_PRESENT:
9097 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9098 break;
9099 case CARDSTATE_ERROR:
9100 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9101 break;
9102 case CARDSTATE_RESTRICTED:
9103 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9104 break;
9105 default:
9106 break;
9107
9108 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009109 List<UiccPortInfo> portInfos = new ArrayList<>();
9110 int[] portIndexes = slot.getPortList();
9111 for (int portIdx : portIndexes) {
9112 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009113 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009114 portInfos.add(new UiccPortInfo(iccId, portIdx,
9115 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009116 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009117 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009118 slot.isEuicc(),
9119 cardId,
9120 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009121 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009122 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009123 //setting the value after compatibility check
9124 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009125 }
9126 return infos;
9127 } finally {
9128 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009129 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009130 }
9131
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009132 /* Returns null if doesn't have read permission or carrier privilege access. */
9133 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9134 boolean hasReadPermission) {
9135 String iccId = slot.getIccId(portIndex);
9136 if (hasReadPermission) { // if has read permission
9137 return iccId;
9138 } else {
9139 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9140 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9141 // if no read permission, checking carrier privilege access
9142 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9143 return iccId;
9144 }
9145 }
9146 }
9147 // No read permission or carrier privilege access.
9148 return UiccPortInfo.ICCID_REDACTED;
9149 }
9150
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009151 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009152 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009153 public boolean switchSlots(int[] physicalSlots) {
9154 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009155
9156 final long identity = Binder.clearCallingIdentity();
9157 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009158 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9159 for (int i = 0; i < physicalSlots.length; i++) {
9160 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9161 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9162 physicalSlots[i], i));
9163 }
9164 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009165 } finally {
9166 Binder.restoreCallingIdentity(identity);
9167 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009168 }
Jack Yu4c988042018-02-27 15:30:01 -08009169
9170 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009171 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9172 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9173 enforceModifyPermission();
9174
9175 final long identity = Binder.clearCallingIdentity();
9176 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009177 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009178 } finally {
9179 Binder.restoreCallingIdentity(identity);
9180 }
9181 }
9182
9183 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009184 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009185 final long identity = Binder.clearCallingIdentity();
9186 try {
9187 return UiccController.getInstance().getCardIdForDefaultEuicc();
9188 } finally {
9189 Binder.restoreCallingIdentity(identity);
9190 }
9191 }
9192
Pengquan Meng85728fb2018-03-12 16:31:21 -07009193 /**
goneil47ffb6e2018-04-06 15:40:58 -07009194 * A test API to reload the UICC profile.
9195 *
9196 * <p>Requires that the calling app has permission
9197 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9198 * @hide
9199 */
9200 @Override
9201 public void refreshUiccProfile(int subId) {
9202 enforceModifyPermission();
9203
9204 final long identity = Binder.clearCallingIdentity();
9205 try {
9206 Phone phone = getPhone(subId);
9207 if (phone == null) {
9208 return;
9209 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009210 UiccPort uiccPort = phone.getUiccPort();
9211 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009212 return;
9213 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009214 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009215 if (uiccProfile == null) {
9216 return;
9217 }
9218 uiccProfile.refresh();
9219 } finally {
9220 Binder.restoreCallingIdentity(identity);
9221 }
9222 }
9223
9224 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009225 * Returns false if the mobile data is disabled by default, otherwise return true.
9226 */
9227 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009228 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009229 }
9230
9231 /**
9232 * Returns true if the data roaming is enabled by default, i.e the system property
9233 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9234 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9235 */
9236 private boolean getDefaultDataRoamingEnabled(int subId) {
9237 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009238 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009239 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009240 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9241 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9242 return isDataRoamingEnabled;
9243 }
9244
9245 /**
9246 * Returns the default network type for the given {@code subId}, if the default network type is
9247 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9248 */
9249 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009250 List<Integer> list = TelephonyProperties.default_network();
9251 int phoneId = mSubscriptionController.getPhoneId(subId);
9252 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9253 return list.get(phoneId);
9254 }
9255 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009256 }
fionaxua13278b2018-03-21 00:08:13 -07009257
9258 @Override
9259 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009260 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009261 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009262
9263 final long identity = Binder.clearCallingIdentity();
9264 try {
9265 final Phone phone = getPhone(subId);
9266 if (phone == null) {
9267 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9268 return;
9269 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009270 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9271 if (cpt != null) {
9272 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9273 }
9274 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009275 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9276 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009277 if (carrierPrivilegeRules == null) {
9278 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9279 } else {
9280 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009282 } finally {
9283 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009284 }
fionaxua13278b2018-03-21 00:08:13 -07009285 }
9286
9287 @Override
9288 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009289 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009290
9291 final long identity = Binder.clearCallingIdentity();
9292 try {
9293 final Phone phone = getPhone(subId);
9294 if (phone == null) {
9295 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9296 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9297 }
9298 return phone.getCarrierIdListVersion();
9299 } finally {
9300 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009301 }
fionaxua13278b2018-03-21 00:08:13 -07009302 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009303
9304 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009305 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9306 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009307 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009308 mApp, subId, callingPackage, callingFeatureId,
9309 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009310 return -1;
9311 }
9312
9313 final long identity = Binder.clearCallingIdentity();
9314 try {
9315 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9316 } finally {
9317 Binder.restoreCallingIdentity(identity);
9318 }
9319 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009320
9321 @Override
9322 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009323 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009324 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009325 mApp, subId, "getCdmaRoamingMode");
9326
9327 final long identity = Binder.clearCallingIdentity();
9328 try {
9329 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9330 } finally {
9331 Binder.restoreCallingIdentity(identity);
9332 }
9333 }
9334
9335 @Override
9336 public boolean setCdmaRoamingMode(int subId, int mode) {
9337 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9338 mApp, subId, "setCdmaRoamingMode");
9339
9340 final long identity = Binder.clearCallingIdentity();
9341 try {
9342 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9343 } finally {
9344 Binder.restoreCallingIdentity(identity);
9345 }
9346 }
9347
9348 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009349 public int getCdmaSubscriptionMode(int subId) {
9350 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009351 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009352 mApp, subId, "getCdmaSubscriptionMode");
9353
9354 final long identity = Binder.clearCallingIdentity();
9355 try {
9356 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9357 } finally {
9358 Binder.restoreCallingIdentity(identity);
9359 }
9360 }
9361
9362 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009363 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9364 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9365 mApp, subId, "setCdmaSubscriptionMode");
9366
9367 final long identity = Binder.clearCallingIdentity();
9368 try {
9369 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9370 } finally {
9371 Binder.restoreCallingIdentity(identity);
9372 }
9373 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009374
sqianc5eccab2018-10-19 18:46:41 -07009375 @Override
sqian8c685422019-02-22 15:55:18 -08009376 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009377 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009378 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009379 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9380 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009381 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9382 }
9383 final long identity = Binder.clearCallingIdentity();
9384 try {
sqian854d44b2018-12-12 16:48:18 -08009385 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9386 for (Phone phone: PhoneFactory.getPhones()) {
9387 if (phone.getEmergencyNumberTracker() != null
9388 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9389 emergencyNumberListInternal.put(
9390 phone.getSubId(),
9391 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9392 }
sqian11b7a0e2018-12-05 18:48:28 -08009393 }
sqian854d44b2018-12-12 16:48:18 -08009394 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009395 } finally {
9396 Binder.restoreCallingIdentity(identity);
9397 }
sqianc5eccab2018-10-19 18:46:41 -07009398 }
9399
9400 @Override
sqian8c685422019-02-22 15:55:18 -08009401 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009402 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009403 if (!exactMatch) {
9404 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009405 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009406 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009407 }
9408 final long identity = Binder.clearCallingIdentity();
9409 try {
sqian854d44b2018-12-12 16:48:18 -08009410 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009411 //Note: we ignore passed in param exactMatch. We can remove it once
9412 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009413 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009414 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009415 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009416 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009417 }
sqian11b7a0e2018-12-05 18:48:28 -08009418 }
9419 return false;
9420 } finally {
9421 Binder.restoreCallingIdentity(identity);
9422 }
9423 }
9424
sqianf4ca7ed2019-01-15 18:32:07 -08009425 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009426 * Start emergency callback mode for GsmCdmaPhone for testing.
9427 */
9428 @Override
9429 public void startEmergencyCallbackMode() {
9430 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9431 "startEmergencyCallbackMode");
9432 enforceModifyPermission();
9433 final long identity = Binder.clearCallingIdentity();
9434 try {
9435 for (Phone phone : PhoneFactory.getPhones()) {
9436 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9437 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9438 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9439 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9440 gsmCdmaPhone.obtainMessage(
9441 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9442 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9443 }
9444 }
9445 } finally {
9446 Binder.restoreCallingIdentity(identity);
9447 }
9448 }
9449
9450 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009451 * Update emergency number list for test mode.
9452 */
9453 @Override
9454 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9455 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9456 "updateEmergencyNumberListTestMode");
9457
9458 final long identity = Binder.clearCallingIdentity();
9459 try {
9460 for (Phone phone: PhoneFactory.getPhones()) {
9461 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9462 if (tracker != null) {
9463 tracker.executeEmergencyNumberTestModeCommand(action, num);
9464 }
9465 }
9466 } finally {
9467 Binder.restoreCallingIdentity(identity);
9468 }
9469 }
9470
9471 /**
9472 * Get the full emergency number list for test mode.
9473 */
9474 @Override
9475 public List<String> getEmergencyNumberListTestMode() {
9476 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9477 "getEmergencyNumberListTestMode");
9478
9479 final long identity = Binder.clearCallingIdentity();
9480 try {
9481 Set<String> emergencyNumbers = new HashSet<>();
9482 for (Phone phone: PhoneFactory.getPhones()) {
9483 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9484 if (tracker != null) {
9485 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9486 emergencyNumbers.add(num.getNumber());
9487 }
9488 }
9489 }
9490 return new ArrayList<>(emergencyNumbers);
9491 } finally {
9492 Binder.restoreCallingIdentity(identity);
9493 }
9494 }
9495
chen xud6b45bd2018-10-30 22:27:10 -07009496 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009497 public int getEmergencyNumberDbVersion(int subId) {
9498 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9499
9500 final long identity = Binder.clearCallingIdentity();
9501 try {
9502 final Phone phone = getPhone(subId);
9503 if (phone == null) {
9504 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9505 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9506 }
9507 return phone.getEmergencyNumberDbVersion();
9508 } finally {
9509 Binder.restoreCallingIdentity(identity);
9510 }
9511 }
9512
9513 @Override
9514 public void notifyOtaEmergencyNumberDbInstalled() {
9515 enforceModifyPermission();
9516
9517 final long identity = Binder.clearCallingIdentity();
9518 try {
9519 for (Phone phone: PhoneFactory.getPhones()) {
9520 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9521 if (tracker != null) {
9522 tracker.updateOtaEmergencyNumberDatabase();
9523 }
9524 }
9525 } finally {
9526 Binder.restoreCallingIdentity(identity);
9527 }
9528 }
9529
9530 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009531 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009532 enforceActiveEmergencySessionPermission();
9533
9534 final long identity = Binder.clearCallingIdentity();
9535 try {
9536 for (Phone phone: PhoneFactory.getPhones()) {
9537 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9538 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009539 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9540 }
9541 }
9542 } finally {
9543 Binder.restoreCallingIdentity(identity);
9544 }
9545 }
9546
9547 @Override
9548 public void resetOtaEmergencyNumberDbFilePath() {
9549 enforceActiveEmergencySessionPermission();
9550
9551 final long identity = Binder.clearCallingIdentity();
9552 try {
9553 for (Phone phone: PhoneFactory.getPhones()) {
9554 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9555 if (tracker != null) {
9556 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009557 }
9558 }
9559 } finally {
9560 Binder.restoreCallingIdentity(identity);
9561 }
9562 }
9563
9564 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009565 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9566 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9567 Phone phone = getPhone(subId);
9568 if (phone == null) {
9569 return null;
9570 }
9571 final long identity = Binder.clearCallingIdentity();
9572 try {
9573 UiccProfile profile = UiccController.getInstance()
9574 .getUiccProfileForPhone(phone.getPhoneId());
9575 if (profile != null) {
9576 return profile.getCertsFromCarrierPrivilegeAccessRules();
9577 }
9578 } finally {
9579 Binder.restoreCallingIdentity(identity);
9580 }
9581 return null;
9582 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009583
9584 /**
9585 * Enable or disable a modem stack.
9586 */
9587 @Override
9588 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9589 enforceModifyPermission();
9590
9591 final long identity = Binder.clearCallingIdentity();
9592 try {
9593 Phone phone = PhoneFactory.getPhone(slotIndex);
9594 if (phone == null) {
9595 return false;
9596 } else {
9597 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9598 }
9599 } finally {
9600 Binder.restoreCallingIdentity(identity);
9601 }
9602 }
Michelecea4cf22018-12-21 15:00:11 -08009603
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009604 /**
9605 * Whether a modem stack is enabled or not.
9606 */
9607 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009608 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9609 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009610 Phone phone = PhoneFactory.getPhone(slotIndex);
9611 if (phone == null) return false;
9612
9613 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009614 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9615 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009616 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9617 }
9618
9619 final long identity = Binder.clearCallingIdentity();
9620 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009621 try {
9622 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9623 } catch (NoSuchElementException ex) {
9624 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9625 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009626 } finally {
9627 Binder.restoreCallingIdentity(identity);
9628 }
9629 }
9630
Michelecea4cf22018-12-21 15:00:11 -08009631 @Override
Michele0ea7d782019-03-19 14:58:42 -07009632 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009633 enforceModifyPermission();
9634
9635 final long identity = Binder.clearCallingIdentity();
9636 try {
9637 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009638 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009639 .commit();
9640 } finally {
9641 Binder.restoreCallingIdentity(identity);
9642 }
9643 }
9644
9645 @Override
Michele0ea7d782019-03-19 14:58:42 -07009646 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009647 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009648 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009649 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9650 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009651 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009652 }
Michelecea4cf22018-12-21 15:00:11 -08009653
9654 final long identity = Binder.clearCallingIdentity();
9655 try {
Michele0ea7d782019-03-19 14:58:42 -07009656 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009657 } finally {
9658 Binder.restoreCallingIdentity(identity);
9659 }
9660 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009661
Michele0ea7d782019-03-19 14:58:42 -07009662 @TelephonyManager.IsMultiSimSupportedResult
9663 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009664 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9665 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9666 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009667 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9668 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009669 }
9670 // Check if the hardware supports multisim functionality. If usage of multisim is not
9671 // supported by the modem, indicate that it is restricted.
9672 PhoneCapability staticCapability =
9673 mPhoneConfigurationManager.getStaticPhoneCapability();
9674 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009675 loge("isMultiSimSupportedInternal: no static configuration available");
9676 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009677 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009678 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009679 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9680 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009681 }
9682 // Check if support of multiple SIMs is restricted by carrier
9683 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009684 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009685 }
9686
Michele0ea7d782019-03-19 14:58:42 -07009687 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009688 }
9689
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009690 /**
9691 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009692 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9693 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9694 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009695 * @param numOfSims number of active sims we want to switch to
9696 */
9697 @Override
9698 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009699 if (numOfSims == 1) {
9700 enforceModifyPermission();
9701 } else {
9702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9703 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9704 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009705 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009706
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009707 try {
Michele30b57b22019-03-01 12:01:14 -08009708 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009709 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009710 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9711 return;
9712 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009713 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9714 } finally {
9715 Binder.restoreCallingIdentity(identity);
9716 }
9717 }
9718
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009719 @Override
9720 public boolean isApplicationOnUicc(int subId, int appType) {
9721 enforceReadPrivilegedPermission("isApplicationOnUicc");
9722 Phone phone = getPhone(subId);
9723 if (phone == null) {
9724 return false;
9725 }
9726 final long identity = Binder.clearCallingIdentity();
9727 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009728 UiccPort uiccPort = phone.getUiccPort();
9729 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009730 return false;
9731 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009732 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009733 if (uiccProfile == null) {
9734 return false;
9735 }
9736 if (TelephonyManager.APPTYPE_SIM <= appType
9737 && appType <= TelephonyManager.APPTYPE_ISIM) {
9738 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9739 }
9740 return false;
9741 } finally {
9742 Binder.restoreCallingIdentity(identity);
9743 }
9744 }
9745
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009746 /**
chen xub4baa772019-04-03 10:23:41 -07009747 * Get whether making changes to modem configurations will trigger reboot.
9748 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009749 */
9750 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009751 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9752 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009753 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009754 mApp, subId, callingPackage, callingFeatureId,
9755 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009756 return false;
9757 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009758 final long identity = Binder.clearCallingIdentity();
9759 try {
9760 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9761 } finally {
9762 Binder.restoreCallingIdentity(identity);
9763 }
9764 }
9765
Nathan Harold29f5f052019-02-15 13:41:57 -08009766 private void updateModemStateMetrics() {
9767 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9768 // TODO: check the state for each modem if the api is ready.
9769 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9770 }
9771
Pengquan Meng3889a572019-01-23 11:16:29 -08009772 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009773 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009774 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009775 // Verify that the callingPackage belongs to the calling UID
9776 mApp.getSystemService(AppOpsManager.class)
9777 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009778 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009779 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009780 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009781 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9782 if (slotInfos != null) {
9783 for (int i = 0; i < slotInfos.length; i++) {
9784 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9785 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9786 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9787 portInfo.getLogicalSlotIndex()));
9788 }
9789 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009790 }
9791 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009792 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009793 } finally {
9794 Binder.restoreCallingIdentity(identity);
9795 }
9796 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009797
9798 /**
9799 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +08009800 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -08009801 */
jimsunf9ec1622022-09-13 21:18:43 +08009802 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -08009803 @Override
9804 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +08009805 return getHalVersion(HAL_SERVICE_RADIO);
9806 }
9807
9808 /**
9809 * Get the HAL Version of a specific service
9810 */
9811 @Override
9812 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -08009813 Phone phone = getDefaultPhone();
9814 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +08009815 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -08009816 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9817 return hv.major * 100 + hv.minor;
9818 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009819
9820 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009821 * Get the current calling package name.
9822 * @return the current calling package name
9823 */
9824 @Override
9825 public String getCurrentPackageName() {
9826 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9827 }
9828
9829 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009830 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9831 * corresponding network requests on a subId.
9832 *
9833 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009834 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009835 * 2) APN is un-metered for this subscription, or
9836 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009837 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009838 *
9839 * @return whether data is allowed for a apn type.
9840 *
9841 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009842 */
9843 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009844 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009845 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9846 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009847
9848 // Now that all security checks passes, perform the operation as ourselves.
9849 final long identity = Binder.clearCallingIdentity();
9850 try {
9851 Phone phone = getPhone(subId);
9852 if (phone == null) return false;
9853
Jack Yu27422a52022-03-21 10:38:05 -07009854 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009855 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -07009856 isMetered = phone.getDataNetworkController().getDataConfigManager()
9857 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9858 phone.getServiceState().getDataRoaming());
9859 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009860 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009861 } finally {
9862 Binder.restoreCallingIdentity(identity);
9863 }
9864 }
9865
9866 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009867 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009868 enforceReadPrivilegedPermission("isApnMetered");
9869
9870 // Now that all security checks passes, perform the operation as ourselves.
9871 final long identity = Binder.clearCallingIdentity();
9872 try {
9873 Phone phone = getPhone(subId);
9874 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -07009875 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9876 DataUtils.apnTypeToNetworkCapability(apnType),
9877 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009878 } finally {
9879 Binder.restoreCallingIdentity(identity);
9880 }
9881 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009882
9883 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009884 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9885 int subscriptionId, IBooleanConsumer resultCallback) {
9886 enforceModifyPermission();
9887 long token = Binder.clearCallingIdentity();
9888 try {
9889 Phone phone = getPhone(subscriptionId);
9890 if (phone == null) {
9891 try {
9892 if (resultCallback != null) {
9893 resultCallback.accept(false);
9894 }
9895 } catch (RemoteException e) {
9896 // ignore
9897 }
9898 return;
9899 }
9900 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9901 Pair.create(specifiers, (x) -> {
9902 try {
9903 if (resultCallback != null) {
9904 resultCallback.accept(x);
9905 }
9906 } catch (RemoteException e) {
9907 // ignore
9908 }
9909 });
9910 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9911 } finally {
9912 Binder.restoreCallingIdentity(token);
9913 }
9914 }
9915
9916 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009917 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9918 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009919 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009920 mApp, subId, "getSystemSelectionChannels");
9921 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9922 final long identity = Binder.clearCallingIdentity();
9923 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009924 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9925 if (result instanceof IllegalStateException) {
9926 throw (IllegalStateException) result;
9927 }
9928 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009929 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9930 return specifiers;
9931 } finally {
9932 Binder.restoreCallingIdentity(identity);
9933 }
9934 }
9935
9936 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009937 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009938 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009939 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009940 }
9941
9942 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009943 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9944 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009945 if (callingPackage == null) {
9946 callingPackage = getCurrentPackageName();
9947 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009948 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9949 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009950 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9951 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009952 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9953 }
9954 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9955 Intent intent = new Intent();
9956 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9957 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9958 // Bring up choose default SMS subscription dialog right now
9959 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9960 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9961 mApp.startActivity(intent);
9962 }
chen xud5ca2d52019-05-28 15:20:57 -07009963
9964 @Override
9965 public String getMmsUAProfUrl(int subId) {
9966 //TODO investigate if this API should require proper permission check in R b/133791609
9967 final long identity = Binder.clearCallingIdentity();
9968 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009969 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9970 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9971 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9972 return carrierUAProfUrl;
9973 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009974 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9975 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009976 } finally {
9977 Binder.restoreCallingIdentity(identity);
9978 }
9979 }
9980
9981 @Override
9982 public String getMmsUserAgent(int subId) {
9983 //TODO investigate if this API should require proper permission check in R b/133791609
9984 final long identity = Binder.clearCallingIdentity();
9985 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009986 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9987 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9988 if (!TextUtils.isEmpty(carrierUserAgent)) {
9989 return carrierUserAgent;
9990 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009991 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9992 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009993 } finally {
9994 Binder.restoreCallingIdentity(identity);
9995 }
9996 }
Jack Yub07d4972019-05-28 16:12:25 -07009997
9998 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009999 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10000 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010001
Jack Yub07d4972019-05-28 16:12:25 -070010002 final long identity = Binder.clearCallingIdentity();
10003 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010004 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010005 if (phone == null) return false;
10006
Ling Maf188d502022-09-16 15:22:36 -070010007 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010008 } finally {
10009 Binder.restoreCallingIdentity(identity);
10010 }
10011 }
10012
10013 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010014 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010015 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010016 enforceModifyPermission();
10017
changbettyd5c246e2019-12-24 15:40:37 +080010018 final long identity = Binder.clearCallingIdentity();
10019 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010020 Phone phone = getPhone(subscriptionId);
10021 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010022
Ling Maf188d502022-09-16 15:22:36 -070010023 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010024 } finally {
10025 Binder.restoreCallingIdentity(identity);
10026 }
10027 }
10028
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010029 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010030 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010031 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10032 * otherwise.
10033 */
10034 @Override
10035 public void setCepEnabled(boolean isCepEnabled) {
10036 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10037
10038 final long identity = Binder.clearCallingIdentity();
10039 try {
10040 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10041 for (Phone phone : PhoneFactory.getPhones()) {
10042 Phone defaultPhone = phone.getImsPhone();
10043 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10044 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10045 ImsPhoneCallTracker imsPhoneCallTracker =
10046 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10047 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10048 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10049 + imsPhone.getMsisdn());
10050 }
10051 }
10052 } finally {
10053 Binder.restoreCallingIdentity(identity);
10054 }
10055 }
allenwtsu46dcc572020-01-08 18:24:03 +080010056
10057 /**
10058 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10059 *
10060 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10061 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10062 * before being read.
10063 */
10064 @Override
10065 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10066 isCompressed) {
10067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10068 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010069 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10070 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10071 }
10072 if (!isImsAvailableOnDevice()) {
10073 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10074 "IMS not available on device.");
10075 }
10076
10077 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010078 try {
Hui Wang761a6682020-10-31 05:12:53 +000010079 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10080 } finally {
10081 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010082 }
10083 }
zoey chene02881a2019-12-30 16:11:23 +080010084
10085 @Override
10086 public boolean isIccLockEnabled(int subId) {
10087 enforceReadPrivilegedPermission("isIccLockEnabled");
10088
10089 // Now that all security checks passes, perform the operation as ourselves.
10090 final long identity = Binder.clearCallingIdentity();
10091 try {
10092 Phone phone = getPhone(subId);
10093 if (phone != null && phone.getIccCard() != null) {
10094 return phone.getIccCard().getIccLockEnabled();
10095 } else {
10096 return false;
10097 }
10098 } finally {
10099 Binder.restoreCallingIdentity(identity);
10100 }
10101 }
10102
10103 /**
10104 * Set the ICC pin lock enabled or disabled.
10105 *
10106 * @return an integer representing the status of IccLock enabled or disabled in the following
10107 * three cases:
10108 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10109 * successfully.
10110 * - Positive number and zero for remaining password attempts.
10111 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10112 *
10113 */
10114 @Override
10115 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10116 enforceModifyPermission();
10117
10118 Phone phone = getPhone(subId);
10119 if (phone == null) {
10120 return 0;
10121 }
10122 // Now that all security checks passes, perform the operation as ourselves.
10123 final long identity = Binder.clearCallingIdentity();
10124 try {
10125 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10126 new Pair<Boolean, String>(enabled, password), phone, null);
10127 return attemptsRemaining;
10128
10129 } catch (Exception e) {
10130 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10131 } finally {
10132 Binder.restoreCallingIdentity(identity);
10133 }
10134 return 0;
10135 }
10136
10137 /**
10138 * Change the ICC password used in ICC pin lock.
10139 *
10140 * @return an integer representing the status of IccLock changed in the following three cases:
10141 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10142 * - Positive number and zero for remaining password attempts.
10143 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10144 *
10145 */
10146 @Override
10147 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10148 enforceModifyPermission();
10149
10150 Phone phone = getPhone(subId);
10151 if (phone == null) {
10152 return 0;
10153 }
10154 // Now that all security checks passes, perform the operation as ourselves.
10155 final long identity = Binder.clearCallingIdentity();
10156 try {
10157 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10158 new Pair<String, String>(oldPassword, newPassword), phone, null);
10159 return attemptsRemaining;
10160
10161 } catch (Exception e) {
10162 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10163 } finally {
10164 Binder.restoreCallingIdentity(identity);
10165 }
10166 return 0;
10167 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010168
10169 /**
10170 * Request for receiving user activity notification
10171 */
10172 @Override
10173 public void requestUserActivityNotification() {
10174 if (!mNotifyUserActivity.get()
10175 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10176 mNotifyUserActivity.set(true);
10177 }
10178 }
10179
10180 /**
10181 * Called when userActivity is signalled in the power manager.
10182 * This is safe to call from any thread, with any window manager locks held or not.
10183 */
10184 @Override
10185 public void userActivity() {
10186 // ***************************************
10187 // * Inherited from PhoneWindowManager *
10188 // ***************************************
10189 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10190 // WITH ITS LOCKS HELD.
10191 //
10192 // This code must be VERY careful about the locks
10193 // it acquires.
10194 // In fact, the current code acquires way too many,
10195 // and probably has lurking deadlocks.
10196
10197 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10198 throw new SecurityException("Only the OS may call notifyUserActivity()");
10199 }
10200
10201 if (mNotifyUserActivity.getAndSet(false)) {
10202 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10203 USER_ACTIVITY_NOTIFICATION_DELAY);
10204 }
10205 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010206
10207 @Override
10208 public boolean canConnectTo5GInDsdsMode() {
10209 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10210 }
Jack Yud10cdd42020-09-28 20:28:01 -070010211
10212 @Override
10213 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10214 String callingFeatureId) {
10215 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10216 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10217 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10218 }
10219
10220 Phone phone = getPhone(subId);
10221 if (phone == null) {
10222 throw new RuntimeException("phone is not available");
10223 }
10224 // Now that all security checks passes, perform the operation as ourselves.
10225 final long identity = Binder.clearCallingIdentity();
10226 try {
10227 return phone.getEquivalentHomePlmns();
10228 } finally {
10229 Binder.restoreCallingIdentity(identity);
10230 }
10231 }
Daniel Bright59e67312020-11-13 11:49:37 -080010232
10233 @Override
10234 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010235 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10236 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010237 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010238 if (radioInterfaceCapabilities == null) {
10239 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010240 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010241 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010242 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010243
Hui Wang641e81c2020-10-12 12:14:23 -070010244 @Override
10245 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10246 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010247 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10248 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10249 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10250 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10251 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010252 if (DBG) {
10253 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10254 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10255 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10256 }
10257
10258 if (!SubscriptionManager.isValidSubscriptionId(subId)
10259 || appType < TelephonyManager.APPTYPE_UNKNOWN
10260 || appType > TelephonyManager.APPTYPE_ISIM
10261 || nafUrl == null || securityProtocol == null || callback == null) {
10262 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10263 if (callback != null) {
10264 try {
10265 callback.onAuthenticationFailure(
10266 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10267 } catch (RemoteException exception) {
10268 log("Fail to notify onAuthenticationFailure due to " + exception);
10269 }
10270 return;
10271 }
10272 }
10273
10274 final long token = Binder.clearCallingIdentity();
10275 try {
10276 getGbaManager(subId).bootstrapAuthenticationRequest(
10277 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10278 forceBootStrapping, callback));
10279 } finally {
10280 Binder.restoreCallingIdentity(token);
10281 }
10282 }
10283
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010284 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010285 * Attempts to set the radio power state for all phones for thermal reason.
10286 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010287 * requested radio power state will actually be set. See {@link
10288 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10289 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010290 * @param enable {@code true} if trying to turn radio on.
10291 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10292 * false}.
10293 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010294 private boolean setRadioPowerForThermal(boolean enable) {
10295 boolean isPhoneAvailable = false;
10296 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10297 Phone phone = PhoneFactory.getPhone(i);
10298 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010299 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010300 isPhoneAvailable = true;
10301 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010302 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010303
10304 // return true if successfully informed the phone object about the thermal radio power
10305 // request.
10306 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010307 }
10308
10309 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010310 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010311 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10312 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10313 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10314 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10315 throw new IllegalArgumentException("modem does not support data throttling");
10316 }
10317
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010318 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10319 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010320 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010321 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10322 }
10323
Sarah Chinecc78c42022-03-31 21:16:48 -070010324 setDataEnabledForReason(
10325 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010326
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010327 if (isDataThrottlingSupported) {
10328 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010329 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010330 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10331 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10332 } else if (thermalMitigationResult
10333 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010334 log("Modem likely does not support data throttling on secondary carrier. Data " +
10335 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10336 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010337 }
10338 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010339 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010340
10341 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010342 }
10343
Jack Nudelman644b91a2021-03-12 14:09:48 -080010344 private static List<String> getThermalMitigationAllowlist(Context context) {
10345 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10346 for (String pckg : context.getResources()
10347 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10348 sThermalMitigationAllowlistedPackages.add(pckg);
10349 }
10350 }
10351
10352 return sThermalMitigationAllowlistedPackages;
10353 }
10354
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010355 private boolean isAnyPhoneInEmergencyState() {
10356 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10357 if (tm.isInEmergencyCall()) {
10358 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10359 return true;
10360 }
10361 for (Phone phone : PhoneFactory.getPhones()) {
10362 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10363 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10364 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10365 + phone.isInEcm());
10366 return true;
10367 }
10368 }
10369
10370 return false;
10371 }
10372
Jack Nudelman644b91a2021-03-12 14:09:48 -080010373 /**
10374 * Used by shell commands to add an authorized package name for thermal mitigation.
10375 * @param packageName name of package to be allowlisted
10376 * @param context
10377 */
10378 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10379 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10380 sThermalMitigationAllowlistedPackages.add(packageName);
10381 }
10382
10383 /**
10384 * Used by shell commands to remove an authorized package name for thermal mitigation.
10385 * @param packageName name of package to remove from allowlist
10386 * @param context
10387 */
10388 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10389 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10390 sThermalMitigationAllowlistedPackages.remove(packageName);
10391 }
10392
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010393 /**
10394 * Thermal mitigation request to control functionalities at modem.
10395 *
10396 * @param subId the id of the subscription.
10397 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010398 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010399 *
10400 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10401 */
10402 @Override
10403 @ThermalMitigationResult
10404 public int sendThermalMitigationRequest(
10405 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010406 ThermalMitigationRequest thermalMitigationRequest,
10407 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010408 enforceModifyPermission();
10409
Jack Nudelman644b91a2021-03-12 14:09:48 -080010410 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10411 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10412 .contains(callingPackage)) {
10413 throw new SecurityException("Calling package must be configured in the device config. "
10414 + "calling package: " + callingPackage);
10415 }
10416
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010417 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10418 final long identity = Binder.clearCallingIdentity();
10419
10420 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10421 try {
10422 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10423 switch (thermalMitigationAction) {
10424 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10425 thermalMitigationResult =
10426 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010427 thermalMitigationRequest.getDataThrottlingRequest(),
10428 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010429 break;
10430 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10431 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10432 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10433 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10434 }
10435
10436 // Ensure that radio is on. If not able to power on due to phone being
10437 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010438 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010439 thermalMitigationResult =
10440 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10441 break;
10442 }
10443
10444 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010445 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010446 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10447 break;
10448 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10449 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10450 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10451 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10452 }
10453
10454 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10455 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010456 Phone phone = getPhone(subId);
10457 if (phone == null) {
10458 thermalMitigationResult =
10459 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10460 break;
10461 }
10462
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010463 TelephonyConnectionService service =
10464 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010465 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010466 Log.e(LOG_TAG, "An emergency call is pending");
10467 thermalMitigationResult =
10468 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10469 break;
10470 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010471 thermalMitigationResult =
10472 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10473 break;
10474 }
10475 } else {
10476 thermalMitigationResult =
10477 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10478 break;
10479 }
10480
10481 // Turn radio off. If not able to power off due to phone being unavailable,
10482 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010483 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010484 thermalMitigationResult =
10485 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10486 break;
10487 }
10488 thermalMitigationResult =
10489 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10490 break;
10491 default:
10492 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10493 + "not exist. Requested action: " + thermalMitigationAction);
10494 }
10495 } catch (IllegalArgumentException e) {
10496 throw e;
10497 } catch (Exception e) {
10498 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10499 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10500 } finally {
10501 Binder.restoreCallingIdentity(identity);
10502 }
10503
10504 if (DBG) {
10505 log("thermalMitigationRequest returning with thermalMitigationResult: "
10506 + thermalMitigationResult);
10507 }
10508
10509 return thermalMitigationResult;
10510 }
Hui Wang641e81c2020-10-12 12:14:23 -070010511
10512 /**
10513 * Set the GbaService Package Name that Telephony will bind to.
10514 *
10515 * @param subId The sim that the GbaService is associated with.
10516 * @param packageName The name of the package to be replaced with.
10517 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10518 */
10519 @Override
10520 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10521 enforceModifyPermission();
10522
10523 final long identity = Binder.clearCallingIdentity();
10524 try {
10525 return getGbaManager(subId).overrideServicePackage(packageName);
10526 } finally {
10527 Binder.restoreCallingIdentity(identity);
10528 }
10529 }
10530
10531 /**
10532 * Return the package name of the currently bound GbaService.
10533 *
10534 * @param subId The sim that the GbaService is associated with.
10535 * @return the package name of the GbaService configuration, null if GBA is not supported.
10536 */
10537 @Override
10538 public String getBoundGbaService(int subId) {
10539 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10540
10541 final long identity = Binder.clearCallingIdentity();
10542 try {
10543 return getGbaManager(subId).getServicePackage();
10544 } finally {
10545 Binder.restoreCallingIdentity(identity);
10546 }
10547 }
10548
10549 /**
10550 * Set the release time for telephony to unbind GbaService.
10551 *
10552 * @param subId The sim that the GbaService is associated with.
10553 * @param interval The release time to unbind GbaService by millisecond.
10554 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10555 */
10556 @Override
10557 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10558 enforceModifyPermission();
10559
10560 final long identity = Binder.clearCallingIdentity();
10561 try {
10562 return getGbaManager(subId).overrideReleaseTime(interval);
10563 } finally {
10564 Binder.restoreCallingIdentity(identity);
10565 }
10566 }
10567
10568 /**
10569 * Return the release time for telephony to unbind GbaService.
10570 *
10571 * @param subId The sim that the GbaService is associated with.
10572 * @return The release time to unbind GbaService by millisecond.
10573 */
10574 @Override
10575 public int getGbaReleaseTime(int subId) {
10576 enforceReadPrivilegedPermission("getGbaReleaseTime");
10577
10578 final long identity = Binder.clearCallingIdentity();
10579 try {
10580 return getGbaManager(subId).getReleaseTime();
10581 } finally {
10582 Binder.restoreCallingIdentity(identity);
10583 }
10584 }
10585
10586 private GbaManager getGbaManager(int subId) {
10587 GbaManager instance = GbaManager.getInstance(subId);
10588 if (instance == null) {
10589 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10590 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10591 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10592 }
10593 return instance;
10594 }
Hui Wang761a6682020-10-31 05:12:53 +000010595
10596 /**
10597 * indicate whether the device and the carrier can support
10598 * RCS VoLTE single registration.
10599 */
10600 @Override
10601 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010602 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10603 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10604 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10605 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010606
10607 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10608 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10609 }
10610
10611 final long identity = Binder.clearCallingIdentity();
10612 try {
10613 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10614 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010615 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10616 if (isCapable != null) {
10617 return isCapable;
10618 }
Hui Wang761a6682020-10-31 05:12:53 +000010619 }
Hui Wang67af90e2021-06-04 16:57:15 -070010620 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10621 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010622 } finally {
10623 Binder.restoreCallingIdentity(identity);
10624 }
10625 }
10626
10627 /**
10628 * Register RCS provisioning callback.
10629 */
10630 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010631 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010632 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010633 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010634 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010635 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10636 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010637
10638 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10639 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10640 }
10641 if (!isImsAvailableOnDevice()) {
10642 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10643 "IMS not available on device.");
10644 }
10645
10646 final long identity = Binder.clearCallingIdentity();
10647 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010648 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010649 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010650 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10651 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010652 }
Hui Wang761a6682020-10-31 05:12:53 +000010653 } finally {
10654 Binder.restoreCallingIdentity(identity);
10655 }
10656 }
10657
10658 /**
10659 * Unregister RCS provisioning callback.
10660 */
10661 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010662 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010663 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010664 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010665 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010666 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10667 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010668
10669 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10670 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10671 }
10672 if (!isImsAvailableOnDevice()) {
10673 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10674 "IMS not available on device.");
10675 }
10676
10677 final long identity = Binder.clearCallingIdentity();
10678 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010679 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010680 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010681 } finally {
10682 Binder.restoreCallingIdentity(identity);
10683 }
10684 }
10685
10686 /**
10687 * trigger RCS reconfiguration.
10688 */
10689 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010690 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10691 "triggerRcsReconfiguration",
10692 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010693
10694 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10695 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10696 }
10697 if (!isImsAvailableOnDevice()) {
10698 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10699 "IMS not available on device.");
10700 }
10701
10702 final long identity = Binder.clearCallingIdentity();
10703 try {
10704 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10705 } finally {
10706 Binder.restoreCallingIdentity(identity);
10707 }
10708 }
10709
10710 /**
10711 * Provide the client configuration parameters of the RCS application.
10712 */
10713 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010714 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10715 "setRcsClientConfiguration",
10716 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010717
10718 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10719 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10720 }
10721 if (!isImsAvailableOnDevice()) {
10722 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10723 "IMS not available on device.");
10724 }
10725
10726 final long identity = Binder.clearCallingIdentity();
10727
10728 try {
10729 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10730 if (configBinder == null) {
10731 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010732 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10733 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010734 } else {
10735 configBinder.setRcsClientConfiguration(rcc);
10736 }
joonhunshin3e154242021-09-17 06:33:39 +000010737
10738 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10739 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010740 } catch (RemoteException e) {
10741 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010742 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10743 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010744 } finally {
10745 Binder.restoreCallingIdentity(identity);
10746 }
10747 }
10748
10749 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010750 * Enables or disables the test mode for RCS VoLTE single registration.
10751 */
10752 @Override
10753 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10754 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10755 "setRcsSingleRegistrationTestModeEnabled");
10756
10757 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10758 }
10759
10760 /**
10761 * Gets the test mode for RCS VoLTE single registration.
10762 */
10763 @Override
10764 public boolean getRcsSingleRegistrationTestModeEnabled() {
10765 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10766 "getRcsSingleRegistrationTestModeEnabled");
10767
10768 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10769 }
10770
10771 /**
Hui Wang761a6682020-10-31 05:12:53 +000010772 * Overrides the config of RCS VoLTE single registration enabled for the device.
10773 */
10774 @Override
10775 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10776 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10777 "setDeviceSingleRegistrationEnabledOverride");
10778 enforceModifyPermission();
10779
10780 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10781 : Boolean.parseBoolean(enabledStr);
10782 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010783 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010784 }
10785
10786 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010787 * Sends a device to device communication message. Only usable via shell.
10788 * @param message message to send.
10789 * @param value message value.
10790 */
10791 @Override
10792 public void sendDeviceToDeviceMessage(int message, int value) {
10793 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010794 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010795 enforceModifyPermission();
10796
10797 final long identity = Binder.clearCallingIdentity();
10798 try {
10799 TelephonyConnectionService service =
10800 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10801 if (service == null) {
10802 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10803 return;
10804 }
10805 service.sendTestDeviceToDeviceMessage(message, value);
10806 } finally {
10807 Binder.restoreCallingIdentity(identity);
10808 }
10809 }
10810
Tyler Gunnbabbda02021-02-10 11:05:02 -080010811 /**
10812 * Sets the specified device to device transport active.
10813 * @param transport The transport to set active.
10814 */
10815 @Override
10816 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10817 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10818 "setActiveDeviceToDeviceTransport");
10819 enforceModifyPermission();
10820
10821 final long identity = Binder.clearCallingIdentity();
10822 try {
10823 TelephonyConnectionService service =
10824 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10825 if (service == null) {
10826 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10827 return;
10828 }
10829 service.setActiveDeviceToDeviceTransport(transport);
10830 } finally {
10831 Binder.restoreCallingIdentity(identity);
10832 }
10833 }
Tyler Gunn92479152021-01-20 16:30:10 -080010834
Tyler Gunnd4339262021-05-03 14:46:49 -070010835 @Override
10836 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10837 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10838 "setDeviceToDeviceForceEnabled");
10839
10840 final long identity = Binder.clearCallingIdentity();
10841 try {
10842 Arrays.stream(PhoneFactory.getPhones()).forEach(
10843 p -> {
10844 Phone thePhone = p.getImsPhone();
10845 if (thePhone != null && thePhone instanceof ImsPhone) {
10846 ImsPhone imsPhone = (ImsPhone) thePhone;
10847 CallTracker tracker = imsPhone.getCallTracker();
10848 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10849 ImsPhoneCallTracker imsPhoneCallTracker =
10850 (ImsPhoneCallTracker) tracker;
10851 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10852 }
10853 }
10854 }
10855 );
10856 } finally {
10857 Binder.restoreCallingIdentity(identity);
10858 }
10859 }
10860
Tyler Gunn92479152021-01-20 16:30:10 -080010861 /**
Hui Wang761a6682020-10-31 05:12:53 +000010862 * Gets the config of RCS VoLTE single registration enabled for the device.
10863 */
10864 @Override
10865 public boolean getDeviceSingleRegistrationEnabled() {
10866 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10867 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10868 }
10869
10870 /**
10871 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10872 */
10873 @Override
10874 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10875 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10876 "setCarrierSingleRegistrationEnabledOverride");
10877 enforceModifyPermission();
10878
10879 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10880 : Boolean.parseBoolean(enabledStr);
10881 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10882 subId, enabled);
10883 }
10884
10885 /**
10886 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10887 */
10888 @Override
10889 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10890 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10891 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10892 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010893
10894 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010895 * Overrides the ims feature validation result
10896 */
10897 @Override
10898 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10899 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10900 "setImsFeatureValidationOverride");
10901
10902 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10903 : Boolean.parseBoolean(enabledStr);
10904 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10905 subId, enabled);
10906 }
10907
10908 /**
10909 * Gets the ims feature validation override value
10910 */
10911 @Override
10912 public boolean getImsFeatureValidationOverride(int subId) {
10913 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10914 "getImsFeatureValidationOverride");
10915 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10916 }
10917
10918 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010919 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10920 * their mobile plan.
10921 */
10922 @Override
10923 public String getMobileProvisioningUrl() {
10924 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10925 final long identity = Binder.clearCallingIdentity();
10926 try {
10927 return getDefaultPhone().getMobileProvisioningUrl();
10928 } finally {
10929 Binder.restoreCallingIdentity(identity);
10930 }
10931 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010932
James.cf Linbcdf8b32021-01-14 16:44:13 +080010933 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010934 * Get the EAB contact from the EAB database.
10935 */
10936 @Override
10937 public String getContactFromEab(String contact) {
10938 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10939 enforceModifyPermission();
10940 final long identity = Binder.clearCallingIdentity();
10941 try {
10942 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10943 } finally {
10944 Binder.restoreCallingIdentity(identity);
10945 }
10946 }
10947
10948 /**
Calvin Pana1434322021-07-01 19:27:01 +080010949 * Get the EAB capability from the EAB database.
10950 */
10951 @Override
10952 public String getCapabilityFromEab(String contact) {
10953 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10954 enforceModifyPermission();
10955 final long identity = Binder.clearCallingIdentity();
10956 try {
10957 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10958 } finally {
10959 Binder.restoreCallingIdentity(identity);
10960 }
10961 }
10962
10963 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010964 * Remove the EAB contacts from the EAB database.
10965 */
10966 @Override
10967 public int removeContactFromEab(int subId, String contacts) {
10968 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10969 enforceModifyPermission();
10970 final long identity = Binder.clearCallingIdentity();
10971 try {
10972 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10973 } finally {
10974 Binder.restoreCallingIdentity(identity);
10975 }
10976 }
10977
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010978 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010979 public boolean getDeviceUceEnabled() {
10980 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10981 final long identity = Binder.clearCallingIdentity();
10982 try {
10983 return mApp.getDeviceUceEnabled();
10984 } finally {
10985 Binder.restoreCallingIdentity(identity);
10986 }
10987 }
10988
10989 @Override
10990 public void setDeviceUceEnabled(boolean isEnabled) {
10991 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10992 final long identity = Binder.clearCallingIdentity();
10993 try {
10994 mApp.setDeviceUceEnabled(isEnabled);
10995 } finally {
10996 Binder.restoreCallingIdentity(identity);
10997 }
10998 }
10999
Brad Ebinger14d467f2021-02-12 06:18:28 +000011000 /**
11001 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11002 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11003 */
11004 // Used for SHELL command only right now.
11005 @Override
11006 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11007 List<String> featureTags) {
11008 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11009 "addUceRegistrationOverrideShell");
11010 final long identity = Binder.clearCallingIdentity();
11011 try {
11012 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11013 new ArraySet<>(featureTags));
11014 } catch (ImsException e) {
11015 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11016 } finally {
11017 Binder.restoreCallingIdentity(identity);
11018 }
11019 }
11020
11021 /**
11022 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11023 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11024 */
11025 // Used for SHELL command only right now.
11026 @Override
11027 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11028 List<String> featureTags) {
11029 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11030 "removeUceRegistrationOverrideShell");
11031 final long identity = Binder.clearCallingIdentity();
11032 try {
11033 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11034 new ArraySet<>(featureTags));
11035 } catch (ImsException e) {
11036 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11037 } finally {
11038 Binder.restoreCallingIdentity(identity);
11039 }
11040 }
11041
11042 /**
11043 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11044 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11045 */
11046 // Used for SHELL command only right now.
11047 @Override
11048 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11049 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11050 "clearUceRegistrationOverrideShell");
11051 final long identity = Binder.clearCallingIdentity();
11052 try {
11053 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11054 } catch (ImsException e) {
11055 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11056 } finally {
11057 Binder.restoreCallingIdentity(identity);
11058 }
11059 }
11060
11061 /**
11062 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11063 */
11064 // Used for SHELL command only right now.
11065 @Override
11066 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11067 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11068 "getLatestRcsContactUceCapabilityShell");
11069 final long identity = Binder.clearCallingIdentity();
11070 try {
11071 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11072 } catch (ImsException e) {
11073 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11074 } finally {
11075 Binder.restoreCallingIdentity(identity);
11076 }
11077 }
11078
11079 /**
11080 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11081 * device does not have an active PUBLISH.
11082 */
11083 // Used for SHELL command only right now.
11084 @Override
11085 public String getLastUcePidfXmlShell(int subId) {
11086 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11087 final long identity = Binder.clearCallingIdentity();
11088 try {
11089 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11090 } catch (ImsException e) {
11091 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11092 } finally {
11093 Binder.restoreCallingIdentity(identity);
11094 }
11095 }
11096
James.cf Line8713a42021-04-29 16:04:26 +080011097 /**
11098 * Remove UCE requests cannot be sent to the network status.
11099 */
11100 // Used for SHELL command only right now.
11101 @Override
11102 public boolean removeUceRequestDisallowedStatus(int subId) {
11103 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11104 final long identity = Binder.clearCallingIdentity();
11105 try {
11106 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11107 } catch (ImsException e) {
11108 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11109 } finally {
11110 Binder.restoreCallingIdentity(identity);
11111 }
11112 }
11113
James.cf Lin18bb9002021-05-25 01:37:38 +080011114 /**
11115 * Remove UCE requests cannot be sent to the network status.
11116 */
11117 // Used for SHELL command only.
11118 @Override
11119 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11120 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11121 final long identity = Binder.clearCallingIdentity();
11122 try {
11123 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11124 } catch (ImsException e) {
11125 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11126 } finally {
11127 Binder.restoreCallingIdentity(identity);
11128 }
11129 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011130
James.cf Lin4b784aa2021-01-31 03:25:15 +080011131 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011132 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11133 String callingPackage) {
11134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11135 mApp, subId, "setSignalStrengthUpdateRequest");
11136
11137 final int callingUid = Binder.getCallingUid();
11138 // Verify that tha callingPackage belongs to the calling UID
11139 mApp.getSystemService(AppOpsManager.class)
11140 .checkPackage(callingUid, callingPackage);
11141
Rambo Wang3607f502021-02-01 21:51:40 -080011142 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011143
11144 final long identity = Binder.clearCallingIdentity();
11145 try {
11146 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11147 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11148
11149 if (result instanceof IllegalStateException) {
11150 throw (IllegalStateException) result;
11151 }
11152 } finally {
11153 Binder.restoreCallingIdentity(identity);
11154 }
11155 }
11156
11157 @Override
11158 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11159 String callingPackage) {
11160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11161 mApp, subId, "clearSignalStrengthUpdateRequest");
11162
11163 final int callingUid = Binder.getCallingUid();
11164 // Verify that tha callingPackage belongs to the calling UID
11165 mApp.getSystemService(AppOpsManager.class)
11166 .checkPackage(callingUid, callingPackage);
11167
11168 final long identity = Binder.clearCallingIdentity();
11169 try {
11170 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11171 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11172
11173 if (result instanceof IllegalStateException) {
11174 throw (IllegalStateException) result;
11175 }
11176 } finally {
11177 Binder.restoreCallingIdentity(identity);
11178 }
11179 }
11180
Rambo Wang3607f502021-02-01 21:51:40 -080011181 private static void validateSignalStrengthUpdateRequest(Context context,
11182 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011183 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11184 // phone/system process do not have further restriction on request
11185 return;
11186 }
11187
11188 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011189 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011190 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011191 context.enforceCallingOrSelfPermission(
11192 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11193 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011194 }
11195
11196 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11197 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11198 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11199 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11200 || info.isEnabled()) {
11201 throw new IllegalArgumentException(
11202 "Only system can set hide fields in SignalThresholdInfo");
11203 }
11204
11205 // Thresholds length for each RAN need in range. This has been validated in
11206 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11207 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11208 final int[] thresholds = info.getThresholds();
11209 Objects.requireNonNull(thresholds);
11210 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11211 || thresholds.length
11212 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11213 throw new IllegalArgumentException(
11214 "thresholds length is out of range: " + thresholds.length);
11215 }
11216 }
11217 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011218
11219 /**
11220 * Gets the current phone capability.
11221 *
11222 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11223 * @return the PhoneCapability which describes the data connection capability of modem.
11224 * It's used to evaluate possible phone config change, for example from single
11225 * SIM device to multi-SIM device.
11226 */
11227 @Override
11228 public PhoneCapability getPhoneCapability() {
11229 enforceReadPrivilegedPermission("getPhoneCapability");
11230 final long identity = Binder.clearCallingIdentity();
11231 try {
11232 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11233 } finally {
11234 Binder.restoreCallingIdentity(identity);
11235 }
11236 }
Michele Berionne5e411512020-11-13 02:36:59 +000011237
11238 /**
11239 * Prepare TelephonyManager for an unattended reboot. The reboot is
11240 * required to be done shortly after the API is invoked.
11241 */
11242 @Override
11243 @TelephonyManager.PrepareUnattendedRebootResult
11244 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011245 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011246 enforceRebootPermission();
11247
11248 final long identity = Binder.clearCallingIdentity();
11249 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011250 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011251 } finally {
11252 Binder.restoreCallingIdentity(identity);
11253 }
11254 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011255
11256 /**
11257 * Request to get the current slicing configuration including URSP rules and
11258 * NSSAIs (configured, allowed and rejected).
11259 *
11260 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11261 */
11262 @Override
11263 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011264 TelephonyPermissions
11265 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11266 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011267
11268 final long identity = Binder.clearCallingIdentity();
11269 try {
11270 Phone phone = getDefaultPhone();
11271 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11272 } finally {
11273 Binder.restoreCallingIdentity(identity);
11274 }
11275 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011276
11277 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011278 * Check whether the given premium capability is available for purchase from the carrier.
11279 *
11280 * @param capability The premium capability to check.
11281 * @param subId The subId to check the premium capability for.
11282 *
11283 * @return Whether the given premium capability is available to purchase.
11284 */
11285 @Override
11286 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11287 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11288 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11289 log("Premium capability "
11290 + TelephonyManager.convertPremiumCapabilityToString(capability)
11291 + " is not available for purchase due to missing permissions.");
11292 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11293 + "permission READ_BASIC_PHONE_STATE.");
11294 }
11295
11296 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011297 if (phone == null) {
11298 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11299 return false;
11300 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011301 final long identity = Binder.clearCallingIdentity();
11302 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011303 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011304 .isPremiumCapabilityAvailableForPurchase(capability);
11305 } finally {
11306 Binder.restoreCallingIdentity(identity);
11307 }
11308 }
11309
11310 /**
11311 * Purchase the given premium capability from the carrier.
11312 *
11313 * @param capability The premium capability to purchase.
11314 * @param callback The result of the purchase request.
11315 * @param subId The subId to purchase the premium capability for.
11316 */
11317 @Override
11318 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11319 log("purchasePremiumCapability: capability="
11320 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11321 + getCurrentPackageName());
11322
11323 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11324 mApp, "purchasePremiumCapability")) {
11325 log("purchasePremiumCapability "
11326 + TelephonyManager.convertPremiumCapabilityToString(capability)
11327 + " failed due to missing permissions.");
11328 throw new SecurityException("purchasePremiumCapability requires permission "
11329 + "READ_BASIC_PHONE_STATE.");
11330 }
11331
11332 Phone phone = getPhone(subId);
Sarah Chin71b3a852022-09-28 15:54:19 -070011333 String appName;
11334 try {
11335 appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager()
11336 .getApplicationInfo(getCurrentPackageName(), 0)).toString();
11337 } catch (PackageManager.NameNotFoundException e) {
11338 appName = "An application";
11339 }
11340 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
11341 new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011342 }
11343
11344 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011345 * Register an IMS connection state callback
11346 */
11347 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011348 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11349 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011350 if (feature == ImsFeature.FEATURE_MMTEL) {
11351 // ImsMmTelManager
11352 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11353 TelephonyPermissions
11354 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11355 mApp, subId, "registerImsStateCallback");
11356 } else if (feature == ImsFeature.FEATURE_RCS) {
11357 // ImsRcsManager or SipDelegateManager
11358 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11359 Binder.getCallingUid(), "registerImsStateCallback",
11360 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11361 Manifest.permission.READ_PRECISE_PHONE_STATE,
11362 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11363 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11364 }
11365
11366 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11367 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11368 "IMS not available on device.");
11369 }
11370
11371 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11372 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11373 }
11374
11375 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11376 if (controller == null) {
11377 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11378 "IMS not available on device.");
11379 }
11380
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011381 if (callingPackage == null) {
11382 callingPackage = getCurrentPackageName();
11383 }
11384
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011385 final long token = Binder.clearCallingIdentity();
11386 try {
11387 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011388 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011389 } catch (ImsException e) {
11390 throw new ServiceSpecificException(e.getCode());
11391 } finally {
11392 Binder.restoreCallingIdentity(token);
11393 }
11394 }
11395
11396 /**
11397 * Unregister an IMS connection state callback
11398 */
11399 @Override
11400 public void unregisterImsStateCallback(IImsStateCallback cb) {
11401 final long token = Binder.clearCallingIdentity();
11402 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11403 if (controller == null) {
11404 return;
11405 }
11406 try {
11407 controller.unregisterImsStateCallback(cb);
11408 } finally {
11409 Binder.restoreCallingIdentity(token);
11410 }
11411 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011412
11413 /**
11414 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11415 *
11416 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11417 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11418 * SecurityException.
11419 * If there is current registered network this value will be same as the registered cell
11420 * identity. If the device goes out of service the previous cell identity is cached and
11421 * will be returned. If the cache age of the Cell identity is more than 24 hours
11422 * it will be cleared and null will be returned.
11423 *
11424 */
11425 @Override
11426 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11427 String callingFeatureId) {
11428 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11429 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11430 LocationAccessPolicy.checkLocationPermission(mApp,
11431 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11432 .setCallingPackage(callingPackage)
11433 .setCallingFeatureId(callingFeatureId)
11434 .setCallingPid(Binder.getCallingPid())
11435 .setCallingUid(Binder.getCallingUid())
11436 .setMethod("getLastKnownCellIdentity")
11437 .setLogAsInfo(true)
11438 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11439 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11440 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11441 .build());
11442
11443 boolean hasFinePermission =
11444 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11445 if (!hasFinePermission
11446 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11447 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011448 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011449 }
11450
11451 final long identity = Binder.clearCallingIdentity();
11452 try {
11453 Phone phone = getPhone(subId);
11454 if (phone == null) return null;
11455 ServiceStateTracker sst = phone.getServiceStateTracker();
11456 if (sst == null) return null;
11457 return sst.getLastKnownCellIdentity();
11458 } finally {
11459 Binder.restoreCallingIdentity(identity);
11460 }
11461 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011462
jimsun3b9ccac2021-10-26 15:01:23 +080011463 /**
11464 * Sets the modem service class Name that Telephony will bind to.
11465 *
11466 * @param serviceName The class name of the modem service.
11467 * @return true if the operation is succeed, otherwise false.
11468 */
11469 public boolean setModemService(String serviceName) {
11470 Log.d(LOG_TAG, "setModemService - " + serviceName);
11471 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11472 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11473 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11474 "setModemService");
11475 return mPhoneConfigurationManager.setModemService(serviceName);
11476 }
11477
11478 /**
11479 * Return the class name of the currently bounded modem service.
11480 *
11481 * @return the class name of the modem service.
11482 */
11483 public String getModemService() {
11484 String result;
11485 Log.d(LOG_TAG, "getModemService");
11486 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11487 TelephonyPermissions
11488 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11489 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11490 "getModemService");
11491 result = mPhoneConfigurationManager.getModemService();
11492 Log.d(LOG_TAG, "result = " + result);
11493 return result;
11494 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011495
11496 @Override
11497 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11498 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11499 mApp.enforceCallingOrSelfPermission(
11500 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11501 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11502
11503 final long identity = Binder.clearCallingIdentity();
11504 try {
11505 Phone phone = getPhone(subId);
11506 if (phone == null) return;
11507 phone.setVoiceServiceStateOverride(hasService);
11508 } finally {
11509 Binder.restoreCallingIdentity(identity);
11510 }
11511 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011512
11513 /**
11514 * set removable eSIM as default eUICC.
11515 *
11516 * @hide
11517 */
11518 @Override
11519 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11520 enforceModifyPermission();
11521 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11522
11523 final long identity = Binder.clearCallingIdentity();
11524 try {
11525 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11526 } finally {
11527 Binder.restoreCallingIdentity(identity);
11528 }
11529 }
11530
11531 /**
11532 * Returns whether the removable eSIM is default eUICC or not.
11533 *
11534 * @hide
11535 */
11536 @Override
11537 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11538 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11539 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11540
11541 final long identity = Binder.clearCallingIdentity();
11542 try {
11543 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11544 } finally {
11545 Binder.restoreCallingIdentity(identity);
11546 }
11547 }
11548
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011549 /**
11550 * Get the component name of the default app to direct respond-via-message intent for the
11551 * user associated with this subscription, update the cache if there is no respond-via-message
11552 * application currently configured for this user.
11553 * @return component name of the app and class to direct Respond Via Message intent to, or
11554 * {@code null} if the functionality is not supported.
11555 * @hide
11556 */
11557 @Override
11558 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11559 boolean updateIfNeeded) {
11560 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011561
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011562 Context context = getPhone(subId).getContext();
11563 UserHandle userHandle = null;
11564 final long identity = Binder.clearCallingIdentity();
11565 try {
11566 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11567 } finally {
11568 Binder.restoreCallingIdentity(identity);
11569 }
11570 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11571 updateIfNeeded, userHandle);
11572 }
11573}