blob: 29d02eff537e26ce1a9b5b3fc3705b0c304ec7d8 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000020import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080021import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Hall Liud892bec2018-11-30 14:51:45 -080022
Shuo Qianccbaf742021-02-22 18:32:21 -080023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
24import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070025import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000027import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070028
Brad Ebinger34c09a52021-02-17 23:23:21 +000029import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080030import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080031import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070032import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000033import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080034import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080036import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070037import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000038import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080039import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000040import android.compat.annotation.ChangeId;
41import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070042import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070043import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.content.Context;
45import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070046import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070047import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070048import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.net.Uri;
50import android.os.AsyncResult;
51import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080052import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Bundle;
54import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070055import android.os.IBinder;
tom hsu0b59d292022-09-29 23:49:21 +080056import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.os.Looper;
58import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070059import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080060import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070061import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070062import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080063import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080064import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070065import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070066import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080067import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070069import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070070import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070071import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070072import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080073import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070074import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000075import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090076import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080077import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080078import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070079import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080080import android.telephony.AccessNetworkConstants;
81import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070082import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070083import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080084import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070085import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080086import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070087import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080088import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060089import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -070090import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080091import android.telephony.CellIdentityCdma;
92import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070094import android.telephony.CellInfoGsm;
95import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070096import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080097import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070098import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070099import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700100import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800101import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700102import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800103import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700104import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800105import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800106import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700107import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800108import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700109import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800110import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800111import android.telephony.SignalStrengthUpdateRequest;
112import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800113import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800114import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800115import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700116import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700117import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800118import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800119import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800120import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800121import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000122import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000123import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000124import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700125import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700126import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800127import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800128import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700129import android.telephony.gba.GbaAuthRequest;
130import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700131import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800132import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000133import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000134import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700135import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000136import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700137import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800138import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700139import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800140import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700141import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000142import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700143import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800144import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800145import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800147import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700148import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800150import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800151
Andrew Lee312e8172014-10-23 17:01:36 -0700152import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800153import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800154import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800155import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800156import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700157import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700158import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700159import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800160import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800161import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700162import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800164import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700165import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800166import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800167import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800168import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700169import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000170import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700171import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800172import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800174import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800175import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800176import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700177import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700178import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700179import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700180import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700181import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800182import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700183import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700184import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700185import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700186import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800187import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800188import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700189import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000190import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700191import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700192import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800193import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800194import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800195import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700196import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000197import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800198import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700199import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800200import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700201import com.android.internal.telephony.imsphone.ImsPhone;
202import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000203import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800204import com.android.internal.telephony.metrics.TelephonyMetrics;
Jack Yu285100e2022-12-02 22:48:35 -0800205import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
206import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700207import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700208import com.android.internal.telephony.uicc.IccIoResult;
209import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800210import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700211import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800212import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700213import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000214import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800215import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000216import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800217import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000218import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700219import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700220import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800221import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800222import com.android.phone.callcomposer.CallComposerPictureManager;
223import com.android.phone.callcomposer.CallComposerPictureTransfer;
224import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700225import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700226import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000227import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700228import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800229import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700230import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700231import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800232import com.android.services.telephony.TelecomAccountRegistry;
233import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800234import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800235
Hall Liu82694d52020-12-11 18:22:04 -0800236import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700237import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800238import java.io.IOException;
239import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700240import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700241import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800242import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000243import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800244import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800245import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800246import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800247import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100248import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800249import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700250import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800251import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800252import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700253import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800254import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800255import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800256import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700257
258/**
259 * Implementation of the ITelephony interface.
260 */
Santos Cordon117fee72014-05-16 17:56:12 -0700261public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700262 private static final String LOG_TAG = "PhoneInterfaceManager";
263 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
264 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800265 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700266
267 // Message codes used with mMainThreadHandler
268 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700269 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
270 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700271 private static final int CMD_OPEN_CHANNEL = 9;
272 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
273 private static final int CMD_CLOSE_CHANNEL = 11;
274 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800275 private static final int CMD_NV_READ_ITEM = 13;
276 private static final int EVENT_NV_READ_ITEM_DONE = 14;
277 private static final int CMD_NV_WRITE_ITEM = 15;
278 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
279 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
280 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700281 private static final int CMD_RESET_MODEM_CONFIG = 19;
282 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800283 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
284 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800285 private static final int CMD_SEND_ENVELOPE = 25;
286 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000287 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
288 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700289 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
290 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
291 private static final int CMD_EXCHANGE_SIM_IO = 31;
292 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800293 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
294 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700295 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
296 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700297 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
298 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700299 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
300 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
301 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
302 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700303 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
304 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
305 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
306 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700307 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800308 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
309 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000310 private static final int CMD_SWITCH_SLOTS = 50;
311 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700312 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
313 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
314 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
315 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
316 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
317 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
318 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
319 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700320 private static final int CMD_GET_ALL_CELL_INFO = 60;
321 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
322 private static final int CMD_GET_CELL_LOCATION = 62;
323 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700324 private static final int CMD_MODEM_REBOOT = 64;
325 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700326 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
327 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800328 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
329 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700330 private static final int CMD_GET_MODEM_STATUS = 70;
331 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700332 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
333 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700334 private static final int CMD_ERASE_MODEM_CONFIG = 74;
335 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800336 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
337 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
338 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
339 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800340 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
341 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800342 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800343 private static final int CMD_GET_CALL_FORWARDING = 83;
344 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
345 private static final int CMD_SET_CALL_FORWARDING = 85;
346 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
347 private static final int CMD_GET_CALL_WAITING = 87;
348 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
349 private static final int CMD_SET_CALL_WAITING = 89;
350 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700351 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
352 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
353 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
354 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700355 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
356 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800357 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
358 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800359 private static final int CMD_SET_DATA_THROTTLING = 99;
360 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800361 private static final int CMD_SET_SIM_POWER = 101;
362 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800363 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
364 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
365 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
366 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800367 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
368 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000369 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800370 private static final int CMD_GET_SLICING_CONFIG = 110;
371 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800372 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700373 private static final int CMD_ENABLE_VONR = 113;
374 private static final int EVENT_ENABLE_VONR_DONE = 114;
375 private static final int CMD_IS_VONR_ENABLED = 115;
376 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700377 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
378 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800379 // Parameters of select command.
380 private static final int SELECT_COMMAND = 0xA4;
381 private static final int SELECT_P1 = 0x04;
382 private static final int SELECT_P2 = 0;
383 private static final int SELECT_P3 = 0x10;
384
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000385 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
386 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
387
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388 /** The singleton instance. */
389 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800390 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700391
Wink Saville3ab207e2014-11-20 13:07:20 -0800392 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800393 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800394 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700395 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800396 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700397 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800398 private MainThreadHandler mMainThreadHandler;
Jack Yue37dd262022-12-16 11:53:37 -0800399 private final SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800400 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700401 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800402 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700403
Peter Wangdafb9ac2020-01-15 14:13:38 -0800404 /** User Activity */
405 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800406 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
407
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700408 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
409
Derek Tan97ebb422014-09-05 16:55:38 -0700410 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
411 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800412 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800413 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700414
Michelecea4cf22018-12-21 15:00:11 -0800415 // String to store multi SIM allowed
416 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
417
Derek Tan740e1672017-06-27 14:56:27 -0700418 // The AID of ISD-R.
419 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
420
yinxub1bed742017-04-17 11:45:04 -0700421 private NetworkScanRequestTracker mNetworkScanRequestTracker;
422
David Kelly5e06a7f2018-03-12 14:10:59 +0000423 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
424 private static final int MANUFACTURER_CODE_LENGTH = 8;
425
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800426 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800427 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800428
Sarah Chin2ec39f62022-08-31 17:03:26 -0700429 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
430 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
431
Derek Tan89e89d42014-07-08 17:00:10 -0700432 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700433 * Experiment flag to enable erase modem config on reset network, default value is false
434 */
435 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
436 "reset_network_erase_modem_config_enabled";
437
Rambo Wang0f050d82021-02-12 11:43:36 -0800438 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800439
Gary Jian76280a42022-12-07 16:18:33 +0800440 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
441
sandeepjsb6c87872021-09-27 15:34:44 +0000442 /**
443 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
444 * one ICCID active at the same time.
445 * Apps should use below API signatures if targeting SDK is T and beyond.
446 *
447 * @hide
448 */
449 @ChangeId
450 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
451 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800452
Naina Nallurid63128d2019-09-17 14:10:30 -0700453 /**
Chen Xu540470b2021-12-14 17:15:47 -0800454 * Apps targeting on Android T and beyond will get exception whenever icc close channel
455 * operation fails.
456 */
457 @ChangeId
458 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
459 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
460
461 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700462 * A request object to use for transmitting data to an ICC.
463 */
464 private static final class IccAPDUArgument {
465 public int channel, cla, command, p1, p2, p3;
466 public String data;
467
468 public IccAPDUArgument(int channel, int cla, int command,
469 int p1, int p2, int p3, String data) {
470 this.channel = channel;
471 this.cla = cla;
472 this.command = command;
473 this.p1 = p1;
474 this.p2 = p2;
475 this.p3 = p3;
476 this.data = data;
477 }
478 }
479
480 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700481 * A request object to use for transmitting data to an ICC.
482 */
483 private static final class ManualNetworkSelectionArgument {
484 public OperatorInfo operatorInfo;
485 public boolean persistSelection;
486
487 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
488 this.operatorInfo = operatorInfo;
489 this.persistSelection = persistSelection;
490 }
491 }
492
Sarah Chin71b3a852022-09-28 15:54:19 -0700493 private static final class PurchasePremiumCapabilityArgument {
494 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700495 public @NonNull IIntegerConsumer callback;
496
497 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800498 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700499 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700500 this.callback = callback;
501 }
502 }
503
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700504 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700505 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
506 * request after sending. The main thread will notify the request when it is complete.
507 */
508 private static final class MainThreadRequest {
509 /** The argument to use for the request */
510 public Object argument;
511 /** The result of the request that is run on the main thread */
512 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800513 // The subscriber id that this request applies to. Defaults to
514 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
515 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700516
Nathan Harold92bed182018-10-12 18:16:49 -0700517 // In cases where subId is unavailable, the caller needs to specify the phone.
518 public Phone phone;
519
vagdeviaf9a5b92018-08-15 16:01:53 -0700520 public WorkSource workSource;
521
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700522 public MainThreadRequest(Object argument) {
523 this.argument = argument;
524 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800525
Nathan Harold92bed182018-10-12 18:16:49 -0700526 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
527 this.argument = argument;
528 if (phone != null) {
529 this.phone = phone;
530 }
531 this.workSource = workSource;
532 }
533
vagdeviaf9a5b92018-08-15 16:01:53 -0700534 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800535 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800536 if (subId != null) {
537 this.subId = subId;
538 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700539 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800540 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700541 }
542
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800543 private static final class IncomingThirdPartyCallArgs {
544 public final ComponentName component;
545 public final String callId;
546 public final String callerDisplayName;
547
548 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
549 String callerDisplayName) {
550 this.component = component;
551 this.callId = callId;
552 this.callerDisplayName = callerDisplayName;
553 }
554 }
555
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700556 /**
557 * A handler that processes messages on the main thread in the phone process. Since many
558 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
559 * inbound binder threads to the main thread in the phone process. The Binder thread
560 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
561 * on, which will be notified when the operation completes and will contain the result of the
562 * request.
563 *
564 * <p>If a MainThreadRequest object is provided in the msg.obj field,
565 * note that request.result must be set to something non-null for the calling thread to
566 * unblock.
567 */
568 private final class MainThreadHandler extends Handler {
569 @Override
570 public void handleMessage(Message msg) {
571 MainThreadRequest request;
572 Message onCompleted;
573 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000574 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700575 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800576 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700577
578 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700579 case CMD_HANDLE_USSD_REQUEST: {
580 request = (MainThreadRequest) msg.obj;
581 final Phone phone = getPhoneFromRequest(request);
582 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800583 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700584 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700585
Pengquan Menga1bb6272018-09-06 09:59:22 -0700586 if (!isUssdApiAllowed(request.subId)) {
587 // Carrier does not support use of this API, return failure.
588 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
589 UssdResponse response = new UssdResponse(ussdRequest, null);
590 Bundle returnData = new Bundle();
591 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
592 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700593
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 request.result = true;
595 notifyRequester(request);
596 return;
597 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700598
Pengquan Menga1bb6272018-09-06 09:59:22 -0700599 try {
600 request.result = phone != null
601 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
602 } catch (CallStateException cse) {
603 request.result = false;
604 }
605 // Wake up the requesting thread
606 notifyRequester(request);
607 break;
pkanwar32d516d2016-10-14 19:37:38 -0700608 }
609
Yorke Lee716f67e2015-06-17 15:39:16 -0700610 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700611 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700612 final Phone phone = getPhoneFromRequest(request);
613 request.result = phone != null ?
614 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
615 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700616 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700618 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700619 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700620
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000624 uiccPort = getUiccPortFromRequest(request);
625 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700626 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800627 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700629 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800631 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000632 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800633 iccArgument.channel, iccArgument.cla, iccArgument.command,
634 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
635 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700636 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 break;
638
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 ar = (AsyncResult) msg.obj;
641 request = (MainThreadRequest) ar.userObj;
642 if (ar.exception == null && ar.result != null) {
643 request.result = ar.result;
644 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800645 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 if (ar.result == null) {
647 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800648 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800650 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 } else {
652 loge("iccTransmitApduLogicalChannel: Unknown exception");
653 }
654 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700655 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700656 break;
657
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
659 request = (MainThreadRequest) msg.obj;
660 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000661 uiccPort = getUiccPortFromRequest(request);
662 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700663 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800664 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700665 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700666 } else {
667 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800668 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000669 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800670 iccArgument.cla, iccArgument.command, iccArgument.p1,
671 iccArgument.p2,
672 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700673 }
674 break;
675
676 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
677 ar = (AsyncResult) msg.obj;
678 request = (MainThreadRequest) ar.userObj;
679 if (ar.exception == null && ar.result != null) {
680 request.result = ar.result;
681 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800682 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700683 if (ar.result == null) {
684 loge("iccTransmitApduBasicChannel: Empty response");
685 } else if (ar.exception instanceof CommandException) {
686 loge("iccTransmitApduBasicChannel: CommandException: " +
687 ar.exception);
688 } else {
689 loge("iccTransmitApduBasicChannel: Unknown exception");
690 }
691 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700692 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700693 break;
694
695 case CMD_EXCHANGE_SIM_IO:
696 request = (MainThreadRequest) msg.obj;
697 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000698 uiccPort = getUiccPortFromRequest(request);
699 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700700 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800701 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700702 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700703 } else {
704 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
705 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000706 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
708 iccArgument.data, onCompleted);
709 }
710 break;
711
712 case EVENT_EXCHANGE_SIM_IO_DONE:
713 ar = (AsyncResult) msg.obj;
714 request = (MainThreadRequest) ar.userObj;
715 if (ar.exception == null && ar.result != null) {
716 request.result = ar.result;
717 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800718 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700719 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700720 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700721 break;
722
Derek Tan4d5e5c12014-02-04 11:54:58 -0800723 case CMD_SEND_ENVELOPE:
724 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000725 uiccPort = getUiccPortFromRequest(request);
726 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700727 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800728 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700729 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700730 } else {
731 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800732 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700733 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800734 break;
735
736 case EVENT_SEND_ENVELOPE_DONE:
737 ar = (AsyncResult) msg.obj;
738 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700739 if (ar.exception == null && ar.result != null) {
740 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800741 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800742 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700743 if (ar.result == null) {
744 loge("sendEnvelopeWithStatus: Empty response");
745 } else if (ar.exception instanceof CommandException) {
746 loge("sendEnvelopeWithStatus: CommandException: " +
747 ar.exception);
748 } else {
749 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
750 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800751 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700752 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800753 break;
754
Shishir Agrawal566b7612013-10-28 14:41:00 -0700755 case CMD_OPEN_CHANNEL:
756 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000757 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800758 IccLogicalChannelRequest openChannelRequest =
759 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000760 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700761 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800762 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800763 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700764 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700765 } else {
766 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800767 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
768 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700769 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700770 break;
771
772 case EVENT_OPEN_CHANNEL_DONE:
773 ar = (AsyncResult) msg.obj;
774 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700775 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700776 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700777 int[] result = (int[]) ar.result;
778 int channelId = result[0];
779 byte[] selectResponse = null;
780 if (result.length > 1) {
781 selectResponse = new byte[result.length - 1];
782 for (int i = 1; i < result.length; ++i) {
783 selectResponse[i - 1] = (byte) result[i];
784 }
785 }
786 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800787 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800788
789 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700790 if (uiccPort == null) {
791 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
792 } else {
793 IccLogicalChannelRequest channelRequest =
794 (IccLogicalChannelRequest) request.argument;
795 channelRequest.channel = channelId;
796 uiccPort.onLogicalChannelOpened(channelRequest);
797 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700798 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700799 if (ar.result == null) {
800 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700801 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700802 if (ar.exception != null) {
803 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
804 }
805
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700806 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700807 if (ar.exception instanceof CommandException) {
808 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800809 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700810 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700811 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700812 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700813 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700814 }
815 }
816 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800817 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700818 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700819 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700820 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700821 break;
822
823 case CMD_CLOSE_CHANNEL:
824 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000825 uiccPort = getUiccPortFromRequest(request);
826 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700827 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800828 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800829 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800830 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700831 } else {
832 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000833 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700834 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700835 break;
836
837 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800838 ar = (AsyncResult) msg.obj;
839 request = (MainThreadRequest) ar.userObj;
840 if (ar.exception == null) {
841 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800842 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700843 if (uiccPort == null) {
844 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
845 } else {
846 final int channelId = (Integer) request.argument;
847 uiccPort.onLogicalChannelClosed(channelId);
848 }
Chen Xu540470b2021-12-14 17:15:47 -0800849 } else {
850 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800851 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800852 if (ar.exception instanceof CommandException) {
853 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
854 CommandException.Error error =
855 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800856 if (error == CommandException.Error.INVALID_ARGUMENTS) {
857 // should only throw exceptions from the binder threads.
858 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800859 "iccCloseLogicalChannel: invalid argument ");
860 }
861 } else {
862 loge("iccCloseLogicalChannel: Unknown exception");
863 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800864 request.result = (exception != null) ? exception :
865 new IllegalStateException(
866 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800867 }
868 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800869 break;
870
871 case CMD_NV_READ_ITEM:
872 request = (MainThreadRequest) msg.obj;
873 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800874 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
875 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800876 break;
877
878 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700879 ar = (AsyncResult) msg.obj;
880 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800881 if (ar.exception == null && ar.result != null) {
882 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700883 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800884 request.result = "";
885 if (ar.result == null) {
886 loge("nvReadItem: Empty response");
887 } else if (ar.exception instanceof CommandException) {
888 loge("nvReadItem: CommandException: " +
889 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700890 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800891 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700892 }
893 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700894 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700895 break;
896
Jake Hambye994d462014-02-03 13:10:13 -0800897 case CMD_NV_WRITE_ITEM:
898 request = (MainThreadRequest) msg.obj;
899 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
900 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800901 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700902 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800903 break;
904
905 case EVENT_NV_WRITE_ITEM_DONE:
906 handleNullReturnEvent(msg, "nvWriteItem");
907 break;
908
909 case CMD_NV_WRITE_CDMA_PRL:
910 request = (MainThreadRequest) msg.obj;
911 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800912 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800913 break;
914
915 case EVENT_NV_WRITE_CDMA_PRL_DONE:
916 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
917 break;
918
chen xu6dac5ab2018-10-26 17:39:23 -0700919 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800920 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700921 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800922 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800923 break;
924
chen xu6dac5ab2018-10-26 17:39:23 -0700925 case EVENT_RESET_MODEM_CONFIG_DONE:
926 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800927 break;
928
Sooraj Sasindran37444802020-08-11 10:40:43 -0700929 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
930 request = (MainThreadRequest) msg.obj;
931 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
932 request);
933 Phone phone = getPhoneFromRequest(request);
934 if (phone != null) {
935 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
936 } else {
937 loge("isNRDualConnectivityEnabled: No phone object");
938 request.result = false;
939 notifyRequester(request);
940 }
941 break;
942 }
943
944 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
945 ar = (AsyncResult) msg.obj;
946 request = (MainThreadRequest) ar.userObj;
947 if (ar.exception == null && ar.result != null) {
948 request.result = ar.result;
949 } else {
950 // request.result must be set to something non-null
951 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700952 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700953 request.result = ar.result;
954 } else {
955 request.result = false;
956 }
957 if (ar.result == null) {
958 loge("isNRDualConnectivityEnabled: Empty response");
959 } else if (ar.exception instanceof CommandException) {
960 loge("isNRDualConnectivityEnabled: CommandException: "
961 + ar.exception);
962 } else {
963 loge("isNRDualConnectivityEnabled: Unknown exception");
964 }
965 }
966 notifyRequester(request);
967 break;
968
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700969 case CMD_IS_VONR_ENABLED: {
970 request = (MainThreadRequest) msg.obj;
971 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
972 request);
973 Phone phone = getPhoneFromRequest(request);
974 if (phone != null) {
975 phone.isVoNrEnabled(onCompleted, request.workSource);
976 } else {
977 loge("isVoNrEnabled: No phone object");
978 request.result = false;
979 notifyRequester(request);
980 }
981 break;
982 }
983
984 case EVENT_IS_VONR_ENABLED_DONE:
985 ar = (AsyncResult) msg.obj;
986 request = (MainThreadRequest) ar.userObj;
987 if (ar.exception == null && ar.result != null) {
988 request.result = ar.result;
989 } else {
990 // request.result must be set to something non-null
991 // for the calling thread to unblock
992 if (ar.result != null) {
993 request.result = ar.result;
994 } else {
995 request.result = false;
996 }
997 if (ar.result == null) {
998 loge("isVoNrEnabled: Empty response");
999 } else if (ar.exception instanceof CommandException) {
1000 loge("isVoNrEnabled: CommandException: "
1001 + ar.exception);
1002 } else {
1003 loge("isVoNrEnabled: Unknown exception");
1004 }
1005 }
1006 notifyRequester(request);
1007 break;
1008
Sooraj Sasindran37444802020-08-11 10:40:43 -07001009 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1010 request = (MainThreadRequest) msg.obj;
1011 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1012 Phone phone = getPhoneFromRequest(request);
1013 if (phone != null) {
1014 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1015 request.workSource);
1016 } else {
1017 loge("enableNrDualConnectivity: No phone object");
1018 request.result =
1019 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1020 notifyRequester(request);
1021 }
1022 break;
1023 }
1024
1025 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1026 ar = (AsyncResult) msg.obj;
1027 request = (MainThreadRequest) ar.userObj;
1028 if (ar.exception == null) {
1029 request.result =
1030 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1031 } else {
1032 request.result =
1033 TelephonyManager
1034 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1035 if (ar.exception instanceof CommandException) {
1036 CommandException.Error error =
1037 ((CommandException) (ar.exception)).getCommandError();
1038 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1039 request.result =
1040 TelephonyManager
1041 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001042 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1043 request.result =
1044 TelephonyManager
1045 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001046 }
1047 loge("enableNrDualConnectivity" + ": CommandException: "
1048 + ar.exception);
1049 } else {
1050 loge("enableNrDualConnectivity" + ": Unknown exception");
1051 }
1052 }
1053 notifyRequester(request);
1054 break;
1055 }
1056
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001057 case CMD_ENABLE_VONR: {
1058 request = (MainThreadRequest) msg.obj;
1059 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1060 Phone phone = getPhoneFromRequest(request);
1061 if (phone != null) {
1062 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1063 request.workSource);
1064 } else {
1065 loge("setVoNrEnabled: No phone object");
1066 request.result =
1067 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1068 notifyRequester(request);
1069 }
1070 break;
1071 }
1072
1073 case EVENT_ENABLE_VONR_DONE: {
1074 ar = (AsyncResult) msg.obj;
1075 request = (MainThreadRequest) ar.userObj;
1076 if (ar.exception == null) {
1077 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1078 } else {
1079 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1080 if (ar.exception instanceof CommandException) {
1081 CommandException.Error error =
1082 ((CommandException) (ar.exception)).getCommandError();
1083 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1084 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1085 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1086 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1087 } else {
1088 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1089 }
1090 loge("setVoNrEnabled" + ": CommandException: "
1091 + ar.exception);
1092 } else {
1093 loge("setVoNrEnabled" + ": Unknown exception");
1094 }
1095 }
1096 notifyRequester(request);
1097 break;
1098 }
1099
SongFerngWang3ef3e072020-12-21 16:41:52 +08001100 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001101 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001102 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1103 request);
1104 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001105 break;
1106
SongFerngWang3ef3e072020-12-21 16:41:52 +08001107 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001108 ar = (AsyncResult) msg.obj;
1109 request = (MainThreadRequest) ar.userObj;
1110 if (ar.exception == null && ar.result != null) {
1111 request.result = ar.result; // Integer
1112 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301113 // request.result must be set to something non-null
1114 // for the calling thread to unblock
1115 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001116 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001117 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001118 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001119 loge("getAllowedNetworkTypesBitmask: CommandException: "
1120 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001121 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001122 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001123 }
1124 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001125 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001126 break;
1127
SongFerngWang3ef3e072020-12-21 16:41:52 +08001128 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001129 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001130 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1131 request);
1132 Pair<Integer, Long> reasonWithNetworkTypes =
1133 (Pair<Integer, Long>) request.argument;
1134 getPhoneFromRequest(request).setAllowedNetworkTypes(
1135 reasonWithNetworkTypes.first,
1136 reasonWithNetworkTypes.second,
1137 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001138 break;
1139
SongFerngWang3ef3e072020-12-21 16:41:52 +08001140 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1141 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001142 break;
1143
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001144 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1145 request = (MainThreadRequest)msg.obj;
1146 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001147 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001148 break;
1149
1150 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1151 ar = (AsyncResult)msg.obj;
1152 request = (MainThreadRequest)ar.userObj;
1153 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001154 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001155 break;
1156
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001157 case CMD_SET_VOICEMAIL_NUMBER:
1158 request = (MainThreadRequest) msg.obj;
1159 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1160 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001161 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1162 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001163 break;
1164
1165 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1166 handleNullReturnEvent(msg, "setVoicemailNumber");
1167 break;
1168
Stuart Scott54788802015-03-30 13:18:01 -07001169 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1170 request = (MainThreadRequest) msg.obj;
1171 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1172 request);
1173 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1174 break;
1175
1176 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1177 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1178 break;
1179
Shishir Agrawal302c8692015-06-19 13:49:39 -07001180 case CMD_PERFORM_NETWORK_SCAN:
1181 request = (MainThreadRequest) msg.obj;
1182 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1183 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1184 break;
1185
Hall Liu27d24262020-09-18 19:04:59 -07001186 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001187 request = (MainThreadRequest) msg.obj;
1188 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001189 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1190 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1191 request.argument;
1192 int callForwardingReason = args.first;
1193 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001194 break;
Hall Liu27d24262020-09-18 19:04:59 -07001195 }
1196 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001197 ar = (AsyncResult) msg.obj;
1198 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001199 TelephonyManager.CallForwardingInfoCallback callback =
1200 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1201 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001202 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001203 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001204 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1205 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1206 // Service Class is a bit mask per 3gpp 27.007. Search for
1207 // any service for voice call.
1208 if ((callForwardInfo.serviceClass
1209 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001210 callForwardingInfo = new CallForwardingInfo(
1211 callForwardInfo.status
1212 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001213 callForwardInfo.reason,
1214 callForwardInfo.number,
1215 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001216 break;
1217 }
1218 }
1219 // Didn't find a call forward info for voice call.
1220 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001221 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1222 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001223 }
Hall Liu27d24262020-09-18 19:04:59 -07001224 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001225 } else {
1226 if (ar.result == null) {
1227 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1228 }
1229 if (ar.exception != null) {
1230 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1231 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001232 int errorCode = TelephonyManager
1233 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001234 if (ar.exception instanceof CommandException) {
1235 CommandException.Error error =
1236 ((CommandException) (ar.exception)).getCommandError();
1237 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001238 errorCode = TelephonyManager
1239 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001240 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001241 errorCode = TelephonyManager
1242 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001243 }
1244 }
Hall Liu27d24262020-09-18 19:04:59 -07001245 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001246 }
Shuo Qian4a594052020-01-23 11:59:30 -08001247 break;
Hall Liu27d24262020-09-18 19:04:59 -07001248 }
Shuo Qian4a594052020-01-23 11:59:30 -08001249
Hall Liu27d24262020-09-18 19:04:59 -07001250 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001251 request = (MainThreadRequest) msg.obj;
1252 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001253 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001254 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001255 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1256 request.argument).first;
1257 request.phone.setCallForwardingOption(
1258 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001259 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001260 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001261 callForwardingInfoToSet.getReason(),
1262 callForwardingInfoToSet.getNumber(),
1263 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1264 break;
Hall Liu27d24262020-09-18 19:04:59 -07001265 }
Shuo Qian4a594052020-01-23 11:59:30 -08001266
Hall Liu27d24262020-09-18 19:04:59 -07001267 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001268 ar = (AsyncResult) msg.obj;
1269 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001270 Consumer<Integer> callback =
1271 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1272 request.argument).second;
1273 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001274 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001275 int errorCode = TelephonyManager.CallForwardingInfoCallback
1276 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001277 if (ar.exception instanceof CommandException) {
1278 CommandException.Error error =
1279 ((CommandException) (ar.exception)).getCommandError();
1280 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001281 errorCode = TelephonyManager.CallForwardingInfoCallback
1282 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001283 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001284 errorCode = TelephonyManager.CallForwardingInfoCallback
1285 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001286 }
1287 }
1288 callback.accept(errorCode);
1289 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001290 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001291 }
Shuo Qian4a594052020-01-23 11:59:30 -08001292 break;
Hall Liu27d24262020-09-18 19:04:59 -07001293 }
Shuo Qian4a594052020-01-23 11:59:30 -08001294
Hall Liu27d24262020-09-18 19:04:59 -07001295 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001296 request = (MainThreadRequest) msg.obj;
1297 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1298 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1299 break;
Hall Liu27d24262020-09-18 19:04:59 -07001300 }
Shuo Qian4a594052020-01-23 11:59:30 -08001301
Hall Liu27d24262020-09-18 19:04:59 -07001302 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001303 ar = (AsyncResult) msg.obj;
1304 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001305 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001306 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001307 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001308 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001309 // Service Class is a bit mask per 3gpp 27.007.
1310 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001311 if (callForwardResults.length > 1
1312 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001313 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001314 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001315 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1316 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001317 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001318 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001319 }
1320 } else {
1321 if (ar.result == null) {
1322 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1323 }
1324 if (ar.exception != null) {
1325 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1326 }
1327 if (ar.exception instanceof CommandException) {
1328 CommandException.Error error =
1329 ((CommandException) (ar.exception)).getCommandError();
1330 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001331 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001332 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001333 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1334 callWaitingStatus =
1335 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001336 }
1337 }
1338 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001339 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001340 break;
Hall Liu27d24262020-09-18 19:04:59 -07001341 }
Shuo Qian4a594052020-01-23 11:59:30 -08001342
Hall Liu27d24262020-09-18 19:04:59 -07001343 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001344 request = (MainThreadRequest) msg.obj;
1345 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001346 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1347 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001348 break;
Hall Liu27d24262020-09-18 19:04:59 -07001349 }
Shuo Qian4a594052020-01-23 11:59:30 -08001350
Hall Liu27d24262020-09-18 19:04:59 -07001351 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001352 ar = (AsyncResult) msg.obj;
1353 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001354 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1355 Consumer<Integer> callback =
1356 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1357 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001358 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001359 if (ar.exception instanceof CommandException) {
1360 CommandException.Error error =
1361 ((CommandException) (ar.exception)).getCommandError();
1362 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1363 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001364 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1365 callback.accept(
1366 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001367 } else {
1368 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1369 }
1370 } else {
1371 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1372 }
1373 } else {
1374 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1375 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001376 }
Shuo Qian4a594052020-01-23 11:59:30 -08001377 break;
Hall Liu27d24262020-09-18 19:04:59 -07001378 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001379 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1380 ar = (AsyncResult) msg.obj;
1381 request = (MainThreadRequest) ar.userObj;
1382 CellNetworkScanResult cellScanResult;
1383 if (ar.exception == null && ar.result != null) {
1384 cellScanResult = new CellNetworkScanResult(
1385 CellNetworkScanResult.STATUS_SUCCESS,
1386 (List<OperatorInfo>) ar.result);
1387 } else {
1388 if (ar.result == null) {
1389 loge("getCellNetworkScanResults: Empty response");
1390 }
1391 if (ar.exception != null) {
1392 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1393 }
1394 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1395 if (ar.exception instanceof CommandException) {
1396 CommandException.Error error =
1397 ((CommandException) (ar.exception)).getCommandError();
1398 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1399 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1400 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1401 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1402 }
1403 }
1404 cellScanResult = new CellNetworkScanResult(errorCode, null);
1405 }
1406 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001407 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001408 break;
1409
1410 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1411 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001412 ManualNetworkSelectionArgument selArg =
1413 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001414 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1415 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001416 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1417 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001418 break;
1419
1420 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001421 ar = (AsyncResult) msg.obj;
1422 request = (MainThreadRequest) ar.userObj;
1423 if (ar.exception == null) {
1424 request.result = true;
1425 } else {
1426 request.result = false;
1427 loge("setNetworkSelectionModeManual " + ar.exception);
1428 }
1429 notifyRequester(request);
1430 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001431 break;
1432
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001433 case CMD_GET_MODEM_ACTIVITY_INFO:
1434 request = (MainThreadRequest) msg.obj;
1435 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001436 if (defaultPhone != null) {
1437 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001438 } else {
1439 ResultReceiver result = (ResultReceiver) request.argument;
1440 Bundle bundle = new Bundle();
1441 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001442 new ModemActivityInfo(0, 0, 0,
1443 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001444 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001445 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001446 break;
1447
Hall Liud0f208c2020-10-14 16:54:44 -07001448 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001449 ar = (AsyncResult) msg.obj;
1450 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001451 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001452 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001453 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001454 if (mLastModemActivityInfo == null) {
1455 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1456 mLastModemActivitySpecificInfo[0] =
1457 new ActivityStatsTechSpecificInfo(
1458 0,
1459 0,
1460 new int[ModemActivityInfo.getNumTxPowerLevels()],
1461 0);
1462 mLastModemActivityInfo =
1463 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1464 }
1465
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001466 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001467 // Update the last modem activity info and the result of the request.
1468 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1469 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001470 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001471 } else {
1472 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001473 }
Kai Shi917fdc62022-11-28 14:01:02 -08001474 // This is needed to decouple ret from mLastModemActivityInfo
1475 // We don't want to return mLastModemActivityInfo which is updated
1476 // inside mergeModemActivityInfo()
1477 ret = new ModemActivityInfo(
1478 mLastModemActivityInfo.getTimestampMillis(),
1479 mLastModemActivityInfo.getSleepTimeMillis(),
1480 mLastModemActivityInfo.getIdleTimeMillis(),
1481 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001482
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001483 } else {
1484 if (ar.result == null) {
1485 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001486 error = TelephonyManager.ModemActivityInfoException
1487 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001488 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001489 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001490 error = TelephonyManager.ModemActivityInfoException
1491 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001492 } else {
1493 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001494 error = TelephonyManager.ModemActivityInfoException
1495 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001496 }
1497 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001498 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001499 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001500 bundle.putParcelable(
1501 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001502 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001503 } else {
1504 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1505 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001506 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001507 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001508 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001509 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001510
Meng Wang1a7c35a2016-05-05 20:56:15 -07001511 case CMD_SET_ALLOWED_CARRIERS:
1512 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001513 CarrierRestrictionRules argument =
1514 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001515 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001516 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001517 break;
1518
1519 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1520 ar = (AsyncResult) msg.obj;
1521 request = (MainThreadRequest) ar.userObj;
1522 if (ar.exception == null && ar.result != null) {
1523 request.result = ar.result;
1524 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001525 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1526 if (ar.exception instanceof CommandException) {
1527 loge("setAllowedCarriers: CommandException: " + ar.exception);
1528 CommandException.Error error =
1529 ((CommandException) (ar.exception)).getCommandError();
1530 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1531 request.result =
1532 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1533 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001534 } else {
1535 loge("setAllowedCarriers: Unknown exception");
1536 }
1537 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001538 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001539 break;
1540
1541 case CMD_GET_ALLOWED_CARRIERS:
1542 request = (MainThreadRequest) msg.obj;
1543 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001544 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001545 break;
1546
1547 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1548 ar = (AsyncResult) msg.obj;
1549 request = (MainThreadRequest) ar.userObj;
1550 if (ar.exception == null && ar.result != null) {
1551 request.result = ar.result;
1552 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001553 request.result = new IllegalStateException(
1554 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001555 if (ar.result == null) {
1556 loge("getAllowedCarriers: Empty response");
1557 } else if (ar.exception instanceof CommandException) {
1558 loge("getAllowedCarriers: CommandException: " +
1559 ar.exception);
1560 } else {
1561 loge("getAllowedCarriers: Unknown exception");
1562 }
1563 }
arunvoddud7401012022-12-15 16:08:12 +00001564 if (request.argument != null) {
1565 // This is for the implementation of carrierRestrictionStatus.
1566 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1567 Consumer<Integer> callback = callbackInfo.getConsumer();
1568 int callerCarrierId = callbackInfo.getCarrierId();
1569 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1570 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1571 CarrierRestrictionRules carrierRestrictionRules =
1572 (CarrierRestrictionRules) ar.result;
1573 int carrierId = -1;
1574 try {
1575 CarrierIdentifier carrierIdentifier =
1576 carrierRestrictionRules.getAllowedCarriers().get(0);
1577 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1578 carrierIdentifier);
1579 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1580 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1581 }
1582 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1583 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1584 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
1585 lockStatus =
1586 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
1587 }
1588 } else {
1589 Rlog.e(LOG_TAG,
1590 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1591 }
1592 callback.accept(lockStatus);
1593 } else {
1594 // This is for the implementation of getAllowedCarriers.
1595 notifyRequester(request);
1596 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001597 break;
1598
Nathan Haroldb3014052017-01-25 15:57:32 -08001599 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1600 ar = (AsyncResult) msg.obj;
1601 request = (MainThreadRequest) ar.userObj;
1602 if (ar.exception == null && ar.result != null) {
1603 request.result = ar.result;
1604 } else {
1605 request.result = new IllegalArgumentException(
1606 "Failed to retrieve Forbidden Plmns");
1607 if (ar.result == null) {
1608 loge("getForbiddenPlmns: Empty response");
1609 } else {
1610 loge("getForbiddenPlmns: Unknown exception");
1611 }
1612 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001613 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001614 break;
1615
1616 case CMD_GET_FORBIDDEN_PLMNS:
1617 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001618 uiccPort = getUiccPortFromRequest(request);
1619 if (uiccPort == null) {
1620 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001621 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001622 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001623 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001624 break;
1625 }
1626 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001627 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001628 if (uiccApp == null) {
1629 loge("getForbiddenPlmns() no app with specified type -- "
1630 + appType);
1631 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001632 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001633 break;
1634 } else {
1635 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1636 + " specified type -- " + appType);
1637 }
1638 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1639 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1640 onCompleted);
1641 break;
1642
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001643 case CMD_SWITCH_SLOTS:
1644 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001645 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001646 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001647 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001648 break;
1649
1650 case EVENT_SWITCH_SLOTS_DONE:
1651 ar = (AsyncResult) msg.obj;
1652 request = (MainThreadRequest) ar.userObj;
1653 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001654 notifyRequester(request);
1655 break;
1656 case CMD_GET_NETWORK_SELECTION_MODE:
1657 request = (MainThreadRequest) msg.obj;
1658 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1659 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1660 break;
1661
1662 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1663 ar = (AsyncResult) msg.obj;
1664 request = (MainThreadRequest) ar.userObj;
1665 if (ar.exception != null) {
1666 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1667 } else {
1668 int mode = ((int[]) ar.result)[0];
1669 if (mode == 0) {
1670 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1671 } else {
1672 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1673 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001674 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001675 notifyRequester(request);
1676 break;
1677 case CMD_GET_CDMA_ROAMING_MODE:
1678 request = (MainThreadRequest) msg.obj;
1679 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1680 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1681 break;
1682 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1683 ar = (AsyncResult) msg.obj;
1684 request = (MainThreadRequest) ar.userObj;
1685 if (ar.exception != null) {
1686 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1687 } else {
1688 request.result = ((int[]) ar.result)[0];
1689 }
1690 notifyRequester(request);
1691 break;
1692 case CMD_SET_CDMA_ROAMING_MODE:
1693 request = (MainThreadRequest) msg.obj;
1694 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1695 int mode = (int) request.argument;
1696 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1697 break;
1698 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1699 ar = (AsyncResult) msg.obj;
1700 request = (MainThreadRequest) ar.userObj;
1701 request.result = ar.exception == null;
1702 notifyRequester(request);
1703 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001704 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1705 request = (MainThreadRequest) msg.obj;
1706 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1707 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1708 break;
1709 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1710 ar = (AsyncResult) msg.obj;
1711 request = (MainThreadRequest) ar.userObj;
1712 if (ar.exception != null) {
1713 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1714 } else {
1715 request.result = ((int[]) ar.result)[0];
1716 }
1717 notifyRequester(request);
1718 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001719 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1720 request = (MainThreadRequest) msg.obj;
1721 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1722 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001723 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1724 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001725 break;
1726 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1727 ar = (AsyncResult) msg.obj;
1728 request = (MainThreadRequest) ar.userObj;
1729 request.result = ar.exception == null;
1730 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001731 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001732 case CMD_GET_ALL_CELL_INFO:
1733 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001734 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001735 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001736 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001737 case EVENT_GET_ALL_CELL_INFO_DONE:
1738 ar = (AsyncResult) msg.obj;
1739 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001740 // If a timeout occurs, the response will be null
1741 request.result = (ar.exception == null && ar.result != null)
1742 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001743 synchronized (request) {
1744 request.notifyAll();
1745 }
1746 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001747 case CMD_REQUEST_CELL_INFO_UPDATE:
1748 request = (MainThreadRequest) msg.obj;
1749 request.phone.requestCellInfoUpdate(request.workSource,
1750 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1751 break;
1752 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1753 ar = (AsyncResult) msg.obj;
1754 request = (MainThreadRequest) ar.userObj;
1755 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1756 try {
1757 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001758 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001759 cb.onError(
1760 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1761 ar.exception.getClass().getName(),
1762 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001763 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001764 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001765 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001766 } else {
1767 // use the result as returned
1768 cb.onCellInfo((List<CellInfo>) ar.result);
1769 }
1770 } catch (RemoteException re) {
1771 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1772 }
1773 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001774 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001775 request = (MainThreadRequest) msg.obj;
1776 WorkSource ws = (WorkSource) request.argument;
1777 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001778 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001779 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001780 }
1781 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001782 ar = (AsyncResult) msg.obj;
1783 request = (MainThreadRequest) ar.userObj;
1784 if (ar.exception == null) {
1785 request.result = ar.result;
1786 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001787 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001788 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001789 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001790 }
1791
1792 synchronized (request) {
1793 request.notifyAll();
1794 }
1795 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001796 }
chen xu6dac5ab2018-10-26 17:39:23 -07001797 case CMD_MODEM_REBOOT:
1798 request = (MainThreadRequest) msg.obj;
1799 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001800 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001801 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001802 case EVENT_CMD_MODEM_REBOOT_DONE:
1803 handleNullReturnEvent(msg, "rebootModem");
1804 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001805 case CMD_REQUEST_ENABLE_MODEM:
1806 request = (MainThreadRequest) msg.obj;
1807 boolean enable = (boolean) request.argument;
1808 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001809 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001810 PhoneConfigurationManager.getInstance()
1811 .enablePhone(request.phone, enable, onCompleted);
1812 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001813 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001814 ar = (AsyncResult) msg.obj;
1815 request = (MainThreadRequest) ar.userObj;
1816 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001817 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001818 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001819 if ((boolean) request.result) {
1820 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1821 updateModemStateMetrics();
1822 } else {
1823 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1824 + ar.exception);
1825 }
1826 notifyRequester(request);
1827 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001828 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001829 case CMD_GET_MODEM_STATUS:
1830 request = (MainThreadRequest) msg.obj;
1831 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1832 PhoneConfigurationManager.getInstance()
1833 .getPhoneStatusFromModem(request.phone, onCompleted);
1834 break;
1835 case EVENT_GET_MODEM_STATUS_DONE:
1836 ar = (AsyncResult) msg.obj;
1837 request = (MainThreadRequest) ar.userObj;
1838 int id = request.phone.getPhoneId();
1839 if (ar.exception == null && ar.result != null) {
1840 request.result = ar.result;
1841 //update the cache as modem status has changed
1842 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1843 (boolean) request.result);
1844 } else {
1845 // Return true if modem status cannot be retrieved. For most cases,
1846 // modem status is on. And for older version modems, GET_MODEM_STATUS
1847 // and disable modem are not supported. Modem is always on.
1848 // TODO: this should be fixed in R to support a third
1849 // status UNKNOWN b/131631629
1850 request.result = true;
1851 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1852 + ar.exception);
1853 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001854 notifyRequester(request);
1855 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001856 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1857 request = (MainThreadRequest) msg.obj;
1858 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1859 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1860 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1861 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1862 break;
1863 }
1864 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1865 ar = (AsyncResult) msg.obj;
1866 request = (MainThreadRequest) ar.userObj;
1867 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1868 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1869 args.second.accept(ar.exception == null);
1870 notifyRequester(request);
1871 break;
1872 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001873 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1874 request = (MainThreadRequest) msg.obj;
1875 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1876 Phone phone = getPhoneFromRequest(request);
1877 if (phone != null) {
1878 phone.getSystemSelectionChannels(onCompleted);
1879 } else {
1880 loge("getSystemSelectionChannels: No phone object");
1881 request.result = new ArrayList<RadioAccessSpecifier>();
1882 notifyRequester(request);
1883 }
1884 break;
1885 }
1886 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1887 ar = (AsyncResult) msg.obj;
1888 request = (MainThreadRequest) ar.userObj;
1889 if (ar.exception == null && ar.result != null) {
1890 request.result = ar.result;
1891 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001892 request.result = new IllegalStateException(
1893 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001894 if (ar.result == null) {
1895 loge("getSystemSelectionChannels: Empty response");
1896 } else {
1897 loge("getSystemSelectionChannels: Unknown exception");
1898 }
1899 }
1900 notifyRequester(request);
1901 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001902 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1903 ar = (AsyncResult) msg.obj;
1904 request = (MainThreadRequest) ar.userObj;
1905 if (ar.exception == null && ar.result != null) {
1906 request.result = ar.result;
1907 } else {
1908 request.result = -1;
1909 loge("Failed to set Forbidden Plmns");
1910 if (ar.result == null) {
1911 loge("setForbidenPlmns: Empty response");
1912 } else if (ar.exception != null) {
1913 loge("setForbiddenPlmns: Exception: " + ar.exception);
1914 request.result = -1;
1915 } else {
1916 loge("setForbiddenPlmns: Unknown exception");
1917 }
1918 }
1919 notifyRequester(request);
1920 break;
1921 case CMD_SET_FORBIDDEN_PLMNS:
1922 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001923 uiccPort = getUiccPortFromRequest(request);
1924 if (uiccPort == null) {
1925 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001926 request.result = -1;
1927 notifyRequester(request);
1928 break;
1929 }
1930 Pair<Integer, List<String>> setFplmnsArgs =
1931 (Pair<Integer, List<String>>) request.argument;
1932 appType = setFplmnsArgs.first;
1933 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001934 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001935 if (uiccApp == null) {
1936 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1937 request.result = -1;
1938 loge("Failed to get UICC App");
1939 notifyRequester(request);
1940 } else {
1941 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1942 ((SIMRecords) uiccApp.getIccRecords())
1943 .setForbiddenPlmns(onCompleted, fplmns);
1944 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001945 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001946 case CMD_ERASE_MODEM_CONFIG:
1947 request = (MainThreadRequest) msg.obj;
1948 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1949 defaultPhone.eraseModemConfig(onCompleted);
1950 break;
1951 case EVENT_ERASE_MODEM_CONFIG_DONE:
1952 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001953 break;
zoey chene02881a2019-12-30 16:11:23 +08001954
Kai Shif70f46f2021-03-03 13:59:46 -08001955 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1956 request = (MainThreadRequest) msg.obj;
1957 request.result = defaultPhone.eraseDataInSharedPreferences();
1958 notifyRequester(request);
1959 break;
1960
zoey chene02881a2019-12-30 16:11:23 +08001961 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1962 request = (MainThreadRequest) msg.obj;
1963 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1964 Pair<String, String> changed = (Pair<String, String>) request.argument;
1965 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1966 changed.first, changed.second, onCompleted);
1967 break;
1968 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1969 ar = (AsyncResult) msg.obj;
1970 request = (MainThreadRequest) ar.userObj;
1971 if (ar.exception == null) {
1972 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001973 // If the operation is successful, update the PIN storage
1974 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1975 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001976 UiccController.getInstance().getPinStorage()
1977 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001978 } else {
1979 request.result = msg.arg1;
1980 }
1981 notifyRequester(request);
1982 break;
1983
Michele Berionne5e411512020-11-13 02:36:59 +00001984 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001985 request = (MainThreadRequest) msg.obj;
1986 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1987 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1988 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1989 enabled.first, enabled.second, onCompleted);
1990 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001991 }
zoey chene02881a2019-12-30 16:11:23 +08001992 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1993 ar = (AsyncResult) msg.obj;
1994 request = (MainThreadRequest) ar.userObj;
1995 if (ar.exception == null) {
1996 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001997 // If the operation is successful, update the PIN storage
1998 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1999 int phoneId = getPhoneFromRequest(request).getPhoneId();
2000 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002001 UiccController.getInstance().getPinStorage()
2002 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002003 } else {
2004 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2005 }
zoey chene02881a2019-12-30 16:11:23 +08002006 } else {
2007 request.result = msg.arg1;
2008 }
Michele Berionne5e411512020-11-13 02:36:59 +00002009
2010
zoey chene02881a2019-12-30 16:11:23 +08002011 notifyRequester(request);
2012 break;
2013
Peter Wangdafb9ac2020-01-15 14:13:38 -08002014 case MSG_NOTIFY_USER_ACTIVITY:
2015 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002016 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002017 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2018 getDefaultPhone().getContext().sendBroadcastAsUser(
2019 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2020 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002021
2022 case CMD_SET_DATA_THROTTLING: {
2023 request = (MainThreadRequest) msg.obj;
2024 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2025 DataThrottlingRequest dataThrottlingRequest =
2026 (DataThrottlingRequest) request.argument;
2027 Phone phone = getPhoneFromRequest(request);
2028 if (phone != null) {
2029 phone.setDataThrottling(onCompleted,
2030 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2031 dataThrottlingRequest.getCompletionDurationMillis());
2032 } else {
2033 loge("setDataThrottling: No phone object");
2034 request.result =
2035 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2036 notifyRequester(request);
2037 }
2038
2039 break;
2040 }
2041 case EVENT_SET_DATA_THROTTLING_DONE:
2042 ar = (AsyncResult) msg.obj;
2043 request = (MainThreadRequest) ar.userObj;
2044
2045 if (ar.exception == null) {
2046 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2047 } else if (ar.exception instanceof CommandException) {
2048 loge("setDataThrottling: CommandException: " + ar.exception);
2049 CommandException.Error error =
2050 ((CommandException) (ar.exception)).getCommandError();
2051
2052 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2053 request.result = TelephonyManager
2054 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2055 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2056 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002057 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2058 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002059 } else {
2060 request.result =
2061 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2062 }
2063 } else {
2064 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2065 }
2066 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2067 notifyRequester(request);
2068 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002069
2070 case CMD_SET_SIM_POWER: {
2071 request = (MainThreadRequest) msg.obj;
2072 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2073 request = (MainThreadRequest) msg.obj;
2074 int stateToSet =
2075 ((Pair<Integer, IIntegerConsumer>)
2076 request.argument).first;
2077 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2078 break;
2079 }
2080 case EVENT_SET_SIM_POWER_DONE: {
2081 ar = (AsyncResult) msg.obj;
2082 request = (MainThreadRequest) ar.userObj;
2083 IIntegerConsumer callback =
2084 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2085 if (ar.exception != null) {
2086 loge("setSimPower exception: " + ar.exception);
2087 int errorCode = TelephonyManager.CallForwardingInfoCallback
2088 .RESULT_ERROR_UNKNOWN;
2089 if (ar.exception instanceof CommandException) {
2090 CommandException.Error error =
2091 ((CommandException) (ar.exception)).getCommandError();
2092 if (error == CommandException.Error.SIM_ERR) {
2093 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2094 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2095 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2096 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2097 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2098 } else {
2099 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2100 }
2101 }
2102 try {
2103 callback.accept(errorCode);
2104 } catch (RemoteException e) {
2105 // Ignore if the remote process is no longer available to call back.
2106 Log.w(LOG_TAG, "setSimPower: callback not available.");
2107 }
2108 } else {
2109 try {
2110 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2111 } catch (RemoteException e) {
2112 // Ignore if the remote process is no longer available to call back.
2113 Log.w(LOG_TAG, "setSimPower: callback not available.");
2114 }
2115 }
2116 break;
2117 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002118 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2119 request = (MainThreadRequest) msg.obj;
2120
2121 final Phone phone = getPhoneFromRequest(request);
2122 if (phone == null || phone.getServiceStateTracker() == null) {
2123 request.result = new IllegalStateException("Phone or SST is null");
2124 notifyRequester(request);
2125 break;
2126 }
2127
2128 Pair<Integer, SignalStrengthUpdateRequest> pair =
2129 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2130 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2131 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002132 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002133 request.subId, pair.first /*callingUid*/,
2134 pair.second /*request*/, onCompleted);
2135 break;
2136 }
2137 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2138 ar = (AsyncResult) msg.obj;
2139 request = (MainThreadRequest) ar.userObj;
2140 // request.result will be the exception of ar if present, true otherwise.
2141 // Be cautious not to leave result null which will wait() forever
2142 request.result = ar.exception != null ? ar.exception : true;
2143 notifyRequester(request);
2144 break;
2145 }
2146 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2147 request = (MainThreadRequest) msg.obj;
2148
2149 Phone phone = getPhoneFromRequest(request);
2150 if (phone == null || phone.getServiceStateTracker() == null) {
2151 request.result = new IllegalStateException("Phone or SST is null");
2152 notifyRequester(request);
2153 break;
2154 }
2155
2156 Pair<Integer, SignalStrengthUpdateRequest> pair =
2157 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2158 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2159 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002160 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002161 request.subId, pair.first /*callingUid*/,
2162 pair.second /*request*/, onCompleted);
2163 break;
2164 }
2165 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2166 ar = (AsyncResult) msg.obj;
2167 request = (MainThreadRequest) ar.userObj;
2168 request.result = ar.exception != null ? ar.exception : true;
2169 notifyRequester(request);
2170 break;
2171 }
Jordan Liu109698e2020-11-24 14:50:34 -08002172
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002173 case CMD_GET_SLICING_CONFIG: {
2174 request = (MainThreadRequest) msg.obj;
2175 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2176 request.phone.getSlicingConfig(onCompleted);
2177 break;
2178 }
2179 case EVENT_GET_SLICING_CONFIG_DONE: {
2180 ar = (AsyncResult) msg.obj;
2181 request = (MainThreadRequest) ar.userObj;
2182 ResultReceiver result = (ResultReceiver) request.argument;
2183
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002184 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002185 Bundle bundle = new Bundle();
2186 int resultCode = 0;
2187 if (ar.exception != null) {
2188 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2189 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002190 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002191 } else if (ar.result == null) {
2192 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002193 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002194 } else {
2195 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002196 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2197 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002198 }
2199
2200 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002201 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002202 }
2203 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2204 result.send(resultCode, bundle);
2205 notifyRequester(request);
2206 break;
2207 }
2208
Sarah Chin71b3a852022-09-28 15:54:19 -07002209 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002210 request = (MainThreadRequest) msg.obj;
2211 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002212 PurchasePremiumCapabilityArgument arg =
2213 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002214 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chinb8218c22023-01-04 13:35:29 -08002215 arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002216 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002217 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002218
Sarah Chin71b3a852022-09-28 15:54:19 -07002219 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002220 ar = (AsyncResult) msg.obj;
2221 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002222 PurchasePremiumCapabilityArgument arg =
2223 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002224 try {
2225 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002226 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002227 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002228 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002229 + ", result= "
2230 + TelephonyManager.convertPurchaseResultToString(result));
2231 } catch (RemoteException e) {
2232 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002233 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002234 + " failed: " + e;
2235 if (DBG) log(logStr);
2236 AnomalyReporter.reportAnomaly(
2237 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2238 }
2239 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002240 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002241
Michele Berionne5e411512020-11-13 02:36:59 +00002242 case CMD_PREPARE_UNATTENDED_REBOOT:
2243 request = (MainThreadRequest) msg.obj;
2244 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002245 UiccController.getInstance().getPinStorage()
2246 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002247 notifyRequester(request);
2248 break;
2249
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002250 default:
2251 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2252 break;
2253 }
2254 }
Jake Hambye994d462014-02-03 13:10:13 -08002255
Pengquan Menga1bb6272018-09-06 09:59:22 -07002256 private void notifyRequester(MainThreadRequest request) {
2257 synchronized (request) {
2258 request.notifyAll();
2259 }
2260 }
2261
Jake Hambye994d462014-02-03 13:10:13 -08002262 private void handleNullReturnEvent(Message msg, String command) {
2263 AsyncResult ar = (AsyncResult) msg.obj;
2264 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2265 if (ar.exception == null) {
2266 request.result = true;
2267 } else {
2268 request.result = false;
2269 if (ar.exception instanceof CommandException) {
2270 loge(command + ": CommandException: " + ar.exception);
2271 } else {
2272 loge(command + ": Unknown exception");
2273 }
2274 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002275 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002276 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 }
2278
2279 /**
2280 * Posts the specified command to be executed on the main thread,
2281 * waits for the request to complete, and returns the result.
2282 * @see #sendRequestAsync
2283 */
2284 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002285 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2286 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002287 }
2288
2289 /**
2290 * Posts the specified command to be executed on the main thread,
2291 * waits for the request to complete, and returns the result.
2292 * @see #sendRequestAsync
2293 */
2294 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2295 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002296 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002297 }
2298
2299 /**
2300 * Posts the specified command to be executed on the main thread,
2301 * waits for the request to complete, and returns the result.
2302 * @see #sendRequestAsync
2303 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002304 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002305 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2306 }
2307
2308 /**
2309 * Posts the specified command to be executed on the main thread,
2310 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2311 * if not timeout or null otherwise.
2312 * @see #sendRequestAsync
2313 */
2314 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2315 long timeoutInMs) {
2316 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002317 }
2318
2319 /**
2320 * Posts the specified command to be executed on the main thread,
2321 * waits for the request to complete, and returns the result.
2322 * @see #sendRequestAsync
2323 */
Nathan Harold92bed182018-10-12 18:16:49 -07002324 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002325 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002326 }
2327
2328 /**
2329 * Posts the specified command to be executed on the main thread,
2330 * waits for the request to complete, and returns the result.
2331 * @see #sendRequestAsync
2332 */
2333 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002334 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2335 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002336 }
2337
2338 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002339 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2340 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2341 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002342 * @see #sendRequestAsync
2343 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002344 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2345 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002346 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2347 throw new RuntimeException("This method will deadlock if called from the main thread.");
2348 }
2349
Nathan Harold92bed182018-10-12 18:16:49 -07002350 MainThreadRequest request = null;
2351 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2352 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2353 } else if (phone != null) {
2354 request = new MainThreadRequest(argument, phone, workSource);
2355 } else {
2356 request = new MainThreadRequest(argument, subId, workSource);
2357 }
2358
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359 Message msg = mMainThreadHandler.obtainMessage(command, request);
2360 msg.sendToTarget();
2361
Rambo Wang0f050d82021-02-12 11:43:36 -08002362
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002364 if (timeoutInMs >= 0) {
2365 // Wait for at least timeoutInMs before returning null request result
2366 long now = SystemClock.elapsedRealtime();
2367 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002368 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002369 try {
2370 request.wait(deadline - now);
2371 } catch (InterruptedException e) {
2372 // Do nothing, go back and check if request is completed or timeout
2373 } finally {
2374 now = SystemClock.elapsedRealtime();
2375 }
2376 }
2377 } else {
2378 // Wait for the request to complete
2379 while (request.result == null) {
2380 try {
2381 request.wait();
2382 } catch (InterruptedException e) {
2383 // Do nothing, go back and wait until the request is complete
2384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002385 }
2386 }
2387 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002388 if (request.result == null) {
2389 Log.wtf(LOG_TAG,
2390 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2391 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 return request.result;
2393 }
2394
2395 /**
2396 * Asynchronous ("fire and forget") version of sendRequest():
2397 * Posts the specified command to be executed on the main thread, and
2398 * returns immediately.
2399 * @see #sendRequest
2400 */
2401 private void sendRequestAsync(int command) {
2402 mMainThreadHandler.sendEmptyMessage(command);
2403 }
2404
2405 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002406 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002407 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002408 */
2409 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002410 sendRequestAsync(command, argument, null, null);
2411 }
2412
2413 /**
2414 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2415 * @see {@link #sendRequest(int,Object)}
2416 */
2417 private void sendRequestAsync(
2418 int command, Object argument, Phone phone, WorkSource workSource) {
2419 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002420 Message msg = mMainThreadHandler.obtainMessage(command, request);
2421 msg.sendToTarget();
2422 }
2423
2424 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425 * Initialize the singleton PhoneInterfaceManager instance.
2426 * This is only done once, at startup, from PhoneApp.onCreate().
2427 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002428 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 synchronized (PhoneInterfaceManager.class) {
2430 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002431 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 } else {
2433 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2434 }
2435 return sInstance;
2436 }
2437 }
2438
2439 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002440 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002442 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002443 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002444 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002446 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002447 mMainThreadHandler = new MainThreadHandler();
Jack Yue37dd262022-12-16 11:53:37 -08002448 if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) {
2449 mSubscriptionController = SubscriptionController.getInstance();
2450 } else {
2451 mSubscriptionController = null;
2452 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002453 mTelephonySharedPreferences =
2454 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002455 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002456 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002457 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002458 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002459 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460 publish();
arunvoddud7401012022-12-15 16:08:12 +00002461 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 }
2463
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002464 @VisibleForTesting
2465 public SharedPreferences getSharedPreferences() {
2466 return mTelephonySharedPreferences;
2467 }
2468
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002469 /**
2470 * Get the default phone for this device.
2471 */
2472 @VisibleForTesting
2473 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002474 Phone thePhone = getPhone(getDefaultSubscription());
2475 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2476 }
2477
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 private void publish() {
2479 if (DBG) log("publish: " + this);
2480
Peter Wangc035ce42020-01-08 21:00:22 -08002481 TelephonyFrameworkInitializer
2482 .getTelephonyServiceManager()
2483 .getTelephonyServiceRegisterer()
2484 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 }
2486
Stuart Scott584921c2015-01-15 17:10:34 -08002487 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002488 if (request.phone != null) {
2489 return request.phone;
2490 } else {
2491 return getPhoneFromSubId(request.subId);
2492 }
2493 }
2494
2495 private Phone getPhoneFromSubId(int subId) {
2496 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2497 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002498 }
2499
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002500 /**
2501 * Get phone object associated with a subscription.
2502 * Return default phone if phone object associated with subscription is null
2503 * @param subId - subscriptionId
2504 * @return phone object associated with a subscription or default phone if null.
2505 */
2506 private Phone getPhoneFromSubIdOrDefault(int subId) {
2507 Phone phone = getPhoneFromSubId(subId);
2508 if (phone == null) {
2509 phone = getDefaultPhone();
2510 }
2511 return phone;
2512 }
2513
Rambo Wange53e07d2022-05-10 13:01:13 -07002514 @Nullable
2515 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002516 Phone phone = getPhoneFromRequest(request);
2517 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002518 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002519 }
2520
Wink Saville36469e72014-06-11 15:17:00 -07002521 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002522 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002523 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002524 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002525
Kai Shif70f46f2021-03-03 13:59:46 -08002526 private void sendEraseModemConfig(@NonNull Phone phone) {
2527 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2528 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2529 }
2530
2531 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2532 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2533 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002534 }
2535
Peter Wang44b186e2020-01-13 23:33:09 -08002536 private boolean isImsAvailableOnDevice() {
2537 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2538 if (pm == null) {
2539 // For some reason package manger is not available.. This will fail internally anyway,
2540 // so do not throw error and allow.
2541 return true;
2542 }
2543 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2544 }
2545
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002546 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002547 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002548 }
2549
Wink Savilleb564aae2014-10-23 10:18:09 -07002550 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002551 if (DBG) log("dial: " + number);
2552 // No permission check needed here: This is just a wrapper around the
2553 // ACTION_DIAL intent, which is available to any app since it puts up
2554 // the UI before it does anything.
2555
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002556 final long identity = Binder.clearCallingIdentity();
2557 try {
2558 String url = createTelUrl(number);
2559 if (url == null) {
2560 return;
2561 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002562
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002563 // PENDING: should we just silently fail if phone is offhook or ringing?
2564 PhoneConstants.State state = mCM.getState(subId);
2565 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2566 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2567 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2568 mApp.startActivity(intent);
2569 }
2570 } finally {
2571 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572 }
2573 }
2574
2575 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002576 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002577 }
2578
Wink Savilleb564aae2014-10-23 10:18:09 -07002579 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002580 if (DBG) log("call: " + number);
2581
2582 // This is just a wrapper around the ACTION_CALL intent, but we still
2583 // need to do a permission check since we're calling startActivity()
2584 // from the context of the phone app.
2585 enforceCallPermission();
2586
Jordan Liu1617b712019-07-10 15:06:26 -07002587 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002588 != AppOpsManager.MODE_ALLOWED) {
2589 return;
2590 }
2591
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002592 final long identity = Binder.clearCallingIdentity();
2593 try {
2594 String url = createTelUrl(number);
2595 if (url == null) {
2596 return;
2597 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002598
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002599 boolean isValid = false;
2600 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2601 if (slist != null) {
2602 for (SubscriptionInfo subInfoRecord : slist) {
2603 if (subInfoRecord.getSubscriptionId() == subId) {
2604 isValid = true;
2605 break;
2606 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002607 }
Wink Saville08874612014-08-31 19:19:58 -07002608 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002609 if (!isValid) {
2610 return;
2611 }
Wink Saville08874612014-08-31 19:19:58 -07002612
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2614 intent.putExtra(SUBSCRIPTION_KEY, subId);
2615 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2616 mApp.startActivity(intent);
2617 } finally {
2618 Binder.restoreCallingIdentity(identity);
2619 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002620 }
2621
Wink Savilleb564aae2014-10-23 10:18:09 -07002622 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002623 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002624 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2625 }
2626
Wink Savilleb564aae2014-10-23 10:18:09 -07002627 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002628 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002629 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2630 }
2631
Wink Savilleb564aae2014-10-23 10:18:09 -07002632 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002633 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002634
2635 final long identity = Binder.clearCallingIdentity();
2636 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002637 Phone phone = getPhone(subId);
2638 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002639 checkSimPin.start();
2640 return checkSimPin.unlockSim(null, pin);
2641 } finally {
2642 Binder.restoreCallingIdentity(identity);
2643 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002644 }
2645
Wink Savilleb564aae2014-10-23 10:18:09 -07002646 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002648
2649 final long identity = Binder.clearCallingIdentity();
2650 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002651 Phone phone = getPhone(subId);
2652 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002653 checkSimPuk.start();
2654 return checkSimPuk.unlockSim(puk, pin);
2655 } finally {
2656 Binder.restoreCallingIdentity(identity);
2657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002658 }
2659
2660 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002661 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002662 * a synchronous one.
2663 */
2664 private static class UnlockSim extends Thread {
2665
2666 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002667 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002668
2669 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002670 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2671 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002672
2673 // For replies from SimCard interface
2674 private Handler mHandler;
2675
2676 // For async handler to identify request type
2677 private static final int SUPPLY_PIN_COMPLETE = 100;
2678
Michele Berionne5e411512020-11-13 02:36:59 +00002679 UnlockSim(int phoneId, IccCard simCard) {
2680 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002681 mSimCard = simCard;
2682 }
2683
2684 @Override
2685 public void run() {
2686 Looper.prepare();
2687 synchronized (UnlockSim.this) {
2688 mHandler = new Handler() {
2689 @Override
2690 public void handleMessage(Message msg) {
2691 AsyncResult ar = (AsyncResult) msg.obj;
2692 switch (msg.what) {
2693 case SUPPLY_PIN_COMPLETE:
2694 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2695 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002696 mRetryCount = msg.arg1;
2697 if (ar.exception != null) {
2698 if (ar.exception instanceof CommandException &&
2699 ((CommandException)(ar.exception)).getCommandError()
2700 == CommandException.Error.PASSWORD_INCORRECT) {
2701 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002702 } //When UiccCardApp dispose,handle message and return exception
2703 else if (ar.exception instanceof CommandException &&
2704 ((CommandException) (ar.exception)).getCommandError()
2705 == CommandException.Error.ABORTED) {
2706 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002707 } else {
2708 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2709 }
2710 } else {
2711 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2712 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002713 mDone = true;
2714 UnlockSim.this.notifyAll();
2715 }
2716 break;
2717 }
2718 }
2719 };
2720 UnlockSim.this.notifyAll();
2721 }
2722 Looper.loop();
2723 }
2724
2725 /*
2726 * Use PIN or PUK to unlock SIM card
2727 *
2728 * If PUK is null, unlock SIM card with PIN
2729 *
2730 * If PUK is not null, unlock SIM card with PUK and set PIN code
2731 */
Wink Saville9de0f752013-10-22 19:04:03 -07002732 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002733
2734 while (mHandler == null) {
2735 try {
2736 wait();
2737 } catch (InterruptedException e) {
2738 Thread.currentThread().interrupt();
2739 }
2740 }
2741 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2742
2743 if (puk == null) {
2744 mSimCard.supplyPin(pin, callback);
2745 } else {
2746 mSimCard.supplyPuk(puk, pin, callback);
2747 }
2748
2749 while (!mDone) {
2750 try {
2751 Log.d(LOG_TAG, "wait for done");
2752 wait();
2753 } catch (InterruptedException e) {
2754 // Restore the interrupted status
2755 Thread.currentThread().interrupt();
2756 }
2757 }
2758 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002759 int[] resultArray = new int[2];
2760 resultArray[0] = mResult;
2761 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002762
2763 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002764 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002765 }
2766
Wink Saville9de0f752013-10-22 19:04:03 -07002767 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002768 }
2769 }
2770
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002771 /**
2772 * This method has been removed due to privacy and stability concerns.
2773 */
2774 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002775 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002776 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2777 return;
Wink Saville36469e72014-06-11 15:17:00 -07002778 }
2779
Nathan Harold1f889d82020-06-04 17:05:26 -07002780 @Override
2781 public void updateServiceLocationWithPackageName(String callingPackage) {
2782 mApp.getSystemService(AppOpsManager.class)
2783 .checkPackage(Binder.getCallingUid(), callingPackage);
2784
Nathan Haroldf096d982020-11-18 17:18:06 -08002785 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002786 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2787 // Callers targeting S have no business invoking this method.
2788 return;
2789 }
2790
2791 LocationAccessPolicy.LocationPermissionResult locationResult =
2792 LocationAccessPolicy.checkLocationPermission(mApp,
2793 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2794 .setCallingPackage(callingPackage)
2795 .setCallingFeatureId(null)
2796 .setCallingPid(Binder.getCallingPid())
2797 .setCallingUid(Binder.getCallingUid())
2798 .setMethod("updateServiceLocation")
2799 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2800 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2801 .build());
2802 // Apps that lack location permission have no business calling this method;
2803 // however, because no permission was declared in the public API, denials must
2804 // all be "soft".
2805 switch (locationResult) {
2806 case DENIED_HARD: /* fall through */
2807 case DENIED_SOFT:
2808 return;
2809 }
2810
2811 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002812 final long identity = Binder.clearCallingIdentity();
2813 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002814 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002815 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002816 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002817 }
2818 } finally {
2819 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002820 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002821 }
2822
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002823 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002824 @Override
2825 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002826 return isRadioOnWithFeature(callingPackage, null);
2827 }
2828
2829
2830 @Override
2831 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2832 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2833 callingFeatureId);
2834 }
2835
2836 @Deprecated
2837 @Override
2838 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2839 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002840 }
2841
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002842 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002843 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2844 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002845 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002846 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002847 return false;
2848 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002849
2850 final long identity = Binder.clearCallingIdentity();
2851 try {
2852 return isRadioOnForSubscriber(subId);
2853 } finally {
2854 Binder.restoreCallingIdentity(identity);
2855 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002856 }
2857
2858 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002859 final long identity = Binder.clearCallingIdentity();
2860 try {
2861 final Phone phone = getPhone(subId);
2862 if (phone != null) {
2863 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2864 } else {
2865 return false;
2866 }
2867 } finally {
2868 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002869 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002870 }
2871
2872 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002873 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002874 }
Wink Saville36469e72014-06-11 15:17:00 -07002875
Wink Savilleb564aae2014-10-23 10:18:09 -07002876 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002877 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002878
2879 final long identity = Binder.clearCallingIdentity();
2880 try {
2881 final Phone phone = getPhone(subId);
2882 if (phone != null) {
2883 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2884 }
2885 } finally {
2886 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002887 }
Wink Saville36469e72014-06-11 15:17:00 -07002888 }
2889
2890 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002891 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002892 }
2893
Wink Savilleb564aae2014-10-23 10:18:09 -07002894 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002895 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002896
2897 final long identity = Binder.clearCallingIdentity();
2898 try {
2899 final Phone phone = getPhone(subId);
2900 if (phone == null) {
2901 return false;
2902 }
2903 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2904 toggleRadioOnOffForSubscriber(subId);
2905 }
2906 return true;
2907 } finally {
2908 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002909 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002910 }
Wink Saville36469e72014-06-11 15:17:00 -07002911
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002912 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002913 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002914 /*
2915 * If any of the Radios are available, it will need to be
2916 * shutdown. So return true if any Radio is available.
2917 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002918 final long identity = Binder.clearCallingIdentity();
2919 try {
2920 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2921 Phone phone = PhoneFactory.getPhone(i);
2922 if (phone != null && phone.isRadioAvailable()) return true;
2923 }
2924 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2925 return false;
2926 } finally {
2927 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002928 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002929 }
2930
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002931 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002932 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002933 enforceModifyPermission();
2934
2935 final long identity = Binder.clearCallingIdentity();
2936 try {
2937 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2938 logv("Shutting down Phone " + i);
2939 shutdownRadioUsingPhoneId(i);
2940 }
2941 } finally {
2942 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002943 }
2944 }
2945
2946 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002947 Phone phone = PhoneFactory.getPhone(phoneId);
2948 if (phone != null && phone.isRadioAvailable()) {
2949 phone.shutdownRadio();
2950 }
2951 }
2952
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002953 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002954 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002955
2956 final long identity = Binder.clearCallingIdentity();
2957 try {
2958 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2959 if (defaultPhone != null) {
2960 defaultPhone.setRadioPower(turnOn);
2961 return true;
2962 } else {
2963 loge("There's no default phone.");
2964 return false;
2965 }
2966 } finally {
2967 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002968 }
Wink Saville36469e72014-06-11 15:17:00 -07002969 }
2970
Wink Savilleb564aae2014-10-23 10:18:09 -07002971 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002972 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002973
2974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 final Phone phone = getPhone(subId);
2977 if (phone != null) {
2978 phone.setRadioPower(turnOn);
2979 return true;
2980 } else {
2981 return false;
2982 }
2983 } finally {
2984 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002985 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002986 }
2987
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002988 /**
2989 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2990 * no reason to power it off. When any of the voters want to power it off, it will be turned
2991 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2992 * powering it off, and these radio off votes will be cleared.
2993 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
2994 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
2995 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
2996 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
2997 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
2998 * check its vote.
2999 *
3000 * @param subId The subscription ID.
3001 * @param reason The reason for powering off radio.
3002 * @return true on success and false on failure.
3003 */
3004 public boolean requestRadioPowerOffForReason(int subId,
3005 @TelephonyManager.RadioPowerReason int reason) {
3006 enforceModifyPermission();
3007
3008 final long identity = Binder.clearCallingIdentity();
3009 try {
3010 final Phone phone = getPhone(subId);
3011 if (phone != null) {
3012 phone.setRadioPowerForReason(false, reason);
3013 return true;
3014 } else {
3015 return false;
3016 }
3017 } finally {
3018 Binder.restoreCallingIdentity(identity);
3019 }
3020 }
3021
3022 /**
3023 * Remove the vote on powering off the radio for a reason, as requested by
3024 * {@link requestRadioPowerOffForReason}.
3025 *
3026 * @param subId The subscription ID.
3027 * @param reason The reason for powering off radio.
3028 * @return true on success and false on failure.
3029 */
3030 public boolean clearRadioPowerOffForReason(int subId,
3031 @TelephonyManager.RadioPowerReason int reason) {
3032 enforceModifyPermission();
3033
3034 final long identity = Binder.clearCallingIdentity();
3035 try {
3036 final Phone phone = getPhone(subId);
3037 if (phone != null) {
3038 phone.setRadioPowerForReason(true, reason);
3039 return true;
3040 } else {
3041 return false;
3042 }
3043 } finally {
3044 Binder.restoreCallingIdentity(identity);
3045 }
3046 }
3047
3048 /**
3049 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3050 *
3051 * @param subId The subscription ID.
3052 * @param callingPackage The package making the call.
3053 * @param callingFeatureId The feature in the package.
3054 * @return List of reasons for powering off radio.
3055 */
3056 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3057 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3058
3059 final long identity = Binder.clearCallingIdentity();
3060 List result = new ArrayList();
3061 try {
3062 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3063 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3064 return result;
3065 }
3066
3067 final Phone phone = getPhone(subId);
3068 if (phone != null) {
3069 result.addAll(phone.getRadioPowerOffReasons());
3070 }
3071 } finally {
3072 Binder.restoreCallingIdentity(identity);
3073 }
3074 return result;
3075 }
3076
Wink Saville36469e72014-06-11 15:17:00 -07003077 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003078 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003079 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003080 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003081
3082 final long identity = Binder.clearCallingIdentity();
3083 try {
Jack Yu285100e2022-12-02 22:48:35 -08003084 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003085 final Phone phone = getPhone(subId);
3086 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003087 phone.getDataSettingsManager().setDataEnabled(
3088 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003089 return true;
3090 } else {
3091 return false;
3092 }
3093 } finally {
3094 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003095 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003096 }
3097
Wink Saville36469e72014-06-11 15:17:00 -07003098 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003099 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003100 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003101 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003102
3103 final long identity = Binder.clearCallingIdentity();
3104 try {
Jack Yu285100e2022-12-02 22:48:35 -08003105 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003106 final Phone phone = getPhone(subId);
3107 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003108 phone.getDataSettingsManager().setDataEnabled(
3109 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003110 return true;
3111 } else {
3112 return false;
3113 }
3114 } finally {
3115 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003116 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003117 }
3118
Sanket Padawe356d7632015-06-22 14:03:32 -07003119 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003120 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003121 final long identity = Binder.clearCallingIdentity();
3122 try {
3123 final Phone phone = getPhone(subId);
3124 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003125 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003126 } else {
3127 return false;
3128 }
3129 } finally {
3130 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003132 }
3133
3134 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003135 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003136 }
3137
pkanwarae03a6b2016-11-06 20:37:09 -08003138 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003139 enforceCallPermission();
3140
3141 final long identity = Binder.clearCallingIdentity();
3142 try {
3143 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3144 return;
3145 }
3146 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3147 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3148 } finally {
3149 Binder.restoreCallingIdentity(identity);
3150 }
pkanwar32d516d2016-10-14 19:37:38 -07003151 };
3152
Wink Savilleb564aae2014-10-23 10:18:09 -07003153 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003154 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003155
3156 final long identity = Binder.clearCallingIdentity();
3157 try {
3158 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3159 return false;
3160 }
3161 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3162 } finally {
3163 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003164 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003165 }
3166
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003167 /**
3168 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3169 * tag on getCallState Binder call.
3170 */
3171 @Deprecated
3172 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003173 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003174 if (CompatChanges.isChangeEnabled(
3175 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3176 Binder.getCallingUid())) {
3177 // Do not allow this API to be called on API version 31+, it should only be
3178 // called on old apps using this Binder call directly.
3179 throw new SecurityException("This method can only be used for applications "
3180 + "targeting API version 30 or less.");
3181 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003182 final long identity = Binder.clearCallingIdentity();
3183 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003184 Phone phone = getPhone(getDefaultSubscription());
3185 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3186 PhoneConstantConversions.convertCallState(phone.getState());
3187 } finally {
3188 Binder.restoreCallingIdentity(identity);
3189 }
3190 }
3191
3192 @Override
3193 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3194 if (CompatChanges.isChangeEnabled(
3195 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3196 Binder.getCallingUid())) {
3197 // Check READ_PHONE_STATE for API version 31+
3198 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3199 featureId, "getCallStateForSubscription")) {
3200 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3201 + "targeting API level 31+.");
3202 }
3203 }
3204 final long identity = Binder.clearCallingIdentity();
3205 try {
3206 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003207 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3208 PhoneConstantConversions.convertCallState(phone.getState());
3209 } finally {
3210 Binder.restoreCallingIdentity(identity);
3211 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003212 }
3213
Sanket Padawe356d7632015-06-22 14:03:32 -07003214 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003215 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003216 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003217 }
3218
3219 @Override
3220 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003221 final long identity = Binder.clearCallingIdentity();
3222 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003223 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003224 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003225 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003226 } else {
3227 return PhoneConstantConversions.convertDataState(
3228 PhoneConstants.DataState.DISCONNECTED);
3229 }
3230 } finally {
3231 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003232 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003233 }
3234
Sanket Padawe356d7632015-06-22 14:03:32 -07003235 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003236 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003237 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003238 }
3239
3240 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003241 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003242 final long identity = Binder.clearCallingIdentity();
3243 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003244 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003245 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003246 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003247 } else {
3248 return TelephonyManager.DATA_ACTIVITY_NONE;
3249 }
3250 } finally {
3251 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003253 }
3254
3255 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003256 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003257 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003258 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003259
3260 LocationAccessPolicy.LocationPermissionResult locationResult =
3261 LocationAccessPolicy.checkLocationPermission(mApp,
3262 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3263 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003264 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003265 .setCallingPid(Binder.getCallingPid())
3266 .setCallingUid(Binder.getCallingUid())
3267 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003268 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003269 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3270 .build());
3271 switch (locationResult) {
3272 case DENIED_HARD:
3273 throw new SecurityException("Not allowed to access cell location");
3274 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003275 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3276 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003277 }
3278
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003279 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003280 final long identity = Binder.clearCallingIdentity();
3281 try {
3282 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003283 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003284 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003285 } finally {
3286 Binder.restoreCallingIdentity(identity);
3287 }
Svetoslav64fad262015-04-14 14:35:21 -07003288 }
3289
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003290 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003291 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003292 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3293 // registered cell info, so return a NULL country instead.
3294 final long identity = Binder.clearCallingIdentity();
3295 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003296 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3297 // Get default phone in this case.
3298 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3299 }
Jack Yu285100e2022-12-02 22:48:35 -08003300 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003301 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003302 if (phone == null) return "";
3303 ServiceStateTracker sst = phone.getServiceStateTracker();
3304 if (sst == null) return "";
3305 LocaleTracker lt = sst.getLocaleTracker();
3306 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003307 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003308 } finally {
3309 Binder.restoreCallingIdentity(identity);
3310 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003311 }
3312
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003313 /**
3314 * This method was removed due to potential issues caused by performing partial
3315 * updates of service state, and lack of a credible use case.
3316 *
3317 * This has the ability to break the telephony implementation by disabling notification of
3318 * changes in device connectivity. DO NOT USE THIS!
3319 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003320 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003321 public void enableLocationUpdates() {
3322 mApp.enforceCallingOrSelfPermission(
3323 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003324 }
3325
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003326 /**
3327 * This method was removed due to potential issues caused by performing partial
3328 * updates of service state, and lack of a credible use case.
3329 *
3330 * This has the ability to break the telephony implementation by disabling notification of
3331 * changes in device connectivity. DO NOT USE THIS!
3332 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003333 @Override
3334 public void disableLocationUpdates() {
3335 mApp.enforceCallingOrSelfPermission(
3336 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003337 }
3338
3339 @Override
3340 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003341 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3342 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003343 try {
3344 mApp.getSystemService(AppOpsManager.class)
3345 .checkPackage(Binder.getCallingUid(), callingPackage);
3346 } catch (SecurityException e) {
3347 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3348 throw e;
3349 }
3350
Nathan Haroldf096d982020-11-18 17:18:06 -08003351 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003352 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3353 throw new SecurityException(
3354 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3355 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003356
Jordan Liu1617b712019-07-10 15:06:26 -07003357 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003358 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3359 return null;
3360 }
Svetoslav64fad262015-04-14 14:35:21 -07003361
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003362 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003363
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003364 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003365 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003366
Nathan Haroldf180aac2018-06-01 18:43:55 -07003367 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3368 for (CellInfo ci : info) {
3369 if (ci instanceof CellInfoGsm) {
3370 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3371 } else if (ci instanceof CellInfoWcdma) {
3372 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3373 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003374 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003375 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003376 }
3377
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003378 private List<CellInfo> getCachedCellInfo() {
3379 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3380 for (Phone phone : PhoneFactory.getPhones()) {
3381 List<CellInfo> info = phone.getAllCellInfo();
3382 if (info != null) cellInfos.addAll(info);
3383 }
3384 return cellInfos;
3385 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003386
3387 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003388 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003389 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003390 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003391
3392 LocationAccessPolicy.LocationPermissionResult locationResult =
3393 LocationAccessPolicy.checkLocationPermission(mApp,
3394 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3395 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003396 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003397 .setCallingPid(Binder.getCallingPid())
3398 .setCallingUid(Binder.getCallingUid())
3399 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003400 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003401 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3402 .build());
3403 switch (locationResult) {
3404 case DENIED_HARD:
3405 throw new SecurityException("Not allowed to access cell info");
3406 case DENIED_SOFT:
3407 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003408 }
3409
Nathan Haroldf096d982020-11-18 17:18:06 -08003410 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003411 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3412 return getCachedCellInfo();
3413 }
3414
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003415 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003416 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003417 final long identity = Binder.clearCallingIdentity();
3418 try {
3419 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3420 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003421 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003422 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003423 if (info != null) cellInfos.addAll(info);
3424 }
3425 return cellInfos;
3426 } finally {
3427 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003428 }
3429 }
3430
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003431 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003432 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3433 String callingFeatureId) {
3434 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3435 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003436 }
3437
3438 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003439 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3440 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003441 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003442 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003443 }
3444
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003445 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3446 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003447 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003448 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003449
3450 LocationAccessPolicy.LocationPermissionResult locationResult =
3451 LocationAccessPolicy.checkLocationPermission(mApp,
3452 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3453 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003454 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003455 .setCallingPid(Binder.getCallingPid())
3456 .setCallingUid(Binder.getCallingUid())
3457 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003458 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3459 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003460 .build());
3461 switch (locationResult) {
3462 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003463 if (TelephonyPermissions
3464 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003465 // Safetynet logging for b/154934934
3466 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3467 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003468 throw new SecurityException("Not allowed to access cell info");
3469 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003470 if (TelephonyPermissions
3471 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003472 // Safetynet logging for b/154934934
3473 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3474 }
Nathan Harold5320c422019-05-09 10:26:08 -07003475 try {
3476 cb.onCellInfo(new ArrayList<CellInfo>());
3477 } catch (RemoteException re) {
3478 // Drop without consequences
3479 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003480 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003481 }
3482
Nathan Harolda939a962019-05-09 10:13:47 -07003483
3484 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003485 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3486
3487 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3488 }
3489
3490 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003491 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003492 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003493 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003494
3495 final long identity = Binder.clearCallingIdentity();
3496 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003497 Phone phone = getPhone(subId);
3498 if (phone == null) {
3499 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3500 } else {
3501 phone.setCellInfoListRate(rateInMillis, workSource);
3502 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003503 } finally {
3504 Binder.restoreCallingIdentity(identity);
3505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003506 }
3507
Shishir Agrawala9f32182016-04-12 12:00:16 -07003508 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003509 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003510 Phone phone = PhoneFactory.getPhone(slotIndex);
3511 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003512 return null;
3513 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003514 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003515 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003516 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003517 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003518 return null;
3519 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003520
3521 final long identity = Binder.clearCallingIdentity();
3522 try {
3523 return phone.getImei();
3524 } finally {
3525 Binder.restoreCallingIdentity(identity);
3526 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003527 }
3528
3529 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003530 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3531 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3532 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3533 callingFeatureId, "getPrimaryImei")) {
3534 throw new SecurityException("Caller does not have permission");
3535 }
3536 final long identity = Binder.clearCallingIdentity();
3537 try {
3538 for (Phone phone : PhoneFactory.getPhones()) {
3539 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3540 return phone.getImei();
3541 }
3542 }
3543 throw new UnsupportedOperationException("Operation not supported");
3544 } finally {
3545 Binder.restoreCallingIdentity(identity);
3546 }
3547 }
3548
3549 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003550 public String getTypeAllocationCodeForSlot(int slotIndex) {
3551 Phone phone = PhoneFactory.getPhone(slotIndex);
3552 String tac = null;
3553 if (phone != null) {
3554 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003555 try {
3556 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3557 } catch (IndexOutOfBoundsException e) {
3558 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3559 return null;
3560 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003561 }
3562 return tac;
3563 }
3564
3565 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003566 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003567 try {
3568 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3569 } catch (SecurityException se) {
3570 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3571 throw new SecurityException("Package " + callingPackage + " does not belong to "
3572 + Binder.getCallingUid());
3573 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003574 Phone phone = PhoneFactory.getPhone(slotIndex);
3575 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003576 return null;
3577 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003578
Jeff Davidson913390f2018-02-23 17:11:49 -08003579 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003580 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003581 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003582 return null;
3583 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003584
3585 final long identity = Binder.clearCallingIdentity();
3586 try {
3587 return phone.getMeid();
3588 } finally {
3589 Binder.restoreCallingIdentity(identity);
3590 }
Jack Yu2af8d712017-03-15 17:14:14 -07003591 }
3592
3593 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003594 public String getManufacturerCodeForSlot(int slotIndex) {
3595 Phone phone = PhoneFactory.getPhone(slotIndex);
3596 String manufacturerCode = null;
3597 if (phone != null) {
3598 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003599 try {
3600 manufacturerCode =
3601 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3602 } catch (IndexOutOfBoundsException e) {
3603 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3604 return null;
3605 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003606 }
3607 return manufacturerCode;
3608 }
3609
3610 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003611 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3612 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003613 Phone phone = PhoneFactory.getPhone(slotIndex);
3614 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003615 return null;
3616 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003617 int subId = phone.getSubId();
3618 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003619 mApp, subId, callingPackage, callingFeatureId,
3620 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003621 return null;
3622 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003623
3624 final long identity = Binder.clearCallingIdentity();
3625 try {
3626 return phone.getDeviceSvn();
3627 } finally {
3628 Binder.restoreCallingIdentity(identity);
3629 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003630 }
3631
fionaxu43304da2017-11-27 22:51:16 -08003632 @Override
3633 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003634 final long identity = Binder.clearCallingIdentity();
3635 try {
3636 final Phone phone = getPhone(subId);
3637 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3638 } finally {
3639 Binder.restoreCallingIdentity(identity);
3640 }
fionaxu43304da2017-11-27 22:51:16 -08003641 }
3642
3643 @Override
3644 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003645 final long identity = Binder.clearCallingIdentity();
3646 try {
3647 final Phone phone = getPhone(subId);
3648 return phone == null ? null : phone.getCarrierName();
3649 } finally {
3650 Binder.restoreCallingIdentity(identity);
3651 }
fionaxu43304da2017-11-27 22:51:16 -08003652 }
3653
calvinpanffe225e2018-11-01 19:43:06 +08003654 @Override
chen xu0026ca62019-03-06 15:28:50 -08003655 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003656 final long identity = Binder.clearCallingIdentity();
3657 try {
3658 final Phone phone = getPhone(subId);
3659 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003660 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003661 } finally {
3662 Binder.restoreCallingIdentity(identity);
3663 }
3664 }
3665
3666 @Override
chen xu0026ca62019-03-06 15:28:50 -08003667 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003668 final long identity = Binder.clearCallingIdentity();
3669 try {
3670 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003671 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003672 } finally {
3673 Binder.restoreCallingIdentity(identity);
3674 }
3675 }
3676
chen xu651eec72018-11-11 19:03:44 -08003677 @Override
chen xu864e11c2018-12-06 22:10:03 -08003678 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3679 if (!isSubscriptionMccMnc) {
3680 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3681 }
chen xu651eec72018-11-11 19:03:44 -08003682 final Phone phone = PhoneFactory.getPhone(slotIndex);
3683 if (phone == null) {
3684 return TelephonyManager.UNKNOWN_CARRIER_ID;
3685 }
3686 final long identity = Binder.clearCallingIdentity();
3687 try {
3688 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3689 } finally {
3690 Binder.restoreCallingIdentity(identity);
3691 }
3692 }
3693
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003694 //
3695 // Internal helper methods.
3696 //
3697
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003698 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003699 * Make sure the caller is the calling package itself
3700 *
3701 * @throws SecurityException if the caller is not the calling package
3702 */
3703 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3704 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003705 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3706 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003707 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003708 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003709 } catch (PackageManager.NameNotFoundException e) {
3710 // packageUid is -1
3711 }
3712 if (packageUid != callingUid) {
3713 throw new SecurityException(message + ": Package " + callingPackage
3714 + " does not belong to " + callingUid);
3715 }
3716 }
3717
3718 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003719 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3720 *
3721 * @throws SecurityException if the caller does not have the required permission
3722 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003723 @VisibleForTesting
3724 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003725 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3726 }
3727
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003728 /**
arunvoddud7401012022-12-15 16:08:12 +00003729 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003730 *
3731 * @throws SecurityException if the caller does not have the required permission
3732 */
3733 @VisibleForTesting
3734 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003735 enforceReadPermission(null);
3736 }
3737
3738 /**
3739 * Make sure the caller has the READ_PHONE_STATE permissions.
3740 *
3741 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3742 */
3743 @VisibleForTesting
3744 public void enforceReadPermission(String msg) {
3745 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003746 }
3747
Shuo Qian3b6ee772019-11-13 17:43:31 -08003748 private void enforceActiveEmergencySessionPermission() {
3749 mApp.enforceCallingOrSelfPermission(
3750 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3751 }
3752
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003753 /**
3754 * Make sure the caller has the CALL_PHONE permission.
3755 *
3756 * @throws SecurityException if the caller does not have the required permission
3757 */
3758 private void enforceCallPermission() {
3759 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3760 }
3761
paulhu5a773602019-08-23 19:17:33 +08003762 private void enforceSettingsPermission() {
3763 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003764 }
3765
Michele Berionne5e411512020-11-13 02:36:59 +00003766 private void enforceRebootPermission() {
3767 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3768 }
3769
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003770 private String createTelUrl(String number) {
3771 if (TextUtils.isEmpty(number)) {
3772 return null;
3773 }
3774
Jake Hambye994d462014-02-03 13:10:13 -08003775 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003776 }
3777
Ihab Awadf9e92732013-12-05 18:02:52 -08003778 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003779 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3780 }
3781
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003782 private static void logv(String msg) {
3783 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3784 }
3785
Ihab Awadf9e92732013-12-05 18:02:52 -08003786 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003787 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3788 }
3789
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003790 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003791 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003792 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003793 }
3794
Sanket Padawe356d7632015-06-22 14:03:32 -07003795 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003796 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003797 final long identity = Binder.clearCallingIdentity();
3798 try {
3799 final Phone phone = PhoneFactory.getPhone(slotIndex);
3800 if (phone == null) {
3801 return PhoneConstants.PHONE_TYPE_NONE;
3802 } else {
3803 return phone.getPhoneType();
3804 }
3805 } finally {
3806 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003807 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003808 }
3809
3810 /**
3811 * Returns the CDMA ERI icon index to display
3812 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003813 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003814 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3815 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3816 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003817 }
3818
Sanket Padawe356d7632015-06-22 14:03:32 -07003819 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003820 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3821 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003822 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003823 mApp, subId, callingPackage, callingFeatureId,
3824 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003825 return -1;
3826 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003827
3828 final long identity = Binder.clearCallingIdentity();
3829 try {
3830 final Phone phone = getPhone(subId);
3831 if (phone != null) {
3832 return phone.getCdmaEriIconIndex();
3833 } else {
3834 return -1;
3835 }
3836 } finally {
3837 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003838 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003839 }
3840
3841 /**
3842 * Returns the CDMA ERI icon mode,
3843 * 0 - ON
3844 * 1 - FLASHING
3845 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003846 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003847 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3848 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3849 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003850 }
3851
Sanket Padawe356d7632015-06-22 14:03:32 -07003852 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003853 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3854 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003855 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003856 mApp, subId, callingPackage, callingFeatureId,
3857 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003858 return -1;
3859 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003860
3861 final long identity = Binder.clearCallingIdentity();
3862 try {
3863 final Phone phone = getPhone(subId);
3864 if (phone != null) {
3865 return phone.getCdmaEriIconMode();
3866 } else {
3867 return -1;
3868 }
3869 } finally {
3870 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003872 }
3873
3874 /**
3875 * Returns the CDMA ERI text,
3876 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003877 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003878 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3879 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3880 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003881 }
3882
Sanket Padawe356d7632015-06-22 14:03:32 -07003883 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003884 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3885 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003886 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003887 mApp, subId, callingPackage, callingFeatureId,
3888 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003889 return null;
3890 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003891
3892 final long identity = Binder.clearCallingIdentity();
3893 try {
3894 final Phone phone = getPhone(subId);
3895 if (phone != null) {
3896 return phone.getCdmaEriText();
3897 } else {
3898 return null;
3899 }
3900 } finally {
3901 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003902 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003903 }
3904
3905 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003906 * Returns the CDMA MDN.
3907 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003908 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003909 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3911 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003912
3913 final long identity = Binder.clearCallingIdentity();
3914 try {
3915 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003916 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003917 return phone.getLine1Number();
3918 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003919 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003920 return null;
3921 }
3922 } finally {
3923 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003924 }
3925 }
3926
3927 /**
3928 * Returns the CDMA MIN.
3929 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003930 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003931 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3933 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003934
3935 final long identity = Binder.clearCallingIdentity();
3936 try {
3937 final Phone phone = getPhone(subId);
3938 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3939 return phone.getCdmaMin();
3940 } else {
3941 return null;
3942 }
3943 } finally {
3944 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003945 }
3946 }
3947
Hall Liud892bec2018-11-30 14:51:45 -08003948 @Override
3949 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3950 INumberVerificationCallback callback, String callingPackage) {
3951 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3952 != PERMISSION_GRANTED) {
3953 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3954 }
3955 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3956
3957 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3958 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003959 throw new SecurityException("Calling package must be configured in the device config: "
3960 + "calling package: " + callingPackage
3961 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003962 }
3963
3964 if (range == null) {
3965 throw new NullPointerException("Range must be non-null");
3966 }
3967
3968 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003969 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003970
3971 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3972 }
3973
Junda Liuca05d5d2014-08-14 22:36:34 -07003974 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003975 * Returns true if CDMA provisioning needs to run.
3976 */
3977 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003978 final long identity = Binder.clearCallingIdentity();
3979 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003980 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003981 } finally {
3982 Binder.restoreCallingIdentity(identity);
3983 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003984 }
3985
3986 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003987 * Sets the voice mail number of a given subId.
3988 */
3989 @Override
3990 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003991 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3992 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003993
3994 final long identity = Binder.clearCallingIdentity();
3995 try {
3996 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3997 new Pair<String, String>(alphaTag, number), new Integer(subId));
3998 return success;
3999 } finally {
4000 Binder.restoreCallingIdentity(identity);
4001 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004002 }
4003
Ta-wei Yen87c49842016-05-13 21:19:52 -07004004 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004005 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4006 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004007 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4008 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004009 if (!TextUtils.equals(callingPackage, systemDialer)) {
4010 throw new SecurityException("caller must be system dialer");
4011 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004012
4013 final long identity = Binder.clearCallingIdentity();
4014 try {
4015 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4016 if (phoneAccountHandle == null) {
4017 return null;
4018 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004019 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004020 } finally {
4021 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004022 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004023 }
4024
4025 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004026 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4027 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004028 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004029 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004030 mApp, subId, callingPackage, callingFeatureId,
4031 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004032 return null;
4033 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004034
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004035 final long identity = Binder.clearCallingIdentity();
4036 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004037 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004038 } finally {
4039 Binder.restoreCallingIdentity(identity);
4040 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004041 }
4042
4043 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004044 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4045 VisualVoicemailSmsFilterSettings settings) {
4046 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004047
4048 final long identity = Binder.clearCallingIdentity();
4049 try {
4050 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004051 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004052 } finally {
4053 Binder.restoreCallingIdentity(identity);
4054 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004055 }
4056
4057 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004058 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4059 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004060
4061 final long identity = Binder.clearCallingIdentity();
4062 try {
4063 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004064 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004065 } finally {
4066 Binder.restoreCallingIdentity(identity);
4067 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004068 }
4069
4070 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004071 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4072 String callingPackage, int subId) {
4073 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004074
4075 final long identity = Binder.clearCallingIdentity();
4076 try {
4077 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004078 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004079 } finally {
4080 Binder.restoreCallingIdentity(identity);
4081 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004082 }
4083
4084 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004085 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004086 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004087
4088 final long identity = Binder.clearCallingIdentity();
4089 try {
4090 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004091 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004092 } finally {
4093 Binder.restoreCallingIdentity(identity);
4094 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004095 }
4096
4097 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004098 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4099 String callingAttributionTag, int subId, String number, int port, String text,
4100 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004101 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004102 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004103 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004104 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004105 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4106 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004107 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004108
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004109 /**
fionaxu0152e512016-11-14 13:36:14 -08004110 * Sets the voice activation state of a given subId.
4111 */
4112 @Override
4113 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004114 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4115 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004116
4117 final long identity = Binder.clearCallingIdentity();
4118 try {
4119 final Phone phone = getPhone(subId);
4120 if (phone != null) {
4121 phone.setVoiceActivationState(activationState);
4122 } else {
4123 loge("setVoiceActivationState fails with invalid subId: " + subId);
4124 }
4125 } finally {
4126 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004127 }
4128 }
4129
4130 /**
4131 * Sets the data activation state of a given subId.
4132 */
4133 @Override
4134 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004135 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4136 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004137
4138 final long identity = Binder.clearCallingIdentity();
4139 try {
4140 final Phone phone = getPhone(subId);
4141 if (phone != null) {
4142 phone.setDataActivationState(activationState);
4143 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004144 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004145 }
4146 } finally {
4147 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004148 }
4149 }
4150
4151 /**
4152 * Returns the voice activation state of a given subId.
4153 */
4154 @Override
4155 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004156 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004157
fionaxu0152e512016-11-14 13:36:14 -08004158 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004159 final long identity = Binder.clearCallingIdentity();
4160 try {
4161 if (phone != null) {
4162 return phone.getVoiceActivationState();
4163 } else {
4164 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4165 }
4166 } finally {
4167 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004168 }
4169 }
4170
4171 /**
4172 * Returns the data activation state of a given subId.
4173 */
4174 @Override
4175 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004176 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004177
fionaxu0152e512016-11-14 13:36:14 -08004178 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004179 final long identity = Binder.clearCallingIdentity();
4180 try {
4181 if (phone != null) {
4182 return phone.getDataActivationState();
4183 } else {
4184 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4185 }
4186 } finally {
4187 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004188 }
4189 }
4190
4191 /**
Wink Saville36469e72014-06-11 15:17:00 -07004192 * Returns the unread count of voicemails for a subId
4193 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004194 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004195 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4196 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004197 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004198 mApp, subId, callingPackage, callingFeatureId,
4199 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004200 return 0;
4201 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004202 final long identity = Binder.clearCallingIdentity();
4203 try {
4204 final Phone phone = getPhone(subId);
4205 if (phone != null) {
4206 return phone.getVoiceMessageCount();
4207 } else {
4208 return 0;
4209 }
4210 } finally {
4211 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004212 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004213 }
4214
4215 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004216 * returns true, if the device is in a state where both voice and data
4217 * are supported simultaneously. This can change based on location or network condition.
4218 */
4219 @Override
4220 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004221 final long identity = Binder.clearCallingIdentity();
4222 try {
4223 final Phone phone = getPhone(subId);
4224 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4225 } finally {
4226 Binder.restoreCallingIdentity(identity);
4227 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004228 }
4229
4230 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004231 * Send the dialer code if called from the current default dialer or the caller has
4232 * carrier privilege.
4233 * @param inputCode The dialer code to send
4234 */
4235 @Override
4236 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004237 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004238 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004239 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4240 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004241 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004242 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004243 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004244 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004245
4246 final long identity = Binder.clearCallingIdentity();
4247 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004248 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004249 } finally {
4250 Binder.restoreCallingIdentity(identity);
4251 }
fionaxu235cc5e2017-03-06 22:25:57 -08004252 }
4253
Pengquan Menga1bb6272018-09-06 09:59:22 -07004254 @Override
4255 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004256 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004257 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004258 mApp, subId, "getNetworkSelectionMode");
4259 final long identity = Binder.clearCallingIdentity();
4260 try {
4261 if (!isActiveSubscription(subId)) {
4262 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4263 }
4264 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4265 } finally {
4266 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004267 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004268 }
4269
Brad Ebinger35c841c2018-10-01 10:40:55 -07004270 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004271 public boolean isInEmergencySmsMode() {
4272 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4273 final long identity = Binder.clearCallingIdentity();
4274 try {
4275 for (Phone phone : PhoneFactory.getPhones()) {
4276 if (phone.isInEmergencySmsMode()) {
4277 return true;
4278 }
4279 }
4280 } finally {
4281 Binder.restoreCallingIdentity(identity);
4282 }
4283 return false;
4284 }
4285
shilu366312e2019-12-17 09:28:10 -08004286 /**
4287 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4288 * @param subId The subscription to use to check the configuration.
4289 * @param c The callback that will be used to send the result.
4290 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004291 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004292 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4293 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004294 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004295 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004296
4297 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4298 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4299 "IMS not available on device.");
4300 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004301 final long token = Binder.clearCallingIdentity();
4302 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004303 int slotId = getSlotIndexOrException(subId);
4304 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004305
4306 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4307 if (controller != null) {
4308 ImsManager imsManager = controller.getImsManager(subId);
4309 if (imsManager != null) {
4310 imsManager.addRegistrationCallbackForSubscription(c, subId);
4311 } else {
4312 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4313 }
4314 } else {
4315 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4316 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004317 } catch (ImsException e) {
4318 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004319 } finally {
4320 Binder.restoreCallingIdentity(token);
4321 }
4322 }
4323
shilu366312e2019-12-17 09:28:10 -08004324 /**
4325 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4326 * @param subId The subscription to use to check the configuration.
4327 * @param c The callback that will be used to send the result.
4328 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004329 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004330 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004331 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004332 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004333 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4334 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4335 }
Meng Wangafbc5852019-09-19 17:37:13 -07004336 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004337
Meng Wangafbc5852019-09-19 17:37:13 -07004338 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004339 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4340 if (controller != null) {
4341 ImsManager imsManager = controller.getImsManager(subId);
4342 if (imsManager != null) {
4343 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4344 } else {
4345 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4346 + "is inactive, ignoring unregister.");
4347 // If the ImsManager is not valid, just return, since the callback
4348 // will already have been removed internally.
4349 }
4350 }
Meng Wangafbc5852019-09-19 17:37:13 -07004351 } finally {
4352 Binder.restoreCallingIdentity(token);
4353 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004354 }
4355
Brad Ebingera34a6c22019-10-22 17:36:18 -07004356 /**
4357 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4358 */
4359 @Override
4360 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4361 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4362 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4363 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4364 "IMS not available on device.");
4365 }
4366 final long token = Binder.clearCallingIdentity();
4367 try {
4368 Phone phone = getPhone(subId);
4369 if (phone == null) {
4370 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4371 + subId + "'");
4372 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4373 }
4374 phone.getImsRegistrationState(regState -> {
4375 try {
4376 consumer.accept((regState == null)
4377 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4378 } catch (RemoteException e) {
4379 // Ignore if the remote process is no longer available to call back.
4380 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4381 }
4382 });
4383 } finally {
4384 Binder.restoreCallingIdentity(token);
4385 }
4386 }
4387
4388 /**
4389 * Get the transport type for the IMS service registration state.
4390 */
4391 @Override
4392 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004393 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004394 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004395 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4396 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4397 "IMS not available on device.");
4398 }
4399 final long token = Binder.clearCallingIdentity();
4400 try {
4401 Phone phone = getPhone(subId);
4402 if (phone == null) {
4403 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4404 + subId + "'");
4405 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4406 }
4407 phone.getImsRegistrationTech(regTech -> {
4408 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4409 int regTechConverted = (regTech == null)
4410 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4411 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4412 regTechConverted);
4413 try {
4414 consumer.accept(regTechConverted);
4415 } catch (RemoteException e) {
4416 // Ignore if the remote process is no longer available to call back.
4417 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4418 }
4419 });
4420 } finally {
4421 Binder.restoreCallingIdentity(token);
4422 }
4423 }
4424
shilu366312e2019-12-17 09:28:10 -08004425 /**
4426 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4427 * @param subId The subscription to use to check the configuration.
4428 * @param c The callback that will be used to send the result.
4429 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004430 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004431 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4432 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004433 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004434 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004435 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4436 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4437 "IMS not available on device.");
4438 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004439 final long token = Binder.clearCallingIdentity();
4440 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004441 int slotId = getSlotIndexOrException(subId);
4442 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004443
4444 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4445 if (controller != null) {
4446 ImsManager imsManager = controller.getImsManager(subId);
4447 if (imsManager != null) {
4448 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4449 } else {
4450 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4451 }
4452 } else {
4453 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4454 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004455 } catch (ImsException e) {
4456 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004457 } finally {
4458 Binder.restoreCallingIdentity(token);
4459 }
4460 }
4461
shilu366312e2019-12-17 09:28:10 -08004462 /**
4463 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4464 * @param subId The subscription to use to check the configuration.
4465 * @param c The callback that will be used to send the result.
4466 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004467 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004468 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004469 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004470 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004471 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4472 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4473 }
Meng Wangafbc5852019-09-19 17:37:13 -07004474
4475 final long token = Binder.clearCallingIdentity();
4476 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004477 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4478 if (controller != null) {
4479 ImsManager imsManager = controller.getImsManager(subId);
4480 if (imsManager != null) {
4481 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4482 } else {
4483 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4484 + " is inactive, ignoring unregister.");
4485 // If the ImsManager is not valid, just return, since the callback
4486 // will already have been removed internally.
4487 }
4488 }
Meng Wangafbc5852019-09-19 17:37:13 -07004489 } finally {
4490 Binder.restoreCallingIdentity(token);
4491 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004492 }
4493
4494 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004495 public boolean isCapable(int subId, int capability, int regTech) {
4496 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004497 final long token = Binder.clearCallingIdentity();
4498 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004499 int slotId = getSlotIndexOrException(subId);
4500 verifyImsMmTelConfiguredOrThrow(slotId);
4501 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4502 } catch (com.android.ims.ImsException e) {
4503 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4504 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004505 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004506 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4507 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004508 } finally {
4509 Binder.restoreCallingIdentity(token);
4510 }
4511 }
4512
4513 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004514 public boolean isAvailable(int subId, int capability, int regTech) {
4515 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004516 final long token = Binder.clearCallingIdentity();
4517 try {
4518 Phone phone = getPhone(subId);
4519 if (phone == null) return false;
4520 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004521 } catch (com.android.ims.ImsException e) {
4522 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4523 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004524 } finally {
4525 Binder.restoreCallingIdentity(token);
4526 }
4527 }
4528
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004529 /**
4530 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4531 * subscription.
4532 * @param subId The subscription to use to check the configuration.
4533 * @param callback The callback that will be used to send the result.
4534 * @param capability The MmTelFeature capability that will be used to send the result.
4535 * @param transportType The transport type of the MmTelFeature capability.
4536 */
4537 @Override
4538 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4539 int transportType) {
4540 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004541 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4542 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4543 "IMS not available on device.");
4544 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004545 final long token = Binder.clearCallingIdentity();
4546 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004547 int slotId = getSlotIndex(subId);
4548 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4549 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4550 + subId + "'");
4551 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4552 }
4553 verifyImsMmTelConfiguredOrThrow(slotId);
4554 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4555 transportType, aBoolean -> {
4556 try {
4557 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4558 } catch (RemoteException e) {
4559 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4560 + "running. Ignore");
4561 }
4562 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004563 } catch (ImsException e) {
4564 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004565 } finally {
4566 Binder.restoreCallingIdentity(token);
4567 }
4568 }
4569
shilu366312e2019-12-17 09:28:10 -08004570 /**
4571 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4572 * @param subId The subscription to use to check the configuration.
4573 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004574 @Override
4575 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004576 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004577 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004578
Brad Ebinger35c841c2018-10-01 10:40:55 -07004579 final long token = Binder.clearCallingIdentity();
4580 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004581 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004582 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004583 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004584 } catch (ImsException e) {
4585 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004586 } finally {
4587 Binder.restoreCallingIdentity(token);
4588 }
4589 }
4590
4591 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004592 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004593 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004594 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004595 final long identity = Binder.clearCallingIdentity();
4596 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004597 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004598 // This setting doesn't require an active ImsService connection, so do not verify. The
4599 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004600 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004601 } catch (ImsException e) {
4602 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004603 } finally {
4604 Binder.restoreCallingIdentity(identity);
4605 }
4606 }
4607
shilu366312e2019-12-17 09:28:10 -08004608 /**
4609 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4610 * @param subId The subscription to use to check the configuration.
4611 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004612 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004613 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004614 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004615 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004616 final long identity = Binder.clearCallingIdentity();
4617 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004618 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004619 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004620 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004621 } catch (ImsException e) {
4622 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004623 } finally {
4624 Binder.restoreCallingIdentity(identity);
4625 }
4626 }
4627
4628 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004629 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004631 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004632 final long identity = Binder.clearCallingIdentity();
4633 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004634 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004635 // This setting doesn't require an active ImsService connection, so do not verify. The
4636 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004637 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004638 } catch (ImsException e) {
4639 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004640 } finally {
4641 Binder.restoreCallingIdentity(identity);
4642 }
4643 }
4644
shilu366312e2019-12-17 09:28:10 -08004645 /**
4646 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4647 * @param subId The subscription to use to check the configuration.
4648 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004649 @Override
4650 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004651 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004652 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004653 final long identity = Binder.clearCallingIdentity();
4654 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004655 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004656 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004657 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004658 } catch (ImsException e) {
4659 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004660 } finally {
4661 Binder.restoreCallingIdentity(identity);
4662 }
4663 }
4664
4665 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004666 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004668 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004669 final long identity = Binder.clearCallingIdentity();
4670 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004671 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004672 // This setting doesn't require an active ImsService connection, so do not verify. The
4673 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004674 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004675 } catch (ImsException e) {
4676 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004677 } finally {
4678 Binder.restoreCallingIdentity(identity);
4679 }
4680 }
4681
shilu366312e2019-12-17 09:28:10 -08004682 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004683 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4684 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4685 * @param subId The subscription to use to check the configuration.
4686 */
4687 @Override
4688 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004689 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004690 mApp, subId, "isCrossSimCallingEnabledByUser");
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).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004696 } catch (ImsException e) {
4697 throw new ServiceSpecificException(e.getCode());
4698 } finally {
4699 Binder.restoreCallingIdentity(identity);
4700 }
4701 }
4702
4703 /**
4704 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4705 * Requires MODIFY_PHONE_STATE permission.
4706 * @param subId The subscription to use to check the configuration.
4707 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4708 * false otherwise
4709 */
4710 @Override
4711 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4713 "setCrossSimCallingEnabled");
4714 final long identity = Binder.clearCallingIdentity();
4715 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004716 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004717 // This setting doesn't require an active ImsService connection, so do not verify. The
4718 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004719 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004720 } catch (ImsException e) {
4721 throw new ServiceSpecificException(e.getCode());
4722 } finally {
4723 Binder.restoreCallingIdentity(identity);
4724 }
4725 }
4726
4727 /**
shilu366312e2019-12-17 09:28:10 -08004728 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4729 * @param subId The subscription to use to check the configuration.
4730 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004731 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004732
Brad Ebinger35c841c2018-10-01 10:40:55 -07004733 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004734 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004735 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004736 final long identity = Binder.clearCallingIdentity();
4737 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004738 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004739 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004740 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004741 } catch (ImsException e) {
4742 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004743 } finally {
4744 Binder.restoreCallingIdentity(identity);
4745 }
4746 }
4747
4748 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004749 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004750 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004751 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004752 final long identity = Binder.clearCallingIdentity();
4753 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004754 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004755 // This setting doesn't require an active ImsService connection, so do not verify. The
4756 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004757 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004758 } catch (ImsException e) {
4759 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004760 } finally {
4761 Binder.restoreCallingIdentity(identity);
4762 }
4763 }
4764
4765 @Override
4766 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4768 "setVoWiFiNonPersistent");
4769 final long identity = Binder.clearCallingIdentity();
4770 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004771 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004772 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004773 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004774 } catch (ImsException e) {
4775 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004776 } finally {
4777 Binder.restoreCallingIdentity(identity);
4778 }
4779 }
4780
shilu366312e2019-12-17 09:28:10 -08004781 /**
4782 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4783 * @param subId The subscription to use to check the configuration.
4784 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004785 @Override
4786 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004787 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004788 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004789 final long identity = Binder.clearCallingIdentity();
4790 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004791 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004792 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004793 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004794 } catch (ImsException e) {
4795 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004796 } finally {
4797 Binder.restoreCallingIdentity(identity);
4798 }
4799 }
4800
4801 @Override
4802 public void setVoWiFiModeSetting(int subId, int mode) {
4803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4804 "setVoWiFiModeSetting");
4805 final long identity = Binder.clearCallingIdentity();
4806 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004807 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004808 // This setting doesn't require an active ImsService connection, so do not verify. The
4809 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004810 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004811 } catch (ImsException e) {
4812 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004813 } finally {
4814 Binder.restoreCallingIdentity(identity);
4815 }
4816 }
4817
4818 @Override
4819 public int getVoWiFiRoamingModeSetting(int subId) {
4820 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4821 final long identity = Binder.clearCallingIdentity();
4822 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004823 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004824 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004825 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004826 } catch (ImsException e) {
4827 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004828 } finally {
4829 Binder.restoreCallingIdentity(identity);
4830 }
4831 }
4832
4833 @Override
4834 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4836 "setVoWiFiRoamingModeSetting");
4837 final long identity = Binder.clearCallingIdentity();
4838 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004839 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004840 // This setting doesn't require an active ImsService connection, so do not verify. The
4841 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004842 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004843 } catch (ImsException e) {
4844 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004845 } finally {
4846 Binder.restoreCallingIdentity(identity);
4847 }
4848 }
4849
4850 @Override
4851 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4853 "setRttCapabilityEnabled");
4854 final long identity = Binder.clearCallingIdentity();
4855 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004856 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004857 // This setting doesn't require an active ImsService connection, so do not verify. The
4858 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004859 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004860 } catch (ImsException e) {
4861 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004862 } finally {
4863 Binder.restoreCallingIdentity(identity);
4864 }
4865 }
4866
shilu366312e2019-12-17 09:28:10 -08004867 /**
4868 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4869 * @param subId The subscription to use to check the configuration.
4870 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004871 @Override
4872 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004873 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004874 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004875 final long identity = Binder.clearCallingIdentity();
4876 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004877 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004878 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004879 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004880 } catch (ImsException e) {
4881 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004882 } finally {
4883 Binder.restoreCallingIdentity(identity);
4884 }
4885 }
4886
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004887 @Override
4888 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4889 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004890
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004891 final long identity = Binder.clearCallingIdentity();
4892 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004893 if (!isImsAvailableOnDevice()) {
4894 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4895 "IMS not available on device.");
4896 }
4897 int slotId = getSlotIndexOrException(subId);
4898 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004899
4900 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4901 if (controller != null) {
4902 ImsManager imsManager = controller.getImsManager(subId);
4903 if (imsManager != null) {
4904 imsManager.addProvisioningCallbackForSubscription(callback, subId);
4905 } else {
4906 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4907 }
4908 } else {
4909 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4910 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004911 } catch (ImsException e) {
4912 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004913 } finally {
4914 Binder.restoreCallingIdentity(identity);
4915 }
4916 }
4917
4918 @Override
4919 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4920 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004921
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004922 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004923 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4924 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4925 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004926 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004927 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4928 if (controller != null) {
4929 ImsManager imsManager = controller.getImsManager(subId);
4930 if (imsManager != null) {
4931 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
4932 } else {
4933 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4934 + " is inactive, ignoring unregister.");
4935 // If the ImsManager is not valid, just return, since the callback will already
4936 // have been removed internally.
4937 }
4938 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004939 } finally {
4940 Binder.restoreCallingIdentity(identity);
4941 }
4942 }
4943
joonhunshincffb7fc2021-11-28 07:32:01 +00004944 @Override
4945 public void registerFeatureProvisioningChangedCallback(int subId,
4946 IFeatureProvisioningCallback callback) {
4947 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4948 mApp, subId, "registerFeatureProvisioningChangedCallback");
4949
4950 final long identity = Binder.clearCallingIdentity();
4951 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4952 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4953 }
4954
joonhunshin91bc1952022-04-29 08:47:15 +00004955 try {
4956 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4957 if (controller == null) {
4958 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4959 "Device does not support IMS");
4960 }
4961 controller.addFeatureProvisioningChangedCallback(subId, callback);
4962 } finally {
4963 Binder.restoreCallingIdentity(identity);
4964 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004965 }
4966
4967 @Override
4968 public void unregisterFeatureProvisioningChangedCallback(int subId,
4969 IFeatureProvisioningCallback callback) {
4970 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4971 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4972
4973 final long identity = Binder.clearCallingIdentity();
4974 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4975 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4976 }
4977
joonhunshin91bc1952022-04-29 08:47:15 +00004978 try {
4979 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4980 if (controller == null) {
4981 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4982 return;
4983 }
4984 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4985 } finally {
4986 Binder.restoreCallingIdentity(identity);
4987 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004988 }
allenwtsu99c623b2020-01-03 18:24:23 +08004989
4990 private void checkModifyPhoneStatePermission(int subId, String message) {
4991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4992 message);
4993 }
4994
allenwtsu99c623b2020-01-03 18:24:23 +08004995 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004996 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004997 boolean isProvisioned) {
4998 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4999
5000 final long identity = Binder.clearCallingIdentity();
5001 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005002 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5003 if (controller == null) {
5004 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5005 return;
5006 }
5007 controller.setRcsProvisioningStatusForCapability(
5008 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005009 } finally {
5010 Binder.restoreCallingIdentity(identity);
5011 }
allenwtsu99c623b2020-01-03 18:24:23 +08005012 }
5013
5014
5015 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005016 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5017 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5018 mApp, subId, "getRcsProvisioningStatusForCapability");
5019
allenwtsu99c623b2020-01-03 18:24:23 +08005020 final long identity = Binder.clearCallingIdentity();
5021 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005022 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5023 if (controller == null) {
5024 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5025
5026 // device does not support IMS, this method will return true always.
5027 return true;
5028 }
5029 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005030 } finally {
5031 Binder.restoreCallingIdentity(identity);
5032 }
5033 }
5034
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005035 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005036 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5037 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005038 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005039
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005040 final long identity = Binder.clearCallingIdentity();
5041 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005042 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5043 if (controller == null) {
5044 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5045 return;
5046 }
5047 controller.setImsProvisioningStatusForCapability(
5048 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005049 } finally {
5050 Binder.restoreCallingIdentity(identity);
5051 }
5052 }
5053
5054 @Override
5055 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005056 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5057 mApp, subId, "getProvisioningStatusForCapability");
5058
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005059 final long identity = Binder.clearCallingIdentity();
5060 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005061 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5062 if (controller == null) {
5063 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005064
joonhunshin91bc1952022-04-29 08:47:15 +00005065 // device does not support IMS, this method will return true always.
5066 return true;
5067 }
5068 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005069 } finally {
5070 Binder.restoreCallingIdentity(identity);
5071 }
5072 }
5073
5074 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005075 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5076 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5077 mApp, subId, "isProvisioningRequiredForCapability");
5078
5079 final long identity = Binder.clearCallingIdentity();
5080 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005081 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5082 if (controller == null) {
5083 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5084
5085 // device does not support IMS, this method will return false
5086 return false;
5087 }
5088 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005089 } finally {
5090 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005091 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005092 }
5093
5094 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005095 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5096 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5097 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005098
joonhunshincffb7fc2021-11-28 07:32:01 +00005099 final long identity = Binder.clearCallingIdentity();
5100 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005101 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5102 if (controller == null) {
5103 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5104
5105 // device does not support IMS, this method will return false
5106 return false;
5107 }
5108 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005109 } finally {
5110 Binder.restoreCallingIdentity(identity);
5111 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005112 }
5113
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005114 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005115 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005116 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5117 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5118 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005119 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5120 mApp, subId, "getImsProvisioningInt");
5121
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005122 final long identity = Binder.clearCallingIdentity();
5123 try {
5124 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005125 int slotId = getSlotIndex(subId);
5126 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5127 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5128 + subId + "' for key:" + key);
5129 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5130 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005131
joonhunshin91bc1952022-04-29 08:47:15 +00005132 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5133 if (controller == null) {
5134 loge("getImsProvisioningInt: Device does not support IMS");
5135
5136 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5137 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5138 }
5139 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005140 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5141 return retVal;
5142 }
5143
calvinpanb5a34062021-02-08 19:59:36 +08005144 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005145 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005146 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5147 + subId + "' for key:" + key);
5148 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005149 } finally {
5150 Binder.restoreCallingIdentity(identity);
5151 }
5152 }
5153
5154 @Override
5155 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005156 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5157 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5158 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005159 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5160 mApp, subId, "getImsProvisioningString");
5161
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005162 final long identity = Binder.clearCallingIdentity();
5163 try {
5164 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005165 int slotId = getSlotIndex(subId);
5166 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5167 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5168 + subId + "' for key:" + key);
5169 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5170 }
calvinpanb5a34062021-02-08 19:59:36 +08005171 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005172 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005173 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5174 + subId + "' for key:" + key);
5175 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005176 } finally {
5177 Binder.restoreCallingIdentity(identity);
5178 }
5179 }
5180
5181 @Override
5182 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005183 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5184 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5185 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005186 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5187 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005188
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005189 final long identity = Binder.clearCallingIdentity();
5190 try {
5191 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005192 int slotId = getSlotIndex(subId);
5193 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5194 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5195 + subId + "' for key:" + key);
5196 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5197 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005198
joonhunshin91bc1952022-04-29 08:47:15 +00005199 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5200 if (controller == null) {
5201 loge("setImsProvisioningInt: Device does not support IMS");
5202
5203 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5204 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5205 }
5206 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005207 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5208 return retVal;
5209 }
5210
calvinpanb5a34062021-02-08 19:59:36 +08005211 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5212 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005213 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005214 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005215 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005216 } finally {
5217 Binder.restoreCallingIdentity(identity);
5218 }
5219 }
5220
5221 @Override
5222 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005223 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5224 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5225 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005226 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5227 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005228 final long identity = Binder.clearCallingIdentity();
5229 try {
5230 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005231 int slotId = getSlotIndex(subId);
5232 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5233 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5234 + subId + "' for key:" + key);
5235 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5236 }
calvinpanb5a34062021-02-08 19:59:36 +08005237 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5238 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005239 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005240 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005241 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005242 } finally {
5243 Binder.restoreCallingIdentity(identity);
5244 }
5245 }
5246
Brad Ebinger919631e2021-06-02 17:46:35 -07005247 /**
5248 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5249 * for the given slot ID or no ImsResolver instance has been created.
5250 * @param slotId The slot ID that the IMS service is created for.
5251 * @throws ImsException If there is no ImsService configured for this slot.
5252 */
5253 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5254 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5255 ImsFeature.FEATURE_MMTEL)) {
5256 throw new ImsException("This subscription does not support MMTEL over IMS",
5257 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5258 }
5259 }
5260
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005261 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005262 int slotId = SubscriptionManager.getSlotIndex(subId);
5263 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005264 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5265 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005266 }
5267 return slotId;
5268 }
5269
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005270 private int getSlotIndex(int subId) {
5271 int slotId = SubscriptionManager.getSlotIndex(subId);
5272 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5273 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5274 }
5275 return slotId;
5276 }
5277
Wink Saville36469e72014-06-11 15:17:00 -07005278 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005279 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005280 */
5281 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005282 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5283 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005284 try {
5285 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5286 } catch (SecurityException se) {
5287 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5288 throw new SecurityException("Package " + callingPackage + " does not belong to "
5289 + Binder.getCallingUid());
5290 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005291 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005292 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005293 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005294 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005295 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005296 mApp, subId, callingPackage, callingFeatureId,
5297 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005298 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5299 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005300
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301 final long identity = Binder.clearCallingIdentity();
5302 try {
5303 final Phone phone = getPhone(subId);
5304 if (phone != null) {
5305 return phone.getServiceState().getDataNetworkType();
5306 } else {
5307 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5308 }
5309 } finally {
5310 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005312 }
5313
5314 /**
5315 * Returns the data network type
5316 */
5317 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005318 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005319 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005320 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005321 }
5322
5323 /**
5324 * Returns the data network type for a subId
5325 */
5326 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005327 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5328 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005329 String functionName = "getDataNetworkTypeForSubscriber";
5330 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5331 mApp, functionName)) {
5332 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5333 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5334 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5335 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005336 }
5337
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005338 final long identity = Binder.clearCallingIdentity();
5339 try {
5340 final Phone phone = getPhone(subId);
5341 if (phone != null) {
5342 return phone.getServiceState().getDataNetworkType();
5343 } else {
5344 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5345 }
5346 } finally {
5347 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005348 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005349 }
5350
5351 /**
Wink Saville36469e72014-06-11 15:17:00 -07005352 * Returns the Voice network type for a subId
5353 */
5354 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005355 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5356 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005357 String functionName = "getVoiceNetworkTypeForSubscriber";
5358 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5359 mApp, functionName)) {
5360 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5361 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5362 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5363 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005364 }
5365
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005366 final long identity = Binder.clearCallingIdentity();
5367 try {
5368 final Phone phone = getPhone(subId);
5369 if (phone != null) {
5370 return phone.getServiceState().getVoiceNetworkType();
5371 } else {
5372 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5373 }
5374 } finally {
5375 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005376 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005377 }
5378
5379 /**
5380 * @return true if a ICC card is present
5381 */
5382 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005383 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005384 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005385 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005386 }
5387
5388 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005389 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005390 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005391 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005392 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393 final long identity = Binder.clearCallingIdentity();
5394 try {
5395 final Phone phone = PhoneFactory.getPhone(slotIndex);
5396 if (phone != null) {
5397 return phone.getIccCard().hasIccCard();
5398 } else {
5399 return false;
5400 }
5401 } finally {
5402 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005404 }
5405
5406 /**
5407 * Return if the current radio is LTE on CDMA. This
5408 * is a tri-state return value as for a period of time
5409 * the mode may be unknown.
5410 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005411 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005412 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005413 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005414 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005415 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005416 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5417 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5418 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005419 }
5420
Sanket Padawe356d7632015-06-22 14:03:32 -07005421 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005422 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5423 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005424 try {
5425 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5426 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005427 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5428 }
5429
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 final long identity = Binder.clearCallingIdentity();
5431 try {
5432 final Phone phone = getPhone(subId);
5433 if (phone == null) {
5434 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5435 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005436 return TelephonyProperties.lte_on_cdma_device()
5437 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005438 }
5439 } finally {
5440 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005441 }
Wink Saville36469e72014-06-11 15:17:00 -07005442 }
5443
Wink Saville36469e72014-06-11 15:17:00 -07005444 /**
5445 * {@hide}
5446 * Returns Default subId, 0 in the case of single standby.
5447 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005448 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005449 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005450 }
5451
Shishir Agrawala9f32182016-04-12 12:00:16 -07005452 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005453 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005454 }
5455
Wink Savilleb564aae2014-10-23 10:18:09 -07005456 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005457 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005458 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005459
Pengquan Menge92a50d2018-09-21 15:54:48 -07005460 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08005461 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
5462 return SubscriptionManagerService.getInstance().isActiveSubId(subId,
5463 mApp.getOpPackageName(), mApp.getFeatureId());
5464 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005465 return mSubscriptionController.isActiveSubId(subId);
5466 }
5467
Ihab Awadf2177b72013-11-25 13:33:23 -08005468 /**
5469 * @see android.telephony.TelephonyManager.WifiCallingChoices
5470 */
5471 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005472 final long identity = Binder.clearCallingIdentity();
5473 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005474 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5476 getWhenToMakeWifiCallsDefaultPreference());
5477 } finally {
5478 Binder.restoreCallingIdentity(identity);
5479 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005480 }
5481
5482 /**
5483 * @see android.telephony.TelephonyManager.WifiCallingChoices
5484 */
5485 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005486 final long identity = Binder.clearCallingIdentity();
5487 try {
5488 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005489 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005490 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5491 } finally {
5492 Binder.restoreCallingIdentity(identity);
5493 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005494 }
5495
Sailesh Nepald1e68152013-12-12 19:08:02 -08005496 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005497 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005498 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005499 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005500
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005501 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5502 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5503 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005504 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005505 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5506 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005507 }
5508 return PhoneFactory.getPhone(phoneId);
5509 }
5510
Shishir Agrawal566b7612013-10-28 14:41:00 -07005511 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005512 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005513 @NonNull IccLogicalChannelRequest request) {
5514 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5515 /*message=*/ "iccOpenLogicalChannel");
5516
5517 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5518 // Verify that the callingPackage in the request belongs to the calling UID
5519 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5520
5521 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005522 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005523
Rambo Wanga1782702021-11-10 20:15:19 -08005524 private Phone getPhoneFromValidIccLogicalChannelRequest(
5525 @NonNull IccLogicalChannelRequest request, String message) {
5526 Phone phone;
5527 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5529 mApp, request.subId, message);
5530 phone = getPhoneFromSubId(request.subId);
5531 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5532 enforceModifyPermission();
5533 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5534 } else {
5535 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005536 }
Rambo Wanga1782702021-11-10 20:15:19 -08005537 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005538 }
5539
5540 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005541 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005542 final long identity = Binder.clearCallingIdentity();
5543 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005544 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005545 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005546 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5547 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005548 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5549 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005550 loge("The calling package is not allowed to access ISD-R.");
5551 throw new SecurityException(
5552 "The calling package is not allowed to access ISD-R.");
5553 }
Derek Tan740e1672017-06-27 14:56:27 -07005554 }
Derek Tan740e1672017-06-27 14:56:27 -07005555
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005556 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005557 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5558 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005559 return response;
5560 } finally {
5561 Binder.restoreCallingIdentity(identity);
5562 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005563 }
5564
5565 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005566 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5567 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5568 /*message=*/"iccCloseLogicalChannel");
5569
5570 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5571
5572 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005573 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005574
Rambo Wanga1782702021-11-10 20:15:19 -08005575 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5576 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005577 // before this feature is enabled, this API should only return false if
5578 // the operation fails instead of throwing runtime exception for
5579 // backward-compatibility.
5580 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5581 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582 final long identity = Binder.clearCallingIdentity();
5583 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005584 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005585 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005586 }
Chen Xue9d737e2022-01-01 23:41:31 -08005587 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005588 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005589 Boolean success = false;
5590 if (result instanceof RuntimeException) {
5591 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005592 if (shouldThrowExceptionOnFailure) {
5593 throw (RuntimeException) result;
5594 } else {
5595 return false;
5596 }
Chen Xue9d737e2022-01-01 23:41:31 -08005597 } else if (result instanceof Boolean) {
5598 success = (Boolean) result;
5599 } else {
5600 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5601 }
Rambo Wanga1782702021-11-10 20:15:19 -08005602 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005603 return success;
5604 } finally {
5605 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005606 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005607 }
5608
5609 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005610 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005611 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5613 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005614 if (DBG) {
5615 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5616 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5617 + p3 + " data=" + data);
5618 }
5619 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5620 command, p1, p2, p3, data);
5621 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005622
Jordan Liu4c733742019-02-28 12:03:40 -08005623 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005624 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5625 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005626 enforceModifyPermission();
5627 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005628 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5629 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5630 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005631 }
5632 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005633 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5634 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005635 }
5636
5637 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5638 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005639 final long identity = Binder.clearCallingIdentity();
5640 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005641 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642 return "";
5643 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005644
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005645 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005646 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5647 null /* workSource */);
5648 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005649
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005650 // Append the returned status code to the end of the response payload.
5651 String s = Integer.toHexString(
5652 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5653 if (response.payload != null) {
5654 s = IccUtils.bytesToHexString(response.payload) + s;
5655 }
5656 return s;
5657 } finally {
5658 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005659 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005660 }
Jake Hambye994d462014-02-03 13:10:13 -08005661
Evan Charltonc66da362014-05-16 14:06:40 -07005662 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005663 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5664 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5666 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005667 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005668 if (DBG) {
5669 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5670 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5671 }
5672 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5673 cla, command, p1, p2, p3, data);
5674 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005675
Jordan Liu4c733742019-02-28 12:03:40 -08005676 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005677 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5678 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005679 enforceModifyPermission();
5680 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5681 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005682 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5683 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5684 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005685 }
5686
5687 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005688 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5689 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005690 }
5691
5692 // open APDU basic channel assuming the caller has sufficient permissions
5693 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5694 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695 final long identity = Binder.clearCallingIdentity();
5696 try {
5697 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5698 && TextUtils.equals(ISDR_AID, data)) {
5699 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005700 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5701 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 if (bestComponent == null
5703 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5704 loge("The calling package is not allowed to select ISD-R.");
5705 throw new SecurityException(
5706 "The calling package is not allowed to select ISD-R.");
5707 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005708 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005709
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005710 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005711 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5712 null /* workSource */);
5713 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005714
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005715 // Append the returned status code to the end of the response payload.
5716 String s = Integer.toHexString(
5717 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5718 if (response.payload != null) {
5719 s = IccUtils.bytesToHexString(response.payload) + s;
5720 }
5721 return s;
5722 } finally {
5723 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005724 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005725 }
5726
5727 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005728 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005729 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5731 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005732
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005733 final long identity = Binder.clearCallingIdentity();
5734 try {
5735 if (DBG) {
5736 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5737 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5738 }
5739
5740 IccIoResult response =
5741 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5742 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5743 subId);
5744
5745 if (DBG) {
5746 log("Exchange SIM_IO [R]" + response);
5747 }
5748
5749 byte[] result = null;
5750 int length = 2;
5751 if (response.payload != null) {
5752 length = 2 + response.payload.length;
5753 result = new byte[length];
5754 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5755 } else {
5756 result = new byte[length];
5757 }
5758
5759 result[length - 1] = (byte) response.sw2;
5760 result[length - 2] = (byte) response.sw1;
5761 return result;
5762 } finally {
5763 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005764 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005765 }
5766
Nathan Haroldb3014052017-01-25 15:57:32 -08005767 /**
5768 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5769 * on a particular subscription
5770 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005771 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5772 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005773 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005774 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005775 return null;
5776 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005777
5778 final long identity = Binder.clearCallingIdentity();
5779 try {
5780 if (appType != TelephonyManager.APPTYPE_USIM
5781 && appType != TelephonyManager.APPTYPE_SIM) {
5782 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5783 return null;
5784 }
5785 Object response = sendRequest(
5786 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5787 if (response instanceof String[]) {
5788 return (String[]) response;
5789 }
yincheng zhao2737e882019-09-06 17:06:54 -07005790 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005792 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005793 } finally {
5794 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005795 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005796 }
5797
yincheng zhao2737e882019-09-06 17:06:54 -07005798 /**
5799 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5800 * subscription.
5801 *
5802 * @param subId the id of the subscription.
5803 * @param appType the uicc app type, must be USIM or SIM.
5804 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5805 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005806 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005807 * @return number of fplmns that is successfully written to the SIM.
5808 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005809 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5810 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5812 mApp, subId, "setForbiddenPlmns");
5813
yincheng zhao2737e882019-09-06 17:06:54 -07005814 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5815 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5816 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5817 }
5818 if (fplmns == null) {
5819 throw new IllegalArgumentException("Fplmn List provided is null");
5820 }
5821 for (String fplmn : fplmns) {
5822 if (!CellIdentity.isValidPlmn(fplmn)) {
5823 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5824 }
5825 }
5826 final long identity = Binder.clearCallingIdentity();
5827 try {
5828 Object response = sendRequest(
5829 CMD_SET_FORBIDDEN_PLMNS,
5830 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5831 subId);
5832 return (int) response;
5833 } finally {
5834 Binder.restoreCallingIdentity(identity);
5835 }
5836 }
5837
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005838 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005839 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5841 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005842
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005843 final long identity = Binder.clearCallingIdentity();
5844 try {
5845 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5846 if (response.payload == null) {
5847 return "";
5848 }
Evan Charltonc66da362014-05-16 14:06:40 -07005849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005850 // Append the returned status code to the end of the response payload.
5851 String s = Integer.toHexString(
5852 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5853 s = IccUtils.bytesToHexString(response.payload) + s;
5854 return s;
5855 } finally {
5856 Binder.restoreCallingIdentity(identity);
5857 }
Evan Charltonc66da362014-05-16 14:06:40 -07005858 }
5859
Jake Hambye994d462014-02-03 13:10:13 -08005860 /**
5861 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5862 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5863 *
5864 * @param itemID the ID of the item to read
5865 * @return the NV item as a String, or null on error.
5866 */
5867 @Override
5868 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005869 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5871 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005872
5873 final long identity = Binder.clearCallingIdentity();
5874 try {
5875 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005876 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005877 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5878 return value;
5879 } finally {
5880 Binder.restoreCallingIdentity(identity);
5881 }
Jake Hambye994d462014-02-03 13:10:13 -08005882 }
5883
5884 /**
5885 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5886 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5887 *
5888 * @param itemID the ID of the item to read
5889 * @param itemValue the value to write, as a String
5890 * @return true on success; false on any failure
5891 */
5892 @Override
5893 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005894 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005895 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5896 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005897
5898 final long identity = Binder.clearCallingIdentity();
5899 try {
5900 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5901 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005902 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005903 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5904 return success;
5905 } finally {
5906 Binder.restoreCallingIdentity(identity);
5907 }
Jake Hambye994d462014-02-03 13:10:13 -08005908 }
5909
5910 /**
5911 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5912 * Used for device configuration by some CDMA operators.
5913 *
5914 * @param preferredRoamingList byte array containing the new PRL
5915 * @return true on success; false on any failure
5916 */
5917 @Override
5918 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005919 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5920 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005921
5922 final long identity = Binder.clearCallingIdentity();
5923 try {
5924 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5925 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5926 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5927 return success;
5928 } finally {
5929 Binder.restoreCallingIdentity(identity);
5930 }
Jake Hambye994d462014-02-03 13:10:13 -08005931 }
5932
5933 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005934 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005935 * Used for device configuration by some CDMA operators.
5936 *
chen xu6dac5ab2018-10-26 17:39:23 -07005937 * @param slotIndex - device slot.
5938 *
Jake Hambye994d462014-02-03 13:10:13 -08005939 * @return true on success; false on any failure
5940 */
5941 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005942 public boolean resetModemConfig(int slotIndex) {
5943 Phone phone = PhoneFactory.getPhone(slotIndex);
5944 if (phone != null) {
5945 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5946 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005947
chen xu6dac5ab2018-10-26 17:39:23 -07005948 final long identity = Binder.clearCallingIdentity();
5949 try {
5950 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5951 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5952 return success;
5953 } finally {
5954 Binder.restoreCallingIdentity(identity);
5955 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005956 }
chen xu6dac5ab2018-10-26 17:39:23 -07005957 return false;
5958 }
5959
5960 /**
5961 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5962 *
5963 * @param slotIndex - device slot.
5964 *
5965 * @return true on success; false on any failure
5966 */
5967 @Override
5968 public boolean rebootModem(int slotIndex) {
5969 Phone phone = PhoneFactory.getPhone(slotIndex);
5970 if (phone != null) {
5971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5972 mApp, phone.getSubId(), "rebootModem");
5973
5974 final long identity = Binder.clearCallingIdentity();
5975 try {
5976 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5977 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5978 return success;
5979 } finally {
5980 Binder.restoreCallingIdentity(identity);
5981 }
5982 }
5983 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005984 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005985
Brad Ebinger51f743a2017-01-23 13:50:20 -08005986 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005987 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5988 * {@link #disableIms(int)}.
5989 * @param slotIndex device slot.
5990 */
5991 public void resetIms(int slotIndex) {
5992 enforceModifyPermission();
5993
5994 final long identity = Binder.clearCallingIdentity();
5995 try {
5996 if (mImsResolver == null) {
5997 // may happen if the does not support IMS.
5998 return;
5999 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006000 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006001 } finally {
6002 Binder.restoreCallingIdentity(identity);
6003 }
6004 }
6005
6006 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006007 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6008 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006009 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006010 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006011 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012
6013 final long identity = Binder.clearCallingIdentity();
6014 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006015 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006016 // may happen if the device does not support IMS.
6017 return;
6018 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006019 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006020 } finally {
6021 Binder.restoreCallingIdentity(identity);
6022 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006023 }
6024
6025 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006026 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6027 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006028 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006029 public void disableIms(int slotId) {
6030 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006031
6032 final long identity = Binder.clearCallingIdentity();
6033 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006034 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006035 // may happen if the device does not support IMS.
6036 return;
6037 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006038 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039 } finally {
6040 Binder.restoreCallingIdentity(identity);
6041 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006042 }
6043
6044 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006045 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6046 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006047 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006048 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006049 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006050 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006051
6052 final long identity = Binder.clearCallingIdentity();
6053 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006054 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006055 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6056 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006057 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006058 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006059 } finally {
6060 Binder.restoreCallingIdentity(identity);
6061 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006062 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006063 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006064 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6065 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006066 @Override
6067 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006068 enforceModifyPermission();
6069
6070 final long identity = Binder.clearCallingIdentity();
6071 try {
6072 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006073 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006074 } finally {
6075 Binder.restoreCallingIdentity(identity);
6076 }
6077 }
6078
6079 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006080 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006081 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006082 */
6083 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6084 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085
6086 final long identity = Binder.clearCallingIdentity();
6087 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006088 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006089 // may happen if the device does not support IMS.
6090 return null;
6091 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006092 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006093 } finally {
6094 Binder.restoreCallingIdentity(identity);
6095 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006096 }
6097
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006098 /**
6099 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006100 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006101 */
6102 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6103 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006104
6105 final long identity = Binder.clearCallingIdentity();
6106 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006107 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006108 // may happen if the device does not support IMS.
6109 return null;
6110 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006111 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112 } finally {
6113 Binder.restoreCallingIdentity(identity);
6114 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006115 }
6116
Brad Ebinger884c07b2018-02-15 16:17:40 -08006117 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006118 * Sets the ImsService Package Name that Telephony will bind to.
6119 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006120 * @param slotIndex the slot ID that the ImsService should bind for.
6121 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006122 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006123 * @param featureTypes An integer array of feature types associated with a packageName.
6124 * @param packageName The name of the package that the current configuration will be replaced
6125 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006126 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006127 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006128 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6129 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006130 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006131 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006132 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006133
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134 final long identity = Binder.clearCallingIdentity();
6135 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006136 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006137 // may happen if the device does not support IMS.
6138 return false;
6139 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006140 Map<Integer, String> featureConfig = new HashMap<>();
6141 for (int featureType : featureTypes) {
6142 featureConfig.put(featureType, packageName);
6143 }
6144 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6145 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006146 } finally {
6147 Binder.restoreCallingIdentity(identity);
6148 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006149 }
6150
6151 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006152 * Clears any carrier ImsService overrides for the slot index specified that were previously
6153 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6154 *
6155 * This should only be used for testing.
6156 *
6157 * @param slotIndex the slot ID that the ImsService should bind for.
6158 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6159 */
6160 @Override
6161 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006162 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6163 "clearCarrierImsServiceOverride");
6164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006165 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006166
6167 final long identity = Binder.clearCallingIdentity();
6168 try {
6169 if (mImsResolver == null) {
6170 // may happen if the device does not support IMS.
6171 return false;
6172 }
6173 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6174 } finally {
6175 Binder.restoreCallingIdentity(identity);
6176 }
6177 }
6178
6179 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006180 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006181 *
6182 * @param slotId The slot that the ImsService is associated with.
6183 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6184 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006185 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006186 * @return the package name of the ImsService configuration.
6187 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006188 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6189 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006190 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006191 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6192 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006193
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006194 final long identity = Binder.clearCallingIdentity();
6195 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006196 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006197 // may happen if the device does not support IMS.
6198 return "";
6199 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006200 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006201 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6202 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006203 } finally {
6204 Binder.restoreCallingIdentity(identity);
6205 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006206 }
6207
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006208 /**
6209 * Get the MmTelFeature state associated with the requested subscription id.
6210 * @param subId The subscription that the MmTelFeature is associated with.
6211 * @param callback A callback with an integer containing the
6212 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6213 */
6214 @Override
6215 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6216 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006217 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6218 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6219 "IMS not available on device.");
6220 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006221 final long token = Binder.clearCallingIdentity();
6222 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006223 int slotId = getSlotIndex(subId);
6224 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6225 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6226 + subId + "'");
6227 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6228 }
6229 verifyImsMmTelConfiguredOrThrow(slotId);
6230 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6231 try {
6232 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6233 } catch (RemoteException e) {
6234 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6235 + "Ignore");
6236 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006237 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006238 } catch (ImsException e) {
6239 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006240 } finally {
6241 Binder.restoreCallingIdentity(token);
6242 }
6243 }
6244
Daniel Brightbb5840b2021-01-12 15:48:18 -08006245 /**
6246 * Sets the ims registration state on all valid {@link Phone}s.
6247 */
6248 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006249 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006250
6251 final long identity = Binder.clearCallingIdentity();
6252 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006253 // NOTE: Before S, this method only set the default phone.
6254 for (final Phone phone : PhoneFactory.getPhones()) {
6255 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6256 phone.setImsRegistrationState(registered);
6257 }
6258 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259 } finally {
6260 Binder.restoreCallingIdentity(identity);
6261 }
Wink Saville36469e72014-06-11 15:17:00 -07006262 }
6263
6264 /**
Stuart Scott54788802015-03-30 13:18:01 -07006265 * Set the network selection mode to automatic.
6266 *
6267 */
6268 @Override
6269 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6271 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006272
6273 final long identity = Binder.clearCallingIdentity();
6274 try {
shilufc958392020-01-20 11:36:01 -08006275 if (!isActiveSubscription(subId)) {
6276 return;
6277 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006278 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006279 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6280 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006281 } finally {
6282 Binder.restoreCallingIdentity(identity);
6283 }
Stuart Scott54788802015-03-30 13:18:01 -07006284 }
6285
Jack Yud10cdd42020-09-28 20:28:01 -07006286 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006287 * Ask the radio to connect to the input network and change selection mode to manual.
6288 *
6289 * @param subId the id of the subscription.
6290 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6291 * the operator to attach to.
6292 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6293 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6294 * normal network selection next time.
6295 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006296 */
6297 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006298 public boolean setNetworkSelectionModeManual(
6299 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006300 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6301 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006302
Jack Yu285100e2022-12-02 22:48:35 -08006303 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006304 if (!isActiveSubscription(subId)) {
6305 return false;
6306 }
6307
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006308 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006309 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006310 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006311 if (DBG) {
6312 log("setNetworkSelectionModeManual: subId: " + subId
6313 + " operator: " + operatorInfo);
6314 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006315 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6316 } finally {
6317 Binder.restoreCallingIdentity(identity);
6318 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006319 }
shilu84f6e8b2019-12-19 13:58:01 -08006320 /**
6321 * Get the manual network selection
6322 *
6323 * @param subId the id of the subscription.
6324 *
6325 * @return the previously saved user selected PLMN
6326 */
6327 @Override
6328 public String getManualNetworkSelectionPlmn(int subId) {
6329 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006330 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006331 mApp, subId, "getManualNetworkSelectionPlmn");
6332
6333 final long identity = Binder.clearCallingIdentity();
6334 try {
6335 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006336 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006337 }
6338
6339 final Phone phone = getPhone(subId);
6340 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006341 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006342 }
6343 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6344 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6345 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6346 } finally {
6347 Binder.restoreCallingIdentity(identity);
6348 }
6349 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006350
6351 /**
6352 * Scans for available networks.
6353 */
6354 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006355 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6356 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6358 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006359 LocationAccessPolicy.LocationPermissionResult locationResult =
6360 LocationAccessPolicy.checkLocationPermission(mApp,
6361 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6362 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006363 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006364 .setCallingPid(Binder.getCallingPid())
6365 .setCallingUid(Binder.getCallingUid())
6366 .setMethod("getCellNetworkScanResults")
6367 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006368 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6369 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006370 .build());
6371 switch (locationResult) {
6372 case DENIED_HARD:
6373 throw new SecurityException("Not allowed to access scan results -- location");
6374 case DENIED_SOFT:
6375 return null;
6376 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006377
Pengquan Menga1bb6272018-09-06 09:59:22 -07006378 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379 try {
6380 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006381 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006382 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006383 } finally {
6384 Binder.restoreCallingIdentity(identity);
6385 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006386 }
6387
6388 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006389 * Get the call forwarding info, given the call forwarding reason.
6390 */
6391 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006392 public void getCallForwarding(int subId, int callForwardingReason,
6393 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006394 enforceReadPrivilegedPermission("getCallForwarding");
6395 long identity = Binder.clearCallingIdentity();
6396 try {
6397 if (DBG) {
6398 log("getCallForwarding: subId " + subId
6399 + " callForwardingReason" + callForwardingReason);
6400 }
Hall Liu27d24262020-09-18 19:04:59 -07006401
6402 Phone phone = getPhone(subId);
6403 if (phone == null) {
6404 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006405 callback.onError(
6406 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006407 } catch (RemoteException e) {
6408 // ignore
6409 }
6410 return;
6411 }
6412
6413 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6414 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6415 @Override
6416 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6417 try {
6418 callback.onCallForwardingInfoAvailable(info);
6419 } catch (RemoteException e) {
6420 // ignore
6421 }
6422 }
6423
6424 @Override
6425 public void onError(int error) {
6426 try {
6427 callback.onError(error);
6428 } catch (RemoteException e) {
6429 // ignore
6430 }
6431 }
6432 });
6433 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006434 } finally {
6435 Binder.restoreCallingIdentity(identity);
6436 }
6437 }
6438
6439 /**
6440 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6441 * reason, the number to forward, and the timeout before the forwarding is attempted.
6442 */
6443 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006444 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6445 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006446 enforceModifyPermission();
6447 long identity = Binder.clearCallingIdentity();
6448 try {
6449 if (DBG) {
6450 log("setCallForwarding: subId " + subId
6451 + " callForwardingInfo" + callForwardingInfo);
6452 }
Hall Liu27d24262020-09-18 19:04:59 -07006453
6454 Phone phone = getPhone(subId);
6455 if (phone == null) {
6456 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006457 callback.accept(
6458 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006459 } catch (RemoteException e) {
6460 // ignore
6461 }
6462 return;
6463 }
6464
6465 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6466 FunctionalUtils.ignoreRemoteException(callback::accept));
6467
6468 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006469 } finally {
6470 Binder.restoreCallingIdentity(identity);
6471 }
6472 }
6473
6474 /**
Hall Liu27d24262020-09-18 19:04:59 -07006475 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006476 */
6477 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006478 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006479 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006480 long identity = Binder.clearCallingIdentity();
6481 try {
Hall Liu27d24262020-09-18 19:04:59 -07006482 Phone phone = getPhone(subId);
6483 if (phone == null) {
6484 try {
6485 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6486 } catch (RemoteException e) {
6487 // ignore
6488 }
6489 return;
6490 }
SongFerngWang0e767992021-03-31 22:08:45 +08006491 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6492 PersistableBundle c = configManager.getConfigForSubId(subId);
6493 boolean requireUssd = c.getBoolean(
6494 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006495
Shuo Qian4a594052020-01-23 11:59:30 -08006496 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006497 if (requireUssd) {
6498 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6499 getSubscriptionCarrierId(subId));
6500 String newUssdCommand = "";
6501 try {
6502 newUssdCommand = carrierXmlParser.getFeature(
6503 CarrierXmlParser.FEATURE_CALL_WAITING)
6504 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6505 } catch (NullPointerException e) {
6506 loge("Failed to generate USSD number" + e);
6507 }
6508 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6509 mMainThreadHandler, callback, carrierXmlParser,
6510 CarrierXmlParser.SsEntry.SSAction.QUERY);
6511 final String ussdCommand = newUssdCommand;
6512 Executors.newSingleThreadExecutor().execute(() -> {
6513 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6514 });
6515 } else {
6516 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6517 callback::accept);
6518 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6519 }
Shuo Qian4a594052020-01-23 11:59:30 -08006520 } finally {
6521 Binder.restoreCallingIdentity(identity);
6522 }
6523 }
6524
6525 /**
Hall Liu27d24262020-09-18 19:04:59 -07006526 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006527 */
6528 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006529 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006530 enforceModifyPermission();
6531 long identity = Binder.clearCallingIdentity();
6532 try {
Hall Liu27d24262020-09-18 19:04:59 -07006533 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6534
6535 Phone phone = getPhone(subId);
6536 if (phone == null) {
6537 try {
6538 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6539 } catch (RemoteException e) {
6540 // ignore
6541 }
6542 return;
6543 }
6544
SongFerngWang0e767992021-03-31 22:08:45 +08006545 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6546 PersistableBundle c = configManager.getConfigForSubId(subId);
6547 boolean requireUssd = c.getBoolean(
6548 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006549
SongFerngWang0e767992021-03-31 22:08:45 +08006550 if (DBG) log("getCallWaitingStatus: subId " + subId);
6551 if (requireUssd) {
6552 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6553 getSubscriptionCarrierId(subId));
6554 CarrierXmlParser.SsEntry.SSAction ssAction =
6555 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6556 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6557 String newUssdCommand = "";
6558 try {
6559 newUssdCommand = carrierXmlParser.getFeature(
6560 CarrierXmlParser.FEATURE_CALL_WAITING)
6561 .makeCommand(ssAction, null);
6562 } catch (NullPointerException e) {
6563 loge("Failed to generate USSD number" + e);
6564 }
6565 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6566 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6567 final String ussdCommand = newUssdCommand;
6568 Executors.newSingleThreadExecutor().execute(() -> {
6569 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6570 });
6571 } else {
6572 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6573 FunctionalUtils.ignoreRemoteException(callback::accept));
6574
6575 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6576 }
Shuo Qian4a594052020-01-23 11:59:30 -08006577 } finally {
6578 Binder.restoreCallingIdentity(identity);
6579 }
6580 }
6581
6582 /**
yinxub1bed742017-04-17 11:45:04 -07006583 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006584 *
yinxub1bed742017-04-17 11:45:04 -07006585 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006586 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6587 * location related information which will be sent if the caller already possess
6588 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006589 * @param request contains the radio access networks with bands/channels to scan
6590 * @param messenger callback messenger for scan results or errors
6591 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006592 * @return the id of the requested scan which can be used to stop the scan.
6593 */
6594 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006595 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6596 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006597 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006598 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6599 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006600 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006601 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6602 if (!renounceFineLocationAccess) {
6603 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6604 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6605 .setCallingPackage(callingPackage)
6606 .setCallingFeatureId(callingFeatureId)
6607 .setCallingPid(Binder.getCallingPid())
6608 .setCallingUid(Binder.getCallingUid())
6609 .setMethod("requestNetworkScan")
6610 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6611 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6612 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6613 .build());
6614 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006615 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006616 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6617 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006618 if (e != null) {
6619 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6620 throw e;
6621 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006622 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006623 return TelephonyScanManager.INVALID_SCAN_ID;
6624 }
6625 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006626 }
Hall Liu912dfd32019-04-25 14:02:26 -07006627 int callingUid = Binder.getCallingUid();
6628 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006629 final long identity = Binder.clearCallingIdentity();
6630 try {
6631 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006632 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006633 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006634 } finally {
6635 Binder.restoreCallingIdentity(identity);
6636 }
yinxu504e1392017-04-12 16:03:22 -07006637 }
6638
Hall Liub2ac8ef2019-02-28 15:56:23 -08006639 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006640 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006641 boolean hasCarrierPriv;
6642 final long identity = Binder.clearCallingIdentity();
6643 try {
6644 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6645 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6646 } finally {
6647 Binder.restoreCallingIdentity(identity);
6648 }
Hall Liu558027f2019-05-15 19:14:05 -07006649 boolean hasNetworkScanPermission =
6650 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6651 == PERMISSION_GRANTED;
6652
6653 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6654 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6655 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006656 }
6657
6658 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6659 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006660 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6661 return new SecurityException("Specific channels must not be"
6662 + " scanned without location access.");
6663 }
6664 }
6665 }
6666
Hall Liub2ac8ef2019-02-28 15:56:23 -08006667 return null;
6668 }
6669
yinxu504e1392017-04-12 16:03:22 -07006670 /**
6671 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006672 *
6673 * @param subId id of the subscription
6674 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006675 */
6676 @Override
6677 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006678 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6679 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006680
Hall Liu912dfd32019-04-25 14:02:26 -07006681 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006682 final long identity = Binder.clearCallingIdentity();
6683 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006684 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006685 } finally {
6686 Binder.restoreCallingIdentity(identity);
6687 }
yinxu504e1392017-04-12 16:03:22 -07006688 }
6689
6690 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006691 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006692 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006693 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006694 */
6695 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006696 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006697 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006698 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006699 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006700
6701 final long identity = Binder.clearCallingIdentity();
6702 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006703 if (DBG) log("getAllowedNetworkTypesBitmask");
6704 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6705 int networkTypesBitmask = (result != null ? result[0] : -1);
6706 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6707 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006708 } finally {
6709 Binder.restoreCallingIdentity(identity);
6710 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006711 }
6712
6713 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006714 * Get the allowed network types for certain reason.
6715 *
6716 * @param subId the id of the subscription.
6717 * @param reason the reason the allowed network type change is taking place
6718 * @return the allowed network types.
6719 */
6720 @Override
6721 public long getAllowedNetworkTypesForReason(int subId,
6722 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006723 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006724 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006725 final long identity = Binder.clearCallingIdentity();
6726 try {
6727 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6728 } finally {
6729 Binder.restoreCallingIdentity(identity);
6730 }
6731 }
6732
6733 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006734 * Enable/Disable E-UTRA-NR Dual Connectivity
6735 * @param subId subscription id of the sim card
6736 * @param nrDualConnectivityState expected NR dual connectivity state
6737 * This can be passed following states
6738 * <ol>
6739 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6740 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6741 * <li>Disable NR dual connectivity and force secondary cell to be released
6742 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6743 * </ol>
6744 * @return operation result.
6745 */
6746 @Override
6747 public int setNrDualConnectivityState(int subId,
6748 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6750 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006751 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006752 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6753 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6754 }
6755
Sooraj Sasindran37444802020-08-11 10:40:43 -07006756 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6757 final long identity = Binder.clearCallingIdentity();
6758 try {
6759 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6760 nrDualConnectivityState, subId,
6761 workSource);
6762 if (DBG) log("enableNRDualConnectivity result: " + result);
6763 return result;
6764 } finally {
6765 Binder.restoreCallingIdentity(identity);
6766 }
6767 }
6768
6769 /**
6770 * Is E-UTRA-NR Dual Connectivity enabled
6771 * @return true if dual connectivity is enabled else false
6772 */
6773 @Override
6774 public boolean isNrDualConnectivityEnabled(int subId) {
6775 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006776 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006777 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006778 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006779 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6780 return false;
6781 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006782 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6783 final long identity = Binder.clearCallingIdentity();
6784 try {
6785 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6786 null, subId, workSource);
6787 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6788 return isEnabled;
6789 } finally {
6790 Binder.restoreCallingIdentity(identity);
6791 }
6792 }
6793
6794 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006795 * Set the allowed network types of the device and
6796 * provide the reason triggering the allowed network change.
6797 *
6798 * @param subId the id of the subscription.
6799 * @param reason the reason the allowed network type change is taking place
6800 * @param allowedNetworkTypes the allowed network types.
6801 * @return true on success; false on any failure.
6802 */
6803 @Override
6804 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006805 @TelephonyManager.AllowedNetworkTypesReason int reason,
6806 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006807 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6808 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006809 // If the caller only has carrier privileges, then they should not be able to override
6810 // any network types which were set for security reasons.
6811 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6812 != PERMISSION_GRANTED
6813 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6814 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6815 throw new SecurityException(
6816 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6817 + " reason "
Jack Yu5b494332023-01-23 18:18:04 +00006818 + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006819 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006820 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006821 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08006822 return false;
6823 }
6824 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6825 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006826 return false;
6827 }
6828
Jack Yu5b494332023-01-23 18:18:04 +00006829 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
6830 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006831
Jack Yue37dd262022-12-16 11:53:37 -08006832 Phone phone = getPhone(subId);
6833 if (phone == null) {
6834 return false;
6835 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006836
Jack Yue37dd262022-12-16 11:53:37 -08006837 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006838 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006839 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006840 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006841
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006842 final long identity = Binder.clearCallingIdentity();
6843 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006844 Boolean success = (Boolean) sendRequest(
6845 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6846 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6847
6848 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6849 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006850 } finally {
6851 Binder.restoreCallingIdentity(identity);
6852 }
6853 }
6854
6855 /**
Miaoa84611c2019-03-15 09:21:10 +08006856 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006857 *
Miaoa84611c2019-03-15 09:21:10 +08006858 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006859 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006860 * @hide
6861 */
6862 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006863 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006864 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006865 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006866 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006867 try {
Miaoa84611c2019-03-15 09:21:10 +08006868 if (phone != null) {
6869 return phone.hasMatchedTetherApnSetting();
6870 } else {
6871 return false;
6872 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006873 } finally {
6874 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006875 }
Junda Liu475951f2014-11-07 16:45:03 -08006876 }
6877
6878 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006879 * Get the user enabled state of Mobile Data.
6880 *
6881 * TODO: remove and use isUserDataEnabled.
6882 * This can't be removed now because some vendor codes
6883 * calls through ITelephony directly while they should
6884 * use TelephonyManager.
6885 *
6886 * @return true on enabled
6887 */
6888 @Override
6889 public boolean getDataEnabled(int subId) {
6890 return isUserDataEnabled(subId);
6891 }
6892
6893 /**
6894 * Get whether mobile data is enabled per user setting.
6895 *
6896 * There are other factors deciding whether mobile data is actually enabled, but they are
6897 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006898 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006899 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6900 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006901 *
6902 * @return {@code true} if data is enabled else {@code false}
6903 */
6904 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006905 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006906 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006907 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006908 try {
6909 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6910 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006911 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006912 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6913 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006914 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006915 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006916 mApp, subId, functionName);
6917
Robert Greenwalt646120a2014-05-23 11:54:03 -07006918 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006919
6920 final long identity = Binder.clearCallingIdentity();
6921 try {
Jack Yu285100e2022-12-02 22:48:35 -08006922 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006923 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6924 Phone phone = PhoneFactory.getPhone(phoneId);
6925 if (phone != null) {
6926 boolean retVal = phone.isUserDataEnabled();
6927 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6928 return retVal;
6929 } else {
6930 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6931 return false;
6932 }
6933 } finally {
6934 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006935 }
6936 }
6937
6938 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006939 * Checks if the device is capable of mobile data by considering whether whether the
6940 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6941 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006942 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006943 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006944 */
6945 @Override
6946 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006947 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006948 try {
6949 try {
6950 mApp.enforceCallingOrSelfPermission(
6951 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006952 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006953 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006954 try {
6955 mApp.enforceCallingOrSelfPermission(
6956 android.Manifest.permission.READ_PHONE_STATE,
6957 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006958 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006959 mApp.enforceCallingOrSelfPermission(
6960 permission.READ_BASIC_PHONE_STATE, functionName);
6961 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006962 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006963 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006964 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006965 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006966
6967 final long identity = Binder.clearCallingIdentity();
6968 try {
Jack Yu285100e2022-12-02 22:48:35 -08006969 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006970 Phone phone = PhoneFactory.getPhone(phoneId);
6971 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006972 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006973 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006974 return retVal;
6975 } else {
6976 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6977 return false;
6978 }
6979 } finally {
6980 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006981 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006982 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006983
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006984 /**
6985 * Check if data is enabled for a specific reason
6986 * @param subId Subscription index
6987 * @param reason the reason the data enable change is taking place
6988 * @return {@code true} if the overall data is enabled; {@code false} if not.
6989 */
6990 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006991 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006992 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006993 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006994 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006995 try {
6996 mApp.enforceCallingOrSelfPermission(
6997 android.Manifest.permission.ACCESS_NETWORK_STATE,
6998 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006999 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007000 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7001 functionName);
7002 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007003 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007004 try {
7005 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007006 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007007 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007009 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007010 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007011 }
7012
7013
7014 final long identity = Binder.clearCallingIdentity();
7015 try {
Jack Yu285100e2022-12-02 22:48:35 -08007016 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007017 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007018 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007019 + " reason=" + reason);
7020 }
7021 Phone phone = PhoneFactory.getPhone(phoneId);
7022 if (phone != null) {
7023 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007024 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007025 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007026 return retVal;
7027 } else {
7028 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007029 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007030 + subId + " retVal=false");
7031 }
7032 return false;
7033 }
7034 } finally {
7035 Binder.restoreCallingIdentity(identity);
7036 }
7037 }
7038
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007039 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007040 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007041 // No permission needed; this only lets the caller inspect their own status.
7042 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007043 }
Junda Liu29340342014-07-10 15:23:27 -07007044
7045 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007046 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007047 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007048 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7049 }
7050
7051 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7052 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007053 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007054 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007055 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7056 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007057 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7058 if (cpt == null) {
7059 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007060 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7061 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007062 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007063 }
7064
7065 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007066 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007067 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007068 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007069 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007070 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007071 Phone phone = getPhone(subId);
7072 if (phone == null) {
7073 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7074 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7075 }
7076 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7077 if (cpt == null) {
7078 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007079 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7080 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007081 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007082 }
7083
7084 @Override
7085 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007086 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007087 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7088 }
7089
7090 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007091 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007092 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007093 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007094 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007095 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7096 Phone phone = PhoneFactory.getPhone(phoneId);
7097 if (phone == null) {
7098 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007099 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007100 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7101 if (cpt == null) {
7102 continue;
7103 }
7104 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007105 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7106 break;
7107 }
7108 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007109 return result;
Junda Liu29340342014-07-10 15:23:27 -07007110 }
Derek Tan89e89d42014-07-08 17:00:10 -07007111
7112 @Override
Junda Liue64de782015-04-16 17:19:16 -07007113 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007114 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007115 Phone phone = PhoneFactory.getPhone(phoneId);
7116 if (phone == null) {
7117 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007118 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007119 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7120 if (cpt == null) {
7121 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007122 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007123 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007124 }
7125
Amith Yamasani6e118872016-02-19 12:53:51 -08007126 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007127 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007128 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007129 Phone phone = PhoneFactory.getPhone(phoneId);
7130 if (phone == null) {
7131 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007132 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007133 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7134 if (cpt == null) {
7135 return Collections.emptyList();
7136 }
7137 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007138 }
7139
chen xuf7e9fe82019-05-09 19:31:02 -07007140 @Override
7141 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007142 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007143 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007144 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007145 try {
7146 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7147 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7148 }
7149 } finally {
7150 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007151 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007152 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007153 }
7154
Rambo Wang6812ffb2022-03-15 16:54:17 -07007155 @Override
7156 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7157 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7158
7159 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7160 if (phone == null) {
7161 return null;
7162 }
7163 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7164 if (cpt == null) {
7165 return null;
7166 }
7167 return cpt.getCarrierServicePackageName();
7168 }
7169
Wink Savilleb564aae2014-10-23 10:18:09 -07007170 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007171 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007172 UiccPort port = phone == null ? null : phone.getUiccPort();
7173 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007174 return null;
7175 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007176 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007177 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007178 return null;
7179 }
7180 return iccId;
7181 }
7182
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007183 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007184 public void setCallComposerStatus(int subId, int status) {
7185 enforceModifyPermission();
7186
7187 final long identity = Binder.clearCallingIdentity();
7188 try {
7189 Phone phone = getPhone(subId);
7190 if (phone != null) {
7191 Phone defaultPhone = phone.getImsPhone();
7192 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7193 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7194 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007195 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7196 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007197 }
7198 }
Shuo Qian284ae752020-12-22 19:10:14 -08007199 } catch (ImsException e) {
7200 throw new ServiceSpecificException(e.getCode());
7201 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007202 Binder.restoreCallingIdentity(identity);
7203 }
7204 }
7205
7206 @Override
7207 public int getCallComposerStatus(int subId) {
7208 enforceReadPrivilegedPermission("getCallComposerStatus");
7209
7210 final long identity = Binder.clearCallingIdentity();
7211 try {
7212 Phone phone = getPhone(subId);
7213 if (phone != null) {
7214 Phone defaultPhone = phone.getImsPhone();
7215 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7216 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7217 return imsPhone.getCallComposerStatus();
7218 }
7219 }
7220 } finally {
7221 Binder.restoreCallingIdentity(identity);
7222 }
7223 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7224 }
7225
7226 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007227 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7228 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007229 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007230 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007231
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007232 final long identity = Binder.clearCallingIdentity();
7233 try {
7234 final String iccId = getIccId(subId);
7235 final Phone phone = getPhone(subId);
7236 if (phone == null) {
7237 return false;
7238 }
7239 final String subscriberId = phone.getSubscriberId();
7240
7241 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007242 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007243 + subscriberId + " to " + number);
7244 }
7245
7246 if (TextUtils.isEmpty(iccId)) {
7247 return false;
7248 }
7249
7250 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7251
7252 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7253 if (alphaTag == null) {
7254 editor.remove(alphaTagPrefKey);
7255 } else {
7256 editor.putString(alphaTagPrefKey, alphaTag);
7257 }
7258
7259 // Record both the line number and IMSI for this ICCID, since we need to
7260 // track all merged IMSIs based on line number
7261 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7262 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7263 if (number == null) {
7264 editor.remove(numberPrefKey);
7265 editor.remove(subscriberPrefKey);
7266 } else {
7267 editor.putString(numberPrefKey, number);
7268 editor.putString(subscriberPrefKey, subscriberId);
7269 }
7270
7271 editor.commit();
7272 return true;
7273 } finally {
7274 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007275 }
Derek Tan7226c842014-07-02 17:42:23 -07007276 }
7277
7278 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007279 public String getLine1NumberForDisplay(int subId, String callingPackage,
7280 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007281 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007282 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007283 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007284 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007285 return null;
7286 }
Derek Tan97ebb422014-09-05 16:55:38 -07007287
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007288 final long identity = Binder.clearCallingIdentity();
7289 try {
7290 String iccId = getIccId(subId);
7291 if (iccId != null) {
7292 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7293 if (DBG_MERGE) {
7294 log("getLine1NumberForDisplay returning "
7295 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7296 }
7297 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007298 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007299 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7300 return null;
7301 } finally {
7302 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007303 }
Derek Tan7226c842014-07-02 17:42:23 -07007304 }
7305
7306 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007307 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7308 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007309 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007310 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007311 return null;
7312 }
Derek Tan97ebb422014-09-05 16:55:38 -07007313
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007314 final long identity = Binder.clearCallingIdentity();
7315 try {
7316 String iccId = getIccId(subId);
7317 if (iccId != null) {
7318 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7319 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7320 }
7321 return null;
7322 } finally {
7323 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007324 }
Derek Tan7226c842014-07-02 17:42:23 -07007325 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007326
7327 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007328 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7329 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007330 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7331 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007332 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007333 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007334 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007335 return null;
7336 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007337
Jordan Liub49b04b2019-05-06 14:45:15 -07007338 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7339 // the process, where TelephonyManager was instantiated.
7340 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007341 final long identity = Binder.clearCallingIdentity();
7342 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007343 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007344 final TelephonyManager tele = TelephonyManager.from(context);
7345 final SubscriptionManager sub = SubscriptionManager.from(context);
7346
7347 // Figure out what subscribers are currently active
7348 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007349
Jordan Liub49b04b2019-05-06 14:45:15 -07007350 // Only consider subs which match the current subId
7351 // This logic can be simplified. See b/131189269 for progress.
7352 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007353 activeSubscriberIds.add(tele.getSubscriberId(subId));
7354 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007355
7356 // First pass, find a number override for an active subscriber
7357 String mergeNumber = null;
7358 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7359 for (String key : prefs.keySet()) {
7360 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7361 final String subscriberId = (String) prefs.get(key);
7362 if (activeSubscriberIds.contains(subscriberId)) {
7363 final String iccId = key.substring(
7364 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7365 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7366 mergeNumber = (String) prefs.get(numberKey);
7367 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007368 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007369 + " for active subscriber " + subscriberId);
7370 }
7371 if (!TextUtils.isEmpty(mergeNumber)) {
7372 break;
7373 }
7374 }
7375 }
7376 }
7377
7378 // Shortcut when no active merged subscribers
7379 if (TextUtils.isEmpty(mergeNumber)) {
7380 return null;
7381 }
7382
7383 // Second pass, find all subscribers under that line override
7384 final ArraySet<String> result = new ArraySet<>();
7385 for (String key : prefs.keySet()) {
7386 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7387 final String number = (String) prefs.get(key);
7388 if (mergeNumber.equals(number)) {
7389 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7390 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7391 final String subscriberId = (String) prefs.get(subscriberKey);
7392 if (!TextUtils.isEmpty(subscriberId)) {
7393 result.add(subscriberId);
7394 }
7395 }
7396 }
7397 }
7398
7399 final String[] resultArray = result.toArray(new String[result.size()]);
7400 Arrays.sort(resultArray);
7401 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007402 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007403 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7404 }
7405 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007406 } finally {
7407 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007408 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007409 }
7410
7411 @Override
zoey chen38003472019-12-13 17:16:31 +08007412 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7413 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007414
7415 final long identity = Binder.clearCallingIdentity();
7416 try {
7417 final TelephonyManager telephonyManager = mApp.getSystemService(
7418 TelephonyManager.class);
7419 String subscriberId = telephonyManager.getSubscriberId(subId);
7420 if (subscriberId == null) {
7421 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007422 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007423 + subId);
7424 }
7425 return null;
7426 }
7427
Jack Yu285100e2022-12-02 22:48:35 -08007428 ParcelUuid groupUuid;
7429 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7430 final SubscriptionInfo info = SubscriptionManagerService.getInstance()
7431 .getSubscriptionInfo(subId);
7432 groupUuid = info.getGroupUuid();
7433 } else {
7434 final SubscriptionInfo info = mSubscriptionController
7435 .getSubscriptionInfo(subId);
7436 groupUuid = info.getGroupUuid();
7437 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007438 // If it doesn't belong to any group, return just subscriberId of itself.
7439 if (groupUuid == null) {
7440 return new String[]{subscriberId};
7441 }
7442
7443 // Get all subscriberIds from the group.
7444 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007445 List<SubscriptionInfo> groupInfos;
7446 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7447 groupInfos = SubscriptionManagerService.getInstance()
7448 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7449 mApp.getAttributionTag());
7450 } else {
7451 groupInfos = mSubscriptionController
7452 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7453 mApp.getAttributionTag());
7454 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007455 for (SubscriptionInfo subInfo : groupInfos) {
7456 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7457 if (subscriberId != null) {
7458 mergedSubscriberIds.add(subscriberId);
7459 }
7460 }
7461
7462 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7463 } finally {
7464 Binder.restoreCallingIdentity(identity);
7465
7466 }
7467 }
7468
7469 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007470 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007471 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007472 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007473
7474 final long identity = Binder.clearCallingIdentity();
7475 try {
7476 final Phone phone = getPhone(subId);
7477 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7478 } finally {
7479 Binder.restoreCallingIdentity(identity);
7480 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007481 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007482
7483 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007484 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007485 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7486 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007487 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7488 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489
7490 final long identity = Binder.clearCallingIdentity();
7491 try {
7492 final Phone phone = getPhone(subId);
7493 if (phone == null) {
7494 return false;
7495 }
7496 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7497 cdmaNonRoamingList);
7498 } finally {
7499 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007500 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007501 }
7502
7503 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007504 @Deprecated
7505 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7506 enforceModifyPermission();
7507
7508 int returnValue = 0;
7509 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007510 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007511 if(result.exception == null) {
7512 if (result.result != null) {
7513 byte[] responseData = (byte[])(result.result);
7514 if(responseData.length > oemResp.length) {
7515 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7516 responseData.length + "bytes. Buffer Size is " +
7517 oemResp.length + "bytes.");
7518 }
7519 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7520 returnValue = responseData.length;
7521 }
7522 } else {
7523 CommandException ex = (CommandException) result.exception;
7524 returnValue = ex.getCommandError().ordinal();
7525 if(returnValue > 0) returnValue *= -1;
7526 }
7527 } catch (RuntimeException e) {
7528 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7529 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7530 if(returnValue > 0) returnValue *= -1;
7531 }
7532
7533 return returnValue;
7534 }
7535
7536 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007537 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007538 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007539 try {
7540 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007541 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007542 mApp, phone.getSubId(), "getRadioAccessFamily");
7543 } catch (SecurityException e) {
7544 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7545 throw e;
7546 }
chen xub97461a2018-10-26 14:17:57 -07007547 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007548 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007549 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007550 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007551 final long identity = Binder.clearCallingIdentity();
7552 try {
chen xub97461a2018-10-26 14:17:57 -07007553 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007554 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007555 mApp, phone.getSubId(), "getRadioAccessFamily");
7556 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007557 } finally {
7558 Binder.restoreCallingIdentity(identity);
7559 }
chen xub97461a2018-10-26 14:17:57 -07007560 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007561 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007562
7563 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007564 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007565 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007566 try {
7567 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7568 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007569 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007570 }
7571 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007572 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007573 }
7574 RoleManager rm = mApp.getSystemService(RoleManager.class);
7575 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7576 if (!dialerRoleHolders.contains(callingPackage)) {
7577 throw new SecurityException("App must be the dialer role holder to"
7578 + " upload a call composer pic");
7579 }
7580
7581 Executors.newSingleThreadExecutor().execute(() -> {
7582 ByteArrayOutputStream output = new ByteArrayOutputStream(
7583 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7584 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7585 boolean readUntilEnd = false;
7586 int totalBytesRead = 0;
7587 byte[] buffer = new byte[16 * 1024];
7588 while (true) {
7589 int numRead;
7590 try {
7591 numRead = input.read(buffer);
7592 } catch (IOException e) {
7593 try {
7594 fd.checkError();
7595 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7596 null);
7597 } catch (IOException e1) {
7598 // This means that the other side closed explicitly with an error. If this
7599 // happens, log and ignore.
7600 loge("Remote end of call composer picture pipe closed: " + e1);
7601 }
7602 break;
7603 }
7604 if (numRead == -1) {
7605 readUntilEnd = true;
7606 break;
7607 }
7608 totalBytesRead += numRead;
7609 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7610 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7611 try {
7612 input.close();
7613 } catch (IOException e) {
7614 // ignore
7615 }
7616 break;
7617 }
7618 output.write(buffer, 0, numRead);
7619 }
7620 // Generally, the remote end will close the file descriptors. The only case where we
7621 // close is above, where the picture size is too big.
7622
7623 try {
7624 fd.checkError();
7625 } catch (IOException e) {
7626 loge("Remote end for call composer closed with an error: " + e);
7627 return;
7628 }
7629
Hall Liuaa4211e2021-01-20 15:43:39 -08007630 if (!readUntilEnd) {
7631 loge("Did not finish reading entire image; aborting");
7632 return;
7633 }
Hall Liu82694d52020-12-11 18:22:04 -08007634
Hall Liuaa4211e2021-01-20 15:43:39 -08007635 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7636 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7637 new CallComposerPictureTransfer.Factory() {},
7638 imageData,
7639 (result) -> {
7640 if (result.first != null) {
7641 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7642 Bundle outputResult = new Bundle();
7643 outputResult.putParcelable(
7644 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7645 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7646 outputResult);
7647 } else {
7648 callback.send(result.second, null);
7649 }
7650 }
7651 );
Hall Liu82694d52020-12-11 18:22:04 -08007652 });
7653 }
7654
7655 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007656 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007657 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007658 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007659
7660 final long identity = Binder.clearCallingIdentity();
7661 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007662 ImsManager.getInstance(defaultPhone.getContext(),
7663 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007664 } finally {
7665 Binder.restoreCallingIdentity(identity);
7666 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007667 }
7668
7669 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007670 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007671 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007672 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7673 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007674 return false;
7675 }
Svet Ganovb320e182015-04-16 12:30:10 -07007676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007677 final long identity = Binder.clearCallingIdentity();
7678 try {
7679 // Check the user preference and the system-level IMS setting. Even if the user has
7680 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7681 // In the long run, we may instead need to check if there exists a connection service
7682 // which can support video calling.
7683 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007684 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007685 return imsManager.isVtEnabledByPlatform()
7686 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7687 && imsManager.isVtEnabledByUser();
7688 } finally {
7689 Binder.restoreCallingIdentity(identity);
7690 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007691 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007692
Andrew Leea1239f22015-03-02 17:44:07 -08007693 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007694 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7695 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007696 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007697 mApp, subId, callingPackage, callingFeatureId,
7698 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007699 return false;
7700 }
7701
7702 final long identity = Binder.clearCallingIdentity();
7703 try {
7704 CarrierConfigManager configManager =
7705 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007706 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007707 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7708 } finally {
7709 Binder.restoreCallingIdentity(identity);
7710 }
Andrew Leea1239f22015-03-02 17:44:07 -08007711 }
7712
7713 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007714 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007715 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007716 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007717 return false;
7718 }
7719
7720 final long identity = Binder.clearCallingIdentity();
7721 try {
7722 CarrierConfigManager configManager =
7723 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007724 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007725 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7726 } finally {
7727 Binder.restoreCallingIdentity(identity);
7728 }
Andrew Leea1239f22015-03-02 17:44:07 -08007729 }
7730
Andrew Lee9431b832015-03-09 18:46:45 -07007731 @Override
7732 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007733 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007734 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007735 }
7736
7737 @Override
7738 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007739 final long identity = Binder.clearCallingIdentity();
7740 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007741 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007742 } finally {
7743 Binder.restoreCallingIdentity(identity);
7744 }
Andrew Lee9431b832015-03-09 18:46:45 -07007745 }
7746
Hall Liuf6668912018-10-31 17:05:23 -07007747 /**
7748 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7749 * support for the feature and device firmware support.
7750 *
7751 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7752 */
7753 @Override
7754 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007755 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007756 final Phone phone = getPhone(subscriptionId);
7757 if (phone == null) {
7758 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7759 return false;
7760 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007761 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007762 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007763 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7764 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007765 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007766 return isCarrierSupported && isDeviceSupported;
7767 } finally {
7768 Binder.restoreCallingIdentity(identity);
7769 }
Hall Liu98187582018-01-22 19:15:32 -08007770 }
7771
Hall Liuf6668912018-10-31 17:05:23 -07007772 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007773 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7774 * RTT setting, will return true if the device and carrier both support RTT.
7775 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007776 */
7777 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007778 final long identity = Binder.clearCallingIdentity();
7779 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007780 boolean isRttSupported = isRttSupported(subscriptionId);
7781 boolean isUserRttSettingOn = Settings.Secure.getInt(
7782 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7783 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7784 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7785 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007786 } finally {
7787 Binder.restoreCallingIdentity(identity);
7788 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007789 }
7790
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007791 @Deprecated
7792 @Override
7793 public String getDeviceId(String callingPackage) {
7794 return getDeviceIdWithFeature(callingPackage, null);
7795 }
7796
Sanket Padawe7310cc72015-01-14 09:53:20 -08007797 /**
7798 * Returns the unique device ID of phone, for example, the IMEI for
7799 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7800 *
7801 * <p>Requires Permission:
7802 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7803 */
7804 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007805 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007806 try {
7807 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7808 } catch (SecurityException se) {
7809 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7810 throw new SecurityException("Package " + callingPackage + " does not belong to "
7811 + Binder.getCallingUid());
7812 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007813 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007814 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007815 return null;
7816 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007817 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007818 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007819 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007820 return null;
7821 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007822
7823 final long identity = Binder.clearCallingIdentity();
7824 try {
7825 return phone.getDeviceId();
7826 } finally {
7827 Binder.restoreCallingIdentity(identity);
7828 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007829 }
7830
Ping Sunc67b7c22016-03-02 19:16:45 +08007831 /**
7832 * {@hide}
7833 * Returns the IMS Registration Status on a particular subid
7834 *
7835 * @param subId
7836 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007837 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007838 Phone phone = getPhone(subId);
7839 if (phone != null) {
7840 return phone.isImsRegistered();
7841 } else {
7842 return false;
7843 }
7844 }
7845
Santos Cordon7a1885b2015-02-03 11:15:19 -08007846 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007847 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007848 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007849 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007850 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007851 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7852 }
7853 final long identity = Binder.clearCallingIdentity();
7854 try {
7855 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7856 } finally {
7857 Binder.restoreCallingIdentity(identity);
7858 }
7859 }
7860
7861 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007862 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007863 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007864 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007865 mApp,
7866 subscriptionId,
7867 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007868 final long identity = Binder.clearCallingIdentity();
7869 try {
7870 Phone phone = getPhone(subscriptionId);
7871 if (phone == null) {
7872 return null;
7873 }
7874 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7875 } finally {
7876 Binder.restoreCallingIdentity(identity);
7877 }
7878 }
7879
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007880 /**
7881 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007882 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007883 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007884 final long identity = Binder.clearCallingIdentity();
7885 try {
7886 Phone phone = getPhone(subId);
7887 if (phone != null) {
7888 return phone.isWifiCallingEnabled();
7889 } else {
7890 return false;
7891 }
7892 } finally {
7893 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007894 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007895 }
7896
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007897 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007898 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007899 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007900 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007901 final long identity = Binder.clearCallingIdentity();
7902 try {
7903 Phone phone = getPhone(subId);
7904 if (phone != null) {
7905 return phone.isVideoEnabled();
7906 } else {
7907 return false;
7908 }
7909 } finally {
7910 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007911 }
7912 }
7913
7914 /**
7915 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7916 * defined in {@link ImsRegistrationImplBase}.
7917 */
7918 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007919 final long identity = Binder.clearCallingIdentity();
7920 try {
7921 Phone phone = getPhone(subId);
7922 if (phone != null) {
7923 return phone.getImsRegistrationTech();
7924 } else {
7925 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7926 }
7927 } finally {
7928 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007929 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007930 }
7931
Stuart Scott8eef64f2015-04-08 15:13:54 -07007932 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007933 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007934 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007935 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7936 return;
7937 }
Kai Shif70f46f2021-03-03 13:59:46 -08007938 Phone defaultPhone = getDefaultPhone();
7939 if (defaultPhone != null) {
7940 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7941 mApp, getDefaultPhone().getSubId(), "factoryReset");
7942 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007943 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007944
Svet Ganovcc087f82015-05-12 20:35:54 -07007945 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007946 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7947 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007948 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007949 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007950 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007951 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007952 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007953 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007954 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007955 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007956 // There has been issues when Sms raw table somehow stores orphan
7957 // fragments. They lead to garbled message when new fragments come
7958 // in and combined with those stale ones. In case this happens again,
7959 // user can reset all network settings which will clean up this table.
7960 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007961 // Clean up IMS settings as well here.
7962 int slotId = getSlotIndex(subId);
7963 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7964 ImsManager.getInstance(mApp, slotId).factoryReset();
7965 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007966
Kai Shif70f46f2021-03-03 13:59:46 -08007967 if (defaultPhone == null) {
7968 return;
7969 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007970 // Erase modem config if erase modem on network setting is enabled.
7971 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7972 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7973 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007974 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007975 }
Kai Shif70f46f2021-03-03 13:59:46 -08007976
7977 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007978 } finally {
7979 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007980 }
7981 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007982
SongFerngWangfd89b102021-05-27 22:44:54 +08007983 @VisibleForTesting
7984 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7985 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7986 return;
7987 }
7988 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7989 RILConstants.PREFERRED_NETWORK_MODE);
7990 SubscriptionManager.setSubscriptionProperty(subId,
7991 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7992 "user=" + defaultNetworkType);
7993 phone.loadAllowedNetworksFromSubscriptionDatabase();
7994 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7995 defaultNetworkType, null);
7996 }
7997
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007998 private void cleanUpSmsRawTable(Context context) {
7999 ContentResolver resolver = context.getContentResolver();
8000 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8001 resolver.delete(uri, null, null);
8002 }
8003
Narayan Kamath1c496c22015-04-16 14:40:19 +01008004 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008005 public String getSimLocaleForSubscriber(int subId) {
8006 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8007 final Phone phone = getPhone(subId);
8008 if (phone == null) {
8009 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008010 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008011 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008012 final long identity = Binder.clearCallingIdentity();
8013 try {
Jack Yu285100e2022-12-02 22:48:35 -08008014 SubscriptionInfo info;
8015 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8016 info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId,
8017 phone.getContext().getOpPackageName(),
8018 phone.getContext().getAttributionTag());
8019 if (info == null) {
8020 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8021 return null;
8022 }
8023 } else {
8024 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
8025 phone.getContext().getOpPackageName(),
8026 phone.getContext().getAttributionTag());
8027 if (info == null) {
8028 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8029 return null;
8030 }
chen xu6291c472019-02-04 12:55:53 -08008031 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008032 // Try and fetch the locale from the carrier properties or from the SIM language
8033 // preferences (EF-PL and EF-LI)...
8034 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008035 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008036 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8037 if (localeFromDefaultSim != null) {
8038 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8039 if (DBG) log("Using locale from subId: " + subId + " locale: "
8040 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008041 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008042 } else {
8043 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008044 }
8045 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008047 // The SIM language preferences only store a language (e.g. fr = French), not an
8048 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8049 // the SIM and carrier preferences does not include a country we add the country
8050 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008051 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008052 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008053 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008054 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008055 }
8056
8057 if (DBG) log("No locale found - returning null");
8058 return null;
8059 } finally {
8060 Binder.restoreCallingIdentity(identity);
8061 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008062 }
8063
tom hsu0b59d292022-09-29 23:49:21 +08008064 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008065 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008066 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008067 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008068 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008069 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8070 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008071 Locale.forLanguageTag(localeTag).getCountry())) {
8072 return localeTag;
8073 }
8074 }
8075 return inputLocale.toLanguageTag();
8076 }
8077
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008078 /**
8079 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8080 */
8081 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08008082 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8083 return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList(
8084 mApp.getOpPackageName(), mApp.getAttributionTag());
8085 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008086 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08008087 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008088 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008089
Gary Jian3aa9a762022-01-24 16:41:19 +08008090 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8091 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008092
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008093 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008094 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8095 * representing the state of the modem.
8096 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008097 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8098 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008099 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008100 */
8101 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008102 public void requestModemActivityInfo(ResultReceiver result) {
8103 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008104 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008105
8106 final long identity = Binder.clearCallingIdentity();
8107 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008108 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008109 } finally {
8110 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008111 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008112 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008113
Gary Jian76280a42022-12-07 16:18:33 +08008114 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008115 // less than total activity duration.
8116 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8117 if (info == null) {
8118 return false;
8119 }
8120 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008121 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008122 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8123
Hall Liu49656c02020-10-09 19:00:11 -07008124 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8125
Siddharth Rayb8114062018-06-17 15:02:38 -07008126 return (info.isValid()
8127 && (info.getSleepTimeMillis() <= activityDurationMs)
Gary Jian76280a42022-12-07 16:18:33 +08008128 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008129 }
8130
Gary Jian3aa9a762022-01-24 16:41:19 +08008131 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8132 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8133 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8134 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8135
8136 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8137 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8138 }
8139
8140 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8141 mLastModemActivityInfo.setReceiveTimeMillis(
8142 rat,
8143 freq,
8144 info.getReceiveTimeMillis(rat, freq)
8145 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8146 }
8147
8148 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8149 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8150 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8151 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8152
8153 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8154 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8155 }
8156 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8157 mLastModemActivityInfo.setReceiveTimeMillis(
8158 rat,
8159 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8160 }
8161
8162 /**
8163 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8164 * @param info recent ModemActivityInfo
8165 */
8166 private void mergeModemActivityInfo(ModemActivityInfo info) {
8167 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008168 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008169 boolean matched;
8170 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8171 matched = false;
8172 int rat = info.getSpecificInfoRat(i);
8173 int freq = info.getSpecificInfoFrequencyRange(i);
8174 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8175 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8176 //if it already exists
8177 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8178 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8179 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8180 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8181 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8182 updateLastModemActivityInfo(info, rat, freq);
8183 matched = true;
8184 }
8185 } else {
8186 updateLastModemActivityInfo(info, rat);
8187 matched = true;
8188 }
8189 }
8190 }
8191
8192 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008193 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008194 new ActivityStatsTechSpecificInfo(
8195 rat,
8196 freq,
8197 info.getTransmitTimeMillis(rat, freq),
8198 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008199 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008200 }
8201 }
8202 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8203 mLastModemActivitySpecificInfo =
8204 new ActivityStatsTechSpecificInfo[merged.size()];
8205 merged.toArray(mLastModemActivitySpecificInfo);
8206
8207 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8208 mLastModemActivityInfo.setSleepTimeMillis(
8209 info.getSleepTimeMillis()
8210 + mLastModemActivityInfo.getSleepTimeMillis());
8211 mLastModemActivityInfo.setIdleTimeMillis(
8212 info.getIdleTimeMillis()
8213 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008214
8215 mLastModemActivityInfo =
8216 new ModemActivityInfo(
8217 mLastModemActivityInfo.getTimestampMillis(),
8218 mLastModemActivityInfo.getSleepTimeMillis(),
8219 mLastModemActivityInfo.getIdleTimeMillis(),
8220 mLastModemActivitySpecificInfo);
8221 }
8222
8223 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8224 ActivityStatsTechSpecificInfo[] info) {
8225 int infoSize = info.length;
8226 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8227 for (int i = 0; i < infoSize; i++) {
8228 ret[i] = new ActivityStatsTechSpecificInfo(
8229 info[i].getRat(), info[i].getFrequencyRange(),
8230 info[i].getTransmitTimeMillis(),
8231 (int) info[i].getReceiveTimeMillis());
8232 }
8233 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008234 }
8235
Jack Yu85bd38a2015-11-09 11:34:32 -08008236 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008237 * Returns the service state information on specified subscription.
8238 */
8239 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008240 public ServiceState getServiceStateForSubscriber(int subId,
8241 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8242 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008243 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008244 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008245 return null;
8246 }
8247
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008248 boolean hasFinePermission = false;
8249 boolean hasCoarsePermission = false;
8250 if (!renounceFineLocationAccess) {
8251 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8252 LocationAccessPolicy.checkLocationPermission(mApp,
8253 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8254 .setCallingPackage(callingPackage)
8255 .setCallingFeatureId(callingFeatureId)
8256 .setCallingPid(Binder.getCallingPid())
8257 .setCallingUid(Binder.getCallingUid())
8258 .setMethod("getServiceStateForSubscriber")
8259 .setLogAsInfo(true)
8260 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8261 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8262 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8263 .build());
8264 hasFinePermission =
8265 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8266 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008267
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008268 if (!renounceCoarseLocationAccess) {
8269 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8270 LocationAccessPolicy.checkLocationPermission(mApp,
8271 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8272 .setCallingPackage(callingPackage)
8273 .setCallingFeatureId(callingFeatureId)
8274 .setCallingPid(Binder.getCallingPid())
8275 .setCallingUid(Binder.getCallingUid())
8276 .setMethod("getServiceStateForSubscriber")
8277 .setLogAsInfo(true)
8278 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8279 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8280 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8281 .build());
8282 hasCoarsePermission =
8283 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8284 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008285
Jack Yu479f40e2020-10-27 21:29:25 -07008286 final Phone phone = getPhone(subId);
8287 if (phone == null) {
8288 return null;
8289 }
8290
Jordan Liu0f2bc442020-11-18 16:47:37 -08008291 final long identity = Binder.clearCallingIdentity();
8292
Jack Yu479f40e2020-10-27 21:29:25 -07008293 boolean isCallingPackageDataService = phone.getDataServicePackages()
8294 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008295 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008296 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008297 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8298 SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance()
8299 .getSubscriptionInfoInternal(subId);
8300 if (subInfo == null || !subInfo.isActive()) {
8301 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8302 + "subId=" + subId);
8303 return null;
8304 }
8305 } else {
8306 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8307 callingFeatureId)) {
8308 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8309 + "subId=" + subId);
8310 return null;
8311 }
Jordan Liuc437b192020-08-17 10:59:12 -07008312 }
8313
Hall Liuf19c44f2018-11-27 14:38:17 -08008314 ServiceState ss = phone.getServiceState();
8315
8316 // Scrub out the location info in ServiceState depending on what level of access
8317 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008318 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008319 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8320 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008321 } finally {
8322 Binder.restoreCallingIdentity(identity);
8323 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008324 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008325
8326 /**
8327 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8328 *
8329 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8330 * voicemail ringtone.
8331 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8332 * PhoneAccount.
8333 */
8334 @Override
8335 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008336 final long identity = Binder.clearCallingIdentity();
8337 try {
8338 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8339 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008340 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008341 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008343 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8344 } finally {
8345 Binder.restoreCallingIdentity(identity);
8346 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008347 }
8348
8349 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008350 * Sets the per-account voicemail ringtone.
8351 *
8352 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8353 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8354 *
8355 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8356 * voicemail ringtone.
8357 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8358 * PhoneAccount.
8359 */
8360 @Override
8361 public void setVoicemailRingtoneUri(String callingPackage,
8362 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008363 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008364 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008365 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8366 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008367 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8368 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8369 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008370 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008371
8372 final long identity = Binder.clearCallingIdentity();
8373 try {
8374 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8375 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008376 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008377 }
8378 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8379 } finally {
8380 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008381 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008382 }
8383
8384 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008385 * Returns whether vibration is set for voicemail notification in Phone settings.
8386 *
8387 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8388 * voicemail vibration setting.
8389 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8390 */
8391 @Override
8392 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008393 final long identity = Binder.clearCallingIdentity();
8394 try {
8395 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8396 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008397 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008398 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008399
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008400 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8401 } finally {
8402 Binder.restoreCallingIdentity(identity);
8403 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008404 }
8405
Youhan Wange64578a2016-05-02 15:32:42 -07008406 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008407 * Sets the per-account voicemail vibration.
8408 *
8409 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8410 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8411 *
8412 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8413 * voicemail vibration setting.
8414 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8415 * specific PhoneAccount.
8416 */
8417 @Override
8418 public void setVoicemailVibrationEnabled(String callingPackage,
8419 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008420 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008421 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008422 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8423 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8425 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8426 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008427 }
8428
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008429 final long identity = Binder.clearCallingIdentity();
8430 try {
8431 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8432 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008433 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008434 }
8435 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8436 } finally {
8437 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008438 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008439 }
8440
8441 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008442 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8443 *
8444 * @throws SecurityException if the caller does not have the required permission
8445 */
arunvoddud7401012022-12-15 16:08:12 +00008446 @VisibleForTesting
8447 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008448 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008449 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008450 }
8451
8452 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008453 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8454 * permission.
8455 *
8456 * @throws SecurityException if the caller does not have the required permission
8457 */
8458 private void enforceSendSmsPermission() {
8459 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8460 }
8461
8462 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008463 * Make sure either called from same process as self (phone) or IPC caller has interact across
8464 * users permission.
8465 *
8466 * @throws SecurityException if the caller does not have the required permission
8467 */
8468 private void enforceInteractAcrossUsersPermission(String message) {
8469 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8470 }
8471
8472 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008473 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008474 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008475 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008476 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008477 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008478 final long identity = Binder.clearCallingIdentity();
8479 try {
8480 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008481 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008482 if (componentName == null) {
8483 throw new SecurityException(
8484 "Caller not current active visual voicemail package[null]");
8485 }
8486 String vvmPackage = componentName.getPackageName();
8487 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008488 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008489 }
8490 } finally {
8491 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008492 }
8493 }
8494
8495 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008496 * Return the application ID for the app type.
8497 *
8498 * @param subId the subscription ID that this request applies to.
8499 * @param appType the uicc app type.
8500 * @return Application ID for specificied app type, or null if no uicc.
8501 */
8502 @Override
8503 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008504 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008505 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008506
8507 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008508 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008509 if (phone == null) {
8510 return null;
8511 }
8512 String aid = null;
8513 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008514 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008515 .getApplicationByType(appType).getAid();
8516 } catch (Exception e) {
8517 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8518 }
8519 return aid;
8520 } finally {
8521 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008522 }
Youhan Wange64578a2016-05-02 15:32:42 -07008523 }
8524
Youhan Wang4001d252016-05-11 10:29:41 -07008525 /**
8526 * Return the Electronic Serial Number.
8527 *
8528 * @param subId the subscription ID that this request applies to.
8529 * @return ESN or null if error.
8530 */
8531 @Override
8532 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008533 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008534 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008535
8536 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008537 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008538 if (phone == null) {
8539 return null;
8540 }
8541 String esn = null;
8542 try {
8543 esn = phone.getEsn();
8544 } catch (Exception e) {
8545 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8546 }
8547 return esn;
8548 } finally {
8549 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008550 }
Youhan Wang4001d252016-05-11 10:29:41 -07008551 }
8552
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008553 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008554 * Return the Preferred Roaming List Version.
8555 *
8556 * @param subId the subscription ID that this request applies to.
8557 * @return PRLVersion or null if error.
8558 */
8559 @Override
8560 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008561 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008562 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008563
8564 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008565 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008566 if (phone == null) {
8567 return null;
8568 }
8569 String cdmaPrlVersion = null;
8570 try {
8571 cdmaPrlVersion = phone.getCdmaPrlVersion();
8572 } catch (Exception e) {
8573 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8574 }
8575 return cdmaPrlVersion;
8576 } finally {
8577 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008578 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008579 }
8580
8581 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008582 * Get snapshot of Telephony histograms
8583 * @return List of Telephony histograms
8584 * @hide
8585 */
8586 @Override
8587 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8589 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008590
8591 final long identity = Binder.clearCallingIdentity();
8592 try {
8593 return RIL.getTelephonyRILTimingHistograms();
8594 } finally {
8595 Binder.restoreCallingIdentity(identity);
8596 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008597 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008598
8599 /**
8600 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008601 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8602 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008603 * Require system privileges. In the future we may add this to carrier APIs.
8604 *
Michele Berionne482f8202018-11-27 18:57:59 -08008605 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008606 */
8607 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008608 @TelephonyManager.SetCarrierRestrictionResult
8609 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008610 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008611 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008612
Michele Berionne482f8202018-11-27 18:57:59 -08008613 if (carrierRestrictionRules == null) {
8614 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008615 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008616
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008617 final long identity = Binder.clearCallingIdentity();
8618 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008619 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008620 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008621 } finally {
8622 Binder.restoreCallingIdentity(identity);
8623 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008624 }
8625
8626 /**
8627 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008628 * Get the allowed carrier list and the excluded carrier list, including the priority between
8629 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008630 * Require system privileges. In the future we may add this to carrier APIs.
8631 *
Michele Berionne482f8202018-11-27 18:57:59 -08008632 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008633 */
8634 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008635 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008636 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008637 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008638
8639 final long identity = Binder.clearCallingIdentity();
8640 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008641 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8642 if (response instanceof CarrierRestrictionRules) {
8643 return (CarrierRestrictionRules) response;
8644 }
8645 // Response is an Exception of some kind,
8646 // which is signalled to the user as a NULL retval
8647 return null;
8648 } catch (Exception e) {
8649 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8650 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008651 } finally {
8652 Binder.restoreCallingIdentity(identity);
8653 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008654 }
8655
fionaxu59545b42016-05-25 15:53:37 -07008656 /**
arunvoddud7401012022-12-15 16:08:12 +00008657 * Fetches the carrier restriction status of the device and sends the status to the caller
8658 * through the callback.
8659 *
8660 * @param callback The callback that will be used to send the result.
8661 * @throws SecurityException if the caller does not have the required permission/privileges or
8662 * the caller is not allowlisted.
8663 */
8664 @Override
8665 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8666 enforceReadPermission("getCarrierRestrictionStatus");
8667 int carrierId = validateCallerAndGetCarrierId(packageName);
8668 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8669 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8670 throw new SecurityException("Not an authorized caller");
8671 }
8672 final long identity = Binder.clearCallingIdentity();
8673 try {
8674 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8675 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8676 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8677 } finally {
8678 Binder.restoreCallingIdentity(identity);
8679 }
8680 }
8681
8682 @VisibleForTesting
8683 public int validateCallerAndGetCarrierId(String packageName) {
8684 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8685 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8686 }
8687
8688 /**
fionaxu59545b42016-05-25 15:53:37 -07008689 * Action set from carrier signalling broadcast receivers to enable/disable radio
8690 * @param subId the subscription ID that this action applies to.
8691 * @param enabled control enable or disable radio.
8692 * {@hide}
8693 */
8694 @Override
8695 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8696 enforceModifyPermission();
8697 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008698
8699 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008700 if (phone == null) {
8701 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8702 return;
8703 }
8704 try {
8705 phone.carrierActionSetRadioEnabled(enabled);
8706 } catch (Exception e) {
8707 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008708 } finally {
8709 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008710 }
8711 }
8712
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008713 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008714 * Enable or disable Voice over NR (VoNR)
8715 * @param subId the subscription ID that this action applies to.
8716 * @param enabled enable or disable VoNR.
8717 * @return operation result.
8718 */
8719 @Override
8720 public int setVoNrEnabled(int subId, boolean enabled) {
8721 enforceModifyPermission();
8722 final Phone phone = getPhone(subId);
8723
8724 final long identity = Binder.clearCallingIdentity();
8725 if (phone == null) {
8726 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8727 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8728 }
8729
8730 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8731 try {
8732 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8733 workSource);
8734 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008735
8736 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8737 if (DBG) {
8738 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8739 }
8740 SubscriptionManager.setSubscriptionProperty(
8741 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8742 (enabled ? "1" : "0"));
8743 }
8744
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008745 return result;
8746 } finally {
8747 Binder.restoreCallingIdentity(identity);
8748 }
8749 }
8750
8751 /**
8752 * Is voice over NR enabled
8753 * @return true if VoNR is enabled else false
8754 */
8755 @Override
8756 public boolean isVoNrEnabled(int subId) {
8757 enforceReadPrivilegedPermission("isVoNrEnabled");
8758 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8759 final long identity = Binder.clearCallingIdentity();
8760 try {
8761 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8762 null, subId, workSource);
8763 if (DBG) log("isVoNrEnabled: " + isEnabled);
8764 return isEnabled;
8765 } finally {
8766 Binder.restoreCallingIdentity(identity);
8767 }
8768 }
8769
8770 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008771 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8772 * network status based on which carrier apps could apply actions accordingly,
8773 * enable/disable default url handler for example.
8774 *
8775 * @param subId the subscription ID that this action applies to.
8776 * @param report control start/stop reporting the default network status.
8777 * {@hide}
8778 */
8779 @Override
8780 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8781 enforceModifyPermission();
8782 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008783
8784 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008785 if (phone == null) {
8786 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8787 return;
8788 }
8789 try {
8790 phone.carrierActionReportDefaultNetworkStatus(report);
8791 } catch (Exception e) {
8792 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008793 } finally {
8794 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008795 }
8796 }
8797
8798 /**
fionaxud9622282017-07-17 17:51:30 -07008799 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8800 * @param subId the subscription ID that this action applies to.
8801 * {@hide}
8802 */
8803 @Override
8804 public void carrierActionResetAll(int subId) {
8805 enforceModifyPermission();
8806 final Phone phone = getPhone(subId);
8807 if (phone == null) {
8808 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8809 return;
8810 }
8811 try {
8812 phone.carrierActionResetAll();
8813 } catch (Exception e) {
8814 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8815 }
8816 }
8817
8818 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008819 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8820 * bug report is being generated.
8821 */
8822 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008823 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008824 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8825 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008826 writer.println("Permission Denial: can't dump Phone from pid="
8827 + Binder.getCallingPid()
8828 + ", uid=" + Binder.getCallingUid()
8829 + "without permission "
8830 + android.Manifest.permission.DUMP);
8831 return;
8832 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008833 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008834 }
Jack Yueb89b242016-06-22 13:27:47 -07008835
Brad Ebingerdac2f002018-04-03 15:17:52 -07008836 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008837 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8838 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8839 @NonNull String[] args) {
8840 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8841 this, in.getFileDescriptor(), out.getFileDescriptor(),
8842 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008843 }
8844
Jack Yueb89b242016-06-22 13:27:47 -07008845 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008846 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008847 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008848 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008849 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008850 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008851 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008852 */
8853 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008854 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008855 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008856 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8857 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8858 try {
8859 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008860 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008861 } catch (SecurityException se) {
8862 enforceModifyPermission();
8863 }
8864 } else {
8865 enforceModifyPermission();
8866 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008867
8868 final long identity = Binder.clearCallingIdentity();
8869 try {
8870 Phone phone = getPhone(subId);
8871 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008872 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8873 phone.carrierActionSetMeteredApnsEnabled(enabled);
8874 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008875 phone.getDataSettingsManager().setDataEnabled(
8876 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008877 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008878 }
8879 } finally {
8880 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008881 }
8882 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008883
8884 /**
8885 * Get Client request stats
8886 * @return List of Client Request Stats
8887 * @hide
8888 */
8889 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008890 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8891 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008892 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008893 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008894 return null;
8895 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008896 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008897
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008898 final long identity = Binder.clearCallingIdentity();
8899 try {
8900 if (phone != null) {
8901 return phone.getClientRequestStats();
8902 }
8903
8904 return null;
8905 } finally {
8906 Binder.restoreCallingIdentity(identity);
8907 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008908 }
8909
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008910 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008911 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008912 if (uid == Process.ROOT_UID && packageName == null) {
8913 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8914 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8915 // exception. ROOT_UID seems not to have a valid package name returned by
8916 // PackageManager, so just fake it here to avoid issues when running telephony shell
8917 // commands that plumb through the RIL as root, like so:
8918 // $ adb root
8919 // $ adb shell cmd phone ...
8920 packageName = "root";
8921 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008922 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008923 }
Jack Yueb4124c2017-02-16 15:32:43 -08008924
8925 /**
Grace Chen70990072017-03-24 17:21:30 -07008926 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008927 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008928 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008929 * @param state State of SIM (power down, power up, pass through)
8930 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8931 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8932 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008933 *
8934 **/
8935 @Override
Grace Chen70990072017-03-24 17:21:30 -07008936 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008937 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008938 Phone phone = PhoneFactory.getPhone(slotIndex);
8939
vagdeviaf9a5b92018-08-15 16:01:53 -07008940 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8941
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008942 final long identity = Binder.clearCallingIdentity();
8943 try {
8944 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008945 phone.setSimPowerState(state, null, workSource);
8946 }
8947 } finally {
8948 Binder.restoreCallingIdentity(identity);
8949 }
8950 }
8951
8952 /**
8953 * Set SIM card power state.
8954 *
8955 * @param slotIndex SIM slot id.
8956 * @param state State of SIM (power down, power up, pass through)
8957 * @param callback callback to trigger after success or failure
8958 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8959 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8960 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8961 *
8962 **/
8963 @Override
8964 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8965 IIntegerConsumer callback) {
8966 enforceModifyPermission();
8967 Phone phone = PhoneFactory.getPhone(slotIndex);
8968
8969 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8970
8971 final long identity = Binder.clearCallingIdentity();
8972 try {
8973 if (phone != null) {
8974 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8975 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008976 }
8977 } finally {
8978 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008979 }
8980 }
Shuo Qiandd210312017-04-12 22:11:33 +00008981
Tyler Gunn65d45c22017-06-05 11:22:26 -07008982 private boolean isUssdApiAllowed(int subId) {
8983 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008984 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008985 if (configManager == null) {
8986 return false;
8987 }
8988 PersistableBundle pb = configManager.getConfigForSubId(subId);
8989 if (pb == null) {
8990 return false;
8991 }
8992 return pb.getBoolean(
8993 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8994 }
8995
Shuo Qiandd210312017-04-12 22:11:33 +00008996 /**
8997 * Check if phone is in emergency callback mode
8998 * @return true if phone is in emergency callback mode
8999 * @param subId sub id
9000 */
goneil9c5f4872017-12-05 14:07:56 -08009001 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009002 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009003 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00009004 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009005
9006 final long identity = Binder.clearCallingIdentity();
9007 try {
9008 if (phone != null) {
9009 return phone.isInEcm();
9010 } else {
9011 return false;
9012 }
9013 } finally {
9014 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009015 }
9016 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009017
9018 /**
9019 * Get the current signal strength information for the given subscription.
9020 * Because this information is not updated when the device is in a low power state
9021 * it should not be relied-upon to be current.
9022 * @param subId Subscription index
9023 * @return the most recent cached signal strength info from the modem
9024 */
9025 @Override
9026 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009027 final long identity = Binder.clearCallingIdentity();
9028 try {
9029 Phone p = getPhone(subId);
9030 if (p == null) {
9031 return null;
9032 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009033
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009034 return p.getSignalStrength();
9035 } finally {
9036 Binder.restoreCallingIdentity(identity);
9037 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009038 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009039
Pengquan Meng77b7f132018-08-22 14:49:57 -07009040 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009041 * Get the current modem radio state for the given slot.
9042 * @param slotIndex slot index.
9043 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009044 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009045 * @return the current radio power state from the modem
9046 */
9047 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009048 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009049 Phone phone = PhoneFactory.getPhone(slotIndex);
9050 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009051 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9052 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009053 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9054 }
9055
9056 final long identity = Binder.clearCallingIdentity();
9057 try {
9058 return phone.getRadioPowerState();
9059 } finally {
9060 Binder.restoreCallingIdentity(identity);
9061 }
9062 }
9063 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9064 }
9065
9066 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009067 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9068 *
9069 * <p>Requires one of the following permissions:
9070 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009071 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009072 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9073 * privileges.
9074 *
9075 * @param subId subscription id
9076 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9077 * {@code false}.
9078 */
9079 @Override
9080 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009081 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009082 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009083 try {
9084 mApp.enforceCallingOrSelfPermission(
9085 android.Manifest.permission.ACCESS_NETWORK_STATE,
9086 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009087 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009088 mApp.enforceCallingOrSelfPermission(
9089 permission.READ_BASIC_PHONE_STATE, functionName);
9090 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009091 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009092 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009093 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009094 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009095
Pengquan Menga1bb6272018-09-06 09:59:22 -07009096 boolean isEnabled = false;
9097 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009098 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009099 Phone phone = getPhone(subId);
9100 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009101 } finally {
9102 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009103 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009104 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009105 }
9106
9107
9108 /**
9109 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9110 *
9111 * <p> Requires permission:
9112 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9113 * privileges.
9114 *
9115 * @param subId subscription id
9116 * @param isEnabled {@code true} means enable, {@code false} means disable.
9117 */
9118 @Override
9119 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9121 mApp, subId, "setDataRoamingEnabled");
9122
Pengquan Menga1bb6272018-09-06 09:59:22 -07009123 final long identity = Binder.clearCallingIdentity();
9124 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009125 Phone phone = getPhone(subId);
9126 if (phone != null) {
9127 phone.setDataRoamingEnabled(isEnabled);
9128 }
9129 } finally {
9130 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009131 }
9132 }
9133
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009134 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009135 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009136 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009137 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07009138 mApp, subId, "isManualNetworkSelectionAllowed");
9139
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009140 boolean isAllowed = true;
9141 final long identity = Binder.clearCallingIdentity();
9142 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009143 Phone phone = getPhone(subId);
9144 if (phone != null) {
9145 isAllowed = phone.isCspPlmnEnabled();
9146 }
9147 } finally {
9148 Binder.restoreCallingIdentity(identity);
9149 }
9150 return isAllowed;
9151 }
9152
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009153 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9154 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009155 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009156 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009157 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009158 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9159 if (phone == null) {
9160 return false;
9161 }
9162 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9163 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9164 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009165 }
9166
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009167 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009168 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009169 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009170 mApp.getSystemService(AppOpsManager.class)
9171 .checkPackage(Binder.getCallingUid(), callingPackage);
9172
Jordan Liu1e142fc2019-04-22 15:10:43 -07009173 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009174 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009175 try {
9176 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009177 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009178 } catch (SecurityException e) {
9179 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9180 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009181 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08009182 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009183 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009184 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009185 }
sandeepjsb6c87872021-09-27 15:34:44 +00009186 // checking compatibility, if calling app's target SDK is T and beyond.
9187 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9188 Binder.getCallingUid())) {
9189 isIccIdAccessRestricted = true;
9190 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009191 final long identity = Binder.clearCallingIdentity();
9192 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009193 UiccController uiccController = UiccController.getInstance();
9194 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009195 if (hasReadPermission) {
9196 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009197 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009198
9199 // Remove private info if the caller doesn't have access
9200 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9201 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009202 //setting the value after compatibility check
9203 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009204 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9205 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009206 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009207 if (card == null) {
9208 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009209 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009210 continue;
9211 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009212 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9213 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009214 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009215 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009216 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009217 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9218 for (UiccPortInfo portInfo : portInfos) {
9219 UiccPort port = uiccController.getUiccPortForSlot(
9220 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9221 if (port == null) {
9222 // assume no access if port is null
9223 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9224 continue;
9225 }
9226 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9227 uiccPortInfos.add(portInfo);
9228 } else {
9229 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9230 }
9231 }
9232 filteredInfos.add(new UiccCardInfo(
9233 cardInfo.isEuicc(),
9234 cardInfo.getCardId(),
9235 null,
9236 cardInfo.getPhysicalSlotIndex(),
9237 cardInfo.isRemovable(),
9238 cardInfo.isMultipleEnabledProfilesSupported(),
9239 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009240 }
9241 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009242 } finally {
9243 Binder.restoreCallingIdentity(identity);
9244 }
9245 }
9246
sandeepjsb6c87872021-09-27 15:34:44 +00009247 /**
9248 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9249 * generally private and require carrier privileges to view.
9250 *
9251 * @hide
9252 */
9253 @NonNull
9254 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9255 List<UiccPortInfo> portinfo = new ArrayList<>();
9256 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9257 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9258 }
9259 return new UiccCardInfo(
9260 cardInfo.isEuicc(),
9261 cardInfo.getCardId(),
9262 null,
9263 cardInfo.getPhysicalSlotIndex(),
9264 cardInfo.isRemovable(),
9265 cardInfo.isMultipleEnabledProfilesSupported(),
9266 portinfo
9267 );
9268 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009269
sandeepjsb6c87872021-09-27 15:34:44 +00009270 /**
9271 * @hide
9272 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9273 * These values are generally private and require carrier privileges to view.
9274 */
9275 @NonNull
9276 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9277 return new UiccPortInfo(
9278 UiccPortInfo.ICCID_REDACTED,
9279 portInfo.getPortIndex(),
9280 portInfo.getLogicalSlotIndex(),
9281 portInfo.isActive()
9282 );
9283 }
9284 @Override
9285 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009286 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009287 mApp.getSystemService(AppOpsManager.class)
9288 .checkPackage(Binder.getCallingUid(), callingPackage);
9289
sandeepjsb6c87872021-09-27 15:34:44 +00009290 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009291
Aman Guptaf3c90b32022-03-17 04:54:16 +00009292 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9293 // we are reading iccId which is PII data.
9294 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009295
9296 // checking compatibility, if calling app's target SDK is T and beyond.
9297 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9298 Binder.getCallingUid())) {
9299 isLogicalSlotAccessRestricted = true;
9300 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009301 final long identity = Binder.clearCallingIdentity();
9302 try {
9303 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009304 if (slots == null || slots.length == 0) {
9305 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009306 return null;
9307 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009308 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9309 for (int i = 0; i < slots.length; i++) {
9310 UiccSlot slot = slots[i];
9311 if (slot == null) {
9312 continue;
9313 }
9314
Jordan Liu7be7e652019-05-06 18:55:02 +00009315 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009316 UiccCard card = slot.getUiccCard();
9317 if (card != null) {
9318 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009319 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009320 cardId = slot.getEid();
9321 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009322 // If cardId is null, use iccId of default port as cardId.
9323 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009324 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009325 }
9326
Jordan Liu857451f2019-05-09 16:35:35 -07009327 if (cardId != null) {
9328 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9329 // if cardId is an EID, it's all digits so this is fine
9330 cardId = IccUtils.stripTrailingFs(cardId);
9331 }
9332
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009333 int cardState = 0;
9334 switch (slot.getCardState()) {
9335 case CARDSTATE_ABSENT:
9336 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9337 break;
9338 case CARDSTATE_PRESENT:
9339 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9340 break;
9341 case CARDSTATE_ERROR:
9342 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9343 break;
9344 case CARDSTATE_RESTRICTED:
9345 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9346 break;
9347 default:
9348 break;
9349
9350 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009351 List<UiccPortInfo> portInfos = new ArrayList<>();
9352 int[] portIndexes = slot.getPortList();
9353 for (int portIdx : portIndexes) {
9354 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009355 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009356 portInfos.add(new UiccPortInfo(iccId, portIdx,
9357 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009358 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009359 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009360 slot.isEuicc(),
9361 cardId,
9362 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009363 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009364 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009365 //setting the value after compatibility check
9366 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009367 }
9368 return infos;
9369 } finally {
9370 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009371 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009372 }
9373
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009374 /* Returns null if doesn't have read permission or carrier privilege access. */
9375 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9376 boolean hasReadPermission) {
9377 String iccId = slot.getIccId(portIndex);
9378 if (hasReadPermission) { // if has read permission
9379 return iccId;
9380 } else {
9381 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9382 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9383 // if no read permission, checking carrier privilege access
9384 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9385 return iccId;
9386 }
9387 }
9388 }
9389 // No read permission or carrier privilege access.
9390 return UiccPortInfo.ICCID_REDACTED;
9391 }
9392
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009393 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009394 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009395 public boolean switchSlots(int[] physicalSlots) {
9396 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009397
9398 final long identity = Binder.clearCallingIdentity();
9399 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009400 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9401 for (int i = 0; i < physicalSlots.length; i++) {
9402 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9403 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9404 physicalSlots[i], i));
9405 }
9406 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009407 } finally {
9408 Binder.restoreCallingIdentity(identity);
9409 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009410 }
Jack Yu4c988042018-02-27 15:30:01 -08009411
9412 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009413 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9414 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9415 enforceModifyPermission();
9416
9417 final long identity = Binder.clearCallingIdentity();
9418 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009419 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009420 } finally {
9421 Binder.restoreCallingIdentity(identity);
9422 }
9423 }
9424
9425 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009426 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009427 final long identity = Binder.clearCallingIdentity();
9428 try {
9429 return UiccController.getInstance().getCardIdForDefaultEuicc();
9430 } finally {
9431 Binder.restoreCallingIdentity(identity);
9432 }
9433 }
9434
Pengquan Meng85728fb2018-03-12 16:31:21 -07009435 /**
goneil47ffb6e2018-04-06 15:40:58 -07009436 * A test API to reload the UICC profile.
9437 *
9438 * <p>Requires that the calling app has permission
9439 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9440 * @hide
9441 */
9442 @Override
9443 public void refreshUiccProfile(int subId) {
9444 enforceModifyPermission();
9445
9446 final long identity = Binder.clearCallingIdentity();
9447 try {
9448 Phone phone = getPhone(subId);
9449 if (phone == null) {
9450 return;
9451 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009452 UiccPort uiccPort = phone.getUiccPort();
9453 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009454 return;
9455 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009456 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009457 if (uiccProfile == null) {
9458 return;
9459 }
9460 uiccProfile.refresh();
9461 } finally {
9462 Binder.restoreCallingIdentity(identity);
9463 }
9464 }
9465
9466 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009467 * Returns false if the mobile data is disabled by default, otherwise return true.
9468 */
9469 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009470 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009471 }
9472
9473 /**
9474 * Returns true if the data roaming is enabled by default, i.e the system property
9475 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9476 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9477 */
9478 private boolean getDefaultDataRoamingEnabled(int subId) {
9479 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009480 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009481 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009482 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9483 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9484 return isDataRoamingEnabled;
9485 }
9486
9487 /**
9488 * Returns the default network type for the given {@code subId}, if the default network type is
9489 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9490 */
9491 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009492 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009493 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009494 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9495 return list.get(phoneId);
9496 }
9497 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009498 }
fionaxua13278b2018-03-21 00:08:13 -07009499
9500 @Override
9501 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009502 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009503 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009504
9505 final long identity = Binder.clearCallingIdentity();
9506 try {
9507 final Phone phone = getPhone(subId);
9508 if (phone == null) {
9509 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9510 return;
9511 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009512 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9513 if (cpt != null) {
9514 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9515 }
9516 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009517 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9518 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009519 if (carrierPrivilegeRules == null) {
9520 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9521 } else {
9522 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9523 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009524 } finally {
9525 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009526 }
fionaxua13278b2018-03-21 00:08:13 -07009527 }
9528
9529 @Override
9530 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009531 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009532
9533 final long identity = Binder.clearCallingIdentity();
9534 try {
9535 final Phone phone = getPhone(subId);
9536 if (phone == null) {
9537 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9538 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9539 }
9540 return phone.getCarrierIdListVersion();
9541 } finally {
9542 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009543 }
fionaxua13278b2018-03-21 00:08:13 -07009544 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009545
9546 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009547 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9548 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009549 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009550 mApp, subId, callingPackage, callingFeatureId,
9551 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009552 return -1;
9553 }
9554
9555 final long identity = Binder.clearCallingIdentity();
9556 try {
9557 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9558 } finally {
9559 Binder.restoreCallingIdentity(identity);
9560 }
9561 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009562
9563 @Override
9564 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009565 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009566 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009567 mApp, subId, "getCdmaRoamingMode");
9568
9569 final long identity = Binder.clearCallingIdentity();
9570 try {
9571 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9572 } finally {
9573 Binder.restoreCallingIdentity(identity);
9574 }
9575 }
9576
9577 @Override
9578 public boolean setCdmaRoamingMode(int subId, int mode) {
9579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9580 mApp, subId, "setCdmaRoamingMode");
9581
9582 final long identity = Binder.clearCallingIdentity();
9583 try {
9584 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9585 } finally {
9586 Binder.restoreCallingIdentity(identity);
9587 }
9588 }
9589
9590 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009591 public int getCdmaSubscriptionMode(int subId) {
9592 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009593 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009594 mApp, subId, "getCdmaSubscriptionMode");
9595
9596 final long identity = Binder.clearCallingIdentity();
9597 try {
9598 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9599 } finally {
9600 Binder.restoreCallingIdentity(identity);
9601 }
9602 }
9603
9604 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009605 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9607 mApp, subId, "setCdmaSubscriptionMode");
9608
9609 final long identity = Binder.clearCallingIdentity();
9610 try {
9611 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9612 } finally {
9613 Binder.restoreCallingIdentity(identity);
9614 }
9615 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009616
sqianc5eccab2018-10-19 18:46:41 -07009617 @Override
sqian8c685422019-02-22 15:55:18 -08009618 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009619 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009620 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009621 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9622 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009623 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9624 }
9625 final long identity = Binder.clearCallingIdentity();
9626 try {
sqian854d44b2018-12-12 16:48:18 -08009627 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9628 for (Phone phone: PhoneFactory.getPhones()) {
9629 if (phone.getEmergencyNumberTracker() != null
9630 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9631 emergencyNumberListInternal.put(
9632 phone.getSubId(),
9633 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9634 }
sqian11b7a0e2018-12-05 18:48:28 -08009635 }
sqian854d44b2018-12-12 16:48:18 -08009636 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009637 } finally {
9638 Binder.restoreCallingIdentity(identity);
9639 }
sqianc5eccab2018-10-19 18:46:41 -07009640 }
9641
9642 @Override
sqian8c685422019-02-22 15:55:18 -08009643 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009644 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009645 if (!exactMatch) {
9646 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009647 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009648 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009649 }
9650 final long identity = Binder.clearCallingIdentity();
9651 try {
sqian854d44b2018-12-12 16:48:18 -08009652 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009653 //Note: we ignore passed in param exactMatch. We can remove it once
9654 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009655 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009656 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009657 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009658 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009659 }
sqian11b7a0e2018-12-05 18:48:28 -08009660 }
9661 return false;
9662 } finally {
9663 Binder.restoreCallingIdentity(identity);
9664 }
9665 }
9666
sqianf4ca7ed2019-01-15 18:32:07 -08009667 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009668 * Start emergency callback mode for GsmCdmaPhone for testing.
9669 */
9670 @Override
9671 public void startEmergencyCallbackMode() {
9672 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9673 "startEmergencyCallbackMode");
9674 enforceModifyPermission();
9675 final long identity = Binder.clearCallingIdentity();
9676 try {
9677 for (Phone phone : PhoneFactory.getPhones()) {
9678 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9679 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9680 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9681 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9682 gsmCdmaPhone.obtainMessage(
9683 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9684 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9685 }
9686 }
9687 } finally {
9688 Binder.restoreCallingIdentity(identity);
9689 }
9690 }
9691
9692 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009693 * Update emergency number list for test mode.
9694 */
9695 @Override
9696 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9697 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9698 "updateEmergencyNumberListTestMode");
9699
9700 final long identity = Binder.clearCallingIdentity();
9701 try {
9702 for (Phone phone: PhoneFactory.getPhones()) {
9703 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9704 if (tracker != null) {
9705 tracker.executeEmergencyNumberTestModeCommand(action, num);
9706 }
9707 }
9708 } finally {
9709 Binder.restoreCallingIdentity(identity);
9710 }
9711 }
9712
9713 /**
9714 * Get the full emergency number list for test mode.
9715 */
9716 @Override
9717 public List<String> getEmergencyNumberListTestMode() {
9718 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9719 "getEmergencyNumberListTestMode");
9720
9721 final long identity = Binder.clearCallingIdentity();
9722 try {
9723 Set<String> emergencyNumbers = new HashSet<>();
9724 for (Phone phone: PhoneFactory.getPhones()) {
9725 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9726 if (tracker != null) {
9727 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9728 emergencyNumbers.add(num.getNumber());
9729 }
9730 }
9731 }
9732 return new ArrayList<>(emergencyNumbers);
9733 } finally {
9734 Binder.restoreCallingIdentity(identity);
9735 }
9736 }
9737
chen xud6b45bd2018-10-30 22:27:10 -07009738 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009739 public int getEmergencyNumberDbVersion(int subId) {
9740 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9741
9742 final long identity = Binder.clearCallingIdentity();
9743 try {
9744 final Phone phone = getPhone(subId);
9745 if (phone == null) {
9746 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9747 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9748 }
9749 return phone.getEmergencyNumberDbVersion();
9750 } finally {
9751 Binder.restoreCallingIdentity(identity);
9752 }
9753 }
9754
9755 @Override
9756 public void notifyOtaEmergencyNumberDbInstalled() {
9757 enforceModifyPermission();
9758
9759 final long identity = Binder.clearCallingIdentity();
9760 try {
9761 for (Phone phone: PhoneFactory.getPhones()) {
9762 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9763 if (tracker != null) {
9764 tracker.updateOtaEmergencyNumberDatabase();
9765 }
9766 }
9767 } finally {
9768 Binder.restoreCallingIdentity(identity);
9769 }
9770 }
9771
9772 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009773 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009774 enforceActiveEmergencySessionPermission();
9775
9776 final long identity = Binder.clearCallingIdentity();
9777 try {
9778 for (Phone phone: PhoneFactory.getPhones()) {
9779 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9780 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009781 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9782 }
9783 }
9784 } finally {
9785 Binder.restoreCallingIdentity(identity);
9786 }
9787 }
9788
9789 @Override
9790 public void resetOtaEmergencyNumberDbFilePath() {
9791 enforceActiveEmergencySessionPermission();
9792
9793 final long identity = Binder.clearCallingIdentity();
9794 try {
9795 for (Phone phone: PhoneFactory.getPhones()) {
9796 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9797 if (tracker != null) {
9798 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009799 }
9800 }
9801 } finally {
9802 Binder.restoreCallingIdentity(identity);
9803 }
9804 }
9805
9806 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009807 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9808 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9809 Phone phone = getPhone(subId);
9810 if (phone == null) {
9811 return null;
9812 }
9813 final long identity = Binder.clearCallingIdentity();
9814 try {
9815 UiccProfile profile = UiccController.getInstance()
9816 .getUiccProfileForPhone(phone.getPhoneId());
9817 if (profile != null) {
9818 return profile.getCertsFromCarrierPrivilegeAccessRules();
9819 }
9820 } finally {
9821 Binder.restoreCallingIdentity(identity);
9822 }
9823 return null;
9824 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009825
9826 /**
9827 * Enable or disable a modem stack.
9828 */
9829 @Override
9830 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9831 enforceModifyPermission();
9832
9833 final long identity = Binder.clearCallingIdentity();
9834 try {
9835 Phone phone = PhoneFactory.getPhone(slotIndex);
9836 if (phone == null) {
9837 return false;
9838 } else {
9839 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9840 }
9841 } finally {
9842 Binder.restoreCallingIdentity(identity);
9843 }
9844 }
Michelecea4cf22018-12-21 15:00:11 -08009845
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009846 /**
9847 * Whether a modem stack is enabled or not.
9848 */
9849 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009850 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9851 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009852 Phone phone = PhoneFactory.getPhone(slotIndex);
9853 if (phone == null) return false;
9854
9855 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009856 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9857 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009858 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9859 }
9860
9861 final long identity = Binder.clearCallingIdentity();
9862 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009863 try {
9864 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9865 } catch (NoSuchElementException ex) {
9866 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9867 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009868 } finally {
9869 Binder.restoreCallingIdentity(identity);
9870 }
9871 }
9872
Michelecea4cf22018-12-21 15:00:11 -08009873 @Override
Michele0ea7d782019-03-19 14:58:42 -07009874 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009875 enforceModifyPermission();
9876
9877 final long identity = Binder.clearCallingIdentity();
9878 try {
9879 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009880 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009881 .commit();
9882 } finally {
9883 Binder.restoreCallingIdentity(identity);
9884 }
9885 }
9886
9887 @Override
Michele0ea7d782019-03-19 14:58:42 -07009888 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009889 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009890 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009891 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9892 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009893 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009894 }
Michelecea4cf22018-12-21 15:00:11 -08009895
9896 final long identity = Binder.clearCallingIdentity();
9897 try {
Michele0ea7d782019-03-19 14:58:42 -07009898 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009899 } finally {
9900 Binder.restoreCallingIdentity(identity);
9901 }
9902 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009903
Michele0ea7d782019-03-19 14:58:42 -07009904 @TelephonyManager.IsMultiSimSupportedResult
9905 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009906 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9907 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9908 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009909 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9910 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009911 }
9912 // Check if the hardware supports multisim functionality. If usage of multisim is not
9913 // supported by the modem, indicate that it is restricted.
9914 PhoneCapability staticCapability =
9915 mPhoneConfigurationManager.getStaticPhoneCapability();
9916 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009917 loge("isMultiSimSupportedInternal: no static configuration available");
9918 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009919 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009920 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009921 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9922 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009923 }
9924 // Check if support of multiple SIMs is restricted by carrier
9925 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009926 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009927 }
9928
Michele0ea7d782019-03-19 14:58:42 -07009929 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009930 }
9931
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009932 /**
9933 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009934 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9935 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9936 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009937 * @param numOfSims number of active sims we want to switch to
9938 */
9939 @Override
9940 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009941 if (numOfSims == 1) {
9942 enforceModifyPermission();
9943 } else {
9944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9945 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9946 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009947 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009948
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009949 try {
Michele30b57b22019-03-01 12:01:14 -08009950 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009951 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009952 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9953 return;
9954 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009955 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9956 } finally {
9957 Binder.restoreCallingIdentity(identity);
9958 }
9959 }
9960
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009961 @Override
9962 public boolean isApplicationOnUicc(int subId, int appType) {
9963 enforceReadPrivilegedPermission("isApplicationOnUicc");
9964 Phone phone = getPhone(subId);
9965 if (phone == null) {
9966 return false;
9967 }
9968 final long identity = Binder.clearCallingIdentity();
9969 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009970 UiccPort uiccPort = phone.getUiccPort();
9971 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009972 return false;
9973 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009974 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009975 if (uiccProfile == null) {
9976 return false;
9977 }
9978 if (TelephonyManager.APPTYPE_SIM <= appType
9979 && appType <= TelephonyManager.APPTYPE_ISIM) {
9980 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9981 }
9982 return false;
9983 } finally {
9984 Binder.restoreCallingIdentity(identity);
9985 }
9986 }
9987
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009988 /**
chen xub4baa772019-04-03 10:23:41 -07009989 * Get whether making changes to modem configurations will trigger reboot.
9990 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009991 */
9992 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009993 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9994 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009995 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009996 mApp, subId, callingPackage, callingFeatureId,
9997 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009998 return false;
9999 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010000 final long identity = Binder.clearCallingIdentity();
10001 try {
10002 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10003 } finally {
10004 Binder.restoreCallingIdentity(identity);
10005 }
10006 }
10007
Nathan Harold29f5f052019-02-15 13:41:57 -080010008 private void updateModemStateMetrics() {
10009 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10010 // TODO: check the state for each modem if the api is ready.
10011 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10012 }
10013
Pengquan Meng3889a572019-01-23 11:16:29 -080010014 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010015 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010016 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010017 // Verify that the callingPackage belongs to the calling UID
10018 mApp.getSystemService(AppOpsManager.class)
10019 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010020 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010021 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010022 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010023 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10024 if (slotInfos != null) {
10025 for (int i = 0; i < slotInfos.length; i++) {
10026 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10027 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10028 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10029 portInfo.getLogicalSlotIndex()));
10030 }
10031 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010032 }
10033 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010034 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010035 } finally {
10036 Binder.restoreCallingIdentity(identity);
10037 }
10038 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010039
10040 /**
10041 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010042 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010043 */
jimsunf9ec1622022-09-13 21:18:43 +080010044 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010045 @Override
10046 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010047 return getHalVersion(HAL_SERVICE_RADIO);
10048 }
10049
10050 /**
10051 * Get the HAL Version of a specific service
10052 */
10053 @Override
10054 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010055 Phone phone = getDefaultPhone();
10056 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010057 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010058 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10059 return hv.major * 100 + hv.minor;
10060 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010061
10062 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010063 * Get the current calling package name.
10064 * @return the current calling package name
10065 */
10066 @Override
10067 public String getCurrentPackageName() {
10068 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10069 }
10070
10071 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010072 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10073 * corresponding network requests on a subId.
10074 *
10075 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010076 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010077 * 2) APN is un-metered for this subscription, or
10078 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010079 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010080 *
10081 * @return whether data is allowed for a apn type.
10082 *
10083 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010084 */
10085 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010086 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010087 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10088 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010089
10090 // Now that all security checks passes, perform the operation as ourselves.
10091 final long identity = Binder.clearCallingIdentity();
10092 try {
10093 Phone phone = getPhone(subId);
10094 if (phone == null) return false;
10095
Jack Yu27422a52022-03-21 10:38:05 -070010096 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010097 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010098 isMetered = phone.getDataNetworkController().getDataConfigManager()
10099 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10100 phone.getServiceState().getDataRoaming());
10101 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010102 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010103 } finally {
10104 Binder.restoreCallingIdentity(identity);
10105 }
10106 }
10107
10108 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010109 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010110 enforceReadPrivilegedPermission("isApnMetered");
10111
10112 // Now that all security checks passes, perform the operation as ourselves.
10113 final long identity = Binder.clearCallingIdentity();
10114 try {
10115 Phone phone = getPhone(subId);
10116 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010117 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10118 DataUtils.apnTypeToNetworkCapability(apnType),
10119 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010120 } finally {
10121 Binder.restoreCallingIdentity(identity);
10122 }
10123 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010124
10125 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010126 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10127 int subscriptionId, IBooleanConsumer resultCallback) {
10128 enforceModifyPermission();
10129 long token = Binder.clearCallingIdentity();
10130 try {
10131 Phone phone = getPhone(subscriptionId);
10132 if (phone == null) {
10133 try {
10134 if (resultCallback != null) {
10135 resultCallback.accept(false);
10136 }
10137 } catch (RemoteException e) {
10138 // ignore
10139 }
10140 return;
10141 }
10142 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10143 Pair.create(specifiers, (x) -> {
10144 try {
10145 if (resultCallback != null) {
10146 resultCallback.accept(x);
10147 }
10148 } catch (RemoteException e) {
10149 // ignore
10150 }
10151 });
10152 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10153 } finally {
10154 Binder.restoreCallingIdentity(token);
10155 }
10156 }
10157
10158 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010159 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10160 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010161 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010162 mApp, subId, "getSystemSelectionChannels");
10163 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10164 final long identity = Binder.clearCallingIdentity();
10165 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010166 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10167 if (result instanceof IllegalStateException) {
10168 throw (IllegalStateException) result;
10169 }
10170 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010171 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10172 return specifiers;
10173 } finally {
10174 Binder.restoreCallingIdentity(identity);
10175 }
10176 }
10177
10178 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010179 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010180 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010181 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010182 }
10183
10184 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010185 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10186 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010187 if (callingPackage == null) {
10188 callingPackage = getCurrentPackageName();
10189 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010190 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10191 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010192 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10193 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010194 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10195 }
10196 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10197 Intent intent = new Intent();
10198 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10199 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10200 // Bring up choose default SMS subscription dialog right now
10201 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10202 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10203 mApp.startActivity(intent);
10204 }
chen xud5ca2d52019-05-28 15:20:57 -070010205
10206 @Override
10207 public String getMmsUAProfUrl(int subId) {
10208 //TODO investigate if this API should require proper permission check in R b/133791609
10209 final long identity = Binder.clearCallingIdentity();
10210 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010211 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10212 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10213 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10214 return carrierUAProfUrl;
10215 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010216 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10217 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010218 } finally {
10219 Binder.restoreCallingIdentity(identity);
10220 }
10221 }
10222
10223 @Override
10224 public String getMmsUserAgent(int subId) {
10225 //TODO investigate if this API should require proper permission check in R b/133791609
10226 final long identity = Binder.clearCallingIdentity();
10227 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010228 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10229 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10230 if (!TextUtils.isEmpty(carrierUserAgent)) {
10231 return carrierUserAgent;
10232 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010233 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10234 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010235 } finally {
10236 Binder.restoreCallingIdentity(identity);
10237 }
10238 }
Jack Yub07d4972019-05-28 16:12:25 -070010239
10240 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010241 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10242 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010243
Jack Yub07d4972019-05-28 16:12:25 -070010244 final long identity = Binder.clearCallingIdentity();
10245 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010246 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010247 if (phone == null) return false;
10248
Ling Maf188d502022-09-16 15:22:36 -070010249 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010250 } finally {
10251 Binder.restoreCallingIdentity(identity);
10252 }
10253 }
10254
10255 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010256 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010257 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010258 enforceModifyPermission();
10259
changbettyd5c246e2019-12-24 15:40:37 +080010260 final long identity = Binder.clearCallingIdentity();
10261 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010262 Phone phone = getPhone(subscriptionId);
10263 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010264
Ling Maf188d502022-09-16 15:22:36 -070010265 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010266 } finally {
10267 Binder.restoreCallingIdentity(identity);
10268 }
10269 }
10270
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010271 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010272 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010273 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10274 * otherwise.
10275 */
10276 @Override
10277 public void setCepEnabled(boolean isCepEnabled) {
10278 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10279
10280 final long identity = Binder.clearCallingIdentity();
10281 try {
10282 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10283 for (Phone phone : PhoneFactory.getPhones()) {
10284 Phone defaultPhone = phone.getImsPhone();
10285 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10286 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10287 ImsPhoneCallTracker imsPhoneCallTracker =
10288 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10289 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10290 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10291 + imsPhone.getMsisdn());
10292 }
10293 }
10294 } finally {
10295 Binder.restoreCallingIdentity(identity);
10296 }
10297 }
allenwtsu46dcc572020-01-08 18:24:03 +080010298
10299 /**
10300 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10301 *
10302 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10303 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10304 * before being read.
10305 */
10306 @Override
10307 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10308 isCompressed) {
10309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10310 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010311 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10312 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10313 }
10314 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010315 // ProvisioningManager can not handle ServiceSpecificException.
10316 // Throw the IllegalStateException and annotate ProvisioningManager.
10317 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010318 }
10319
10320 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010321 try {
Hui Wang761a6682020-10-31 05:12:53 +000010322 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10323 } finally {
10324 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010325 }
10326 }
zoey chene02881a2019-12-30 16:11:23 +080010327
10328 @Override
10329 public boolean isIccLockEnabled(int subId) {
10330 enforceReadPrivilegedPermission("isIccLockEnabled");
10331
10332 // Now that all security checks passes, perform the operation as ourselves.
10333 final long identity = Binder.clearCallingIdentity();
10334 try {
10335 Phone phone = getPhone(subId);
10336 if (phone != null && phone.getIccCard() != null) {
10337 return phone.getIccCard().getIccLockEnabled();
10338 } else {
10339 return false;
10340 }
10341 } finally {
10342 Binder.restoreCallingIdentity(identity);
10343 }
10344 }
10345
10346 /**
10347 * Set the ICC pin lock enabled or disabled.
10348 *
10349 * @return an integer representing the status of IccLock enabled or disabled in the following
10350 * three cases:
10351 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10352 * successfully.
10353 * - Positive number and zero for remaining password attempts.
10354 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10355 *
10356 */
10357 @Override
10358 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10359 enforceModifyPermission();
10360
10361 Phone phone = getPhone(subId);
10362 if (phone == null) {
10363 return 0;
10364 }
10365 // Now that all security checks passes, perform the operation as ourselves.
10366 final long identity = Binder.clearCallingIdentity();
10367 try {
10368 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10369 new Pair<Boolean, String>(enabled, password), phone, null);
10370 return attemptsRemaining;
10371
10372 } catch (Exception e) {
10373 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10374 } finally {
10375 Binder.restoreCallingIdentity(identity);
10376 }
10377 return 0;
10378 }
10379
10380 /**
10381 * Change the ICC password used in ICC pin lock.
10382 *
10383 * @return an integer representing the status of IccLock changed in the following three cases:
10384 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10385 * - Positive number and zero for remaining password attempts.
10386 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10387 *
10388 */
10389 @Override
10390 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10391 enforceModifyPermission();
10392
10393 Phone phone = getPhone(subId);
10394 if (phone == null) {
10395 return 0;
10396 }
10397 // Now that all security checks passes, perform the operation as ourselves.
10398 final long identity = Binder.clearCallingIdentity();
10399 try {
10400 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10401 new Pair<String, String>(oldPassword, newPassword), phone, null);
10402 return attemptsRemaining;
10403
10404 } catch (Exception e) {
10405 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10406 } finally {
10407 Binder.restoreCallingIdentity(identity);
10408 }
10409 return 0;
10410 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010411
10412 /**
10413 * Request for receiving user activity notification
10414 */
10415 @Override
10416 public void requestUserActivityNotification() {
10417 if (!mNotifyUserActivity.get()
10418 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10419 mNotifyUserActivity.set(true);
10420 }
10421 }
10422
10423 /**
10424 * Called when userActivity is signalled in the power manager.
10425 * This is safe to call from any thread, with any window manager locks held or not.
10426 */
10427 @Override
10428 public void userActivity() {
10429 // ***************************************
10430 // * Inherited from PhoneWindowManager *
10431 // ***************************************
10432 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10433 // WITH ITS LOCKS HELD.
10434 //
10435 // This code must be VERY careful about the locks
10436 // it acquires.
10437 // In fact, the current code acquires way too many,
10438 // and probably has lurking deadlocks.
10439
10440 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10441 throw new SecurityException("Only the OS may call notifyUserActivity()");
10442 }
10443
10444 if (mNotifyUserActivity.getAndSet(false)) {
10445 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10446 USER_ACTIVITY_NOTIFICATION_DELAY);
10447 }
10448 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010449
10450 @Override
10451 public boolean canConnectTo5GInDsdsMode() {
10452 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10453 }
Jack Yud10cdd42020-09-28 20:28:01 -070010454
10455 @Override
10456 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10457 String callingFeatureId) {
10458 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10459 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10460 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10461 }
10462
10463 Phone phone = getPhone(subId);
10464 if (phone == null) {
10465 throw new RuntimeException("phone is not available");
10466 }
10467 // Now that all security checks passes, perform the operation as ourselves.
10468 final long identity = Binder.clearCallingIdentity();
10469 try {
10470 return phone.getEquivalentHomePlmns();
10471 } finally {
10472 Binder.restoreCallingIdentity(identity);
10473 }
10474 }
Daniel Bright59e67312020-11-13 11:49:37 -080010475
10476 @Override
10477 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010478 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10479 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010480 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010481 if (radioInterfaceCapabilities == null) {
10482 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010483 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010484 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010485 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010486
Hui Wang641e81c2020-10-12 12:14:23 -070010487 @Override
10488 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10489 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010490 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10491 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10492 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10493 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10494 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010495 if (DBG) {
10496 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10497 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10498 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10499 }
10500
10501 if (!SubscriptionManager.isValidSubscriptionId(subId)
10502 || appType < TelephonyManager.APPTYPE_UNKNOWN
10503 || appType > TelephonyManager.APPTYPE_ISIM
10504 || nafUrl == null || securityProtocol == null || callback == null) {
10505 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10506 if (callback != null) {
10507 try {
10508 callback.onAuthenticationFailure(
10509 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10510 } catch (RemoteException exception) {
10511 log("Fail to notify onAuthenticationFailure due to " + exception);
10512 }
10513 return;
10514 }
10515 }
10516
10517 final long token = Binder.clearCallingIdentity();
10518 try {
10519 getGbaManager(subId).bootstrapAuthenticationRequest(
10520 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10521 forceBootStrapping, callback));
10522 } finally {
10523 Binder.restoreCallingIdentity(token);
10524 }
10525 }
10526
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010527 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010528 * Attempts to set the radio power state for all phones for thermal reason.
10529 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010530 * requested radio power state will actually be set. See {@link
10531 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10532 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010533 * @param enable {@code true} if trying to turn radio on.
10534 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10535 * false}.
10536 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010537 private boolean setRadioPowerForThermal(boolean enable) {
10538 boolean isPhoneAvailable = false;
10539 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10540 Phone phone = PhoneFactory.getPhone(i);
10541 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010542 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010543 isPhoneAvailable = true;
10544 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010545 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010546
10547 // return true if successfully informed the phone object about the thermal radio power
10548 // request.
10549 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010550 }
10551
10552 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010553 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010554 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10555 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10556 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10557 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10558 throw new IllegalArgumentException("modem does not support data throttling");
10559 }
10560
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010561 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10562 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010563 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010564 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10565 }
10566
Sarah Chinecc78c42022-03-31 21:16:48 -070010567 setDataEnabledForReason(
10568 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010569
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010570 if (isDataThrottlingSupported) {
10571 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010572 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010573 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10574 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10575 } else if (thermalMitigationResult
10576 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010577 log("Modem likely does not support data throttling on secondary carrier. Data " +
10578 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10579 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010580 }
10581 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010582 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010583
10584 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010585 }
10586
Jack Nudelman644b91a2021-03-12 14:09:48 -080010587 private static List<String> getThermalMitigationAllowlist(Context context) {
10588 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10589 for (String pckg : context.getResources()
10590 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10591 sThermalMitigationAllowlistedPackages.add(pckg);
10592 }
10593 }
10594
10595 return sThermalMitigationAllowlistedPackages;
10596 }
10597
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010598 private boolean isAnyPhoneInEmergencyState() {
10599 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10600 if (tm.isInEmergencyCall()) {
10601 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10602 return true;
10603 }
10604 for (Phone phone : PhoneFactory.getPhones()) {
10605 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10606 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10607 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10608 + phone.isInEcm());
10609 return true;
10610 }
10611 }
10612
10613 return false;
10614 }
10615
Jack Nudelman644b91a2021-03-12 14:09:48 -080010616 /**
10617 * Used by shell commands to add an authorized package name for thermal mitigation.
10618 * @param packageName name of package to be allowlisted
10619 * @param context
10620 */
10621 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10622 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10623 sThermalMitigationAllowlistedPackages.add(packageName);
10624 }
10625
10626 /**
10627 * Used by shell commands to remove an authorized package name for thermal mitigation.
10628 * @param packageName name of package to remove from allowlist
10629 * @param context
10630 */
10631 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10632 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10633 sThermalMitigationAllowlistedPackages.remove(packageName);
10634 }
10635
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010636 /**
10637 * Thermal mitigation request to control functionalities at modem.
10638 *
10639 * @param subId the id of the subscription.
10640 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010641 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010642 *
10643 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10644 */
10645 @Override
10646 @ThermalMitigationResult
10647 public int sendThermalMitigationRequest(
10648 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010649 ThermalMitigationRequest thermalMitigationRequest,
10650 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010651 enforceModifyPermission();
10652
Jack Nudelman644b91a2021-03-12 14:09:48 -080010653 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10654 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10655 .contains(callingPackage)) {
10656 throw new SecurityException("Calling package must be configured in the device config. "
10657 + "calling package: " + callingPackage);
10658 }
10659
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010660 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10661 final long identity = Binder.clearCallingIdentity();
10662
10663 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10664 try {
10665 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10666 switch (thermalMitigationAction) {
10667 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10668 thermalMitigationResult =
10669 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010670 thermalMitigationRequest.getDataThrottlingRequest(),
10671 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010672 break;
10673 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10674 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10675 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10676 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10677 }
10678
10679 // Ensure that radio is on. If not able to power on due to phone being
10680 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010681 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010682 thermalMitigationResult =
10683 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10684 break;
10685 }
10686
10687 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010688 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010689 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10690 break;
10691 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10692 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10693 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10694 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10695 }
10696
10697 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10698 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010699 Phone phone = getPhone(subId);
10700 if (phone == null) {
10701 thermalMitigationResult =
10702 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10703 break;
10704 }
10705
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010706 TelephonyConnectionService service =
10707 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010708 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010709 Log.e(LOG_TAG, "An emergency call is pending");
10710 thermalMitigationResult =
10711 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10712 break;
10713 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010714 thermalMitigationResult =
10715 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10716 break;
10717 }
10718 } else {
10719 thermalMitigationResult =
10720 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10721 break;
10722 }
10723
10724 // Turn radio off. If not able to power off due to phone being unavailable,
10725 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010726 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010727 thermalMitigationResult =
10728 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10729 break;
10730 }
10731 thermalMitigationResult =
10732 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10733 break;
10734 default:
10735 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10736 + "not exist. Requested action: " + thermalMitigationAction);
10737 }
10738 } catch (IllegalArgumentException e) {
10739 throw e;
10740 } catch (Exception e) {
10741 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10742 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10743 } finally {
10744 Binder.restoreCallingIdentity(identity);
10745 }
10746
10747 if (DBG) {
10748 log("thermalMitigationRequest returning with thermalMitigationResult: "
10749 + thermalMitigationResult);
10750 }
10751
10752 return thermalMitigationResult;
10753 }
Hui Wang641e81c2020-10-12 12:14:23 -070010754
10755 /**
10756 * Set the GbaService Package Name that Telephony will bind to.
10757 *
10758 * @param subId The sim that the GbaService is associated with.
10759 * @param packageName The name of the package to be replaced with.
10760 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10761 */
10762 @Override
10763 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10764 enforceModifyPermission();
10765
10766 final long identity = Binder.clearCallingIdentity();
10767 try {
10768 return getGbaManager(subId).overrideServicePackage(packageName);
10769 } finally {
10770 Binder.restoreCallingIdentity(identity);
10771 }
10772 }
10773
10774 /**
10775 * Return the package name of the currently bound GbaService.
10776 *
10777 * @param subId The sim that the GbaService is associated with.
10778 * @return the package name of the GbaService configuration, null if GBA is not supported.
10779 */
10780 @Override
10781 public String getBoundGbaService(int subId) {
10782 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10783
10784 final long identity = Binder.clearCallingIdentity();
10785 try {
10786 return getGbaManager(subId).getServicePackage();
10787 } finally {
10788 Binder.restoreCallingIdentity(identity);
10789 }
10790 }
10791
10792 /**
10793 * Set the release time for telephony to unbind GbaService.
10794 *
10795 * @param subId The sim that the GbaService is associated with.
10796 * @param interval The release time to unbind GbaService by millisecond.
10797 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10798 */
10799 @Override
10800 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10801 enforceModifyPermission();
10802
10803 final long identity = Binder.clearCallingIdentity();
10804 try {
10805 return getGbaManager(subId).overrideReleaseTime(interval);
10806 } finally {
10807 Binder.restoreCallingIdentity(identity);
10808 }
10809 }
10810
10811 /**
10812 * Return the release time for telephony to unbind GbaService.
10813 *
10814 * @param subId The sim that the GbaService is associated with.
10815 * @return The release time to unbind GbaService by millisecond.
10816 */
10817 @Override
10818 public int getGbaReleaseTime(int subId) {
10819 enforceReadPrivilegedPermission("getGbaReleaseTime");
10820
10821 final long identity = Binder.clearCallingIdentity();
10822 try {
10823 return getGbaManager(subId).getReleaseTime();
10824 } finally {
10825 Binder.restoreCallingIdentity(identity);
10826 }
10827 }
10828
10829 private GbaManager getGbaManager(int subId) {
10830 GbaManager instance = GbaManager.getInstance(subId);
10831 if (instance == null) {
10832 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10833 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10834 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10835 }
10836 return instance;
10837 }
Hui Wang761a6682020-10-31 05:12:53 +000010838
10839 /**
10840 * indicate whether the device and the carrier can support
10841 * RCS VoLTE single registration.
10842 */
10843 @Override
10844 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010845 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10846 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10847 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10848 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010849
10850 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10851 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10852 }
10853
10854 final long identity = Binder.clearCallingIdentity();
10855 try {
10856 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10857 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010858 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10859 if (isCapable != null) {
10860 return isCapable;
10861 }
Hui Wang761a6682020-10-31 05:12:53 +000010862 }
Hui Wang67af90e2021-06-04 16:57:15 -070010863 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10864 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010865 } finally {
10866 Binder.restoreCallingIdentity(identity);
10867 }
10868 }
10869
10870 /**
10871 * Register RCS provisioning callback.
10872 */
10873 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010874 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010875 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010876 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010877 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010878 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10879 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010880
10881 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10882 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10883 }
10884 if (!isImsAvailableOnDevice()) {
10885 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10886 "IMS not available on device.");
10887 }
10888
10889 final long identity = Binder.clearCallingIdentity();
10890 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010891 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010892 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010893 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10894 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010895 }
Hui Wang761a6682020-10-31 05:12:53 +000010896 } finally {
10897 Binder.restoreCallingIdentity(identity);
10898 }
10899 }
10900
10901 /**
10902 * Unregister RCS provisioning callback.
10903 */
10904 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010905 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010906 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010907 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010908 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010909 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10910 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010911
10912 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10913 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10914 }
10915 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010916 // operation failed silently
10917 Rlog.w(LOG_TAG, "IMS not available on device.");
10918 return;
Hui Wang761a6682020-10-31 05:12:53 +000010919 }
10920
10921 final long identity = Binder.clearCallingIdentity();
10922 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010923 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010924 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010925 } finally {
10926 Binder.restoreCallingIdentity(identity);
10927 }
10928 }
10929
10930 /**
10931 * trigger RCS reconfiguration.
10932 */
10933 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010934 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10935 "triggerRcsReconfiguration",
10936 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010937
10938 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10939 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10940 }
10941 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010942 // ProvisioningManager can not handle ServiceSpecificException.
10943 // Throw the IllegalStateException and annotate ProvisioningManager.
10944 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010945 }
10946
10947 final long identity = Binder.clearCallingIdentity();
10948 try {
10949 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10950 } finally {
10951 Binder.restoreCallingIdentity(identity);
10952 }
10953 }
10954
10955 /**
10956 * Provide the client configuration parameters of the RCS application.
10957 */
10958 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010959 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10960 "setRcsClientConfiguration",
10961 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010962
10963 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10964 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10965 }
10966 if (!isImsAvailableOnDevice()) {
10967 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10968 "IMS not available on device.");
10969 }
10970
10971 final long identity = Binder.clearCallingIdentity();
10972
10973 try {
10974 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10975 if (configBinder == null) {
10976 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010977 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10978 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010979 } else {
10980 configBinder.setRcsClientConfiguration(rcc);
10981 }
joonhunshin3e154242021-09-17 06:33:39 +000010982
10983 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10984 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010985 } catch (RemoteException e) {
10986 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010987 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10988 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010989 } finally {
10990 Binder.restoreCallingIdentity(identity);
10991 }
10992 }
10993
10994 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010995 * Enables or disables the test mode for RCS VoLTE single registration.
10996 */
10997 @Override
10998 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10999 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11000 "setRcsSingleRegistrationTestModeEnabled");
11001
11002 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11003 }
11004
11005 /**
11006 * Gets the test mode for RCS VoLTE single registration.
11007 */
11008 @Override
11009 public boolean getRcsSingleRegistrationTestModeEnabled() {
11010 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11011 "getRcsSingleRegistrationTestModeEnabled");
11012
11013 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11014 }
11015
11016 /**
Hui Wang761a6682020-10-31 05:12:53 +000011017 * Overrides the config of RCS VoLTE single registration enabled for the device.
11018 */
11019 @Override
11020 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11021 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11022 "setDeviceSingleRegistrationEnabledOverride");
11023 enforceModifyPermission();
11024
11025 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11026 : Boolean.parseBoolean(enabledStr);
11027 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011028 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011029 }
11030
11031 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011032 * Sends a device to device communication message. Only usable via shell.
11033 * @param message message to send.
11034 * @param value message value.
11035 */
11036 @Override
11037 public void sendDeviceToDeviceMessage(int message, int value) {
11038 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011039 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011040 enforceModifyPermission();
11041
11042 final long identity = Binder.clearCallingIdentity();
11043 try {
11044 TelephonyConnectionService service =
11045 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11046 if (service == null) {
11047 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11048 return;
11049 }
11050 service.sendTestDeviceToDeviceMessage(message, value);
11051 } finally {
11052 Binder.restoreCallingIdentity(identity);
11053 }
11054 }
11055
Tyler Gunnbabbda02021-02-10 11:05:02 -080011056 /**
11057 * Sets the specified device to device transport active.
11058 * @param transport The transport to set active.
11059 */
11060 @Override
11061 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11062 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11063 "setActiveDeviceToDeviceTransport");
11064 enforceModifyPermission();
11065
11066 final long identity = Binder.clearCallingIdentity();
11067 try {
11068 TelephonyConnectionService service =
11069 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11070 if (service == null) {
11071 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11072 return;
11073 }
11074 service.setActiveDeviceToDeviceTransport(transport);
11075 } finally {
11076 Binder.restoreCallingIdentity(identity);
11077 }
11078 }
Tyler Gunn92479152021-01-20 16:30:10 -080011079
Tyler Gunnd4339262021-05-03 14:46:49 -070011080 @Override
11081 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11082 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11083 "setDeviceToDeviceForceEnabled");
11084
11085 final long identity = Binder.clearCallingIdentity();
11086 try {
11087 Arrays.stream(PhoneFactory.getPhones()).forEach(
11088 p -> {
11089 Phone thePhone = p.getImsPhone();
11090 if (thePhone != null && thePhone instanceof ImsPhone) {
11091 ImsPhone imsPhone = (ImsPhone) thePhone;
11092 CallTracker tracker = imsPhone.getCallTracker();
11093 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11094 ImsPhoneCallTracker imsPhoneCallTracker =
11095 (ImsPhoneCallTracker) tracker;
11096 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11097 }
11098 }
11099 }
11100 );
11101 } finally {
11102 Binder.restoreCallingIdentity(identity);
11103 }
11104 }
11105
Tyler Gunn92479152021-01-20 16:30:10 -080011106 /**
Hui Wang761a6682020-10-31 05:12:53 +000011107 * Gets the config of RCS VoLTE single registration enabled for the device.
11108 */
11109 @Override
11110 public boolean getDeviceSingleRegistrationEnabled() {
11111 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11112 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11113 }
11114
11115 /**
11116 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11117 */
11118 @Override
11119 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11120 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11121 "setCarrierSingleRegistrationEnabledOverride");
11122 enforceModifyPermission();
11123
11124 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11125 : Boolean.parseBoolean(enabledStr);
11126 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11127 subId, enabled);
11128 }
11129
11130 /**
11131 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11132 */
11133 @Override
11134 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11135 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11136 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11137 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011138
11139 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011140 * Overrides the ims feature validation result
11141 */
11142 @Override
11143 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11144 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11145 "setImsFeatureValidationOverride");
11146
11147 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11148 : Boolean.parseBoolean(enabledStr);
11149 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11150 subId, enabled);
11151 }
11152
11153 /**
11154 * Gets the ims feature validation override value
11155 */
11156 @Override
11157 public boolean getImsFeatureValidationOverride(int subId) {
11158 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11159 "getImsFeatureValidationOverride");
11160 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11161 }
11162
11163 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011164 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11165 * their mobile plan.
11166 */
11167 @Override
11168 public String getMobileProvisioningUrl() {
11169 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11170 final long identity = Binder.clearCallingIdentity();
11171 try {
11172 return getDefaultPhone().getMobileProvisioningUrl();
11173 } finally {
11174 Binder.restoreCallingIdentity(identity);
11175 }
11176 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011177
James.cf Linbcdf8b32021-01-14 16:44:13 +080011178 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011179 * Get the EAB contact from the EAB database.
11180 */
11181 @Override
11182 public String getContactFromEab(String contact) {
11183 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11184 enforceModifyPermission();
11185 final long identity = Binder.clearCallingIdentity();
11186 try {
11187 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11188 } finally {
11189 Binder.restoreCallingIdentity(identity);
11190 }
11191 }
11192
11193 /**
Calvin Pana1434322021-07-01 19:27:01 +080011194 * Get the EAB capability from the EAB database.
11195 */
11196 @Override
11197 public String getCapabilityFromEab(String contact) {
11198 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11199 enforceModifyPermission();
11200 final long identity = Binder.clearCallingIdentity();
11201 try {
11202 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11203 } finally {
11204 Binder.restoreCallingIdentity(identity);
11205 }
11206 }
11207
11208 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011209 * Remove the EAB contacts from the EAB database.
11210 */
11211 @Override
11212 public int removeContactFromEab(int subId, String contacts) {
11213 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11214 enforceModifyPermission();
11215 final long identity = Binder.clearCallingIdentity();
11216 try {
11217 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11218 } finally {
11219 Binder.restoreCallingIdentity(identity);
11220 }
11221 }
11222
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011223 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011224 public boolean getDeviceUceEnabled() {
11225 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11226 final long identity = Binder.clearCallingIdentity();
11227 try {
11228 return mApp.getDeviceUceEnabled();
11229 } finally {
11230 Binder.restoreCallingIdentity(identity);
11231 }
11232 }
11233
11234 @Override
11235 public void setDeviceUceEnabled(boolean isEnabled) {
11236 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11237 final long identity = Binder.clearCallingIdentity();
11238 try {
11239 mApp.setDeviceUceEnabled(isEnabled);
11240 } finally {
11241 Binder.restoreCallingIdentity(identity);
11242 }
11243 }
11244
Brad Ebinger14d467f2021-02-12 06:18:28 +000011245 /**
11246 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11247 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11248 */
11249 // Used for SHELL command only right now.
11250 @Override
11251 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11252 List<String> featureTags) {
11253 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11254 "addUceRegistrationOverrideShell");
11255 final long identity = Binder.clearCallingIdentity();
11256 try {
11257 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11258 new ArraySet<>(featureTags));
11259 } catch (ImsException e) {
11260 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11261 } finally {
11262 Binder.restoreCallingIdentity(identity);
11263 }
11264 }
11265
11266 /**
11267 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11268 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11269 */
11270 // Used for SHELL command only right now.
11271 @Override
11272 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11273 List<String> featureTags) {
11274 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11275 "removeUceRegistrationOverrideShell");
11276 final long identity = Binder.clearCallingIdentity();
11277 try {
11278 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11279 new ArraySet<>(featureTags));
11280 } catch (ImsException e) {
11281 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11282 } finally {
11283 Binder.restoreCallingIdentity(identity);
11284 }
11285 }
11286
11287 /**
11288 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11289 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11290 */
11291 // Used for SHELL command only right now.
11292 @Override
11293 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11294 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11295 "clearUceRegistrationOverrideShell");
11296 final long identity = Binder.clearCallingIdentity();
11297 try {
11298 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11299 } catch (ImsException e) {
11300 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11301 } finally {
11302 Binder.restoreCallingIdentity(identity);
11303 }
11304 }
11305
11306 /**
11307 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11308 */
11309 // Used for SHELL command only right now.
11310 @Override
11311 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11312 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11313 "getLatestRcsContactUceCapabilityShell");
11314 final long identity = Binder.clearCallingIdentity();
11315 try {
11316 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11317 } catch (ImsException e) {
11318 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11319 } finally {
11320 Binder.restoreCallingIdentity(identity);
11321 }
11322 }
11323
11324 /**
11325 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11326 * device does not have an active PUBLISH.
11327 */
11328 // Used for SHELL command only right now.
11329 @Override
11330 public String getLastUcePidfXmlShell(int subId) {
11331 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11332 final long identity = Binder.clearCallingIdentity();
11333 try {
11334 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11335 } catch (ImsException e) {
11336 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11337 } finally {
11338 Binder.restoreCallingIdentity(identity);
11339 }
11340 }
11341
James.cf Line8713a42021-04-29 16:04:26 +080011342 /**
11343 * Remove UCE requests cannot be sent to the network status.
11344 */
11345 // Used for SHELL command only right now.
11346 @Override
11347 public boolean removeUceRequestDisallowedStatus(int subId) {
11348 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11349 final long identity = Binder.clearCallingIdentity();
11350 try {
11351 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11352 } catch (ImsException e) {
11353 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11354 } finally {
11355 Binder.restoreCallingIdentity(identity);
11356 }
11357 }
11358
James.cf Lin18bb9002021-05-25 01:37:38 +080011359 /**
11360 * Remove UCE requests cannot be sent to the network status.
11361 */
11362 // Used for SHELL command only.
11363 @Override
11364 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11365 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11366 final long identity = Binder.clearCallingIdentity();
11367 try {
11368 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11369 } catch (ImsException e) {
11370 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11371 } finally {
11372 Binder.restoreCallingIdentity(identity);
11373 }
11374 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011375
James.cf Lin4b784aa2021-01-31 03:25:15 +080011376 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011377 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11378 String callingPackage) {
11379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11380 mApp, subId, "setSignalStrengthUpdateRequest");
11381
11382 final int callingUid = Binder.getCallingUid();
11383 // Verify that tha callingPackage belongs to the calling UID
11384 mApp.getSystemService(AppOpsManager.class)
11385 .checkPackage(callingUid, callingPackage);
11386
Rambo Wang3607f502021-02-01 21:51:40 -080011387 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011388
11389 final long identity = Binder.clearCallingIdentity();
11390 try {
11391 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11392 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11393
11394 if (result instanceof IllegalStateException) {
11395 throw (IllegalStateException) result;
11396 }
11397 } finally {
11398 Binder.restoreCallingIdentity(identity);
11399 }
11400 }
11401
11402 @Override
11403 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11404 String callingPackage) {
11405 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11406 mApp, subId, "clearSignalStrengthUpdateRequest");
11407
11408 final int callingUid = Binder.getCallingUid();
11409 // Verify that tha callingPackage belongs to the calling UID
11410 mApp.getSystemService(AppOpsManager.class)
11411 .checkPackage(callingUid, callingPackage);
11412
11413 final long identity = Binder.clearCallingIdentity();
11414 try {
11415 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11416 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11417
11418 if (result instanceof IllegalStateException) {
11419 throw (IllegalStateException) result;
11420 }
11421 } finally {
11422 Binder.restoreCallingIdentity(identity);
11423 }
11424 }
11425
Rambo Wang3607f502021-02-01 21:51:40 -080011426 private static void validateSignalStrengthUpdateRequest(Context context,
11427 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011428 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11429 // phone/system process do not have further restriction on request
11430 return;
11431 }
11432
11433 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011434 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011435 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011436 context.enforceCallingOrSelfPermission(
11437 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11438 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011439 }
11440
11441 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011442 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011443 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011444 || info.isEnabled()) {
11445 throw new IllegalArgumentException(
11446 "Only system can set hide fields in SignalThresholdInfo");
11447 }
11448
11449 // Thresholds length for each RAN need in range. This has been validated in
11450 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11451 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11452 final int[] thresholds = info.getThresholds();
11453 Objects.requireNonNull(thresholds);
11454 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11455 || thresholds.length
11456 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11457 throw new IllegalArgumentException(
11458 "thresholds length is out of range: " + thresholds.length);
11459 }
11460 }
11461 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011462
11463 /**
11464 * Gets the current phone capability.
11465 *
11466 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11467 * @return the PhoneCapability which describes the data connection capability of modem.
11468 * It's used to evaluate possible phone config change, for example from single
11469 * SIM device to multi-SIM device.
11470 */
11471 @Override
11472 public PhoneCapability getPhoneCapability() {
11473 enforceReadPrivilegedPermission("getPhoneCapability");
11474 final long identity = Binder.clearCallingIdentity();
11475 try {
11476 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11477 } finally {
11478 Binder.restoreCallingIdentity(identity);
11479 }
11480 }
Michele Berionne5e411512020-11-13 02:36:59 +000011481
11482 /**
11483 * Prepare TelephonyManager for an unattended reboot. The reboot is
11484 * required to be done shortly after the API is invoked.
11485 */
11486 @Override
11487 @TelephonyManager.PrepareUnattendedRebootResult
11488 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011489 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011490 enforceRebootPermission();
11491
11492 final long identity = Binder.clearCallingIdentity();
11493 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011494 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011495 } finally {
11496 Binder.restoreCallingIdentity(identity);
11497 }
11498 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011499
11500 /**
11501 * Request to get the current slicing configuration including URSP rules and
11502 * NSSAIs (configured, allowed and rejected).
11503 *
11504 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11505 */
11506 @Override
11507 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011508 TelephonyPermissions
11509 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11510 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011511
11512 final long identity = Binder.clearCallingIdentity();
11513 try {
11514 Phone phone = getDefaultPhone();
11515 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11516 } finally {
11517 Binder.restoreCallingIdentity(identity);
11518 }
11519 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011520
11521 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011522 * Check whether the given premium capability is available for purchase from the carrier.
11523 *
11524 * @param capability The premium capability to check.
11525 * @param subId The subId to check the premium capability for.
11526 *
11527 * @return Whether the given premium capability is available to purchase.
11528 */
11529 @Override
11530 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11531 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11532 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11533 log("Premium capability "
11534 + TelephonyManager.convertPremiumCapabilityToString(capability)
11535 + " is not available for purchase due to missing permissions.");
11536 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11537 + "permission READ_BASIC_PHONE_STATE.");
11538 }
11539
11540 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011541 if (phone == null) {
11542 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11543 return false;
11544 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011545 final long identity = Binder.clearCallingIdentity();
11546 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011547 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011548 .isPremiumCapabilityAvailableForPurchase(capability);
11549 } finally {
11550 Binder.restoreCallingIdentity(identity);
11551 }
11552 }
11553
11554 /**
11555 * Purchase the given premium capability from the carrier.
11556 *
11557 * @param capability The premium capability to purchase.
11558 * @param callback The result of the purchase request.
11559 * @param subId The subId to purchase the premium capability for.
11560 */
11561 @Override
11562 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11563 log("purchasePremiumCapability: capability="
11564 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11565 + getCurrentPackageName());
11566
11567 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11568 mApp, "purchasePremiumCapability")) {
11569 log("purchasePremiumCapability "
11570 + TelephonyManager.convertPremiumCapabilityToString(capability)
11571 + " failed due to missing permissions.");
11572 throw new SecurityException("purchasePremiumCapability requires permission "
11573 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011574 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11575 mApp, "purchasePremiumCapability")) {
11576 log("purchasePremiumCapability "
11577 + TelephonyManager.convertPremiumCapabilityToString(capability)
11578 + " failed due to missing permissions.");
11579 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011580 }
11581
11582 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011583 if (phone == null) {
11584 try {
11585 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11586 callback.accept(result);
11587 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11588 } catch (RemoteException e) {
11589 String logStr = "Purchase premium capability "
11590 + TelephonyManager.convertPremiumCapabilityToString(capability)
11591 + " failed due to RemoteException handling null phone: " + e;
11592 if (DBG) log(logStr);
11593 AnomalyReporter.reportAnomaly(
11594 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11595 }
11596 return;
11597 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011598
11599 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011600 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011601 callingProcess = mApp.getPackageManager().getApplicationInfo(
11602 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011603 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011604 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011605 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011606
11607 boolean isVisible = false;
11608 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11609 if (am != null) {
11610 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11611 if (processes != null) {
11612 for (ActivityManager.RunningAppProcessInfo process : processes) {
11613 log("purchasePremiumCapability: process " + process.processName
11614 + "has importance " + process.importance);
11615 if (process.processName.equals(callingProcess) && process.importance
11616 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11617 isVisible = true;
11618 break;
11619 }
11620 }
11621 }
11622 }
11623
11624 if (!isVisible) {
11625 try {
11626 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11627 callback.accept(result);
11628 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11629 } catch (RemoteException e) {
11630 String logStr = "Purchase premium capability "
11631 + TelephonyManager.convertPremiumCapabilityToString(capability)
11632 + " failed due to RemoteException handling background application: " + e;
11633 if (DBG) log(logStr);
11634 AnomalyReporter.reportAnomaly(
11635 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11636 }
11637 return;
11638 }
11639
Sarah Chin71b3a852022-09-28 15:54:19 -070011640 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011641 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011642 }
11643
11644 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011645 * Register an IMS connection state callback
11646 */
11647 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011648 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11649 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011650 if (feature == ImsFeature.FEATURE_MMTEL) {
11651 // ImsMmTelManager
11652 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11653 TelephonyPermissions
11654 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11655 mApp, subId, "registerImsStateCallback");
11656 } else if (feature == ImsFeature.FEATURE_RCS) {
11657 // ImsRcsManager or SipDelegateManager
11658 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11659 Binder.getCallingUid(), "registerImsStateCallback",
11660 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11661 Manifest.permission.READ_PRECISE_PHONE_STATE,
11662 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11663 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11664 }
11665
11666 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11667 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11668 "IMS not available on device.");
11669 }
11670
11671 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11672 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11673 }
11674
11675 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11676 if (controller == null) {
11677 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11678 "IMS not available on device.");
11679 }
11680
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011681 if (callingPackage == null) {
11682 callingPackage = getCurrentPackageName();
11683 }
11684
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011685 final long token = Binder.clearCallingIdentity();
11686 try {
11687 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011688 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011689 } catch (ImsException e) {
11690 throw new ServiceSpecificException(e.getCode());
11691 } finally {
11692 Binder.restoreCallingIdentity(token);
11693 }
11694 }
11695
11696 /**
11697 * Unregister an IMS connection state callback
11698 */
11699 @Override
11700 public void unregisterImsStateCallback(IImsStateCallback cb) {
11701 final long token = Binder.clearCallingIdentity();
11702 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11703 if (controller == null) {
11704 return;
11705 }
11706 try {
11707 controller.unregisterImsStateCallback(cb);
11708 } finally {
11709 Binder.restoreCallingIdentity(token);
11710 }
11711 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011712
11713 /**
11714 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11715 *
11716 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11717 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11718 * SecurityException.
11719 * If there is current registered network this value will be same as the registered cell
11720 * identity. If the device goes out of service the previous cell identity is cached and
11721 * will be returned. If the cache age of the Cell identity is more than 24 hours
11722 * it will be cleared and null will be returned.
11723 *
11724 */
11725 @Override
11726 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11727 String callingFeatureId) {
11728 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11729 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11730 LocationAccessPolicy.checkLocationPermission(mApp,
11731 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11732 .setCallingPackage(callingPackage)
11733 .setCallingFeatureId(callingFeatureId)
11734 .setCallingPid(Binder.getCallingPid())
11735 .setCallingUid(Binder.getCallingUid())
11736 .setMethod("getLastKnownCellIdentity")
11737 .setLogAsInfo(true)
11738 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11739 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11740 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11741 .build());
11742
11743 boolean hasFinePermission =
11744 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11745 if (!hasFinePermission
11746 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11747 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011748 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011749 }
11750
11751 final long identity = Binder.clearCallingIdentity();
11752 try {
11753 Phone phone = getPhone(subId);
11754 if (phone == null) return null;
11755 ServiceStateTracker sst = phone.getServiceStateTracker();
11756 if (sst == null) return null;
11757 return sst.getLastKnownCellIdentity();
11758 } finally {
11759 Binder.restoreCallingIdentity(identity);
11760 }
11761 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011762
jimsun3b9ccac2021-10-26 15:01:23 +080011763 /**
11764 * Sets the modem service class Name that Telephony will bind to.
11765 *
11766 * @param serviceName The class name of the modem service.
11767 * @return true if the operation is succeed, otherwise false.
11768 */
11769 public boolean setModemService(String serviceName) {
11770 Log.d(LOG_TAG, "setModemService - " + serviceName);
11771 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11773 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11774 "setModemService");
11775 return mPhoneConfigurationManager.setModemService(serviceName);
11776 }
11777
11778 /**
11779 * Return the class name of the currently bounded modem service.
11780 *
11781 * @return the class name of the modem service.
11782 */
11783 public String getModemService() {
11784 String result;
11785 Log.d(LOG_TAG, "getModemService");
11786 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11787 TelephonyPermissions
11788 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11789 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11790 "getModemService");
11791 result = mPhoneConfigurationManager.getModemService();
11792 Log.d(LOG_TAG, "result = " + result);
11793 return result;
11794 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011795
11796 @Override
11797 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11798 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11799 mApp.enforceCallingOrSelfPermission(
11800 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11801 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11802
11803 final long identity = Binder.clearCallingIdentity();
11804 try {
11805 Phone phone = getPhone(subId);
11806 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080011807 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
11808 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011809 phone.setVoiceServiceStateOverride(hasService);
11810 } finally {
11811 Binder.restoreCallingIdentity(identity);
11812 }
11813 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011814
11815 /**
11816 * set removable eSIM as default eUICC.
11817 *
11818 * @hide
11819 */
11820 @Override
11821 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11822 enforceModifyPermission();
11823 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11824
11825 final long identity = Binder.clearCallingIdentity();
11826 try {
11827 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11828 } finally {
11829 Binder.restoreCallingIdentity(identity);
11830 }
11831 }
11832
11833 /**
11834 * Returns whether the removable eSIM is default eUICC or not.
11835 *
11836 * @hide
11837 */
11838 @Override
11839 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11840 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11841 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11842
11843 final long identity = Binder.clearCallingIdentity();
11844 try {
11845 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11846 } finally {
11847 Binder.restoreCallingIdentity(identity);
11848 }
11849 }
11850
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011851 /**
11852 * Get the component name of the default app to direct respond-via-message intent for the
11853 * user associated with this subscription, update the cache if there is no respond-via-message
11854 * application currently configured for this user.
11855 * @return component name of the app and class to direct Respond Via Message intent to, or
11856 * {@code null} if the functionality is not supported.
11857 * @hide
11858 */
11859 @Override
11860 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11861 boolean updateIfNeeded) {
11862 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011863
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000011864 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
11865
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011866 UserHandle userHandle = null;
11867 final long identity = Binder.clearCallingIdentity();
11868 try {
11869 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11870 } finally {
11871 Binder.restoreCallingIdentity(identity);
11872 }
11873 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11874 updateIfNeeded, userHandle);
11875 }
Jack Yuf5badd92022-12-08 00:50:53 -080011876
11877 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011878 * Set whether the device is able to connect with null ciphering or integrity
11879 * algorithms. This is a global setting and will apply to all active subscriptions
11880 * and all new subscriptions after this.
11881 *
11882 * @param enabled when true, null cipher and integrity algorithms are allowed.
11883 * @hide
11884 */
11885 @Override
11886 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11887 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11888 enforceModifyPermission();
11889 checkForNullCipherAndIntegritySupport();
11890
11891 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11892 // for listening to these preference changes and applying them immediately.
11893 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11894 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11895 editor.apply();
11896
11897 for (Phone phone: PhoneFactory.getPhones()) {
11898 phone.handleNullCipherEnabledChange();
11899 }
11900 }
11901
11902
11903 /**
11904 * Get whether the device is able to connect with null ciphering or integrity
11905 * algorithms. Note that this retrieves the phone-global preference and not
11906 * the state of the radio.
11907 *
11908 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11909 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11910 * version for this feature.
11911 * @hide
11912 */
11913 @Override
11914 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11915 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11916 enforceReadPermission();
11917 checkForNullCipherAndIntegritySupport();
11918 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11919 }
11920
11921 private void checkForNullCipherAndIntegritySupport() {
11922 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11923 throw new UnsupportedOperationException(
11924 "Null cipher and integrity operations require HAL 2.1 or above");
11925 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000011926 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
11927 throw new UnsupportedOperationException(
11928 "Null cipher and integrity operations unsupported by modem");
11929 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011930 }
11931
11932 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011933 * Get the SIM state for the slot index.
11934 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11935 *
11936 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11937 */
11938 @Override
11939 @SimState
11940 public int getSimStateForSlotIndex(int slotIndex) {
11941 IccCardConstants.State simState;
11942 if (slotIndex < 0) {
11943 simState = IccCardConstants.State.UNKNOWN;
11944 } else {
11945 Phone phone = null;
11946 try {
11947 phone = PhoneFactory.getPhone(slotIndex);
11948 } catch (IllegalStateException e) {
11949 // ignore
11950 }
11951 if (phone == null) {
11952 simState = IccCardConstants.State.UNKNOWN;
11953 } else {
11954 IccCard icc = phone.getIccCard();
11955 if (icc == null) {
11956 simState = IccCardConstants.State.UNKNOWN;
11957 } else {
11958 simState = icc.getState();
11959 }
11960 }
11961 }
11962 return simState.ordinal();
11963 }
Hui Wang9b5793a2022-12-05 14:38:06 -060011964
11965 /**
11966 * Get current cell broadcast ranges.
11967 */
11968 @Override
11969 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
11970 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
11971 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
11972 "getCellBroadcastIdRanges");
11973 final long identity = Binder.clearCallingIdentity();
11974 try {
11975 return getPhone(subId).getCellBroadcastIdRanges();
11976 } finally {
11977 Binder.restoreCallingIdentity(identity);
11978 }
11979 }
11980
11981 /**
11982 * Set reception of cell broadcast messages with the list of the given ranges
11983 *
11984 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
11985 */
11986 @Override
11987 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
11988 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
11989 @Nullable IIntegerConsumer callback) {
11990 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
11991 "setCellBroadcastIdRanges");
11992 final long identity = Binder.clearCallingIdentity();
11993 try {
11994 Phone phone = getPhoneFromSubId(subId);
11995 if (DBG) {
11996 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
11997 }
11998 phone.setCellBroadcastIdRanges(ranges, result -> {
11999 if (callback != null) {
12000 try {
12001 callback.accept(result);
12002 } catch (RemoteException e) {
12003 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12004 }
12005 }
12006 });
12007 } finally {
12008 Binder.restoreCallingIdentity(identity);
12009 }
12010 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012011
12012 /**
12013 * Returns whether the device supports the domain selection service.
12014 *
12015 * @return {@code true} if the device supports the domain selection service.
12016 */
12017 @Override
12018 public boolean isDomainSelectionSupported() {
12019 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12020 "isDomainSelectionSupported");
12021
12022 final long identity = Binder.clearCallingIdentity();
12023 try {
12024 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12025 } finally {
12026 Binder.restoreCallingIdentity(identity);
12027 }
12028 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012029
12030 /**
12031 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12032 *
12033 * <p>This method behaves in one of the following ways:
12034 * <ul>
12035 * <li>return true : if the calling package has the appop permission {@link
12036 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12037 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12038 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12039 * Owner device identifier access check, or the calling package has carrier privileges</>
12040 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12041 * </ul>
12042 */
12043 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12044 String callingPackage, @Nullable String callingFeatureId, String message) {
12045 for (Phone phone : PhoneFactory.getPhones()) {
12046 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12047 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12048 return true;
12049 }
12050 }
12051 return false;
12052 }
arunvoddud7401012022-12-15 16:08:12 +000012053
12054 /**
12055 * Class binds the consumer[callback] and carrierId.
12056 */
12057 private static class CallerCallbackInfo {
12058 private final Consumer<Integer> mConsumer;
12059 private final int mCarrierId;
12060
12061 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12062 mConsumer = consumer;
12063 mCarrierId = carrierId;
12064 }
12065
12066 public Consumer<Integer> getConsumer() {
12067 return mConsumer;
12068 }
12069
12070 public int getCarrierId() {
12071 return mCarrierId;
12072 }
12073 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012074}