blob: f82769a59a74d3475a4333a1bdff0c65a7aa44d3 [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
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006813 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006814 throw new SecurityException(
6815 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006816 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006817 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006818 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006819 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08006820 return false;
6821 }
6822 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6823 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006824 return false;
6825 }
6826
Jack Yu5b494332023-01-23 18:18:04 +00006827 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
6828 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006829
Jack Yue37dd262022-12-16 11:53:37 -08006830 Phone phone = getPhone(subId);
6831 if (phone == null) {
6832 return false;
6833 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006834
Jack Yue37dd262022-12-16 11:53:37 -08006835 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006836 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006837 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006838 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006839
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006840 final long identity = Binder.clearCallingIdentity();
6841 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006842 Boolean success = (Boolean) sendRequest(
6843 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6844 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6845
6846 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6847 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006848 } finally {
6849 Binder.restoreCallingIdentity(identity);
6850 }
6851 }
6852
6853 /**
Miaoa84611c2019-03-15 09:21:10 +08006854 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006855 *
Miaoa84611c2019-03-15 09:21:10 +08006856 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006857 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006858 * @hide
6859 */
6860 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006861 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006862 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006863 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006864 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006865 try {
Miaoa84611c2019-03-15 09:21:10 +08006866 if (phone != null) {
6867 return phone.hasMatchedTetherApnSetting();
6868 } else {
6869 return false;
6870 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006871 } finally {
6872 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006873 }
Junda Liu475951f2014-11-07 16:45:03 -08006874 }
6875
6876 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006877 * Get the user enabled state of Mobile Data.
6878 *
6879 * TODO: remove and use isUserDataEnabled.
6880 * This can't be removed now because some vendor codes
6881 * calls through ITelephony directly while they should
6882 * use TelephonyManager.
6883 *
6884 * @return true on enabled
6885 */
6886 @Override
6887 public boolean getDataEnabled(int subId) {
6888 return isUserDataEnabled(subId);
6889 }
6890
6891 /**
6892 * Get whether mobile data is enabled per user setting.
6893 *
6894 * There are other factors deciding whether mobile data is actually enabled, but they are
6895 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006896 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006897 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6898 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006899 *
6900 * @return {@code true} if data is enabled else {@code false}
6901 */
6902 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006903 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006904 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006905 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006906 try {
6907 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6908 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006909 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006910 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6911 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006912 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006914 mApp, subId, functionName);
6915
Robert Greenwalt646120a2014-05-23 11:54:03 -07006916 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006917
6918 final long identity = Binder.clearCallingIdentity();
6919 try {
Jack Yu285100e2022-12-02 22:48:35 -08006920 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006921 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6922 Phone phone = PhoneFactory.getPhone(phoneId);
6923 if (phone != null) {
6924 boolean retVal = phone.isUserDataEnabled();
6925 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6926 return retVal;
6927 } else {
6928 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6929 return false;
6930 }
6931 } finally {
6932 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006933 }
6934 }
6935
6936 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006937 * Checks if the device is capable of mobile data by considering whether whether the
6938 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6939 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006940 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006941 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006942 */
6943 @Override
6944 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006945 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006946 try {
6947 try {
6948 mApp.enforceCallingOrSelfPermission(
6949 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006950 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006951 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006952 try {
6953 mApp.enforceCallingOrSelfPermission(
6954 android.Manifest.permission.READ_PHONE_STATE,
6955 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006956 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006957 mApp.enforceCallingOrSelfPermission(
6958 permission.READ_BASIC_PHONE_STATE, functionName);
6959 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006960 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006961 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006962 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006963 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006964
6965 final long identity = Binder.clearCallingIdentity();
6966 try {
Jack Yu285100e2022-12-02 22:48:35 -08006967 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006968 Phone phone = PhoneFactory.getPhone(phoneId);
6969 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006970 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006971 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006972 return retVal;
6973 } else {
6974 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6975 return false;
6976 }
6977 } finally {
6978 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006979 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006980 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006981
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006982 /**
6983 * Check if data is enabled for a specific reason
6984 * @param subId Subscription index
6985 * @param reason the reason the data enable change is taking place
6986 * @return {@code true} if the overall data is enabled; {@code false} if not.
6987 */
6988 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006989 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006990 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006991 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006992 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006993 try {
6994 mApp.enforceCallingOrSelfPermission(
6995 android.Manifest.permission.ACCESS_NETWORK_STATE,
6996 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006997 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006998 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6999 functionName);
7000 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007001 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007002 try {
7003 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007004 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007005 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007007 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007008 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007009 }
7010
7011
7012 final long identity = Binder.clearCallingIdentity();
7013 try {
Jack Yu285100e2022-12-02 22:48:35 -08007014 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007015 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007016 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007017 + " reason=" + reason);
7018 }
7019 Phone phone = PhoneFactory.getPhone(phoneId);
7020 if (phone != null) {
7021 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007022 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007023 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007024 return retVal;
7025 } else {
7026 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007027 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007028 + subId + " retVal=false");
7029 }
7030 return false;
7031 }
7032 } finally {
7033 Binder.restoreCallingIdentity(identity);
7034 }
7035 }
7036
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007037 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007038 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007039 // No permission needed; this only lets the caller inspect their own status.
7040 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007041 }
Junda Liu29340342014-07-10 15:23:27 -07007042
7043 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007044 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007045 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007046 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7047 }
7048
7049 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7050 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007051 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007052 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007053 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7054 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007055 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7056 if (cpt == null) {
7057 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007058 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7059 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007060 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007061 }
7062
7063 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007064 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007065 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007066 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007067 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007068 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007069 Phone phone = getPhone(subId);
7070 if (phone == null) {
7071 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7072 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7073 }
7074 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7075 if (cpt == null) {
7076 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007077 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7078 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007079 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007080 }
7081
7082 @Override
7083 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007084 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007085 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7086 }
7087
7088 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007089 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007090 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007091 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007092 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007093 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7094 Phone phone = PhoneFactory.getPhone(phoneId);
7095 if (phone == null) {
7096 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007097 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007098 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7099 if (cpt == null) {
7100 continue;
7101 }
7102 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007103 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7104 break;
7105 }
7106 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007107 return result;
Junda Liu29340342014-07-10 15:23:27 -07007108 }
Derek Tan89e89d42014-07-08 17:00:10 -07007109
7110 @Override
Junda Liue64de782015-04-16 17:19:16 -07007111 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007112 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007113 Phone phone = PhoneFactory.getPhone(phoneId);
7114 if (phone == null) {
7115 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007116 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007117 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7118 if (cpt == null) {
7119 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007120 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007121 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007122 }
7123
Amith Yamasani6e118872016-02-19 12:53:51 -08007124 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007125 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007126 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007127 Phone phone = PhoneFactory.getPhone(phoneId);
7128 if (phone == null) {
7129 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007130 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007131 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7132 if (cpt == null) {
7133 return Collections.emptyList();
7134 }
7135 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007136 }
7137
chen xuf7e9fe82019-05-09 19:31:02 -07007138 @Override
7139 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007140 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007141 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007142 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007143 try {
7144 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7145 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7146 }
7147 } finally {
7148 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007149 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007150 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007151 }
7152
Rambo Wang6812ffb2022-03-15 16:54:17 -07007153 @Override
7154 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7155 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7156
7157 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7158 if (phone == null) {
7159 return null;
7160 }
7161 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7162 if (cpt == null) {
7163 return null;
7164 }
7165 return cpt.getCarrierServicePackageName();
7166 }
7167
Wink Savilleb564aae2014-10-23 10:18:09 -07007168 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007169 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007170 UiccPort port = phone == null ? null : phone.getUiccPort();
7171 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007172 return null;
7173 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007174 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007175 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007176 return null;
7177 }
7178 return iccId;
7179 }
7180
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007181 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007182 public void setCallComposerStatus(int subId, int status) {
7183 enforceModifyPermission();
7184
7185 final long identity = Binder.clearCallingIdentity();
7186 try {
7187 Phone phone = getPhone(subId);
7188 if (phone != null) {
7189 Phone defaultPhone = phone.getImsPhone();
7190 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7191 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7192 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007193 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7194 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007195 }
7196 }
Shuo Qian284ae752020-12-22 19:10:14 -08007197 } catch (ImsException e) {
7198 throw new ServiceSpecificException(e.getCode());
7199 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007200 Binder.restoreCallingIdentity(identity);
7201 }
7202 }
7203
7204 @Override
7205 public int getCallComposerStatus(int subId) {
7206 enforceReadPrivilegedPermission("getCallComposerStatus");
7207
7208 final long identity = Binder.clearCallingIdentity();
7209 try {
7210 Phone phone = getPhone(subId);
7211 if (phone != null) {
7212 Phone defaultPhone = phone.getImsPhone();
7213 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7214 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7215 return imsPhone.getCallComposerStatus();
7216 }
7217 }
7218 } finally {
7219 Binder.restoreCallingIdentity(identity);
7220 }
7221 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7222 }
7223
7224 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007225 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7226 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007227 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007228 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007230 final long identity = Binder.clearCallingIdentity();
7231 try {
7232 final String iccId = getIccId(subId);
7233 final Phone phone = getPhone(subId);
7234 if (phone == null) {
7235 return false;
7236 }
7237 final String subscriberId = phone.getSubscriberId();
7238
7239 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007240 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007241 + subscriberId + " to " + number);
7242 }
7243
7244 if (TextUtils.isEmpty(iccId)) {
7245 return false;
7246 }
7247
7248 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7249
7250 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7251 if (alphaTag == null) {
7252 editor.remove(alphaTagPrefKey);
7253 } else {
7254 editor.putString(alphaTagPrefKey, alphaTag);
7255 }
7256
7257 // Record both the line number and IMSI for this ICCID, since we need to
7258 // track all merged IMSIs based on line number
7259 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7260 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7261 if (number == null) {
7262 editor.remove(numberPrefKey);
7263 editor.remove(subscriberPrefKey);
7264 } else {
7265 editor.putString(numberPrefKey, number);
7266 editor.putString(subscriberPrefKey, subscriberId);
7267 }
7268
7269 editor.commit();
7270 return true;
7271 } finally {
7272 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007273 }
Derek Tan7226c842014-07-02 17:42:23 -07007274 }
7275
7276 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007277 public String getLine1NumberForDisplay(int subId, String callingPackage,
7278 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007279 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007280 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007281 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007282 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007283 return null;
7284 }
Derek Tan97ebb422014-09-05 16:55:38 -07007285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007286 final long identity = Binder.clearCallingIdentity();
7287 try {
7288 String iccId = getIccId(subId);
7289 if (iccId != null) {
7290 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7291 if (DBG_MERGE) {
7292 log("getLine1NumberForDisplay returning "
7293 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7294 }
7295 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007296 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007297 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7298 return null;
7299 } finally {
7300 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007301 }
Derek Tan7226c842014-07-02 17:42:23 -07007302 }
7303
7304 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007305 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7306 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007307 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007308 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007309 return null;
7310 }
Derek Tan97ebb422014-09-05 16:55:38 -07007311
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007312 final long identity = Binder.clearCallingIdentity();
7313 try {
7314 String iccId = getIccId(subId);
7315 if (iccId != null) {
7316 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7317 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7318 }
7319 return null;
7320 } finally {
7321 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007322 }
Derek Tan7226c842014-07-02 17:42:23 -07007323 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007324
7325 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007326 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7327 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007328 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7329 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007330 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007331 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007332 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007333 return null;
7334 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007335
Jordan Liub49b04b2019-05-06 14:45:15 -07007336 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7337 // the process, where TelephonyManager was instantiated.
7338 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007339 final long identity = Binder.clearCallingIdentity();
7340 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007341 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007342 final TelephonyManager tele = TelephonyManager.from(context);
7343 final SubscriptionManager sub = SubscriptionManager.from(context);
7344
7345 // Figure out what subscribers are currently active
7346 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007347
Jordan Liub49b04b2019-05-06 14:45:15 -07007348 // Only consider subs which match the current subId
7349 // This logic can be simplified. See b/131189269 for progress.
7350 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007351 activeSubscriberIds.add(tele.getSubscriberId(subId));
7352 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007353
7354 // First pass, find a number override for an active subscriber
7355 String mergeNumber = null;
7356 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7357 for (String key : prefs.keySet()) {
7358 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7359 final String subscriberId = (String) prefs.get(key);
7360 if (activeSubscriberIds.contains(subscriberId)) {
7361 final String iccId = key.substring(
7362 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7363 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7364 mergeNumber = (String) prefs.get(numberKey);
7365 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007366 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007367 + " for active subscriber " + subscriberId);
7368 }
7369 if (!TextUtils.isEmpty(mergeNumber)) {
7370 break;
7371 }
7372 }
7373 }
7374 }
7375
7376 // Shortcut when no active merged subscribers
7377 if (TextUtils.isEmpty(mergeNumber)) {
7378 return null;
7379 }
7380
7381 // Second pass, find all subscribers under that line override
7382 final ArraySet<String> result = new ArraySet<>();
7383 for (String key : prefs.keySet()) {
7384 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7385 final String number = (String) prefs.get(key);
7386 if (mergeNumber.equals(number)) {
7387 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7388 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7389 final String subscriberId = (String) prefs.get(subscriberKey);
7390 if (!TextUtils.isEmpty(subscriberId)) {
7391 result.add(subscriberId);
7392 }
7393 }
7394 }
7395 }
7396
7397 final String[] resultArray = result.toArray(new String[result.size()]);
7398 Arrays.sort(resultArray);
7399 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007400 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007401 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7402 }
7403 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007404 } finally {
7405 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007406 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007407 }
7408
7409 @Override
zoey chen38003472019-12-13 17:16:31 +08007410 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7411 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007412
7413 final long identity = Binder.clearCallingIdentity();
7414 try {
7415 final TelephonyManager telephonyManager = mApp.getSystemService(
7416 TelephonyManager.class);
7417 String subscriberId = telephonyManager.getSubscriberId(subId);
7418 if (subscriberId == null) {
7419 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007420 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007421 + subId);
7422 }
7423 return null;
7424 }
7425
Jack Yu285100e2022-12-02 22:48:35 -08007426 ParcelUuid groupUuid;
7427 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7428 final SubscriptionInfo info = SubscriptionManagerService.getInstance()
7429 .getSubscriptionInfo(subId);
7430 groupUuid = info.getGroupUuid();
7431 } else {
7432 final SubscriptionInfo info = mSubscriptionController
7433 .getSubscriptionInfo(subId);
7434 groupUuid = info.getGroupUuid();
7435 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007436 // If it doesn't belong to any group, return just subscriberId of itself.
7437 if (groupUuid == null) {
7438 return new String[]{subscriberId};
7439 }
7440
7441 // Get all subscriberIds from the group.
7442 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007443 List<SubscriptionInfo> groupInfos;
7444 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7445 groupInfos = SubscriptionManagerService.getInstance()
7446 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7447 mApp.getAttributionTag());
7448 } else {
7449 groupInfos = mSubscriptionController
7450 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7451 mApp.getAttributionTag());
7452 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007453 for (SubscriptionInfo subInfo : groupInfos) {
7454 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7455 if (subscriberId != null) {
7456 mergedSubscriberIds.add(subscriberId);
7457 }
7458 }
7459
7460 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7461 } finally {
7462 Binder.restoreCallingIdentity(identity);
7463
7464 }
7465 }
7466
7467 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007468 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007469 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007470 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007471
7472 final long identity = Binder.clearCallingIdentity();
7473 try {
7474 final Phone phone = getPhone(subId);
7475 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7476 } finally {
7477 Binder.restoreCallingIdentity(identity);
7478 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007479 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007480
7481 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007482 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007483 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7484 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007485 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7486 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487
7488 final long identity = Binder.clearCallingIdentity();
7489 try {
7490 final Phone phone = getPhone(subId);
7491 if (phone == null) {
7492 return false;
7493 }
7494 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7495 cdmaNonRoamingList);
7496 } finally {
7497 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007498 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007499 }
7500
7501 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007502 @Deprecated
7503 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7504 enforceModifyPermission();
7505
7506 int returnValue = 0;
7507 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007508 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007509 if(result.exception == null) {
7510 if (result.result != null) {
7511 byte[] responseData = (byte[])(result.result);
7512 if(responseData.length > oemResp.length) {
7513 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7514 responseData.length + "bytes. Buffer Size is " +
7515 oemResp.length + "bytes.");
7516 }
7517 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7518 returnValue = responseData.length;
7519 }
7520 } else {
7521 CommandException ex = (CommandException) result.exception;
7522 returnValue = ex.getCommandError().ordinal();
7523 if(returnValue > 0) returnValue *= -1;
7524 }
7525 } catch (RuntimeException e) {
7526 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7527 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7528 if(returnValue > 0) returnValue *= -1;
7529 }
7530
7531 return returnValue;
7532 }
7533
7534 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007535 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007536 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007537 try {
7538 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007539 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007540 mApp, phone.getSubId(), "getRadioAccessFamily");
7541 } catch (SecurityException e) {
7542 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7543 throw e;
7544 }
chen xub97461a2018-10-26 14:17:57 -07007545 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007546 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007547 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007548 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007549 final long identity = Binder.clearCallingIdentity();
7550 try {
chen xub97461a2018-10-26 14:17:57 -07007551 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007552 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007553 mApp, phone.getSubId(), "getRadioAccessFamily");
7554 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007555 } finally {
7556 Binder.restoreCallingIdentity(identity);
7557 }
chen xub97461a2018-10-26 14:17:57 -07007558 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007559 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007560
7561 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007562 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007563 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007564 try {
7565 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7566 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007567 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007568 }
7569 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007570 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007571 }
7572 RoleManager rm = mApp.getSystemService(RoleManager.class);
7573 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7574 if (!dialerRoleHolders.contains(callingPackage)) {
7575 throw new SecurityException("App must be the dialer role holder to"
7576 + " upload a call composer pic");
7577 }
7578
7579 Executors.newSingleThreadExecutor().execute(() -> {
7580 ByteArrayOutputStream output = new ByteArrayOutputStream(
7581 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7582 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7583 boolean readUntilEnd = false;
7584 int totalBytesRead = 0;
7585 byte[] buffer = new byte[16 * 1024];
7586 while (true) {
7587 int numRead;
7588 try {
7589 numRead = input.read(buffer);
7590 } catch (IOException e) {
7591 try {
7592 fd.checkError();
7593 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7594 null);
7595 } catch (IOException e1) {
7596 // This means that the other side closed explicitly with an error. If this
7597 // happens, log and ignore.
7598 loge("Remote end of call composer picture pipe closed: " + e1);
7599 }
7600 break;
7601 }
7602 if (numRead == -1) {
7603 readUntilEnd = true;
7604 break;
7605 }
7606 totalBytesRead += numRead;
7607 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7608 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7609 try {
7610 input.close();
7611 } catch (IOException e) {
7612 // ignore
7613 }
7614 break;
7615 }
7616 output.write(buffer, 0, numRead);
7617 }
7618 // Generally, the remote end will close the file descriptors. The only case where we
7619 // close is above, where the picture size is too big.
7620
7621 try {
7622 fd.checkError();
7623 } catch (IOException e) {
7624 loge("Remote end for call composer closed with an error: " + e);
7625 return;
7626 }
7627
Hall Liuaa4211e2021-01-20 15:43:39 -08007628 if (!readUntilEnd) {
7629 loge("Did not finish reading entire image; aborting");
7630 return;
7631 }
Hall Liu82694d52020-12-11 18:22:04 -08007632
Hall Liuaa4211e2021-01-20 15:43:39 -08007633 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7634 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7635 new CallComposerPictureTransfer.Factory() {},
7636 imageData,
7637 (result) -> {
7638 if (result.first != null) {
7639 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7640 Bundle outputResult = new Bundle();
7641 outputResult.putParcelable(
7642 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7643 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7644 outputResult);
7645 } else {
7646 callback.send(result.second, null);
7647 }
7648 }
7649 );
Hall Liu82694d52020-12-11 18:22:04 -08007650 });
7651 }
7652
7653 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007654 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007655 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007656 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007657
7658 final long identity = Binder.clearCallingIdentity();
7659 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007660 ImsManager.getInstance(defaultPhone.getContext(),
7661 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007662 } finally {
7663 Binder.restoreCallingIdentity(identity);
7664 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007665 }
7666
7667 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007668 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007669 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007670 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7671 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007672 return false;
7673 }
Svet Ganovb320e182015-04-16 12:30:10 -07007674
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007675 final long identity = Binder.clearCallingIdentity();
7676 try {
7677 // Check the user preference and the system-level IMS setting. Even if the user has
7678 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7679 // In the long run, we may instead need to check if there exists a connection service
7680 // which can support video calling.
7681 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007682 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007683 return imsManager.isVtEnabledByPlatform()
7684 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7685 && imsManager.isVtEnabledByUser();
7686 } finally {
7687 Binder.restoreCallingIdentity(identity);
7688 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007689 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007690
Andrew Leea1239f22015-03-02 17:44:07 -08007691 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007692 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7693 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007694 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007695 mApp, subId, callingPackage, callingFeatureId,
7696 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007697 return false;
7698 }
7699
7700 final long identity = Binder.clearCallingIdentity();
7701 try {
7702 CarrierConfigManager configManager =
7703 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007704 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007705 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7706 } finally {
7707 Binder.restoreCallingIdentity(identity);
7708 }
Andrew Leea1239f22015-03-02 17:44:07 -08007709 }
7710
7711 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007712 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007713 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007714 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007715 return false;
7716 }
7717
7718 final long identity = Binder.clearCallingIdentity();
7719 try {
7720 CarrierConfigManager configManager =
7721 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007722 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007723 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7724 } finally {
7725 Binder.restoreCallingIdentity(identity);
7726 }
Andrew Leea1239f22015-03-02 17:44:07 -08007727 }
7728
Andrew Lee9431b832015-03-09 18:46:45 -07007729 @Override
7730 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007731 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007732 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007733 }
7734
7735 @Override
7736 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007737 final long identity = Binder.clearCallingIdentity();
7738 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007739 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007740 } finally {
7741 Binder.restoreCallingIdentity(identity);
7742 }
Andrew Lee9431b832015-03-09 18:46:45 -07007743 }
7744
Hall Liuf6668912018-10-31 17:05:23 -07007745 /**
7746 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7747 * support for the feature and device firmware support.
7748 *
7749 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7750 */
7751 @Override
7752 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007753 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007754 final Phone phone = getPhone(subscriptionId);
7755 if (phone == null) {
7756 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7757 return false;
7758 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007759 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007760 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007761 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7762 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007763 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007764 return isCarrierSupported && isDeviceSupported;
7765 } finally {
7766 Binder.restoreCallingIdentity(identity);
7767 }
Hall Liu98187582018-01-22 19:15:32 -08007768 }
7769
Hall Liuf6668912018-10-31 17:05:23 -07007770 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007771 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7772 * RTT setting, will return true if the device and carrier both support RTT.
7773 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007774 */
7775 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007776 final long identity = Binder.clearCallingIdentity();
7777 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007778 boolean isRttSupported = isRttSupported(subscriptionId);
7779 boolean isUserRttSettingOn = Settings.Secure.getInt(
7780 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7781 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7782 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7783 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007784 } finally {
7785 Binder.restoreCallingIdentity(identity);
7786 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007787 }
7788
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007789 @Deprecated
7790 @Override
7791 public String getDeviceId(String callingPackage) {
7792 return getDeviceIdWithFeature(callingPackage, null);
7793 }
7794
Sanket Padawe7310cc72015-01-14 09:53:20 -08007795 /**
7796 * Returns the unique device ID of phone, for example, the IMEI for
7797 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7798 *
7799 * <p>Requires Permission:
7800 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7801 */
7802 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007803 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007804 try {
7805 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7806 } catch (SecurityException se) {
7807 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7808 throw new SecurityException("Package " + callingPackage + " does not belong to "
7809 + Binder.getCallingUid());
7810 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007811 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007812 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007813 return null;
7814 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007815 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007816 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007817 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007818 return null;
7819 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007820
7821 final long identity = Binder.clearCallingIdentity();
7822 try {
7823 return phone.getDeviceId();
7824 } finally {
7825 Binder.restoreCallingIdentity(identity);
7826 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007827 }
7828
Ping Sunc67b7c22016-03-02 19:16:45 +08007829 /**
7830 * {@hide}
7831 * Returns the IMS Registration Status on a particular subid
7832 *
7833 * @param subId
7834 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007835 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007836 Phone phone = getPhone(subId);
7837 if (phone != null) {
7838 return phone.isImsRegistered();
7839 } else {
7840 return false;
7841 }
7842 }
7843
Santos Cordon7a1885b2015-02-03 11:15:19 -08007844 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007845 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007846 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007847 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007848 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007849 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7850 }
7851 final long identity = Binder.clearCallingIdentity();
7852 try {
7853 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7854 } finally {
7855 Binder.restoreCallingIdentity(identity);
7856 }
7857 }
7858
7859 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007860 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007861 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007862 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007863 mApp,
7864 subscriptionId,
7865 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007866 final long identity = Binder.clearCallingIdentity();
7867 try {
7868 Phone phone = getPhone(subscriptionId);
7869 if (phone == null) {
7870 return null;
7871 }
7872 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7873 } finally {
7874 Binder.restoreCallingIdentity(identity);
7875 }
7876 }
7877
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007878 /**
7879 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007880 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007881 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007882 final long identity = Binder.clearCallingIdentity();
7883 try {
7884 Phone phone = getPhone(subId);
7885 if (phone != null) {
7886 return phone.isWifiCallingEnabled();
7887 } else {
7888 return false;
7889 }
7890 } finally {
7891 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007892 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007893 }
7894
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007895 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007896 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007897 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007898 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007899 final long identity = Binder.clearCallingIdentity();
7900 try {
7901 Phone phone = getPhone(subId);
7902 if (phone != null) {
7903 return phone.isVideoEnabled();
7904 } else {
7905 return false;
7906 }
7907 } finally {
7908 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007909 }
7910 }
7911
7912 /**
7913 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7914 * defined in {@link ImsRegistrationImplBase}.
7915 */
7916 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007917 final long identity = Binder.clearCallingIdentity();
7918 try {
7919 Phone phone = getPhone(subId);
7920 if (phone != null) {
7921 return phone.getImsRegistrationTech();
7922 } else {
7923 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7924 }
7925 } finally {
7926 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007927 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007928 }
7929
Stuart Scott8eef64f2015-04-08 15:13:54 -07007930 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007931 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007932 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007933 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7934 return;
7935 }
Kai Shif70f46f2021-03-03 13:59:46 -08007936 Phone defaultPhone = getDefaultPhone();
7937 if (defaultPhone != null) {
7938 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7939 mApp, getDefaultPhone().getSubId(), "factoryReset");
7940 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007941 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007942
Svet Ganovcc087f82015-05-12 20:35:54 -07007943 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007944 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7945 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007946 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007947 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007948 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007949 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007950 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007951 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007952 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007953 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007954 // There has been issues when Sms raw table somehow stores orphan
7955 // fragments. They lead to garbled message when new fragments come
7956 // in and combined with those stale ones. In case this happens again,
7957 // user can reset all network settings which will clean up this table.
7958 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007959 // Clean up IMS settings as well here.
7960 int slotId = getSlotIndex(subId);
7961 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7962 ImsManager.getInstance(mApp, slotId).factoryReset();
7963 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007964
Kai Shif70f46f2021-03-03 13:59:46 -08007965 if (defaultPhone == null) {
7966 return;
7967 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007968 // Erase modem config if erase modem on network setting is enabled.
7969 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7970 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7971 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007972 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007973 }
Kai Shif70f46f2021-03-03 13:59:46 -08007974
7975 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007976 } finally {
7977 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007978 }
7979 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007980
SongFerngWangfd89b102021-05-27 22:44:54 +08007981 @VisibleForTesting
7982 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7983 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7984 return;
7985 }
7986 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7987 RILConstants.PREFERRED_NETWORK_MODE);
7988 SubscriptionManager.setSubscriptionProperty(subId,
7989 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7990 "user=" + defaultNetworkType);
7991 phone.loadAllowedNetworksFromSubscriptionDatabase();
7992 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7993 defaultNetworkType, null);
7994 }
7995
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007996 private void cleanUpSmsRawTable(Context context) {
7997 ContentResolver resolver = context.getContentResolver();
7998 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7999 resolver.delete(uri, null, null);
8000 }
8001
Narayan Kamath1c496c22015-04-16 14:40:19 +01008002 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008003 public String getSimLocaleForSubscriber(int subId) {
8004 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8005 final Phone phone = getPhone(subId);
8006 if (phone == null) {
8007 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008008 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008009 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008010 final long identity = Binder.clearCallingIdentity();
8011 try {
Jack Yu285100e2022-12-02 22:48:35 -08008012 SubscriptionInfo info;
8013 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8014 info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId,
8015 phone.getContext().getOpPackageName(),
8016 phone.getContext().getAttributionTag());
8017 if (info == null) {
8018 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8019 return null;
8020 }
8021 } else {
8022 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
8023 phone.getContext().getOpPackageName(),
8024 phone.getContext().getAttributionTag());
8025 if (info == null) {
8026 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8027 return null;
8028 }
chen xu6291c472019-02-04 12:55:53 -08008029 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008030 // Try and fetch the locale from the carrier properties or from the SIM language
8031 // preferences (EF-PL and EF-LI)...
8032 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008033 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008034 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8035 if (localeFromDefaultSim != null) {
8036 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8037 if (DBG) log("Using locale from subId: " + subId + " locale: "
8038 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008039 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008040 } else {
8041 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008042 }
8043 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008044
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008045 // The SIM language preferences only store a language (e.g. fr = French), not an
8046 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8047 // the SIM and carrier preferences does not include a country we add the country
8048 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008049 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008050 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008051 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008052 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008053 }
8054
8055 if (DBG) log("No locale found - returning null");
8056 return null;
8057 } finally {
8058 Binder.restoreCallingIdentity(identity);
8059 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008060 }
8061
tom hsu0b59d292022-09-29 23:49:21 +08008062 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008063 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008064 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008065 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008066 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008067 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8068 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008069 Locale.forLanguageTag(localeTag).getCountry())) {
8070 return localeTag;
8071 }
8072 }
8073 return inputLocale.toLanguageTag();
8074 }
8075
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008076 /**
8077 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8078 */
8079 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08008080 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8081 return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList(
8082 mApp.getOpPackageName(), mApp.getAttributionTag());
8083 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008084 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08008085 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008086 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008087
Gary Jian3aa9a762022-01-24 16:41:19 +08008088 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8089 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008090
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008091 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008092 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8093 * representing the state of the modem.
8094 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008095 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8096 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008097 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008098 */
8099 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008100 public void requestModemActivityInfo(ResultReceiver result) {
8101 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008102 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008103
8104 final long identity = Binder.clearCallingIdentity();
8105 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008106 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008107 } finally {
8108 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008109 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008110 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008111
Gary Jian76280a42022-12-07 16:18:33 +08008112 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008113 // less than total activity duration.
8114 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8115 if (info == null) {
8116 return false;
8117 }
8118 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008119 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008120 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8121
Hall Liu49656c02020-10-09 19:00:11 -07008122 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8123
Siddharth Rayb8114062018-06-17 15:02:38 -07008124 return (info.isValid()
8125 && (info.getSleepTimeMillis() <= activityDurationMs)
Gary Jian76280a42022-12-07 16:18:33 +08008126 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008127 }
8128
Gary Jian3aa9a762022-01-24 16:41:19 +08008129 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8130 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8131 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8132 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8133
8134 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8135 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8136 }
8137
8138 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8139 mLastModemActivityInfo.setReceiveTimeMillis(
8140 rat,
8141 freq,
8142 info.getReceiveTimeMillis(rat, freq)
8143 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8144 }
8145
8146 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8147 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8148 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8149 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8150
8151 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8152 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8153 }
8154 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8155 mLastModemActivityInfo.setReceiveTimeMillis(
8156 rat,
8157 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8158 }
8159
8160 /**
8161 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8162 * @param info recent ModemActivityInfo
8163 */
8164 private void mergeModemActivityInfo(ModemActivityInfo info) {
8165 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008166 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008167 boolean matched;
8168 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8169 matched = false;
8170 int rat = info.getSpecificInfoRat(i);
8171 int freq = info.getSpecificInfoFrequencyRange(i);
8172 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8173 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8174 //if it already exists
8175 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8176 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8177 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8178 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8179 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8180 updateLastModemActivityInfo(info, rat, freq);
8181 matched = true;
8182 }
8183 } else {
8184 updateLastModemActivityInfo(info, rat);
8185 matched = true;
8186 }
8187 }
8188 }
8189
8190 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008191 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008192 new ActivityStatsTechSpecificInfo(
8193 rat,
8194 freq,
8195 info.getTransmitTimeMillis(rat, freq),
8196 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008197 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008198 }
8199 }
8200 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8201 mLastModemActivitySpecificInfo =
8202 new ActivityStatsTechSpecificInfo[merged.size()];
8203 merged.toArray(mLastModemActivitySpecificInfo);
8204
8205 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8206 mLastModemActivityInfo.setSleepTimeMillis(
8207 info.getSleepTimeMillis()
8208 + mLastModemActivityInfo.getSleepTimeMillis());
8209 mLastModemActivityInfo.setIdleTimeMillis(
8210 info.getIdleTimeMillis()
8211 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008212
8213 mLastModemActivityInfo =
8214 new ModemActivityInfo(
8215 mLastModemActivityInfo.getTimestampMillis(),
8216 mLastModemActivityInfo.getSleepTimeMillis(),
8217 mLastModemActivityInfo.getIdleTimeMillis(),
8218 mLastModemActivitySpecificInfo);
8219 }
8220
8221 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8222 ActivityStatsTechSpecificInfo[] info) {
8223 int infoSize = info.length;
8224 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8225 for (int i = 0; i < infoSize; i++) {
8226 ret[i] = new ActivityStatsTechSpecificInfo(
8227 info[i].getRat(), info[i].getFrequencyRange(),
8228 info[i].getTransmitTimeMillis(),
8229 (int) info[i].getReceiveTimeMillis());
8230 }
8231 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008232 }
8233
Jack Yu85bd38a2015-11-09 11:34:32 -08008234 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008235 * Returns the service state information on specified subscription.
8236 */
8237 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008238 public ServiceState getServiceStateForSubscriber(int subId,
8239 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8240 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008241 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008242 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008243 return null;
8244 }
8245
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008246 boolean hasFinePermission = false;
8247 boolean hasCoarsePermission = false;
8248 if (!renounceFineLocationAccess) {
8249 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8250 LocationAccessPolicy.checkLocationPermission(mApp,
8251 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8252 .setCallingPackage(callingPackage)
8253 .setCallingFeatureId(callingFeatureId)
8254 .setCallingPid(Binder.getCallingPid())
8255 .setCallingUid(Binder.getCallingUid())
8256 .setMethod("getServiceStateForSubscriber")
8257 .setLogAsInfo(true)
8258 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8259 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8260 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8261 .build());
8262 hasFinePermission =
8263 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8264 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008265
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008266 if (!renounceCoarseLocationAccess) {
8267 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8268 LocationAccessPolicy.checkLocationPermission(mApp,
8269 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8270 .setCallingPackage(callingPackage)
8271 .setCallingFeatureId(callingFeatureId)
8272 .setCallingPid(Binder.getCallingPid())
8273 .setCallingUid(Binder.getCallingUid())
8274 .setMethod("getServiceStateForSubscriber")
8275 .setLogAsInfo(true)
8276 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8277 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8278 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8279 .build());
8280 hasCoarsePermission =
8281 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8282 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008283
Jack Yu479f40e2020-10-27 21:29:25 -07008284 final Phone phone = getPhone(subId);
8285 if (phone == null) {
8286 return null;
8287 }
8288
Jordan Liu0f2bc442020-11-18 16:47:37 -08008289 final long identity = Binder.clearCallingIdentity();
8290
Jack Yu479f40e2020-10-27 21:29:25 -07008291 boolean isCallingPackageDataService = phone.getDataServicePackages()
8292 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008294 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008295 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8296 SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance()
8297 .getSubscriptionInfoInternal(subId);
8298 if (subInfo == null || !subInfo.isActive()) {
8299 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8300 + "subId=" + subId);
8301 return null;
8302 }
8303 } else {
8304 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8305 callingFeatureId)) {
8306 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8307 + "subId=" + subId);
8308 return null;
8309 }
Jordan Liuc437b192020-08-17 10:59:12 -07008310 }
8311
Hall Liuf19c44f2018-11-27 14:38:17 -08008312 ServiceState ss = phone.getServiceState();
8313
8314 // Scrub out the location info in ServiceState depending on what level of access
8315 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008316 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008317 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8318 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008319 } finally {
8320 Binder.restoreCallingIdentity(identity);
8321 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008322 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008323
8324 /**
8325 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8326 *
8327 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8328 * voicemail ringtone.
8329 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8330 * PhoneAccount.
8331 */
8332 @Override
8333 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008334 final long identity = Binder.clearCallingIdentity();
8335 try {
8336 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8337 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008338 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008339 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008341 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8342 } finally {
8343 Binder.restoreCallingIdentity(identity);
8344 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008345 }
8346
8347 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008348 * Sets the per-account voicemail ringtone.
8349 *
8350 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8351 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8352 *
8353 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8354 * voicemail ringtone.
8355 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8356 * PhoneAccount.
8357 */
8358 @Override
8359 public void setVoicemailRingtoneUri(String callingPackage,
8360 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008361 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008362 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008363 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8364 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8366 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8367 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008368 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008369
8370 final long identity = Binder.clearCallingIdentity();
8371 try {
8372 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8373 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008374 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008375 }
8376 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8377 } finally {
8378 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008379 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008380 }
8381
8382 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008383 * Returns whether vibration is set for voicemail notification in Phone settings.
8384 *
8385 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8386 * voicemail vibration setting.
8387 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8388 */
8389 @Override
8390 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008391 final long identity = Binder.clearCallingIdentity();
8392 try {
8393 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8394 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008395 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008396 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008398 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8399 } finally {
8400 Binder.restoreCallingIdentity(identity);
8401 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008402 }
8403
Youhan Wange64578a2016-05-02 15:32:42 -07008404 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008405 * Sets the per-account voicemail vibration.
8406 *
8407 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8408 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8409 *
8410 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8411 * voicemail vibration setting.
8412 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8413 * specific PhoneAccount.
8414 */
8415 @Override
8416 public void setVoicemailVibrationEnabled(String callingPackage,
8417 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008418 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008419 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008420 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8421 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008422 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8423 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8424 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008425 }
8426
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008427 final long identity = Binder.clearCallingIdentity();
8428 try {
8429 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8430 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008431 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008432 }
8433 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8434 } finally {
8435 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008436 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008437 }
8438
8439 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008440 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8441 *
8442 * @throws SecurityException if the caller does not have the required permission
8443 */
arunvoddud7401012022-12-15 16:08:12 +00008444 @VisibleForTesting
8445 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008446 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008447 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008448 }
8449
8450 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008451 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8452 * permission.
8453 *
8454 * @throws SecurityException if the caller does not have the required permission
8455 */
8456 private void enforceSendSmsPermission() {
8457 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8458 }
8459
8460 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008461 * Make sure either called from same process as self (phone) or IPC caller has interact across
8462 * users permission.
8463 *
8464 * @throws SecurityException if the caller does not have the required permission
8465 */
8466 private void enforceInteractAcrossUsersPermission(String message) {
8467 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8468 }
8469
8470 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008471 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008472 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008473 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008474 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008475 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008476 final long identity = Binder.clearCallingIdentity();
8477 try {
8478 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008479 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008480 if (componentName == null) {
8481 throw new SecurityException(
8482 "Caller not current active visual voicemail package[null]");
8483 }
8484 String vvmPackage = componentName.getPackageName();
8485 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008486 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008487 }
8488 } finally {
8489 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008490 }
8491 }
8492
8493 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008494 * Return the application ID for the app type.
8495 *
8496 * @param subId the subscription ID that this request applies to.
8497 * @param appType the uicc app type.
8498 * @return Application ID for specificied app type, or null if no uicc.
8499 */
8500 @Override
8501 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008502 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008503 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008504
8505 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008506 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008507 if (phone == null) {
8508 return null;
8509 }
8510 String aid = null;
8511 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008512 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008513 .getApplicationByType(appType).getAid();
8514 } catch (Exception e) {
8515 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8516 }
8517 return aid;
8518 } finally {
8519 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008520 }
Youhan Wange64578a2016-05-02 15:32:42 -07008521 }
8522
Youhan Wang4001d252016-05-11 10:29:41 -07008523 /**
8524 * Return the Electronic Serial Number.
8525 *
8526 * @param subId the subscription ID that this request applies to.
8527 * @return ESN or null if error.
8528 */
8529 @Override
8530 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008531 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008532 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008533
8534 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008535 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008536 if (phone == null) {
8537 return null;
8538 }
8539 String esn = null;
8540 try {
8541 esn = phone.getEsn();
8542 } catch (Exception e) {
8543 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8544 }
8545 return esn;
8546 } finally {
8547 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008548 }
Youhan Wang4001d252016-05-11 10:29:41 -07008549 }
8550
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008551 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008552 * Return the Preferred Roaming List Version.
8553 *
8554 * @param subId the subscription ID that this request applies to.
8555 * @return PRLVersion or null if error.
8556 */
8557 @Override
8558 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008559 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008560 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008561
8562 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008563 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008564 if (phone == null) {
8565 return null;
8566 }
8567 String cdmaPrlVersion = null;
8568 try {
8569 cdmaPrlVersion = phone.getCdmaPrlVersion();
8570 } catch (Exception e) {
8571 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8572 }
8573 return cdmaPrlVersion;
8574 } finally {
8575 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008576 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008577 }
8578
8579 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008580 * Get snapshot of Telephony histograms
8581 * @return List of Telephony histograms
8582 * @hide
8583 */
8584 @Override
8585 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8587 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008588
8589 final long identity = Binder.clearCallingIdentity();
8590 try {
8591 return RIL.getTelephonyRILTimingHistograms();
8592 } finally {
8593 Binder.restoreCallingIdentity(identity);
8594 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008595 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008596
8597 /**
8598 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008599 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8600 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008601 * Require system privileges. In the future we may add this to carrier APIs.
8602 *
Michele Berionne482f8202018-11-27 18:57:59 -08008603 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008604 */
8605 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008606 @TelephonyManager.SetCarrierRestrictionResult
8607 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008608 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008609 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008610
Michele Berionne482f8202018-11-27 18:57:59 -08008611 if (carrierRestrictionRules == null) {
8612 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008613 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008614
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008615 final long identity = Binder.clearCallingIdentity();
8616 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008617 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008618 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008619 } finally {
8620 Binder.restoreCallingIdentity(identity);
8621 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008622 }
8623
8624 /**
8625 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008626 * Get the allowed carrier list and the excluded carrier list, including the priority between
8627 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008628 * Require system privileges. In the future we may add this to carrier APIs.
8629 *
Michele Berionne482f8202018-11-27 18:57:59 -08008630 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008631 */
8632 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008633 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008634 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008635 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008636
8637 final long identity = Binder.clearCallingIdentity();
8638 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008639 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8640 if (response instanceof CarrierRestrictionRules) {
8641 return (CarrierRestrictionRules) response;
8642 }
8643 // Response is an Exception of some kind,
8644 // which is signalled to the user as a NULL retval
8645 return null;
8646 } catch (Exception e) {
8647 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8648 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008649 } finally {
8650 Binder.restoreCallingIdentity(identity);
8651 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008652 }
8653
fionaxu59545b42016-05-25 15:53:37 -07008654 /**
arunvoddud7401012022-12-15 16:08:12 +00008655 * Fetches the carrier restriction status of the device and sends the status to the caller
8656 * through the callback.
8657 *
8658 * @param callback The callback that will be used to send the result.
8659 * @throws SecurityException if the caller does not have the required permission/privileges or
8660 * the caller is not allowlisted.
8661 */
8662 @Override
8663 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8664 enforceReadPermission("getCarrierRestrictionStatus");
8665 int carrierId = validateCallerAndGetCarrierId(packageName);
8666 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8667 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8668 throw new SecurityException("Not an authorized caller");
8669 }
8670 final long identity = Binder.clearCallingIdentity();
8671 try {
8672 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8673 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8674 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8675 } finally {
8676 Binder.restoreCallingIdentity(identity);
8677 }
8678 }
8679
8680 @VisibleForTesting
8681 public int validateCallerAndGetCarrierId(String packageName) {
8682 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8683 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8684 }
8685
8686 /**
fionaxu59545b42016-05-25 15:53:37 -07008687 * Action set from carrier signalling broadcast receivers to enable/disable radio
8688 * @param subId the subscription ID that this action applies to.
8689 * @param enabled control enable or disable radio.
8690 * {@hide}
8691 */
8692 @Override
8693 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8694 enforceModifyPermission();
8695 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008696
8697 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008698 if (phone == null) {
8699 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8700 return;
8701 }
8702 try {
8703 phone.carrierActionSetRadioEnabled(enabled);
8704 } catch (Exception e) {
8705 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008706 } finally {
8707 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008708 }
8709 }
8710
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008711 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008712 * Enable or disable Voice over NR (VoNR)
8713 * @param subId the subscription ID that this action applies to.
8714 * @param enabled enable or disable VoNR.
8715 * @return operation result.
8716 */
8717 @Override
8718 public int setVoNrEnabled(int subId, boolean enabled) {
8719 enforceModifyPermission();
8720 final Phone phone = getPhone(subId);
8721
8722 final long identity = Binder.clearCallingIdentity();
8723 if (phone == null) {
8724 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8725 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8726 }
8727
8728 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8729 try {
8730 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8731 workSource);
8732 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008733
8734 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8735 if (DBG) {
8736 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8737 }
8738 SubscriptionManager.setSubscriptionProperty(
8739 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8740 (enabled ? "1" : "0"));
8741 }
8742
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008743 return result;
8744 } finally {
8745 Binder.restoreCallingIdentity(identity);
8746 }
8747 }
8748
8749 /**
8750 * Is voice over NR enabled
8751 * @return true if VoNR is enabled else false
8752 */
8753 @Override
8754 public boolean isVoNrEnabled(int subId) {
8755 enforceReadPrivilegedPermission("isVoNrEnabled");
8756 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8757 final long identity = Binder.clearCallingIdentity();
8758 try {
8759 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8760 null, subId, workSource);
8761 if (DBG) log("isVoNrEnabled: " + isEnabled);
8762 return isEnabled;
8763 } finally {
8764 Binder.restoreCallingIdentity(identity);
8765 }
8766 }
8767
8768 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008769 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8770 * network status based on which carrier apps could apply actions accordingly,
8771 * enable/disable default url handler for example.
8772 *
8773 * @param subId the subscription ID that this action applies to.
8774 * @param report control start/stop reporting the default network status.
8775 * {@hide}
8776 */
8777 @Override
8778 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8779 enforceModifyPermission();
8780 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008781
8782 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008783 if (phone == null) {
8784 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8785 return;
8786 }
8787 try {
8788 phone.carrierActionReportDefaultNetworkStatus(report);
8789 } catch (Exception e) {
8790 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008791 } finally {
8792 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008793 }
8794 }
8795
8796 /**
fionaxud9622282017-07-17 17:51:30 -07008797 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8798 * @param subId the subscription ID that this action applies to.
8799 * {@hide}
8800 */
8801 @Override
8802 public void carrierActionResetAll(int subId) {
8803 enforceModifyPermission();
8804 final Phone phone = getPhone(subId);
8805 if (phone == null) {
8806 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8807 return;
8808 }
8809 try {
8810 phone.carrierActionResetAll();
8811 } catch (Exception e) {
8812 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8813 }
8814 }
8815
8816 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008817 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8818 * bug report is being generated.
8819 */
8820 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008821 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008822 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8823 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008824 writer.println("Permission Denial: can't dump Phone from pid="
8825 + Binder.getCallingPid()
8826 + ", uid=" + Binder.getCallingUid()
8827 + "without permission "
8828 + android.Manifest.permission.DUMP);
8829 return;
8830 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008831 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008832 }
Jack Yueb89b242016-06-22 13:27:47 -07008833
Brad Ebingerdac2f002018-04-03 15:17:52 -07008834 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008835 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8836 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8837 @NonNull String[] args) {
8838 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8839 this, in.getFileDescriptor(), out.getFileDescriptor(),
8840 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008841 }
8842
Jack Yueb89b242016-06-22 13:27:47 -07008843 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008844 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008845 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008846 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008847 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008848 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008849 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008850 */
8851 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008852 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008853 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008854 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8855 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8856 try {
8857 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008858 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008859 } catch (SecurityException se) {
8860 enforceModifyPermission();
8861 }
8862 } else {
8863 enforceModifyPermission();
8864 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008865
8866 final long identity = Binder.clearCallingIdentity();
8867 try {
8868 Phone phone = getPhone(subId);
8869 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008870 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8871 phone.carrierActionSetMeteredApnsEnabled(enabled);
8872 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008873 phone.getDataSettingsManager().setDataEnabled(
8874 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008876 }
8877 } finally {
8878 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008879 }
8880 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008881
8882 /**
8883 * Get Client request stats
8884 * @return List of Client Request Stats
8885 * @hide
8886 */
8887 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008888 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8889 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008890 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008891 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008892 return null;
8893 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008894 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008895
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008896 final long identity = Binder.clearCallingIdentity();
8897 try {
8898 if (phone != null) {
8899 return phone.getClientRequestStats();
8900 }
8901
8902 return null;
8903 } finally {
8904 Binder.restoreCallingIdentity(identity);
8905 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008906 }
8907
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008908 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008909 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008910 if (uid == Process.ROOT_UID && packageName == null) {
8911 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8912 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8913 // exception. ROOT_UID seems not to have a valid package name returned by
8914 // PackageManager, so just fake it here to avoid issues when running telephony shell
8915 // commands that plumb through the RIL as root, like so:
8916 // $ adb root
8917 // $ adb shell cmd phone ...
8918 packageName = "root";
8919 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008920 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008921 }
Jack Yueb4124c2017-02-16 15:32:43 -08008922
8923 /**
Grace Chen70990072017-03-24 17:21:30 -07008924 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008925 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008926 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008927 * @param state State of SIM (power down, power up, pass through)
8928 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8929 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8930 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008931 *
8932 **/
8933 @Override
Grace Chen70990072017-03-24 17:21:30 -07008934 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008935 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008936 Phone phone = PhoneFactory.getPhone(slotIndex);
8937
vagdeviaf9a5b92018-08-15 16:01:53 -07008938 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8939
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008940 final long identity = Binder.clearCallingIdentity();
8941 try {
8942 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008943 phone.setSimPowerState(state, null, workSource);
8944 }
8945 } finally {
8946 Binder.restoreCallingIdentity(identity);
8947 }
8948 }
8949
8950 /**
8951 * Set SIM card power state.
8952 *
8953 * @param slotIndex SIM slot id.
8954 * @param state State of SIM (power down, power up, pass through)
8955 * @param callback callback to trigger after success or failure
8956 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8957 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8958 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8959 *
8960 **/
8961 @Override
8962 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8963 IIntegerConsumer callback) {
8964 enforceModifyPermission();
8965 Phone phone = PhoneFactory.getPhone(slotIndex);
8966
8967 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8968
8969 final long identity = Binder.clearCallingIdentity();
8970 try {
8971 if (phone != null) {
8972 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8973 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008974 }
8975 } finally {
8976 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008977 }
8978 }
Shuo Qiandd210312017-04-12 22:11:33 +00008979
Tyler Gunn65d45c22017-06-05 11:22:26 -07008980 private boolean isUssdApiAllowed(int subId) {
8981 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008982 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008983 if (configManager == null) {
8984 return false;
8985 }
8986 PersistableBundle pb = configManager.getConfigForSubId(subId);
8987 if (pb == null) {
8988 return false;
8989 }
8990 return pb.getBoolean(
8991 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8992 }
8993
Shuo Qiandd210312017-04-12 22:11:33 +00008994 /**
8995 * Check if phone is in emergency callback mode
8996 * @return true if phone is in emergency callback mode
8997 * @param subId sub id
8998 */
goneil9c5f4872017-12-05 14:07:56 -08008999 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009000 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009001 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00009002 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009003
9004 final long identity = Binder.clearCallingIdentity();
9005 try {
9006 if (phone != null) {
9007 return phone.isInEcm();
9008 } else {
9009 return false;
9010 }
9011 } finally {
9012 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009013 }
9014 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009015
9016 /**
9017 * Get the current signal strength information for the given subscription.
9018 * Because this information is not updated when the device is in a low power state
9019 * it should not be relied-upon to be current.
9020 * @param subId Subscription index
9021 * @return the most recent cached signal strength info from the modem
9022 */
9023 @Override
9024 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009025 final long identity = Binder.clearCallingIdentity();
9026 try {
9027 Phone p = getPhone(subId);
9028 if (p == null) {
9029 return null;
9030 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009031
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009032 return p.getSignalStrength();
9033 } finally {
9034 Binder.restoreCallingIdentity(identity);
9035 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009036 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009037
Pengquan Meng77b7f132018-08-22 14:49:57 -07009038 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009039 * Get the current modem radio state for the given slot.
9040 * @param slotIndex slot index.
9041 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009042 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009043 * @return the current radio power state from the modem
9044 */
9045 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009046 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009047 Phone phone = PhoneFactory.getPhone(slotIndex);
9048 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009049 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9050 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009051 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9052 }
9053
9054 final long identity = Binder.clearCallingIdentity();
9055 try {
9056 return phone.getRadioPowerState();
9057 } finally {
9058 Binder.restoreCallingIdentity(identity);
9059 }
9060 }
9061 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9062 }
9063
9064 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009065 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9066 *
9067 * <p>Requires one of the following permissions:
9068 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009069 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009070 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9071 * privileges.
9072 *
9073 * @param subId subscription id
9074 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9075 * {@code false}.
9076 */
9077 @Override
9078 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009079 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009080 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009081 try {
9082 mApp.enforceCallingOrSelfPermission(
9083 android.Manifest.permission.ACCESS_NETWORK_STATE,
9084 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009085 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009086 mApp.enforceCallingOrSelfPermission(
9087 permission.READ_BASIC_PHONE_STATE, functionName);
9088 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009089 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009090 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009091 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009092 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009093
Pengquan Menga1bb6272018-09-06 09:59:22 -07009094 boolean isEnabled = false;
9095 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009096 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009097 Phone phone = getPhone(subId);
9098 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009099 } finally {
9100 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009101 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009102 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009103 }
9104
9105
9106 /**
9107 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9108 *
9109 * <p> Requires permission:
9110 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9111 * privileges.
9112 *
9113 * @param subId subscription id
9114 * @param isEnabled {@code true} means enable, {@code false} means disable.
9115 */
9116 @Override
9117 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009118 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9119 mApp, subId, "setDataRoamingEnabled");
9120
Pengquan Menga1bb6272018-09-06 09:59:22 -07009121 final long identity = Binder.clearCallingIdentity();
9122 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009123 Phone phone = getPhone(subId);
9124 if (phone != null) {
9125 phone.setDataRoamingEnabled(isEnabled);
9126 }
9127 } finally {
9128 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009129 }
9130 }
9131
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009132 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009133 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009134 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009135 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07009136 mApp, subId, "isManualNetworkSelectionAllowed");
9137
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009138 boolean isAllowed = true;
9139 final long identity = Binder.clearCallingIdentity();
9140 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009141 Phone phone = getPhone(subId);
9142 if (phone != null) {
9143 isAllowed = phone.isCspPlmnEnabled();
9144 }
9145 } finally {
9146 Binder.restoreCallingIdentity(identity);
9147 }
9148 return isAllowed;
9149 }
9150
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009151 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9152 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009153 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009154 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009155 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009156 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9157 if (phone == null) {
9158 return false;
9159 }
9160 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9161 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9162 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009163 }
9164
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009165 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009166 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009167 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009168 mApp.getSystemService(AppOpsManager.class)
9169 .checkPackage(Binder.getCallingUid(), callingPackage);
9170
Jordan Liu1e142fc2019-04-22 15:10:43 -07009171 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009172 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009173 try {
9174 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009175 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009176 } catch (SecurityException e) {
9177 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9178 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009179 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08009180 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009181 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009182 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009183 }
sandeepjsb6c87872021-09-27 15:34:44 +00009184 // checking compatibility, if calling app's target SDK is T and beyond.
9185 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9186 Binder.getCallingUid())) {
9187 isIccIdAccessRestricted = true;
9188 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009189 final long identity = Binder.clearCallingIdentity();
9190 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009191 UiccController uiccController = UiccController.getInstance();
9192 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009193 if (hasReadPermission) {
9194 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009195 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009196
9197 // Remove private info if the caller doesn't have access
9198 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9199 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009200 //setting the value after compatibility check
9201 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009202 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9203 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009204 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009205 if (card == null) {
9206 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009207 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009208 continue;
9209 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009210 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9211 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009212 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009213 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009214 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009215 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9216 for (UiccPortInfo portInfo : portInfos) {
9217 UiccPort port = uiccController.getUiccPortForSlot(
9218 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9219 if (port == null) {
9220 // assume no access if port is null
9221 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9222 continue;
9223 }
9224 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9225 uiccPortInfos.add(portInfo);
9226 } else {
9227 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9228 }
9229 }
9230 filteredInfos.add(new UiccCardInfo(
9231 cardInfo.isEuicc(),
9232 cardInfo.getCardId(),
9233 null,
9234 cardInfo.getPhysicalSlotIndex(),
9235 cardInfo.isRemovable(),
9236 cardInfo.isMultipleEnabledProfilesSupported(),
9237 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009238 }
9239 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009240 } finally {
9241 Binder.restoreCallingIdentity(identity);
9242 }
9243 }
9244
sandeepjsb6c87872021-09-27 15:34:44 +00009245 /**
9246 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9247 * generally private and require carrier privileges to view.
9248 *
9249 * @hide
9250 */
9251 @NonNull
9252 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9253 List<UiccPortInfo> portinfo = new ArrayList<>();
9254 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9255 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9256 }
9257 return new UiccCardInfo(
9258 cardInfo.isEuicc(),
9259 cardInfo.getCardId(),
9260 null,
9261 cardInfo.getPhysicalSlotIndex(),
9262 cardInfo.isRemovable(),
9263 cardInfo.isMultipleEnabledProfilesSupported(),
9264 portinfo
9265 );
9266 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009267
sandeepjsb6c87872021-09-27 15:34:44 +00009268 /**
9269 * @hide
9270 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9271 * These values are generally private and require carrier privileges to view.
9272 */
9273 @NonNull
9274 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9275 return new UiccPortInfo(
9276 UiccPortInfo.ICCID_REDACTED,
9277 portInfo.getPortIndex(),
9278 portInfo.getLogicalSlotIndex(),
9279 portInfo.isActive()
9280 );
9281 }
9282 @Override
9283 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009284 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009285 mApp.getSystemService(AppOpsManager.class)
9286 .checkPackage(Binder.getCallingUid(), callingPackage);
9287
sandeepjsb6c87872021-09-27 15:34:44 +00009288 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009289
Aman Guptaf3c90b32022-03-17 04:54:16 +00009290 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9291 // we are reading iccId which is PII data.
9292 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009293
9294 // checking compatibility, if calling app's target SDK is T and beyond.
9295 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9296 Binder.getCallingUid())) {
9297 isLogicalSlotAccessRestricted = true;
9298 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009299 final long identity = Binder.clearCallingIdentity();
9300 try {
9301 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009302 if (slots == null || slots.length == 0) {
9303 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009304 return null;
9305 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009306 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9307 for (int i = 0; i < slots.length; i++) {
9308 UiccSlot slot = slots[i];
9309 if (slot == null) {
9310 continue;
9311 }
9312
Jordan Liu7be7e652019-05-06 18:55:02 +00009313 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009314 UiccCard card = slot.getUiccCard();
9315 if (card != null) {
9316 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009317 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009318 cardId = slot.getEid();
9319 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009320 // If cardId is null, use iccId of default port as cardId.
9321 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009322 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009323 }
9324
Jordan Liu857451f2019-05-09 16:35:35 -07009325 if (cardId != null) {
9326 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9327 // if cardId is an EID, it's all digits so this is fine
9328 cardId = IccUtils.stripTrailingFs(cardId);
9329 }
9330
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009331 int cardState = 0;
9332 switch (slot.getCardState()) {
9333 case CARDSTATE_ABSENT:
9334 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9335 break;
9336 case CARDSTATE_PRESENT:
9337 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9338 break;
9339 case CARDSTATE_ERROR:
9340 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9341 break;
9342 case CARDSTATE_RESTRICTED:
9343 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9344 break;
9345 default:
9346 break;
9347
9348 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009349 List<UiccPortInfo> portInfos = new ArrayList<>();
9350 int[] portIndexes = slot.getPortList();
9351 for (int portIdx : portIndexes) {
9352 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009353 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009354 portInfos.add(new UiccPortInfo(iccId, portIdx,
9355 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009356 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009357 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009358 slot.isEuicc(),
9359 cardId,
9360 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009361 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009362 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009363 //setting the value after compatibility check
9364 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009365 }
9366 return infos;
9367 } finally {
9368 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009369 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009370 }
9371
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009372 /* Returns null if doesn't have read permission or carrier privilege access. */
9373 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9374 boolean hasReadPermission) {
9375 String iccId = slot.getIccId(portIndex);
9376 if (hasReadPermission) { // if has read permission
9377 return iccId;
9378 } else {
9379 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9380 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9381 // if no read permission, checking carrier privilege access
9382 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9383 return iccId;
9384 }
9385 }
9386 }
9387 // No read permission or carrier privilege access.
9388 return UiccPortInfo.ICCID_REDACTED;
9389 }
9390
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009391 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009392 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009393 public boolean switchSlots(int[] physicalSlots) {
9394 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009395
9396 final long identity = Binder.clearCallingIdentity();
9397 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009398 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9399 for (int i = 0; i < physicalSlots.length; i++) {
9400 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9401 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9402 physicalSlots[i], i));
9403 }
9404 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009405 } finally {
9406 Binder.restoreCallingIdentity(identity);
9407 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009408 }
Jack Yu4c988042018-02-27 15:30:01 -08009409
9410 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009411 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9412 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9413 enforceModifyPermission();
9414
9415 final long identity = Binder.clearCallingIdentity();
9416 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009417 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009418 } finally {
9419 Binder.restoreCallingIdentity(identity);
9420 }
9421 }
9422
9423 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009424 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009425 final long identity = Binder.clearCallingIdentity();
9426 try {
9427 return UiccController.getInstance().getCardIdForDefaultEuicc();
9428 } finally {
9429 Binder.restoreCallingIdentity(identity);
9430 }
9431 }
9432
Pengquan Meng85728fb2018-03-12 16:31:21 -07009433 /**
goneil47ffb6e2018-04-06 15:40:58 -07009434 * A test API to reload the UICC profile.
9435 *
9436 * <p>Requires that the calling app has permission
9437 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9438 * @hide
9439 */
9440 @Override
9441 public void refreshUiccProfile(int subId) {
9442 enforceModifyPermission();
9443
9444 final long identity = Binder.clearCallingIdentity();
9445 try {
9446 Phone phone = getPhone(subId);
9447 if (phone == null) {
9448 return;
9449 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009450 UiccPort uiccPort = phone.getUiccPort();
9451 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009452 return;
9453 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009454 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009455 if (uiccProfile == null) {
9456 return;
9457 }
9458 uiccProfile.refresh();
9459 } finally {
9460 Binder.restoreCallingIdentity(identity);
9461 }
9462 }
9463
9464 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009465 * Returns false if the mobile data is disabled by default, otherwise return true.
9466 */
9467 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009468 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009469 }
9470
9471 /**
9472 * Returns true if the data roaming is enabled by default, i.e the system property
9473 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9474 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9475 */
9476 private boolean getDefaultDataRoamingEnabled(int subId) {
9477 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009478 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009479 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009480 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9481 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9482 return isDataRoamingEnabled;
9483 }
9484
9485 /**
9486 * Returns the default network type for the given {@code subId}, if the default network type is
9487 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9488 */
9489 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009490 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009491 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009492 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9493 return list.get(phoneId);
9494 }
9495 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009496 }
fionaxua13278b2018-03-21 00:08:13 -07009497
9498 @Override
9499 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009500 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009501 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009502
9503 final long identity = Binder.clearCallingIdentity();
9504 try {
9505 final Phone phone = getPhone(subId);
9506 if (phone == null) {
9507 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9508 return;
9509 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009510 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9511 if (cpt != null) {
9512 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9513 }
9514 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009515 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9516 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009517 if (carrierPrivilegeRules == null) {
9518 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9519 } else {
9520 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9521 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009522 } finally {
9523 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009524 }
fionaxua13278b2018-03-21 00:08:13 -07009525 }
9526
9527 @Override
9528 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009529 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009530
9531 final long identity = Binder.clearCallingIdentity();
9532 try {
9533 final Phone phone = getPhone(subId);
9534 if (phone == null) {
9535 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9536 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9537 }
9538 return phone.getCarrierIdListVersion();
9539 } finally {
9540 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009541 }
fionaxua13278b2018-03-21 00:08:13 -07009542 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009543
9544 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009545 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9546 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009547 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009548 mApp, subId, callingPackage, callingFeatureId,
9549 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009550 return -1;
9551 }
9552
9553 final long identity = Binder.clearCallingIdentity();
9554 try {
9555 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9556 } finally {
9557 Binder.restoreCallingIdentity(identity);
9558 }
9559 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009560
9561 @Override
9562 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009563 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009564 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009565 mApp, subId, "getCdmaRoamingMode");
9566
9567 final long identity = Binder.clearCallingIdentity();
9568 try {
9569 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9570 } finally {
9571 Binder.restoreCallingIdentity(identity);
9572 }
9573 }
9574
9575 @Override
9576 public boolean setCdmaRoamingMode(int subId, int mode) {
9577 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9578 mApp, subId, "setCdmaRoamingMode");
9579
9580 final long identity = Binder.clearCallingIdentity();
9581 try {
9582 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9583 } finally {
9584 Binder.restoreCallingIdentity(identity);
9585 }
9586 }
9587
9588 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009589 public int getCdmaSubscriptionMode(int subId) {
9590 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009591 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009592 mApp, subId, "getCdmaSubscriptionMode");
9593
9594 final long identity = Binder.clearCallingIdentity();
9595 try {
9596 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9597 } finally {
9598 Binder.restoreCallingIdentity(identity);
9599 }
9600 }
9601
9602 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009603 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9605 mApp, subId, "setCdmaSubscriptionMode");
9606
9607 final long identity = Binder.clearCallingIdentity();
9608 try {
9609 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9610 } finally {
9611 Binder.restoreCallingIdentity(identity);
9612 }
9613 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009614
sqianc5eccab2018-10-19 18:46:41 -07009615 @Override
sqian8c685422019-02-22 15:55:18 -08009616 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009617 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009618 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009619 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9620 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009621 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9622 }
9623 final long identity = Binder.clearCallingIdentity();
9624 try {
sqian854d44b2018-12-12 16:48:18 -08009625 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9626 for (Phone phone: PhoneFactory.getPhones()) {
9627 if (phone.getEmergencyNumberTracker() != null
9628 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9629 emergencyNumberListInternal.put(
9630 phone.getSubId(),
9631 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9632 }
sqian11b7a0e2018-12-05 18:48:28 -08009633 }
sqian854d44b2018-12-12 16:48:18 -08009634 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009635 } finally {
9636 Binder.restoreCallingIdentity(identity);
9637 }
sqianc5eccab2018-10-19 18:46:41 -07009638 }
9639
9640 @Override
sqian8c685422019-02-22 15:55:18 -08009641 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009642 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009643 if (!exactMatch) {
9644 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009645 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009646 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009647 }
9648 final long identity = Binder.clearCallingIdentity();
9649 try {
sqian854d44b2018-12-12 16:48:18 -08009650 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009651 //Note: we ignore passed in param exactMatch. We can remove it once
9652 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009653 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009654 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009655 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009656 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009657 }
sqian11b7a0e2018-12-05 18:48:28 -08009658 }
9659 return false;
9660 } finally {
9661 Binder.restoreCallingIdentity(identity);
9662 }
9663 }
9664
sqianf4ca7ed2019-01-15 18:32:07 -08009665 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009666 * Start emergency callback mode for GsmCdmaPhone for testing.
9667 */
9668 @Override
9669 public void startEmergencyCallbackMode() {
9670 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9671 "startEmergencyCallbackMode");
9672 enforceModifyPermission();
9673 final long identity = Binder.clearCallingIdentity();
9674 try {
9675 for (Phone phone : PhoneFactory.getPhones()) {
9676 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9677 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9678 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9679 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9680 gsmCdmaPhone.obtainMessage(
9681 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9682 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9683 }
9684 }
9685 } finally {
9686 Binder.restoreCallingIdentity(identity);
9687 }
9688 }
9689
9690 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009691 * Update emergency number list for test mode.
9692 */
9693 @Override
9694 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9695 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9696 "updateEmergencyNumberListTestMode");
9697
9698 final long identity = Binder.clearCallingIdentity();
9699 try {
9700 for (Phone phone: PhoneFactory.getPhones()) {
9701 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9702 if (tracker != null) {
9703 tracker.executeEmergencyNumberTestModeCommand(action, num);
9704 }
9705 }
9706 } finally {
9707 Binder.restoreCallingIdentity(identity);
9708 }
9709 }
9710
9711 /**
9712 * Get the full emergency number list for test mode.
9713 */
9714 @Override
9715 public List<String> getEmergencyNumberListTestMode() {
9716 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9717 "getEmergencyNumberListTestMode");
9718
9719 final long identity = Binder.clearCallingIdentity();
9720 try {
9721 Set<String> emergencyNumbers = new HashSet<>();
9722 for (Phone phone: PhoneFactory.getPhones()) {
9723 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9724 if (tracker != null) {
9725 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9726 emergencyNumbers.add(num.getNumber());
9727 }
9728 }
9729 }
9730 return new ArrayList<>(emergencyNumbers);
9731 } finally {
9732 Binder.restoreCallingIdentity(identity);
9733 }
9734 }
9735
chen xud6b45bd2018-10-30 22:27:10 -07009736 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009737 public int getEmergencyNumberDbVersion(int subId) {
9738 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9739
9740 final long identity = Binder.clearCallingIdentity();
9741 try {
9742 final Phone phone = getPhone(subId);
9743 if (phone == null) {
9744 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9745 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9746 }
9747 return phone.getEmergencyNumberDbVersion();
9748 } finally {
9749 Binder.restoreCallingIdentity(identity);
9750 }
9751 }
9752
9753 @Override
9754 public void notifyOtaEmergencyNumberDbInstalled() {
9755 enforceModifyPermission();
9756
9757 final long identity = Binder.clearCallingIdentity();
9758 try {
9759 for (Phone phone: PhoneFactory.getPhones()) {
9760 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9761 if (tracker != null) {
9762 tracker.updateOtaEmergencyNumberDatabase();
9763 }
9764 }
9765 } finally {
9766 Binder.restoreCallingIdentity(identity);
9767 }
9768 }
9769
9770 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009771 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009772 enforceActiveEmergencySessionPermission();
9773
9774 final long identity = Binder.clearCallingIdentity();
9775 try {
9776 for (Phone phone: PhoneFactory.getPhones()) {
9777 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9778 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009779 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9780 }
9781 }
9782 } finally {
9783 Binder.restoreCallingIdentity(identity);
9784 }
9785 }
9786
9787 @Override
9788 public void resetOtaEmergencyNumberDbFilePath() {
9789 enforceActiveEmergencySessionPermission();
9790
9791 final long identity = Binder.clearCallingIdentity();
9792 try {
9793 for (Phone phone: PhoneFactory.getPhones()) {
9794 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9795 if (tracker != null) {
9796 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009797 }
9798 }
9799 } finally {
9800 Binder.restoreCallingIdentity(identity);
9801 }
9802 }
9803
9804 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009805 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9806 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9807 Phone phone = getPhone(subId);
9808 if (phone == null) {
9809 return null;
9810 }
9811 final long identity = Binder.clearCallingIdentity();
9812 try {
9813 UiccProfile profile = UiccController.getInstance()
9814 .getUiccProfileForPhone(phone.getPhoneId());
9815 if (profile != null) {
9816 return profile.getCertsFromCarrierPrivilegeAccessRules();
9817 }
9818 } finally {
9819 Binder.restoreCallingIdentity(identity);
9820 }
9821 return null;
9822 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009823
9824 /**
9825 * Enable or disable a modem stack.
9826 */
9827 @Override
9828 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9829 enforceModifyPermission();
9830
9831 final long identity = Binder.clearCallingIdentity();
9832 try {
9833 Phone phone = PhoneFactory.getPhone(slotIndex);
9834 if (phone == null) {
9835 return false;
9836 } else {
9837 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9838 }
9839 } finally {
9840 Binder.restoreCallingIdentity(identity);
9841 }
9842 }
Michelecea4cf22018-12-21 15:00:11 -08009843
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009844 /**
9845 * Whether a modem stack is enabled or not.
9846 */
9847 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009848 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9849 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009850 Phone phone = PhoneFactory.getPhone(slotIndex);
9851 if (phone == null) return false;
9852
9853 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009854 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9855 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009856 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9857 }
9858
9859 final long identity = Binder.clearCallingIdentity();
9860 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009861 try {
9862 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9863 } catch (NoSuchElementException ex) {
9864 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9865 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009866 } finally {
9867 Binder.restoreCallingIdentity(identity);
9868 }
9869 }
9870
Michelecea4cf22018-12-21 15:00:11 -08009871 @Override
Michele0ea7d782019-03-19 14:58:42 -07009872 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009873 enforceModifyPermission();
9874
9875 final long identity = Binder.clearCallingIdentity();
9876 try {
9877 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009878 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009879 .commit();
9880 } finally {
9881 Binder.restoreCallingIdentity(identity);
9882 }
9883 }
9884
9885 @Override
Michele0ea7d782019-03-19 14:58:42 -07009886 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009887 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009888 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009889 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9890 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009891 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009892 }
Michelecea4cf22018-12-21 15:00:11 -08009893
9894 final long identity = Binder.clearCallingIdentity();
9895 try {
Michele0ea7d782019-03-19 14:58:42 -07009896 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009897 } finally {
9898 Binder.restoreCallingIdentity(identity);
9899 }
9900 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009901
Michele0ea7d782019-03-19 14:58:42 -07009902 @TelephonyManager.IsMultiSimSupportedResult
9903 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009904 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9905 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9906 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009907 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9908 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009909 }
9910 // Check if the hardware supports multisim functionality. If usage of multisim is not
9911 // supported by the modem, indicate that it is restricted.
9912 PhoneCapability staticCapability =
9913 mPhoneConfigurationManager.getStaticPhoneCapability();
9914 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009915 loge("isMultiSimSupportedInternal: no static configuration available");
9916 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009917 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009918 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009919 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9920 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009921 }
9922 // Check if support of multiple SIMs is restricted by carrier
9923 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009924 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009925 }
9926
Michele0ea7d782019-03-19 14:58:42 -07009927 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009928 }
9929
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009930 /**
9931 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009932 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9933 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9934 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009935 * @param numOfSims number of active sims we want to switch to
9936 */
9937 @Override
9938 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009939 if (numOfSims == 1) {
9940 enforceModifyPermission();
9941 } else {
9942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9943 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9944 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009945 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009946
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009947 try {
Michele30b57b22019-03-01 12:01:14 -08009948 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009949 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009950 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9951 return;
9952 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009953 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9954 } finally {
9955 Binder.restoreCallingIdentity(identity);
9956 }
9957 }
9958
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009959 @Override
9960 public boolean isApplicationOnUicc(int subId, int appType) {
9961 enforceReadPrivilegedPermission("isApplicationOnUicc");
9962 Phone phone = getPhone(subId);
9963 if (phone == null) {
9964 return false;
9965 }
9966 final long identity = Binder.clearCallingIdentity();
9967 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009968 UiccPort uiccPort = phone.getUiccPort();
9969 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009970 return false;
9971 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009972 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009973 if (uiccProfile == null) {
9974 return false;
9975 }
9976 if (TelephonyManager.APPTYPE_SIM <= appType
9977 && appType <= TelephonyManager.APPTYPE_ISIM) {
9978 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9979 }
9980 return false;
9981 } finally {
9982 Binder.restoreCallingIdentity(identity);
9983 }
9984 }
9985
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009986 /**
chen xub4baa772019-04-03 10:23:41 -07009987 * Get whether making changes to modem configurations will trigger reboot.
9988 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009989 */
9990 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009991 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9992 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009993 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009994 mApp, subId, callingPackage, callingFeatureId,
9995 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009996 return false;
9997 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009998 final long identity = Binder.clearCallingIdentity();
9999 try {
10000 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10001 } finally {
10002 Binder.restoreCallingIdentity(identity);
10003 }
10004 }
10005
Nathan Harold29f5f052019-02-15 13:41:57 -080010006 private void updateModemStateMetrics() {
10007 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10008 // TODO: check the state for each modem if the api is ready.
10009 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10010 }
10011
Pengquan Meng3889a572019-01-23 11:16:29 -080010012 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010013 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010014 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010015 // Verify that the callingPackage belongs to the calling UID
10016 mApp.getSystemService(AppOpsManager.class)
10017 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010018 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010019 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010020 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010021 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10022 if (slotInfos != null) {
10023 for (int i = 0; i < slotInfos.length; i++) {
10024 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10025 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10026 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10027 portInfo.getLogicalSlotIndex()));
10028 }
10029 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010030 }
10031 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010032 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010033 } finally {
10034 Binder.restoreCallingIdentity(identity);
10035 }
10036 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010037
10038 /**
10039 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010040 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010041 */
jimsunf9ec1622022-09-13 21:18:43 +080010042 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010043 @Override
10044 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010045 return getHalVersion(HAL_SERVICE_RADIO);
10046 }
10047
10048 /**
10049 * Get the HAL Version of a specific service
10050 */
10051 @Override
10052 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010053 Phone phone = getDefaultPhone();
10054 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010055 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010056 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10057 return hv.major * 100 + hv.minor;
10058 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010059
10060 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010061 * Get the current calling package name.
10062 * @return the current calling package name
10063 */
10064 @Override
10065 public String getCurrentPackageName() {
10066 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10067 }
10068
10069 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010070 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10071 * corresponding network requests on a subId.
10072 *
10073 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010074 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010075 * 2) APN is un-metered for this subscription, or
10076 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010077 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010078 *
10079 * @return whether data is allowed for a apn type.
10080 *
10081 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010082 */
10083 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010084 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010085 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10086 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010087
10088 // Now that all security checks passes, perform the operation as ourselves.
10089 final long identity = Binder.clearCallingIdentity();
10090 try {
10091 Phone phone = getPhone(subId);
10092 if (phone == null) return false;
10093
Jack Yu27422a52022-03-21 10:38:05 -070010094 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010095 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010096 isMetered = phone.getDataNetworkController().getDataConfigManager()
10097 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10098 phone.getServiceState().getDataRoaming());
10099 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010100 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010101 } finally {
10102 Binder.restoreCallingIdentity(identity);
10103 }
10104 }
10105
10106 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010107 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010108 enforceReadPrivilegedPermission("isApnMetered");
10109
10110 // Now that all security checks passes, perform the operation as ourselves.
10111 final long identity = Binder.clearCallingIdentity();
10112 try {
10113 Phone phone = getPhone(subId);
10114 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010115 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10116 DataUtils.apnTypeToNetworkCapability(apnType),
10117 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010118 } finally {
10119 Binder.restoreCallingIdentity(identity);
10120 }
10121 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010122
10123 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010124 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10125 int subscriptionId, IBooleanConsumer resultCallback) {
10126 enforceModifyPermission();
10127 long token = Binder.clearCallingIdentity();
10128 try {
10129 Phone phone = getPhone(subscriptionId);
10130 if (phone == null) {
10131 try {
10132 if (resultCallback != null) {
10133 resultCallback.accept(false);
10134 }
10135 } catch (RemoteException e) {
10136 // ignore
10137 }
10138 return;
10139 }
10140 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10141 Pair.create(specifiers, (x) -> {
10142 try {
10143 if (resultCallback != null) {
10144 resultCallback.accept(x);
10145 }
10146 } catch (RemoteException e) {
10147 // ignore
10148 }
10149 });
10150 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10151 } finally {
10152 Binder.restoreCallingIdentity(token);
10153 }
10154 }
10155
10156 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010157 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10158 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010159 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010160 mApp, subId, "getSystemSelectionChannels");
10161 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10162 final long identity = Binder.clearCallingIdentity();
10163 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010164 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10165 if (result instanceof IllegalStateException) {
10166 throw (IllegalStateException) result;
10167 }
10168 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010169 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10170 return specifiers;
10171 } finally {
10172 Binder.restoreCallingIdentity(identity);
10173 }
10174 }
10175
10176 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010177 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010178 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010179 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010180 }
10181
10182 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010183 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10184 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010185 if (callingPackage == null) {
10186 callingPackage = getCurrentPackageName();
10187 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010188 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10189 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010190 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10191 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010192 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10193 }
10194 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10195 Intent intent = new Intent();
10196 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10197 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10198 // Bring up choose default SMS subscription dialog right now
10199 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10200 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10201 mApp.startActivity(intent);
10202 }
chen xud5ca2d52019-05-28 15:20:57 -070010203
10204 @Override
10205 public String getMmsUAProfUrl(int subId) {
10206 //TODO investigate if this API should require proper permission check in R b/133791609
10207 final long identity = Binder.clearCallingIdentity();
10208 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010209 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10210 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10211 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10212 return carrierUAProfUrl;
10213 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010214 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10215 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010216 } finally {
10217 Binder.restoreCallingIdentity(identity);
10218 }
10219 }
10220
10221 @Override
10222 public String getMmsUserAgent(int subId) {
10223 //TODO investigate if this API should require proper permission check in R b/133791609
10224 final long identity = Binder.clearCallingIdentity();
10225 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010226 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10227 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10228 if (!TextUtils.isEmpty(carrierUserAgent)) {
10229 return carrierUserAgent;
10230 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010231 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10232 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010233 } finally {
10234 Binder.restoreCallingIdentity(identity);
10235 }
10236 }
Jack Yub07d4972019-05-28 16:12:25 -070010237
10238 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010239 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10240 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010241
Jack Yub07d4972019-05-28 16:12:25 -070010242 final long identity = Binder.clearCallingIdentity();
10243 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010244 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010245 if (phone == null) return false;
10246
Ling Maf188d502022-09-16 15:22:36 -070010247 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010248 } finally {
10249 Binder.restoreCallingIdentity(identity);
10250 }
10251 }
10252
10253 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010254 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010255 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010256 enforceModifyPermission();
10257
changbettyd5c246e2019-12-24 15:40:37 +080010258 final long identity = Binder.clearCallingIdentity();
10259 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010260 Phone phone = getPhone(subscriptionId);
10261 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010262
Ling Maf188d502022-09-16 15:22:36 -070010263 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010264 } finally {
10265 Binder.restoreCallingIdentity(identity);
10266 }
10267 }
10268
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010269 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010270 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010271 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10272 * otherwise.
10273 */
10274 @Override
10275 public void setCepEnabled(boolean isCepEnabled) {
10276 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10277
10278 final long identity = Binder.clearCallingIdentity();
10279 try {
10280 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10281 for (Phone phone : PhoneFactory.getPhones()) {
10282 Phone defaultPhone = phone.getImsPhone();
10283 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10284 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10285 ImsPhoneCallTracker imsPhoneCallTracker =
10286 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10287 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10288 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10289 + imsPhone.getMsisdn());
10290 }
10291 }
10292 } finally {
10293 Binder.restoreCallingIdentity(identity);
10294 }
10295 }
allenwtsu46dcc572020-01-08 18:24:03 +080010296
10297 /**
10298 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10299 *
10300 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10301 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10302 * before being read.
10303 */
10304 @Override
10305 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10306 isCompressed) {
10307 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10308 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010309 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10310 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10311 }
10312 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010313 // ProvisioningManager can not handle ServiceSpecificException.
10314 // Throw the IllegalStateException and annotate ProvisioningManager.
10315 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010316 }
10317
10318 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010319 try {
Hui Wang761a6682020-10-31 05:12:53 +000010320 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10321 } finally {
10322 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010323 }
10324 }
zoey chene02881a2019-12-30 16:11:23 +080010325
10326 @Override
10327 public boolean isIccLockEnabled(int subId) {
10328 enforceReadPrivilegedPermission("isIccLockEnabled");
10329
10330 // Now that all security checks passes, perform the operation as ourselves.
10331 final long identity = Binder.clearCallingIdentity();
10332 try {
10333 Phone phone = getPhone(subId);
10334 if (phone != null && phone.getIccCard() != null) {
10335 return phone.getIccCard().getIccLockEnabled();
10336 } else {
10337 return false;
10338 }
10339 } finally {
10340 Binder.restoreCallingIdentity(identity);
10341 }
10342 }
10343
10344 /**
10345 * Set the ICC pin lock enabled or disabled.
10346 *
10347 * @return an integer representing the status of IccLock enabled or disabled in the following
10348 * three cases:
10349 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10350 * successfully.
10351 * - Positive number and zero for remaining password attempts.
10352 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10353 *
10354 */
10355 @Override
10356 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10357 enforceModifyPermission();
10358
10359 Phone phone = getPhone(subId);
10360 if (phone == null) {
10361 return 0;
10362 }
10363 // Now that all security checks passes, perform the operation as ourselves.
10364 final long identity = Binder.clearCallingIdentity();
10365 try {
10366 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10367 new Pair<Boolean, String>(enabled, password), phone, null);
10368 return attemptsRemaining;
10369
10370 } catch (Exception e) {
10371 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10372 } finally {
10373 Binder.restoreCallingIdentity(identity);
10374 }
10375 return 0;
10376 }
10377
10378 /**
10379 * Change the ICC password used in ICC pin lock.
10380 *
10381 * @return an integer representing the status of IccLock changed in the following three cases:
10382 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10383 * - Positive number and zero for remaining password attempts.
10384 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10385 *
10386 */
10387 @Override
10388 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10389 enforceModifyPermission();
10390
10391 Phone phone = getPhone(subId);
10392 if (phone == null) {
10393 return 0;
10394 }
10395 // Now that all security checks passes, perform the operation as ourselves.
10396 final long identity = Binder.clearCallingIdentity();
10397 try {
10398 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10399 new Pair<String, String>(oldPassword, newPassword), phone, null);
10400 return attemptsRemaining;
10401
10402 } catch (Exception e) {
10403 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10404 } finally {
10405 Binder.restoreCallingIdentity(identity);
10406 }
10407 return 0;
10408 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010409
10410 /**
10411 * Request for receiving user activity notification
10412 */
10413 @Override
10414 public void requestUserActivityNotification() {
10415 if (!mNotifyUserActivity.get()
10416 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10417 mNotifyUserActivity.set(true);
10418 }
10419 }
10420
10421 /**
10422 * Called when userActivity is signalled in the power manager.
10423 * This is safe to call from any thread, with any window manager locks held or not.
10424 */
10425 @Override
10426 public void userActivity() {
10427 // ***************************************
10428 // * Inherited from PhoneWindowManager *
10429 // ***************************************
10430 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10431 // WITH ITS LOCKS HELD.
10432 //
10433 // This code must be VERY careful about the locks
10434 // it acquires.
10435 // In fact, the current code acquires way too many,
10436 // and probably has lurking deadlocks.
10437
10438 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10439 throw new SecurityException("Only the OS may call notifyUserActivity()");
10440 }
10441
10442 if (mNotifyUserActivity.getAndSet(false)) {
10443 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10444 USER_ACTIVITY_NOTIFICATION_DELAY);
10445 }
10446 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010447
10448 @Override
10449 public boolean canConnectTo5GInDsdsMode() {
10450 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10451 }
Jack Yud10cdd42020-09-28 20:28:01 -070010452
10453 @Override
10454 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10455 String callingFeatureId) {
10456 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10457 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10458 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10459 }
10460
10461 Phone phone = getPhone(subId);
10462 if (phone == null) {
10463 throw new RuntimeException("phone is not available");
10464 }
10465 // Now that all security checks passes, perform the operation as ourselves.
10466 final long identity = Binder.clearCallingIdentity();
10467 try {
10468 return phone.getEquivalentHomePlmns();
10469 } finally {
10470 Binder.restoreCallingIdentity(identity);
10471 }
10472 }
Daniel Bright59e67312020-11-13 11:49:37 -080010473
10474 @Override
10475 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010476 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10477 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010478 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010479 if (radioInterfaceCapabilities == null) {
10480 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010481 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010482 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010483 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010484
Hui Wang641e81c2020-10-12 12:14:23 -070010485 @Override
10486 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10487 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010488 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10489 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10490 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10491 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10492 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010493 if (DBG) {
10494 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10495 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10496 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10497 }
10498
10499 if (!SubscriptionManager.isValidSubscriptionId(subId)
10500 || appType < TelephonyManager.APPTYPE_UNKNOWN
10501 || appType > TelephonyManager.APPTYPE_ISIM
10502 || nafUrl == null || securityProtocol == null || callback == null) {
10503 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10504 if (callback != null) {
10505 try {
10506 callback.onAuthenticationFailure(
10507 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10508 } catch (RemoteException exception) {
10509 log("Fail to notify onAuthenticationFailure due to " + exception);
10510 }
10511 return;
10512 }
10513 }
10514
10515 final long token = Binder.clearCallingIdentity();
10516 try {
10517 getGbaManager(subId).bootstrapAuthenticationRequest(
10518 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10519 forceBootStrapping, callback));
10520 } finally {
10521 Binder.restoreCallingIdentity(token);
10522 }
10523 }
10524
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010525 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010526 * Attempts to set the radio power state for all phones for thermal reason.
10527 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010528 * requested radio power state will actually be set. See {@link
10529 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10530 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010531 * @param enable {@code true} if trying to turn radio on.
10532 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10533 * false}.
10534 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010535 private boolean setRadioPowerForThermal(boolean enable) {
10536 boolean isPhoneAvailable = false;
10537 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10538 Phone phone = PhoneFactory.getPhone(i);
10539 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010540 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010541 isPhoneAvailable = true;
10542 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010543 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010544
10545 // return true if successfully informed the phone object about the thermal radio power
10546 // request.
10547 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010548 }
10549
10550 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010551 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010552 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10553 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10554 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10555 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10556 throw new IllegalArgumentException("modem does not support data throttling");
10557 }
10558
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010559 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10560 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010561 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010562 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10563 }
10564
Sarah Chinecc78c42022-03-31 21:16:48 -070010565 setDataEnabledForReason(
10566 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010567
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010568 if (isDataThrottlingSupported) {
10569 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010570 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010571 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10572 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10573 } else if (thermalMitigationResult
10574 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010575 log("Modem likely does not support data throttling on secondary carrier. Data " +
10576 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10577 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010578 }
10579 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010580 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010581
10582 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010583 }
10584
Jack Nudelman644b91a2021-03-12 14:09:48 -080010585 private static List<String> getThermalMitigationAllowlist(Context context) {
10586 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10587 for (String pckg : context.getResources()
10588 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10589 sThermalMitigationAllowlistedPackages.add(pckg);
10590 }
10591 }
10592
10593 return sThermalMitigationAllowlistedPackages;
10594 }
10595
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010596 private boolean isAnyPhoneInEmergencyState() {
10597 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10598 if (tm.isInEmergencyCall()) {
10599 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10600 return true;
10601 }
10602 for (Phone phone : PhoneFactory.getPhones()) {
10603 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10604 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10605 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10606 + phone.isInEcm());
10607 return true;
10608 }
10609 }
10610
10611 return false;
10612 }
10613
Jack Nudelman644b91a2021-03-12 14:09:48 -080010614 /**
10615 * Used by shell commands to add an authorized package name for thermal mitigation.
10616 * @param packageName name of package to be allowlisted
10617 * @param context
10618 */
10619 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10620 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10621 sThermalMitigationAllowlistedPackages.add(packageName);
10622 }
10623
10624 /**
10625 * Used by shell commands to remove an authorized package name for thermal mitigation.
10626 * @param packageName name of package to remove from allowlist
10627 * @param context
10628 */
10629 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10630 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10631 sThermalMitigationAllowlistedPackages.remove(packageName);
10632 }
10633
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010634 /**
10635 * Thermal mitigation request to control functionalities at modem.
10636 *
10637 * @param subId the id of the subscription.
10638 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010639 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010640 *
10641 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10642 */
10643 @Override
10644 @ThermalMitigationResult
10645 public int sendThermalMitigationRequest(
10646 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010647 ThermalMitigationRequest thermalMitigationRequest,
10648 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010649 enforceModifyPermission();
10650
Jack Nudelman644b91a2021-03-12 14:09:48 -080010651 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10652 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10653 .contains(callingPackage)) {
10654 throw new SecurityException("Calling package must be configured in the device config. "
10655 + "calling package: " + callingPackage);
10656 }
10657
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010658 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10659 final long identity = Binder.clearCallingIdentity();
10660
10661 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10662 try {
10663 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10664 switch (thermalMitigationAction) {
10665 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10666 thermalMitigationResult =
10667 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010668 thermalMitigationRequest.getDataThrottlingRequest(),
10669 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010670 break;
10671 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10672 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10673 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10674 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10675 }
10676
10677 // Ensure that radio is on. If not able to power on due to phone being
10678 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010679 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010680 thermalMitigationResult =
10681 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10682 break;
10683 }
10684
10685 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010686 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010687 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10688 break;
10689 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10690 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10691 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10692 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10693 }
10694
10695 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10696 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010697 Phone phone = getPhone(subId);
10698 if (phone == null) {
10699 thermalMitigationResult =
10700 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10701 break;
10702 }
10703
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010704 TelephonyConnectionService service =
10705 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010706 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010707 Log.e(LOG_TAG, "An emergency call is pending");
10708 thermalMitigationResult =
10709 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10710 break;
10711 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010712 thermalMitigationResult =
10713 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10714 break;
10715 }
10716 } else {
10717 thermalMitigationResult =
10718 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10719 break;
10720 }
10721
10722 // Turn radio off. If not able to power off due to phone being unavailable,
10723 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010724 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010725 thermalMitigationResult =
10726 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10727 break;
10728 }
10729 thermalMitigationResult =
10730 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10731 break;
10732 default:
10733 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10734 + "not exist. Requested action: " + thermalMitigationAction);
10735 }
10736 } catch (IllegalArgumentException e) {
10737 throw e;
10738 } catch (Exception e) {
10739 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10740 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10741 } finally {
10742 Binder.restoreCallingIdentity(identity);
10743 }
10744
10745 if (DBG) {
10746 log("thermalMitigationRequest returning with thermalMitigationResult: "
10747 + thermalMitigationResult);
10748 }
10749
10750 return thermalMitigationResult;
10751 }
Hui Wang641e81c2020-10-12 12:14:23 -070010752
10753 /**
10754 * Set the GbaService Package Name that Telephony will bind to.
10755 *
10756 * @param subId The sim that the GbaService is associated with.
10757 * @param packageName The name of the package to be replaced with.
10758 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10759 */
10760 @Override
10761 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10762 enforceModifyPermission();
10763
10764 final long identity = Binder.clearCallingIdentity();
10765 try {
10766 return getGbaManager(subId).overrideServicePackage(packageName);
10767 } finally {
10768 Binder.restoreCallingIdentity(identity);
10769 }
10770 }
10771
10772 /**
10773 * Return the package name of the currently bound GbaService.
10774 *
10775 * @param subId The sim that the GbaService is associated with.
10776 * @return the package name of the GbaService configuration, null if GBA is not supported.
10777 */
10778 @Override
10779 public String getBoundGbaService(int subId) {
10780 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10781
10782 final long identity = Binder.clearCallingIdentity();
10783 try {
10784 return getGbaManager(subId).getServicePackage();
10785 } finally {
10786 Binder.restoreCallingIdentity(identity);
10787 }
10788 }
10789
10790 /**
10791 * Set the release time for telephony to unbind GbaService.
10792 *
10793 * @param subId The sim that the GbaService is associated with.
10794 * @param interval The release time to unbind GbaService by millisecond.
10795 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10796 */
10797 @Override
10798 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10799 enforceModifyPermission();
10800
10801 final long identity = Binder.clearCallingIdentity();
10802 try {
10803 return getGbaManager(subId).overrideReleaseTime(interval);
10804 } finally {
10805 Binder.restoreCallingIdentity(identity);
10806 }
10807 }
10808
10809 /**
10810 * Return the release time for telephony to unbind GbaService.
10811 *
10812 * @param subId The sim that the GbaService is associated with.
10813 * @return The release time to unbind GbaService by millisecond.
10814 */
10815 @Override
10816 public int getGbaReleaseTime(int subId) {
10817 enforceReadPrivilegedPermission("getGbaReleaseTime");
10818
10819 final long identity = Binder.clearCallingIdentity();
10820 try {
10821 return getGbaManager(subId).getReleaseTime();
10822 } finally {
10823 Binder.restoreCallingIdentity(identity);
10824 }
10825 }
10826
10827 private GbaManager getGbaManager(int subId) {
10828 GbaManager instance = GbaManager.getInstance(subId);
10829 if (instance == null) {
10830 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10831 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10832 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10833 }
10834 return instance;
10835 }
Hui Wang761a6682020-10-31 05:12:53 +000010836
10837 /**
10838 * indicate whether the device and the carrier can support
10839 * RCS VoLTE single registration.
10840 */
10841 @Override
10842 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010843 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10844 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10845 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10846 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010847
10848 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10849 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10850 }
10851
10852 final long identity = Binder.clearCallingIdentity();
10853 try {
10854 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10855 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010856 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10857 if (isCapable != null) {
10858 return isCapable;
10859 }
Hui Wang761a6682020-10-31 05:12:53 +000010860 }
Hui Wang67af90e2021-06-04 16:57:15 -070010861 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10862 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010863 } finally {
10864 Binder.restoreCallingIdentity(identity);
10865 }
10866 }
10867
10868 /**
10869 * Register RCS provisioning callback.
10870 */
10871 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010872 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010873 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010874 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010875 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010876 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10877 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010878
10879 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10880 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10881 }
10882 if (!isImsAvailableOnDevice()) {
10883 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10884 "IMS not available on device.");
10885 }
10886
10887 final long identity = Binder.clearCallingIdentity();
10888 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010889 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010890 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010891 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10892 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010893 }
Hui Wang761a6682020-10-31 05:12:53 +000010894 } finally {
10895 Binder.restoreCallingIdentity(identity);
10896 }
10897 }
10898
10899 /**
10900 * Unregister RCS provisioning callback.
10901 */
10902 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010903 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010904 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010905 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010906 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010907 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10908 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010909
10910 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10911 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10912 }
10913 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010914 // operation failed silently
10915 Rlog.w(LOG_TAG, "IMS not available on device.");
10916 return;
Hui Wang761a6682020-10-31 05:12:53 +000010917 }
10918
10919 final long identity = Binder.clearCallingIdentity();
10920 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010921 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010922 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010923 } finally {
10924 Binder.restoreCallingIdentity(identity);
10925 }
10926 }
10927
10928 /**
10929 * trigger RCS reconfiguration.
10930 */
10931 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010932 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10933 "triggerRcsReconfiguration",
10934 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010935
10936 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10937 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10938 }
10939 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010940 // ProvisioningManager can not handle ServiceSpecificException.
10941 // Throw the IllegalStateException and annotate ProvisioningManager.
10942 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010943 }
10944
10945 final long identity = Binder.clearCallingIdentity();
10946 try {
10947 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10948 } finally {
10949 Binder.restoreCallingIdentity(identity);
10950 }
10951 }
10952
10953 /**
10954 * Provide the client configuration parameters of the RCS application.
10955 */
10956 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010957 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10958 "setRcsClientConfiguration",
10959 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010960
10961 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10962 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10963 }
10964 if (!isImsAvailableOnDevice()) {
10965 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10966 "IMS not available on device.");
10967 }
10968
10969 final long identity = Binder.clearCallingIdentity();
10970
10971 try {
10972 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10973 if (configBinder == null) {
10974 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010975 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10976 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010977 } else {
10978 configBinder.setRcsClientConfiguration(rcc);
10979 }
joonhunshin3e154242021-09-17 06:33:39 +000010980
10981 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10982 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010983 } catch (RemoteException e) {
10984 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010985 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10986 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010987 } finally {
10988 Binder.restoreCallingIdentity(identity);
10989 }
10990 }
10991
10992 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010993 * Enables or disables the test mode for RCS VoLTE single registration.
10994 */
10995 @Override
10996 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10997 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10998 "setRcsSingleRegistrationTestModeEnabled");
10999
11000 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11001 }
11002
11003 /**
11004 * Gets the test mode for RCS VoLTE single registration.
11005 */
11006 @Override
11007 public boolean getRcsSingleRegistrationTestModeEnabled() {
11008 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11009 "getRcsSingleRegistrationTestModeEnabled");
11010
11011 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11012 }
11013
11014 /**
Hui Wang761a6682020-10-31 05:12:53 +000011015 * Overrides the config of RCS VoLTE single registration enabled for the device.
11016 */
11017 @Override
11018 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11019 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11020 "setDeviceSingleRegistrationEnabledOverride");
11021 enforceModifyPermission();
11022
11023 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11024 : Boolean.parseBoolean(enabledStr);
11025 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011026 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011027 }
11028
11029 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011030 * Sends a device to device communication message. Only usable via shell.
11031 * @param message message to send.
11032 * @param value message value.
11033 */
11034 @Override
11035 public void sendDeviceToDeviceMessage(int message, int value) {
11036 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011037 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011038 enforceModifyPermission();
11039
11040 final long identity = Binder.clearCallingIdentity();
11041 try {
11042 TelephonyConnectionService service =
11043 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11044 if (service == null) {
11045 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11046 return;
11047 }
11048 service.sendTestDeviceToDeviceMessage(message, value);
11049 } finally {
11050 Binder.restoreCallingIdentity(identity);
11051 }
11052 }
11053
Tyler Gunnbabbda02021-02-10 11:05:02 -080011054 /**
11055 * Sets the specified device to device transport active.
11056 * @param transport The transport to set active.
11057 */
11058 @Override
11059 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11060 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11061 "setActiveDeviceToDeviceTransport");
11062 enforceModifyPermission();
11063
11064 final long identity = Binder.clearCallingIdentity();
11065 try {
11066 TelephonyConnectionService service =
11067 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11068 if (service == null) {
11069 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11070 return;
11071 }
11072 service.setActiveDeviceToDeviceTransport(transport);
11073 } finally {
11074 Binder.restoreCallingIdentity(identity);
11075 }
11076 }
Tyler Gunn92479152021-01-20 16:30:10 -080011077
Tyler Gunnd4339262021-05-03 14:46:49 -070011078 @Override
11079 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11080 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11081 "setDeviceToDeviceForceEnabled");
11082
11083 final long identity = Binder.clearCallingIdentity();
11084 try {
11085 Arrays.stream(PhoneFactory.getPhones()).forEach(
11086 p -> {
11087 Phone thePhone = p.getImsPhone();
11088 if (thePhone != null && thePhone instanceof ImsPhone) {
11089 ImsPhone imsPhone = (ImsPhone) thePhone;
11090 CallTracker tracker = imsPhone.getCallTracker();
11091 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11092 ImsPhoneCallTracker imsPhoneCallTracker =
11093 (ImsPhoneCallTracker) tracker;
11094 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11095 }
11096 }
11097 }
11098 );
11099 } finally {
11100 Binder.restoreCallingIdentity(identity);
11101 }
11102 }
11103
Tyler Gunn92479152021-01-20 16:30:10 -080011104 /**
Hui Wang761a6682020-10-31 05:12:53 +000011105 * Gets the config of RCS VoLTE single registration enabled for the device.
11106 */
11107 @Override
11108 public boolean getDeviceSingleRegistrationEnabled() {
11109 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11110 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11111 }
11112
11113 /**
11114 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11115 */
11116 @Override
11117 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11118 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11119 "setCarrierSingleRegistrationEnabledOverride");
11120 enforceModifyPermission();
11121
11122 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11123 : Boolean.parseBoolean(enabledStr);
11124 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11125 subId, enabled);
11126 }
11127
11128 /**
11129 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11130 */
11131 @Override
11132 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11133 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11134 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11135 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011136
11137 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011138 * Overrides the ims feature validation result
11139 */
11140 @Override
11141 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11142 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11143 "setImsFeatureValidationOverride");
11144
11145 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11146 : Boolean.parseBoolean(enabledStr);
11147 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11148 subId, enabled);
11149 }
11150
11151 /**
11152 * Gets the ims feature validation override value
11153 */
11154 @Override
11155 public boolean getImsFeatureValidationOverride(int subId) {
11156 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11157 "getImsFeatureValidationOverride");
11158 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11159 }
11160
11161 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011162 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11163 * their mobile plan.
11164 */
11165 @Override
11166 public String getMobileProvisioningUrl() {
11167 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11168 final long identity = Binder.clearCallingIdentity();
11169 try {
11170 return getDefaultPhone().getMobileProvisioningUrl();
11171 } finally {
11172 Binder.restoreCallingIdentity(identity);
11173 }
11174 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011175
James.cf Linbcdf8b32021-01-14 16:44:13 +080011176 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011177 * Get the EAB contact from the EAB database.
11178 */
11179 @Override
11180 public String getContactFromEab(String contact) {
11181 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11182 enforceModifyPermission();
11183 final long identity = Binder.clearCallingIdentity();
11184 try {
11185 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11186 } finally {
11187 Binder.restoreCallingIdentity(identity);
11188 }
11189 }
11190
11191 /**
Calvin Pana1434322021-07-01 19:27:01 +080011192 * Get the EAB capability from the EAB database.
11193 */
11194 @Override
11195 public String getCapabilityFromEab(String contact) {
11196 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11197 enforceModifyPermission();
11198 final long identity = Binder.clearCallingIdentity();
11199 try {
11200 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11201 } finally {
11202 Binder.restoreCallingIdentity(identity);
11203 }
11204 }
11205
11206 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011207 * Remove the EAB contacts from the EAB database.
11208 */
11209 @Override
11210 public int removeContactFromEab(int subId, String contacts) {
11211 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11212 enforceModifyPermission();
11213 final long identity = Binder.clearCallingIdentity();
11214 try {
11215 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11216 } finally {
11217 Binder.restoreCallingIdentity(identity);
11218 }
11219 }
11220
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011221 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011222 public boolean getDeviceUceEnabled() {
11223 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11224 final long identity = Binder.clearCallingIdentity();
11225 try {
11226 return mApp.getDeviceUceEnabled();
11227 } finally {
11228 Binder.restoreCallingIdentity(identity);
11229 }
11230 }
11231
11232 @Override
11233 public void setDeviceUceEnabled(boolean isEnabled) {
11234 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11235 final long identity = Binder.clearCallingIdentity();
11236 try {
11237 mApp.setDeviceUceEnabled(isEnabled);
11238 } finally {
11239 Binder.restoreCallingIdentity(identity);
11240 }
11241 }
11242
Brad Ebinger14d467f2021-02-12 06:18:28 +000011243 /**
11244 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11245 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11246 */
11247 // Used for SHELL command only right now.
11248 @Override
11249 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11250 List<String> featureTags) {
11251 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11252 "addUceRegistrationOverrideShell");
11253 final long identity = Binder.clearCallingIdentity();
11254 try {
11255 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11256 new ArraySet<>(featureTags));
11257 } catch (ImsException e) {
11258 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11259 } finally {
11260 Binder.restoreCallingIdentity(identity);
11261 }
11262 }
11263
11264 /**
11265 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11266 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11267 */
11268 // Used for SHELL command only right now.
11269 @Override
11270 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11271 List<String> featureTags) {
11272 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11273 "removeUceRegistrationOverrideShell");
11274 final long identity = Binder.clearCallingIdentity();
11275 try {
11276 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11277 new ArraySet<>(featureTags));
11278 } catch (ImsException e) {
11279 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11280 } finally {
11281 Binder.restoreCallingIdentity(identity);
11282 }
11283 }
11284
11285 /**
11286 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11287 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11288 */
11289 // Used for SHELL command only right now.
11290 @Override
11291 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11292 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11293 "clearUceRegistrationOverrideShell");
11294 final long identity = Binder.clearCallingIdentity();
11295 try {
11296 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11297 } catch (ImsException e) {
11298 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11299 } finally {
11300 Binder.restoreCallingIdentity(identity);
11301 }
11302 }
11303
11304 /**
11305 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11306 */
11307 // Used for SHELL command only right now.
11308 @Override
11309 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11310 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11311 "getLatestRcsContactUceCapabilityShell");
11312 final long identity = Binder.clearCallingIdentity();
11313 try {
11314 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11315 } catch (ImsException e) {
11316 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11317 } finally {
11318 Binder.restoreCallingIdentity(identity);
11319 }
11320 }
11321
11322 /**
11323 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11324 * device does not have an active PUBLISH.
11325 */
11326 // Used for SHELL command only right now.
11327 @Override
11328 public String getLastUcePidfXmlShell(int subId) {
11329 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11330 final long identity = Binder.clearCallingIdentity();
11331 try {
11332 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11333 } catch (ImsException e) {
11334 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11335 } finally {
11336 Binder.restoreCallingIdentity(identity);
11337 }
11338 }
11339
James.cf Line8713a42021-04-29 16:04:26 +080011340 /**
11341 * Remove UCE requests cannot be sent to the network status.
11342 */
11343 // Used for SHELL command only right now.
11344 @Override
11345 public boolean removeUceRequestDisallowedStatus(int subId) {
11346 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11347 final long identity = Binder.clearCallingIdentity();
11348 try {
11349 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11350 } catch (ImsException e) {
11351 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11352 } finally {
11353 Binder.restoreCallingIdentity(identity);
11354 }
11355 }
11356
James.cf Lin18bb9002021-05-25 01:37:38 +080011357 /**
11358 * Remove UCE requests cannot be sent to the network status.
11359 */
11360 // Used for SHELL command only.
11361 @Override
11362 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11363 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11364 final long identity = Binder.clearCallingIdentity();
11365 try {
11366 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11367 } catch (ImsException e) {
11368 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11369 } finally {
11370 Binder.restoreCallingIdentity(identity);
11371 }
11372 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011373
James.cf Lin4b784aa2021-01-31 03:25:15 +080011374 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011375 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11376 String callingPackage) {
11377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11378 mApp, subId, "setSignalStrengthUpdateRequest");
11379
11380 final int callingUid = Binder.getCallingUid();
11381 // Verify that tha callingPackage belongs to the calling UID
11382 mApp.getSystemService(AppOpsManager.class)
11383 .checkPackage(callingUid, callingPackage);
11384
Rambo Wang3607f502021-02-01 21:51:40 -080011385 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011386
11387 final long identity = Binder.clearCallingIdentity();
11388 try {
11389 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11390 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11391
11392 if (result instanceof IllegalStateException) {
11393 throw (IllegalStateException) result;
11394 }
11395 } finally {
11396 Binder.restoreCallingIdentity(identity);
11397 }
11398 }
11399
11400 @Override
11401 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11402 String callingPackage) {
11403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11404 mApp, subId, "clearSignalStrengthUpdateRequest");
11405
11406 final int callingUid = Binder.getCallingUid();
11407 // Verify that tha callingPackage belongs to the calling UID
11408 mApp.getSystemService(AppOpsManager.class)
11409 .checkPackage(callingUid, callingPackage);
11410
11411 final long identity = Binder.clearCallingIdentity();
11412 try {
11413 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11414 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11415
11416 if (result instanceof IllegalStateException) {
11417 throw (IllegalStateException) result;
11418 }
11419 } finally {
11420 Binder.restoreCallingIdentity(identity);
11421 }
11422 }
11423
Rambo Wang3607f502021-02-01 21:51:40 -080011424 private static void validateSignalStrengthUpdateRequest(Context context,
11425 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011426 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11427 // phone/system process do not have further restriction on request
11428 return;
11429 }
11430
11431 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011432 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011433 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011434 context.enforceCallingOrSelfPermission(
11435 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11436 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011437 }
11438
11439 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011440 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011441 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011442 || info.isEnabled()) {
11443 throw new IllegalArgumentException(
11444 "Only system can set hide fields in SignalThresholdInfo");
11445 }
11446
11447 // Thresholds length for each RAN need in range. This has been validated in
11448 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11449 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11450 final int[] thresholds = info.getThresholds();
11451 Objects.requireNonNull(thresholds);
11452 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11453 || thresholds.length
11454 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11455 throw new IllegalArgumentException(
11456 "thresholds length is out of range: " + thresholds.length);
11457 }
11458 }
11459 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011460
11461 /**
11462 * Gets the current phone capability.
11463 *
11464 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11465 * @return the PhoneCapability which describes the data connection capability of modem.
11466 * It's used to evaluate possible phone config change, for example from single
11467 * SIM device to multi-SIM device.
11468 */
11469 @Override
11470 public PhoneCapability getPhoneCapability() {
11471 enforceReadPrivilegedPermission("getPhoneCapability");
11472 final long identity = Binder.clearCallingIdentity();
11473 try {
11474 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11475 } finally {
11476 Binder.restoreCallingIdentity(identity);
11477 }
11478 }
Michele Berionne5e411512020-11-13 02:36:59 +000011479
11480 /**
11481 * Prepare TelephonyManager for an unattended reboot. The reboot is
11482 * required to be done shortly after the API is invoked.
11483 */
11484 @Override
11485 @TelephonyManager.PrepareUnattendedRebootResult
11486 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011487 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011488 enforceRebootPermission();
11489
11490 final long identity = Binder.clearCallingIdentity();
11491 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011492 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011493 } finally {
11494 Binder.restoreCallingIdentity(identity);
11495 }
11496 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011497
11498 /**
11499 * Request to get the current slicing configuration including URSP rules and
11500 * NSSAIs (configured, allowed and rejected).
11501 *
11502 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11503 */
11504 @Override
11505 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011506 TelephonyPermissions
11507 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11508 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011509
11510 final long identity = Binder.clearCallingIdentity();
11511 try {
11512 Phone phone = getDefaultPhone();
11513 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11514 } finally {
11515 Binder.restoreCallingIdentity(identity);
11516 }
11517 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011518
11519 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011520 * Check whether the given premium capability is available for purchase from the carrier.
11521 *
11522 * @param capability The premium capability to check.
11523 * @param subId The subId to check the premium capability for.
11524 *
11525 * @return Whether the given premium capability is available to purchase.
11526 */
11527 @Override
11528 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11529 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11530 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11531 log("Premium capability "
11532 + TelephonyManager.convertPremiumCapabilityToString(capability)
11533 + " is not available for purchase due to missing permissions.");
11534 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11535 + "permission READ_BASIC_PHONE_STATE.");
11536 }
11537
11538 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011539 if (phone == null) {
11540 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11541 return false;
11542 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011543 final long identity = Binder.clearCallingIdentity();
11544 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011545 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011546 .isPremiumCapabilityAvailableForPurchase(capability);
11547 } finally {
11548 Binder.restoreCallingIdentity(identity);
11549 }
11550 }
11551
11552 /**
11553 * Purchase the given premium capability from the carrier.
11554 *
11555 * @param capability The premium capability to purchase.
11556 * @param callback The result of the purchase request.
11557 * @param subId The subId to purchase the premium capability for.
11558 */
11559 @Override
11560 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11561 log("purchasePremiumCapability: capability="
11562 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11563 + getCurrentPackageName());
11564
11565 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11566 mApp, "purchasePremiumCapability")) {
11567 log("purchasePremiumCapability "
11568 + TelephonyManager.convertPremiumCapabilityToString(capability)
11569 + " failed due to missing permissions.");
11570 throw new SecurityException("purchasePremiumCapability requires permission "
11571 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011572 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11573 mApp, "purchasePremiumCapability")) {
11574 log("purchasePremiumCapability "
11575 + TelephonyManager.convertPremiumCapabilityToString(capability)
11576 + " failed due to missing permissions.");
11577 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011578 }
11579
11580 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011581 if (phone == null) {
11582 try {
11583 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11584 callback.accept(result);
11585 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11586 } catch (RemoteException e) {
11587 String logStr = "Purchase premium capability "
11588 + TelephonyManager.convertPremiumCapabilityToString(capability)
11589 + " failed due to RemoteException handling null phone: " + e;
11590 if (DBG) log(logStr);
11591 AnomalyReporter.reportAnomaly(
11592 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11593 }
11594 return;
11595 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011596
11597 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011598 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011599 callingProcess = mApp.getPackageManager().getApplicationInfo(
11600 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011601 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011602 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011603 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011604
11605 boolean isVisible = false;
11606 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11607 if (am != null) {
11608 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11609 if (processes != null) {
11610 for (ActivityManager.RunningAppProcessInfo process : processes) {
11611 log("purchasePremiumCapability: process " + process.processName
11612 + "has importance " + process.importance);
11613 if (process.processName.equals(callingProcess) && process.importance
11614 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11615 isVisible = true;
11616 break;
11617 }
11618 }
11619 }
11620 }
11621
11622 if (!isVisible) {
11623 try {
11624 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11625 callback.accept(result);
11626 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11627 } catch (RemoteException e) {
11628 String logStr = "Purchase premium capability "
11629 + TelephonyManager.convertPremiumCapabilityToString(capability)
11630 + " failed due to RemoteException handling background application: " + e;
11631 if (DBG) log(logStr);
11632 AnomalyReporter.reportAnomaly(
11633 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11634 }
11635 return;
11636 }
11637
Sarah Chin71b3a852022-09-28 15:54:19 -070011638 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011639 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011640 }
11641
11642 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011643 * Register an IMS connection state callback
11644 */
11645 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011646 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11647 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011648 if (feature == ImsFeature.FEATURE_MMTEL) {
11649 // ImsMmTelManager
11650 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11651 TelephonyPermissions
11652 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11653 mApp, subId, "registerImsStateCallback");
11654 } else if (feature == ImsFeature.FEATURE_RCS) {
11655 // ImsRcsManager or SipDelegateManager
11656 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11657 Binder.getCallingUid(), "registerImsStateCallback",
11658 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11659 Manifest.permission.READ_PRECISE_PHONE_STATE,
11660 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11661 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11662 }
11663
11664 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11665 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11666 "IMS not available on device.");
11667 }
11668
11669 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11670 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11671 }
11672
11673 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11674 if (controller == null) {
11675 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11676 "IMS not available on device.");
11677 }
11678
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011679 if (callingPackage == null) {
11680 callingPackage = getCurrentPackageName();
11681 }
11682
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011683 final long token = Binder.clearCallingIdentity();
11684 try {
11685 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011686 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011687 } catch (ImsException e) {
11688 throw new ServiceSpecificException(e.getCode());
11689 } finally {
11690 Binder.restoreCallingIdentity(token);
11691 }
11692 }
11693
11694 /**
11695 * Unregister an IMS connection state callback
11696 */
11697 @Override
11698 public void unregisterImsStateCallback(IImsStateCallback cb) {
11699 final long token = Binder.clearCallingIdentity();
11700 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11701 if (controller == null) {
11702 return;
11703 }
11704 try {
11705 controller.unregisterImsStateCallback(cb);
11706 } finally {
11707 Binder.restoreCallingIdentity(token);
11708 }
11709 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011710
11711 /**
11712 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11713 *
11714 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11715 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11716 * SecurityException.
11717 * If there is current registered network this value will be same as the registered cell
11718 * identity. If the device goes out of service the previous cell identity is cached and
11719 * will be returned. If the cache age of the Cell identity is more than 24 hours
11720 * it will be cleared and null will be returned.
11721 *
11722 */
11723 @Override
11724 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11725 String callingFeatureId) {
11726 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11727 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11728 LocationAccessPolicy.checkLocationPermission(mApp,
11729 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11730 .setCallingPackage(callingPackage)
11731 .setCallingFeatureId(callingFeatureId)
11732 .setCallingPid(Binder.getCallingPid())
11733 .setCallingUid(Binder.getCallingUid())
11734 .setMethod("getLastKnownCellIdentity")
11735 .setLogAsInfo(true)
11736 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11737 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11738 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11739 .build());
11740
11741 boolean hasFinePermission =
11742 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11743 if (!hasFinePermission
11744 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11745 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011746 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011747 }
11748
11749 final long identity = Binder.clearCallingIdentity();
11750 try {
11751 Phone phone = getPhone(subId);
11752 if (phone == null) return null;
11753 ServiceStateTracker sst = phone.getServiceStateTracker();
11754 if (sst == null) return null;
11755 return sst.getLastKnownCellIdentity();
11756 } finally {
11757 Binder.restoreCallingIdentity(identity);
11758 }
11759 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011760
jimsun3b9ccac2021-10-26 15:01:23 +080011761 /**
11762 * Sets the modem service class Name that Telephony will bind to.
11763 *
11764 * @param serviceName The class name of the modem service.
11765 * @return true if the operation is succeed, otherwise false.
11766 */
11767 public boolean setModemService(String serviceName) {
11768 Log.d(LOG_TAG, "setModemService - " + serviceName);
11769 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11771 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11772 "setModemService");
11773 return mPhoneConfigurationManager.setModemService(serviceName);
11774 }
11775
11776 /**
11777 * Return the class name of the currently bounded modem service.
11778 *
11779 * @return the class name of the modem service.
11780 */
11781 public String getModemService() {
11782 String result;
11783 Log.d(LOG_TAG, "getModemService");
11784 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11785 TelephonyPermissions
11786 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11787 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11788 "getModemService");
11789 result = mPhoneConfigurationManager.getModemService();
11790 Log.d(LOG_TAG, "result = " + result);
11791 return result;
11792 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011793
11794 @Override
11795 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11796 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11797 mApp.enforceCallingOrSelfPermission(
11798 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11799 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11800
11801 final long identity = Binder.clearCallingIdentity();
11802 try {
11803 Phone phone = getPhone(subId);
11804 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080011805 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
11806 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011807 phone.setVoiceServiceStateOverride(hasService);
11808 } finally {
11809 Binder.restoreCallingIdentity(identity);
11810 }
11811 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011812
11813 /**
11814 * set removable eSIM as default eUICC.
11815 *
11816 * @hide
11817 */
11818 @Override
11819 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11820 enforceModifyPermission();
11821 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11822
11823 final long identity = Binder.clearCallingIdentity();
11824 try {
11825 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11826 } finally {
11827 Binder.restoreCallingIdentity(identity);
11828 }
11829 }
11830
11831 /**
11832 * Returns whether the removable eSIM is default eUICC or not.
11833 *
11834 * @hide
11835 */
11836 @Override
11837 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11838 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11839 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11840
11841 final long identity = Binder.clearCallingIdentity();
11842 try {
11843 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11844 } finally {
11845 Binder.restoreCallingIdentity(identity);
11846 }
11847 }
11848
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011849 /**
11850 * Get the component name of the default app to direct respond-via-message intent for the
11851 * user associated with this subscription, update the cache if there is no respond-via-message
11852 * application currently configured for this user.
11853 * @return component name of the app and class to direct Respond Via Message intent to, or
11854 * {@code null} if the functionality is not supported.
11855 * @hide
11856 */
11857 @Override
11858 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11859 boolean updateIfNeeded) {
11860 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011861
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000011862 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
11863
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011864 UserHandle userHandle = null;
11865 final long identity = Binder.clearCallingIdentity();
11866 try {
11867 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11868 } finally {
11869 Binder.restoreCallingIdentity(identity);
11870 }
11871 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11872 updateIfNeeded, userHandle);
11873 }
Jack Yuf5badd92022-12-08 00:50:53 -080011874
11875 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011876 * Set whether the device is able to connect with null ciphering or integrity
11877 * algorithms. This is a global setting and will apply to all active subscriptions
11878 * and all new subscriptions after this.
11879 *
11880 * @param enabled when true, null cipher and integrity algorithms are allowed.
11881 * @hide
11882 */
11883 @Override
11884 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11885 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11886 enforceModifyPermission();
11887 checkForNullCipherAndIntegritySupport();
11888
11889 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11890 // for listening to these preference changes and applying them immediately.
11891 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11892 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11893 editor.apply();
11894
11895 for (Phone phone: PhoneFactory.getPhones()) {
11896 phone.handleNullCipherEnabledChange();
11897 }
11898 }
11899
11900
11901 /**
11902 * Get whether the device is able to connect with null ciphering or integrity
11903 * algorithms. Note that this retrieves the phone-global preference and not
11904 * the state of the radio.
11905 *
11906 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11907 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11908 * version for this feature.
11909 * @hide
11910 */
11911 @Override
11912 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11913 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11914 enforceReadPermission();
11915 checkForNullCipherAndIntegritySupport();
11916 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11917 }
11918
11919 private void checkForNullCipherAndIntegritySupport() {
11920 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11921 throw new UnsupportedOperationException(
11922 "Null cipher and integrity operations require HAL 2.1 or above");
11923 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000011924 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
11925 throw new UnsupportedOperationException(
11926 "Null cipher and integrity operations unsupported by modem");
11927 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011928 }
11929
11930 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011931 * Get the SIM state for the slot index.
11932 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11933 *
11934 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11935 */
11936 @Override
11937 @SimState
11938 public int getSimStateForSlotIndex(int slotIndex) {
11939 IccCardConstants.State simState;
11940 if (slotIndex < 0) {
11941 simState = IccCardConstants.State.UNKNOWN;
11942 } else {
11943 Phone phone = null;
11944 try {
11945 phone = PhoneFactory.getPhone(slotIndex);
11946 } catch (IllegalStateException e) {
11947 // ignore
11948 }
11949 if (phone == null) {
11950 simState = IccCardConstants.State.UNKNOWN;
11951 } else {
11952 IccCard icc = phone.getIccCard();
11953 if (icc == null) {
11954 simState = IccCardConstants.State.UNKNOWN;
11955 } else {
11956 simState = icc.getState();
11957 }
11958 }
11959 }
11960 return simState.ordinal();
11961 }
Hui Wang9b5793a2022-12-05 14:38:06 -060011962
11963 /**
11964 * Get current cell broadcast ranges.
11965 */
11966 @Override
11967 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
11968 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
11969 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
11970 "getCellBroadcastIdRanges");
11971 final long identity = Binder.clearCallingIdentity();
11972 try {
11973 return getPhone(subId).getCellBroadcastIdRanges();
11974 } finally {
11975 Binder.restoreCallingIdentity(identity);
11976 }
11977 }
11978
11979 /**
11980 * Set reception of cell broadcast messages with the list of the given ranges
11981 *
11982 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
11983 */
11984 @Override
11985 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
11986 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
11987 @Nullable IIntegerConsumer callback) {
11988 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
11989 "setCellBroadcastIdRanges");
11990 final long identity = Binder.clearCallingIdentity();
11991 try {
11992 Phone phone = getPhoneFromSubId(subId);
11993 if (DBG) {
11994 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
11995 }
11996 phone.setCellBroadcastIdRanges(ranges, result -> {
11997 if (callback != null) {
11998 try {
11999 callback.accept(result);
12000 } catch (RemoteException e) {
12001 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12002 }
12003 }
12004 });
12005 } finally {
12006 Binder.restoreCallingIdentity(identity);
12007 }
12008 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012009
12010 /**
12011 * Returns whether the device supports the domain selection service.
12012 *
12013 * @return {@code true} if the device supports the domain selection service.
12014 */
12015 @Override
12016 public boolean isDomainSelectionSupported() {
12017 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12018 "isDomainSelectionSupported");
12019
12020 final long identity = Binder.clearCallingIdentity();
12021 try {
12022 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12023 } finally {
12024 Binder.restoreCallingIdentity(identity);
12025 }
12026 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012027
12028 /**
12029 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12030 *
12031 * <p>This method behaves in one of the following ways:
12032 * <ul>
12033 * <li>return true : if the calling package has the appop permission {@link
12034 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12035 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12036 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12037 * Owner device identifier access check, or the calling package has carrier privileges</>
12038 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12039 * </ul>
12040 */
12041 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12042 String callingPackage, @Nullable String callingFeatureId, String message) {
12043 for (Phone phone : PhoneFactory.getPhones()) {
12044 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12045 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12046 return true;
12047 }
12048 }
12049 return false;
12050 }
arunvoddud7401012022-12-15 16:08:12 +000012051
12052 /**
12053 * Class binds the consumer[callback] and carrierId.
12054 */
12055 private static class CallerCallbackInfo {
12056 private final Consumer<Integer> mConsumer;
12057 private final int mCarrierId;
12058
12059 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12060 mConsumer = consumer;
12061 mCarrierId = carrierId;
12062 }
12063
12064 public Consumer<Integer> getConsumer() {
12065 return mConsumer;
12066 }
12067
12068 public int getCarrierId() {
12069 return mCarrierId;
12070 }
12071 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012072}