blob: ccef4d8e27279b6d3151813e02e5bd73a4e97800 [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;
Gil Cukierman6dac5eb2022-09-19 16:09:04 +0000403 private final Telephony2gUpdater mTelephony2gUpdater;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404
Peter Wangdafb9ac2020-01-15 14:13:38 -0800405 /** User Activity */
406 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800407 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
408
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700409 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
410
Derek Tan97ebb422014-09-05 16:55:38 -0700411 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
412 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800413 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800414 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700415
Michelecea4cf22018-12-21 15:00:11 -0800416 // String to store multi SIM allowed
417 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
418
Derek Tan740e1672017-06-27 14:56:27 -0700419 // The AID of ISD-R.
420 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
421
yinxub1bed742017-04-17 11:45:04 -0700422 private NetworkScanRequestTracker mNetworkScanRequestTracker;
423
David Kelly5e06a7f2018-03-12 14:10:59 +0000424 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
425 private static final int MANUFACTURER_CODE_LENGTH = 8;
426
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800427 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800428 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800429
Sarah Chin2ec39f62022-08-31 17:03:26 -0700430 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
431 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
432
Derek Tan89e89d42014-07-08 17:00:10 -0700433 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700434 * Experiment flag to enable erase modem config on reset network, default value is false
435 */
436 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
437 "reset_network_erase_modem_config_enabled";
438
Rambo Wang0f050d82021-02-12 11:43:36 -0800439 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800440
Gary Jian76280a42022-12-07 16:18:33 +0800441 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
442
sandeepjsb6c87872021-09-27 15:34:44 +0000443 /**
444 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
445 * one ICCID active at the same time.
446 * Apps should use below API signatures if targeting SDK is T and beyond.
447 *
448 * @hide
449 */
450 @ChangeId
451 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
452 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800453
Naina Nallurid63128d2019-09-17 14:10:30 -0700454 /**
Chen Xu540470b2021-12-14 17:15:47 -0800455 * Apps targeting on Android T and beyond will get exception whenever icc close channel
456 * operation fails.
457 */
458 @ChangeId
459 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
460 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
461
462 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700463 * A request object to use for transmitting data to an ICC.
464 */
465 private static final class IccAPDUArgument {
466 public int channel, cla, command, p1, p2, p3;
467 public String data;
468
469 public IccAPDUArgument(int channel, int cla, int command,
470 int p1, int p2, int p3, String data) {
471 this.channel = channel;
472 this.cla = cla;
473 this.command = command;
474 this.p1 = p1;
475 this.p2 = p2;
476 this.p3 = p3;
477 this.data = data;
478 }
479 }
480
481 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700482 * A request object to use for transmitting data to an ICC.
483 */
484 private static final class ManualNetworkSelectionArgument {
485 public OperatorInfo operatorInfo;
486 public boolean persistSelection;
487
488 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
489 this.operatorInfo = operatorInfo;
490 this.persistSelection = persistSelection;
491 }
492 }
493
Sarah Chin71b3a852022-09-28 15:54:19 -0700494 private static final class PurchasePremiumCapabilityArgument {
495 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700496 public @NonNull IIntegerConsumer callback;
497
498 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800499 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700500 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700501 this.callback = callback;
502 }
503 }
504
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700505 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700506 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
507 * request after sending. The main thread will notify the request when it is complete.
508 */
509 private static final class MainThreadRequest {
510 /** The argument to use for the request */
511 public Object argument;
512 /** The result of the request that is run on the main thread */
513 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800514 // The subscriber id that this request applies to. Defaults to
515 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
516 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700517
Nathan Harold92bed182018-10-12 18:16:49 -0700518 // In cases where subId is unavailable, the caller needs to specify the phone.
519 public Phone phone;
520
vagdeviaf9a5b92018-08-15 16:01:53 -0700521 public WorkSource workSource;
522
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700523 public MainThreadRequest(Object argument) {
524 this.argument = argument;
525 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800526
Nathan Harold92bed182018-10-12 18:16:49 -0700527 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
528 this.argument = argument;
529 if (phone != null) {
530 this.phone = phone;
531 }
532 this.workSource = workSource;
533 }
534
vagdeviaf9a5b92018-08-15 16:01:53 -0700535 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800536 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800537 if (subId != null) {
538 this.subId = subId;
539 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700540 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800541 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700542 }
543
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800544 private static final class IncomingThirdPartyCallArgs {
545 public final ComponentName component;
546 public final String callId;
547 public final String callerDisplayName;
548
549 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
550 String callerDisplayName) {
551 this.component = component;
552 this.callId = callId;
553 this.callerDisplayName = callerDisplayName;
554 }
555 }
556
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700557 /**
558 * A handler that processes messages on the main thread in the phone process. Since many
559 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
560 * inbound binder threads to the main thread in the phone process. The Binder thread
561 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
562 * on, which will be notified when the operation completes and will contain the result of the
563 * request.
564 *
565 * <p>If a MainThreadRequest object is provided in the msg.obj field,
566 * note that request.result must be set to something non-null for the calling thread to
567 * unblock.
568 */
569 private final class MainThreadHandler extends Handler {
570 @Override
571 public void handleMessage(Message msg) {
572 MainThreadRequest request;
573 Message onCompleted;
574 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000575 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700576 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800577 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700578
579 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700580 case CMD_HANDLE_USSD_REQUEST: {
581 request = (MainThreadRequest) msg.obj;
582 final Phone phone = getPhoneFromRequest(request);
583 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800584 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700585 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700586
Pengquan Menga1bb6272018-09-06 09:59:22 -0700587 if (!isUssdApiAllowed(request.subId)) {
588 // Carrier does not support use of this API, return failure.
589 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
590 UssdResponse response = new UssdResponse(ussdRequest, null);
591 Bundle returnData = new Bundle();
592 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
593 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700594
Pengquan Menga1bb6272018-09-06 09:59:22 -0700595 request.result = true;
596 notifyRequester(request);
597 return;
598 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700599
Pengquan Menga1bb6272018-09-06 09:59:22 -0700600 try {
601 request.result = phone != null
602 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
603 } catch (CallStateException cse) {
604 request.result = false;
605 }
606 // Wake up the requesting thread
607 notifyRequester(request);
608 break;
pkanwar32d516d2016-10-14 19:37:38 -0700609 }
610
Yorke Lee716f67e2015-06-17 15:39:16 -0700611 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700612 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700613 final Phone phone = getPhoneFromRequest(request);
614 request.result = phone != null ?
615 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
616 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700617 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700618 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700619 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700621
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700622 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700624 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000625 uiccPort = getUiccPortFromRequest(request);
626 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700627 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800628 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700630 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700631 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800632 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000633 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800634 iccArgument.channel, iccArgument.cla, iccArgument.command,
635 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
636 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700637 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 break;
639
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700640 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 ar = (AsyncResult) msg.obj;
642 request = (MainThreadRequest) ar.userObj;
643 if (ar.exception == null && ar.result != null) {
644 request.result = ar.result;
645 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800646 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 if (ar.result == null) {
648 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800649 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800651 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 } else {
653 loge("iccTransmitApduLogicalChannel: Unknown exception");
654 }
655 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 break;
658
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700659 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
660 request = (MainThreadRequest) msg.obj;
661 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000662 uiccPort = getUiccPortFromRequest(request);
663 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700664 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800665 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700666 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 } else {
668 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800669 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000670 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800671 iccArgument.cla, iccArgument.command, iccArgument.p1,
672 iccArgument.p2,
673 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700674 }
675 break;
676
677 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
678 ar = (AsyncResult) msg.obj;
679 request = (MainThreadRequest) ar.userObj;
680 if (ar.exception == null && ar.result != null) {
681 request.result = ar.result;
682 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800683 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700684 if (ar.result == null) {
685 loge("iccTransmitApduBasicChannel: Empty response");
686 } else if (ar.exception instanceof CommandException) {
687 loge("iccTransmitApduBasicChannel: CommandException: " +
688 ar.exception);
689 } else {
690 loge("iccTransmitApduBasicChannel: Unknown exception");
691 }
692 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700693 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700694 break;
695
696 case CMD_EXCHANGE_SIM_IO:
697 request = (MainThreadRequest) msg.obj;
698 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000699 uiccPort = getUiccPortFromRequest(request);
700 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700701 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800702 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700703 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700704 } else {
705 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
706 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000707 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
709 iccArgument.data, onCompleted);
710 }
711 break;
712
713 case EVENT_EXCHANGE_SIM_IO_DONE:
714 ar = (AsyncResult) msg.obj;
715 request = (MainThreadRequest) ar.userObj;
716 if (ar.exception == null && ar.result != null) {
717 request.result = ar.result;
718 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800719 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700720 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700721 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700722 break;
723
Derek Tan4d5e5c12014-02-04 11:54:58 -0800724 case CMD_SEND_ENVELOPE:
725 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000726 uiccPort = getUiccPortFromRequest(request);
727 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700728 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800729 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700730 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700731 } else {
732 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800733 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700734 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800735 break;
736
737 case EVENT_SEND_ENVELOPE_DONE:
738 ar = (AsyncResult) msg.obj;
739 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700740 if (ar.exception == null && ar.result != null) {
741 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800742 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800743 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700744 if (ar.result == null) {
745 loge("sendEnvelopeWithStatus: Empty response");
746 } else if (ar.exception instanceof CommandException) {
747 loge("sendEnvelopeWithStatus: CommandException: " +
748 ar.exception);
749 } else {
750 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
751 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800752 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700753 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800754 break;
755
Shishir Agrawal566b7612013-10-28 14:41:00 -0700756 case CMD_OPEN_CHANNEL:
757 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000758 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800759 IccLogicalChannelRequest openChannelRequest =
760 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000761 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700762 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800763 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800764 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700765 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700766 } else {
767 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800768 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
769 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700770 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700771 break;
772
773 case EVENT_OPEN_CHANNEL_DONE:
774 ar = (AsyncResult) msg.obj;
775 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700776 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700777 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700778 int[] result = (int[]) ar.result;
779 int channelId = result[0];
780 byte[] selectResponse = null;
781 if (result.length > 1) {
782 selectResponse = new byte[result.length - 1];
783 for (int i = 1; i < result.length; ++i) {
784 selectResponse[i - 1] = (byte) result[i];
785 }
786 }
787 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800788 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800789
790 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700791 if (uiccPort == null) {
792 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
793 } else {
794 IccLogicalChannelRequest channelRequest =
795 (IccLogicalChannelRequest) request.argument;
796 channelRequest.channel = channelId;
797 uiccPort.onLogicalChannelOpened(channelRequest);
798 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700799 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700800 if (ar.result == null) {
801 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700802 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700803 if (ar.exception != null) {
804 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
805 }
806
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700807 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700808 if (ar.exception instanceof CommandException) {
809 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800810 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700811 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700812 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700813 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700814 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700815 }
816 }
817 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800818 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700819 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700820 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700821 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700822 break;
823
824 case CMD_CLOSE_CHANNEL:
825 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000826 uiccPort = getUiccPortFromRequest(request);
827 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700828 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800829 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800830 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800831 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700832 } else {
833 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000834 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700835 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700836 break;
837
838 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800839 ar = (AsyncResult) msg.obj;
840 request = (MainThreadRequest) ar.userObj;
841 if (ar.exception == null) {
842 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800843 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700844 if (uiccPort == null) {
845 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
846 } else {
847 final int channelId = (Integer) request.argument;
848 uiccPort.onLogicalChannelClosed(channelId);
849 }
Chen Xu540470b2021-12-14 17:15:47 -0800850 } else {
851 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800852 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800853 if (ar.exception instanceof CommandException) {
854 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
855 CommandException.Error error =
856 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800857 if (error == CommandException.Error.INVALID_ARGUMENTS) {
858 // should only throw exceptions from the binder threads.
859 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800860 "iccCloseLogicalChannel: invalid argument ");
861 }
862 } else {
863 loge("iccCloseLogicalChannel: Unknown exception");
864 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800865 request.result = (exception != null) ? exception :
866 new IllegalStateException(
867 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800868 }
869 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800870 break;
871
872 case CMD_NV_READ_ITEM:
873 request = (MainThreadRequest) msg.obj;
874 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800875 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
876 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800877 break;
878
879 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700880 ar = (AsyncResult) msg.obj;
881 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800882 if (ar.exception == null && ar.result != null) {
883 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700884 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800885 request.result = "";
886 if (ar.result == null) {
887 loge("nvReadItem: Empty response");
888 } else if (ar.exception instanceof CommandException) {
889 loge("nvReadItem: CommandException: " +
890 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700891 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800892 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700893 }
894 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700895 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700896 break;
897
Jake Hambye994d462014-02-03 13:10:13 -0800898 case CMD_NV_WRITE_ITEM:
899 request = (MainThreadRequest) msg.obj;
900 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
901 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800902 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700903 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800904 break;
905
906 case EVENT_NV_WRITE_ITEM_DONE:
907 handleNullReturnEvent(msg, "nvWriteItem");
908 break;
909
910 case CMD_NV_WRITE_CDMA_PRL:
911 request = (MainThreadRequest) msg.obj;
912 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800913 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800914 break;
915
916 case EVENT_NV_WRITE_CDMA_PRL_DONE:
917 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
918 break;
919
chen xu6dac5ab2018-10-26 17:39:23 -0700920 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800921 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700922 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800923 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800924 break;
925
chen xu6dac5ab2018-10-26 17:39:23 -0700926 case EVENT_RESET_MODEM_CONFIG_DONE:
927 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800928 break;
929
Sooraj Sasindran37444802020-08-11 10:40:43 -0700930 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
931 request = (MainThreadRequest) msg.obj;
932 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
933 request);
934 Phone phone = getPhoneFromRequest(request);
935 if (phone != null) {
936 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
937 } else {
938 loge("isNRDualConnectivityEnabled: No phone object");
939 request.result = false;
940 notifyRequester(request);
941 }
942 break;
943 }
944
945 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
946 ar = (AsyncResult) msg.obj;
947 request = (MainThreadRequest) ar.userObj;
948 if (ar.exception == null && ar.result != null) {
949 request.result = ar.result;
950 } else {
951 // request.result must be set to something non-null
952 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700953 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700954 request.result = ar.result;
955 } else {
956 request.result = false;
957 }
958 if (ar.result == null) {
959 loge("isNRDualConnectivityEnabled: Empty response");
960 } else if (ar.exception instanceof CommandException) {
961 loge("isNRDualConnectivityEnabled: CommandException: "
962 + ar.exception);
963 } else {
964 loge("isNRDualConnectivityEnabled: Unknown exception");
965 }
966 }
967 notifyRequester(request);
968 break;
969
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700970 case CMD_IS_VONR_ENABLED: {
971 request = (MainThreadRequest) msg.obj;
972 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
973 request);
974 Phone phone = getPhoneFromRequest(request);
975 if (phone != null) {
976 phone.isVoNrEnabled(onCompleted, request.workSource);
977 } else {
978 loge("isVoNrEnabled: No phone object");
979 request.result = false;
980 notifyRequester(request);
981 }
982 break;
983 }
984
985 case EVENT_IS_VONR_ENABLED_DONE:
986 ar = (AsyncResult) msg.obj;
987 request = (MainThreadRequest) ar.userObj;
988 if (ar.exception == null && ar.result != null) {
989 request.result = ar.result;
990 } else {
991 // request.result must be set to something non-null
992 // for the calling thread to unblock
993 if (ar.result != null) {
994 request.result = ar.result;
995 } else {
996 request.result = false;
997 }
998 if (ar.result == null) {
999 loge("isVoNrEnabled: Empty response");
1000 } else if (ar.exception instanceof CommandException) {
1001 loge("isVoNrEnabled: CommandException: "
1002 + ar.exception);
1003 } else {
1004 loge("isVoNrEnabled: Unknown exception");
1005 }
1006 }
1007 notifyRequester(request);
1008 break;
1009
Sooraj Sasindran37444802020-08-11 10:40:43 -07001010 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1011 request = (MainThreadRequest) msg.obj;
1012 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1013 Phone phone = getPhoneFromRequest(request);
1014 if (phone != null) {
1015 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1016 request.workSource);
1017 } else {
1018 loge("enableNrDualConnectivity: No phone object");
1019 request.result =
1020 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1021 notifyRequester(request);
1022 }
1023 break;
1024 }
1025
1026 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1027 ar = (AsyncResult) msg.obj;
1028 request = (MainThreadRequest) ar.userObj;
1029 if (ar.exception == null) {
1030 request.result =
1031 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1032 } else {
1033 request.result =
1034 TelephonyManager
1035 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1036 if (ar.exception instanceof CommandException) {
1037 CommandException.Error error =
1038 ((CommandException) (ar.exception)).getCommandError();
1039 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1040 request.result =
1041 TelephonyManager
1042 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001043 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1044 request.result =
1045 TelephonyManager
1046 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001047 }
1048 loge("enableNrDualConnectivity" + ": CommandException: "
1049 + ar.exception);
1050 } else {
1051 loge("enableNrDualConnectivity" + ": Unknown exception");
1052 }
1053 }
1054 notifyRequester(request);
1055 break;
1056 }
1057
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001058 case CMD_ENABLE_VONR: {
1059 request = (MainThreadRequest) msg.obj;
1060 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1061 Phone phone = getPhoneFromRequest(request);
1062 if (phone != null) {
1063 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1064 request.workSource);
1065 } else {
1066 loge("setVoNrEnabled: No phone object");
1067 request.result =
1068 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1069 notifyRequester(request);
1070 }
1071 break;
1072 }
1073
1074 case EVENT_ENABLE_VONR_DONE: {
1075 ar = (AsyncResult) msg.obj;
1076 request = (MainThreadRequest) ar.userObj;
1077 if (ar.exception == null) {
1078 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1079 } else {
1080 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1081 if (ar.exception instanceof CommandException) {
1082 CommandException.Error error =
1083 ((CommandException) (ar.exception)).getCommandError();
1084 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1085 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1086 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1087 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1088 } else {
1089 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1090 }
1091 loge("setVoNrEnabled" + ": CommandException: "
1092 + ar.exception);
1093 } else {
1094 loge("setVoNrEnabled" + ": Unknown exception");
1095 }
1096 }
1097 notifyRequester(request);
1098 break;
1099 }
1100
SongFerngWang3ef3e072020-12-21 16:41:52 +08001101 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001102 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001103 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1104 request);
1105 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001106 break;
1107
SongFerngWang3ef3e072020-12-21 16:41:52 +08001108 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001109 ar = (AsyncResult) msg.obj;
1110 request = (MainThreadRequest) ar.userObj;
1111 if (ar.exception == null && ar.result != null) {
1112 request.result = ar.result; // Integer
1113 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301114 // request.result must be set to something non-null
1115 // for the calling thread to unblock
1116 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001117 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001118 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001119 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001120 loge("getAllowedNetworkTypesBitmask: CommandException: "
1121 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001122 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001123 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001124 }
1125 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001126 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001127 break;
1128
SongFerngWang3ef3e072020-12-21 16:41:52 +08001129 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001130 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001131 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1132 request);
1133 Pair<Integer, Long> reasonWithNetworkTypes =
1134 (Pair<Integer, Long>) request.argument;
1135 getPhoneFromRequest(request).setAllowedNetworkTypes(
1136 reasonWithNetworkTypes.first,
1137 reasonWithNetworkTypes.second,
1138 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001139 break;
1140
SongFerngWang3ef3e072020-12-21 16:41:52 +08001141 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1142 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001143 break;
1144
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001145 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1146 request = (MainThreadRequest)msg.obj;
1147 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001148 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001149 break;
1150
1151 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1152 ar = (AsyncResult)msg.obj;
1153 request = (MainThreadRequest)ar.userObj;
1154 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001155 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001156 break;
1157
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001158 case CMD_SET_VOICEMAIL_NUMBER:
1159 request = (MainThreadRequest) msg.obj;
1160 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1161 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001162 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1163 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001164 break;
1165
1166 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1167 handleNullReturnEvent(msg, "setVoicemailNumber");
1168 break;
1169
Stuart Scott54788802015-03-30 13:18:01 -07001170 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1171 request = (MainThreadRequest) msg.obj;
1172 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1173 request);
1174 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1175 break;
1176
1177 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1178 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1179 break;
1180
Shishir Agrawal302c8692015-06-19 13:49:39 -07001181 case CMD_PERFORM_NETWORK_SCAN:
1182 request = (MainThreadRequest) msg.obj;
1183 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1184 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1185 break;
1186
Hall Liu27d24262020-09-18 19:04:59 -07001187 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001188 request = (MainThreadRequest) msg.obj;
1189 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001190 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1191 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1192 request.argument;
1193 int callForwardingReason = args.first;
1194 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001195 break;
Hall Liu27d24262020-09-18 19:04:59 -07001196 }
1197 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001198 ar = (AsyncResult) msg.obj;
1199 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001200 TelephonyManager.CallForwardingInfoCallback callback =
1201 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1202 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001203 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001204 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001205 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1206 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1207 // Service Class is a bit mask per 3gpp 27.007. Search for
1208 // any service for voice call.
1209 if ((callForwardInfo.serviceClass
1210 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001211 callForwardingInfo = new CallForwardingInfo(
1212 callForwardInfo.status
1213 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001214 callForwardInfo.reason,
1215 callForwardInfo.number,
1216 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001217 break;
1218 }
1219 }
1220 // Didn't find a call forward info for voice call.
1221 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001222 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1223 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001224 }
Hall Liu27d24262020-09-18 19:04:59 -07001225 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001226 } else {
1227 if (ar.result == null) {
1228 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1229 }
1230 if (ar.exception != null) {
1231 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1232 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001233 int errorCode = TelephonyManager
1234 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001235 if (ar.exception instanceof CommandException) {
1236 CommandException.Error error =
1237 ((CommandException) (ar.exception)).getCommandError();
1238 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001239 errorCode = TelephonyManager
1240 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001241 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001242 errorCode = TelephonyManager
1243 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001244 }
1245 }
Hall Liu27d24262020-09-18 19:04:59 -07001246 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001247 }
Shuo Qian4a594052020-01-23 11:59:30 -08001248 break;
Hall Liu27d24262020-09-18 19:04:59 -07001249 }
Shuo Qian4a594052020-01-23 11:59:30 -08001250
Hall Liu27d24262020-09-18 19:04:59 -07001251 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001252 request = (MainThreadRequest) msg.obj;
1253 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001254 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001255 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001256 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1257 request.argument).first;
1258 request.phone.setCallForwardingOption(
1259 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001260 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001261 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001262 callForwardingInfoToSet.getReason(),
1263 callForwardingInfoToSet.getNumber(),
1264 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1265 break;
Hall Liu27d24262020-09-18 19:04:59 -07001266 }
Shuo Qian4a594052020-01-23 11:59:30 -08001267
Hall Liu27d24262020-09-18 19:04:59 -07001268 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001269 ar = (AsyncResult) msg.obj;
1270 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001271 Consumer<Integer> callback =
1272 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1273 request.argument).second;
1274 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001275 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001276 int errorCode = TelephonyManager.CallForwardingInfoCallback
1277 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001278 if (ar.exception instanceof CommandException) {
1279 CommandException.Error error =
1280 ((CommandException) (ar.exception)).getCommandError();
1281 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001282 errorCode = TelephonyManager.CallForwardingInfoCallback
1283 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001284 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001285 errorCode = TelephonyManager.CallForwardingInfoCallback
1286 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001287 }
1288 }
1289 callback.accept(errorCode);
1290 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001291 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001292 }
Shuo Qian4a594052020-01-23 11:59:30 -08001293 break;
Hall Liu27d24262020-09-18 19:04:59 -07001294 }
Shuo Qian4a594052020-01-23 11:59:30 -08001295
Hall Liu27d24262020-09-18 19:04:59 -07001296 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001297 request = (MainThreadRequest) msg.obj;
1298 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1299 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1300 break;
Hall Liu27d24262020-09-18 19:04:59 -07001301 }
Shuo Qian4a594052020-01-23 11:59:30 -08001302
Hall Liu27d24262020-09-18 19:04:59 -07001303 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001304 ar = (AsyncResult) msg.obj;
1305 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001306 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001307 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001308 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001309 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001310 // Service Class is a bit mask per 3gpp 27.007.
1311 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001312 if (callForwardResults.length > 1
1313 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001314 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001315 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001316 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1317 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001318 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001319 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001320 }
1321 } else {
1322 if (ar.result == null) {
1323 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1324 }
1325 if (ar.exception != null) {
1326 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1327 }
1328 if (ar.exception instanceof CommandException) {
1329 CommandException.Error error =
1330 ((CommandException) (ar.exception)).getCommandError();
1331 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001332 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001333 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001334 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1335 callWaitingStatus =
1336 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001337 }
1338 }
1339 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001340 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001341 break;
Hall Liu27d24262020-09-18 19:04:59 -07001342 }
Shuo Qian4a594052020-01-23 11:59:30 -08001343
Hall Liu27d24262020-09-18 19:04:59 -07001344 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001345 request = (MainThreadRequest) msg.obj;
1346 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001347 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1348 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001349 break;
Hall Liu27d24262020-09-18 19:04:59 -07001350 }
Shuo Qian4a594052020-01-23 11:59:30 -08001351
Hall Liu27d24262020-09-18 19:04:59 -07001352 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001353 ar = (AsyncResult) msg.obj;
1354 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001355 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1356 Consumer<Integer> callback =
1357 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1358 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001359 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001360 if (ar.exception instanceof CommandException) {
1361 CommandException.Error error =
1362 ((CommandException) (ar.exception)).getCommandError();
1363 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1364 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001365 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1366 callback.accept(
1367 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001368 } else {
1369 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1370 }
1371 } else {
1372 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1373 }
1374 } else {
1375 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1376 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001377 }
Shuo Qian4a594052020-01-23 11:59:30 -08001378 break;
Hall Liu27d24262020-09-18 19:04:59 -07001379 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001380 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1381 ar = (AsyncResult) msg.obj;
1382 request = (MainThreadRequest) ar.userObj;
1383 CellNetworkScanResult cellScanResult;
1384 if (ar.exception == null && ar.result != null) {
1385 cellScanResult = new CellNetworkScanResult(
1386 CellNetworkScanResult.STATUS_SUCCESS,
1387 (List<OperatorInfo>) ar.result);
1388 } else {
1389 if (ar.result == null) {
1390 loge("getCellNetworkScanResults: Empty response");
1391 }
1392 if (ar.exception != null) {
1393 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1394 }
1395 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1396 if (ar.exception instanceof CommandException) {
1397 CommandException.Error error =
1398 ((CommandException) (ar.exception)).getCommandError();
1399 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1400 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1401 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1402 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1403 }
1404 }
1405 cellScanResult = new CellNetworkScanResult(errorCode, null);
1406 }
1407 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001408 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001409 break;
1410
1411 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1412 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001413 ManualNetworkSelectionArgument selArg =
1414 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001415 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1416 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001417 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1418 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001419 break;
1420
1421 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001422 ar = (AsyncResult) msg.obj;
1423 request = (MainThreadRequest) ar.userObj;
1424 if (ar.exception == null) {
1425 request.result = true;
1426 } else {
1427 request.result = false;
1428 loge("setNetworkSelectionModeManual " + ar.exception);
1429 }
1430 notifyRequester(request);
1431 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001432 break;
1433
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001434 case CMD_GET_MODEM_ACTIVITY_INFO:
1435 request = (MainThreadRequest) msg.obj;
1436 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001437 if (defaultPhone != null) {
1438 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001439 } else {
1440 ResultReceiver result = (ResultReceiver) request.argument;
1441 Bundle bundle = new Bundle();
1442 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001443 new ModemActivityInfo(0, 0, 0,
1444 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001445 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001446 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001447 break;
1448
Hall Liud0f208c2020-10-14 16:54:44 -07001449 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001450 ar = (AsyncResult) msg.obj;
1451 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001452 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001453 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001454 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001455 if (mLastModemActivityInfo == null) {
1456 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1457 mLastModemActivitySpecificInfo[0] =
1458 new ActivityStatsTechSpecificInfo(
1459 0,
1460 0,
1461 new int[ModemActivityInfo.getNumTxPowerLevels()],
1462 0);
1463 mLastModemActivityInfo =
1464 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1465 }
1466
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001467 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001468 // Update the last modem activity info and the result of the request.
1469 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1470 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001471 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001472 } else {
1473 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001474 }
Kai Shi917fdc62022-11-28 14:01:02 -08001475 // This is needed to decouple ret from mLastModemActivityInfo
1476 // We don't want to return mLastModemActivityInfo which is updated
1477 // inside mergeModemActivityInfo()
1478 ret = new ModemActivityInfo(
1479 mLastModemActivityInfo.getTimestampMillis(),
1480 mLastModemActivityInfo.getSleepTimeMillis(),
1481 mLastModemActivityInfo.getIdleTimeMillis(),
1482 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001483
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001484 } else {
1485 if (ar.result == null) {
1486 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001487 error = TelephonyManager.ModemActivityInfoException
1488 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001489 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001490 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001491 error = TelephonyManager.ModemActivityInfoException
1492 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001493 } else {
1494 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001495 error = TelephonyManager.ModemActivityInfoException
1496 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001497 }
1498 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001499 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001500 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001501 bundle.putParcelable(
1502 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001503 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001504 } else {
1505 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1506 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001507 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001508 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001509 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001510 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001511
Meng Wang1a7c35a2016-05-05 20:56:15 -07001512 case CMD_SET_ALLOWED_CARRIERS:
1513 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001514 CarrierRestrictionRules argument =
1515 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001516 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001517 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001518 break;
1519
1520 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1521 ar = (AsyncResult) msg.obj;
1522 request = (MainThreadRequest) ar.userObj;
1523 if (ar.exception == null && ar.result != null) {
1524 request.result = ar.result;
1525 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001526 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1527 if (ar.exception instanceof CommandException) {
1528 loge("setAllowedCarriers: CommandException: " + ar.exception);
1529 CommandException.Error error =
1530 ((CommandException) (ar.exception)).getCommandError();
1531 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1532 request.result =
1533 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1534 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001535 } else {
1536 loge("setAllowedCarriers: Unknown exception");
1537 }
1538 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001539 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001540 break;
1541
1542 case CMD_GET_ALLOWED_CARRIERS:
1543 request = (MainThreadRequest) msg.obj;
1544 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001545 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001546 break;
1547
1548 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1549 ar = (AsyncResult) msg.obj;
1550 request = (MainThreadRequest) ar.userObj;
1551 if (ar.exception == null && ar.result != null) {
1552 request.result = ar.result;
1553 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001554 request.result = new IllegalStateException(
1555 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001556 if (ar.result == null) {
1557 loge("getAllowedCarriers: Empty response");
1558 } else if (ar.exception instanceof CommandException) {
1559 loge("getAllowedCarriers: CommandException: " +
1560 ar.exception);
1561 } else {
1562 loge("getAllowedCarriers: Unknown exception");
1563 }
1564 }
arunvoddud7401012022-12-15 16:08:12 +00001565 if (request.argument != null) {
1566 // This is for the implementation of carrierRestrictionStatus.
1567 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1568 Consumer<Integer> callback = callbackInfo.getConsumer();
1569 int callerCarrierId = callbackInfo.getCarrierId();
1570 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1571 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1572 CarrierRestrictionRules carrierRestrictionRules =
1573 (CarrierRestrictionRules) ar.result;
1574 int carrierId = -1;
1575 try {
1576 CarrierIdentifier carrierIdentifier =
1577 carrierRestrictionRules.getAllowedCarriers().get(0);
1578 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1579 carrierIdentifier);
1580 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1581 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1582 }
1583 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1584 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1585 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
1586 lockStatus =
1587 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
1588 }
1589 } else {
1590 Rlog.e(LOG_TAG,
1591 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1592 }
1593 callback.accept(lockStatus);
1594 } else {
1595 // This is for the implementation of getAllowedCarriers.
1596 notifyRequester(request);
1597 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001598 break;
1599
Nathan Haroldb3014052017-01-25 15:57:32 -08001600 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1601 ar = (AsyncResult) msg.obj;
1602 request = (MainThreadRequest) ar.userObj;
1603 if (ar.exception == null && ar.result != null) {
1604 request.result = ar.result;
1605 } else {
1606 request.result = new IllegalArgumentException(
1607 "Failed to retrieve Forbidden Plmns");
1608 if (ar.result == null) {
1609 loge("getForbiddenPlmns: Empty response");
1610 } else {
1611 loge("getForbiddenPlmns: Unknown exception");
1612 }
1613 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001614 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001615 break;
1616
1617 case CMD_GET_FORBIDDEN_PLMNS:
1618 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001619 uiccPort = getUiccPortFromRequest(request);
1620 if (uiccPort == null) {
1621 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001622 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001623 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001624 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001625 break;
1626 }
1627 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001628 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001629 if (uiccApp == null) {
1630 loge("getForbiddenPlmns() no app with specified type -- "
1631 + appType);
1632 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001633 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001634 break;
1635 } else {
1636 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1637 + " specified type -- " + appType);
1638 }
1639 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1640 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1641 onCompleted);
1642 break;
1643
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001644 case CMD_SWITCH_SLOTS:
1645 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001646 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001647 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001648 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001649 break;
1650
1651 case EVENT_SWITCH_SLOTS_DONE:
1652 ar = (AsyncResult) msg.obj;
1653 request = (MainThreadRequest) ar.userObj;
1654 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001655 notifyRequester(request);
1656 break;
1657 case CMD_GET_NETWORK_SELECTION_MODE:
1658 request = (MainThreadRequest) msg.obj;
1659 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1660 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1661 break;
1662
1663 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1664 ar = (AsyncResult) msg.obj;
1665 request = (MainThreadRequest) ar.userObj;
1666 if (ar.exception != null) {
1667 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1668 } else {
1669 int mode = ((int[]) ar.result)[0];
1670 if (mode == 0) {
1671 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1672 } else {
1673 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1674 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001675 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001676 notifyRequester(request);
1677 break;
1678 case CMD_GET_CDMA_ROAMING_MODE:
1679 request = (MainThreadRequest) msg.obj;
1680 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1681 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1682 break;
1683 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1684 ar = (AsyncResult) msg.obj;
1685 request = (MainThreadRequest) ar.userObj;
1686 if (ar.exception != null) {
1687 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1688 } else {
1689 request.result = ((int[]) ar.result)[0];
1690 }
1691 notifyRequester(request);
1692 break;
1693 case CMD_SET_CDMA_ROAMING_MODE:
1694 request = (MainThreadRequest) msg.obj;
1695 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1696 int mode = (int) request.argument;
1697 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1698 break;
1699 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1700 ar = (AsyncResult) msg.obj;
1701 request = (MainThreadRequest) ar.userObj;
1702 request.result = ar.exception == null;
1703 notifyRequester(request);
1704 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001705 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1706 request = (MainThreadRequest) msg.obj;
1707 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1708 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1709 break;
1710 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1711 ar = (AsyncResult) msg.obj;
1712 request = (MainThreadRequest) ar.userObj;
1713 if (ar.exception != null) {
1714 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1715 } else {
1716 request.result = ((int[]) ar.result)[0];
1717 }
1718 notifyRequester(request);
1719 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001720 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1721 request = (MainThreadRequest) msg.obj;
1722 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1723 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001724 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1725 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001726 break;
1727 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1728 ar = (AsyncResult) msg.obj;
1729 request = (MainThreadRequest) ar.userObj;
1730 request.result = ar.exception == null;
1731 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001732 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001733 case CMD_GET_ALL_CELL_INFO:
1734 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001735 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001736 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001737 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001738 case EVENT_GET_ALL_CELL_INFO_DONE:
1739 ar = (AsyncResult) msg.obj;
1740 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001741 // If a timeout occurs, the response will be null
1742 request.result = (ar.exception == null && ar.result != null)
1743 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001744 synchronized (request) {
1745 request.notifyAll();
1746 }
1747 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001748 case CMD_REQUEST_CELL_INFO_UPDATE:
1749 request = (MainThreadRequest) msg.obj;
1750 request.phone.requestCellInfoUpdate(request.workSource,
1751 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1752 break;
1753 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1754 ar = (AsyncResult) msg.obj;
1755 request = (MainThreadRequest) ar.userObj;
1756 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1757 try {
1758 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001759 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001760 cb.onError(
1761 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1762 ar.exception.getClass().getName(),
1763 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001764 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001765 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001766 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001767 } else {
1768 // use the result as returned
1769 cb.onCellInfo((List<CellInfo>) ar.result);
1770 }
1771 } catch (RemoteException re) {
1772 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1773 }
1774 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001775 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001776 request = (MainThreadRequest) msg.obj;
1777 WorkSource ws = (WorkSource) request.argument;
1778 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001779 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001780 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001781 }
1782 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001783 ar = (AsyncResult) msg.obj;
1784 request = (MainThreadRequest) ar.userObj;
1785 if (ar.exception == null) {
1786 request.result = ar.result;
1787 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001788 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001789 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001790 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001791 }
1792
1793 synchronized (request) {
1794 request.notifyAll();
1795 }
1796 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001797 }
chen xu6dac5ab2018-10-26 17:39:23 -07001798 case CMD_MODEM_REBOOT:
1799 request = (MainThreadRequest) msg.obj;
1800 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001801 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001802 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001803 case EVENT_CMD_MODEM_REBOOT_DONE:
1804 handleNullReturnEvent(msg, "rebootModem");
1805 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001806 case CMD_REQUEST_ENABLE_MODEM:
1807 request = (MainThreadRequest) msg.obj;
1808 boolean enable = (boolean) request.argument;
1809 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001810 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001811 PhoneConfigurationManager.getInstance()
1812 .enablePhone(request.phone, enable, onCompleted);
1813 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001814 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001815 ar = (AsyncResult) msg.obj;
1816 request = (MainThreadRequest) ar.userObj;
1817 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001818 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001819 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001820 if ((boolean) request.result) {
1821 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1822 updateModemStateMetrics();
1823 } else {
1824 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1825 + ar.exception);
1826 }
1827 notifyRequester(request);
1828 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001829 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001830 case CMD_GET_MODEM_STATUS:
1831 request = (MainThreadRequest) msg.obj;
1832 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1833 PhoneConfigurationManager.getInstance()
1834 .getPhoneStatusFromModem(request.phone, onCompleted);
1835 break;
1836 case EVENT_GET_MODEM_STATUS_DONE:
1837 ar = (AsyncResult) msg.obj;
1838 request = (MainThreadRequest) ar.userObj;
1839 int id = request.phone.getPhoneId();
1840 if (ar.exception == null && ar.result != null) {
1841 request.result = ar.result;
1842 //update the cache as modem status has changed
1843 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1844 (boolean) request.result);
1845 } else {
1846 // Return true if modem status cannot be retrieved. For most cases,
1847 // modem status is on. And for older version modems, GET_MODEM_STATUS
1848 // and disable modem are not supported. Modem is always on.
1849 // TODO: this should be fixed in R to support a third
1850 // status UNKNOWN b/131631629
1851 request.result = true;
1852 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1853 + ar.exception);
1854 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001855 notifyRequester(request);
1856 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001857 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1858 request = (MainThreadRequest) msg.obj;
1859 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1860 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1861 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1862 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1863 break;
1864 }
1865 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1866 ar = (AsyncResult) msg.obj;
1867 request = (MainThreadRequest) ar.userObj;
1868 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1869 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1870 args.second.accept(ar.exception == null);
1871 notifyRequester(request);
1872 break;
1873 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001874 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1875 request = (MainThreadRequest) msg.obj;
1876 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1877 Phone phone = getPhoneFromRequest(request);
1878 if (phone != null) {
1879 phone.getSystemSelectionChannels(onCompleted);
1880 } else {
1881 loge("getSystemSelectionChannels: No phone object");
1882 request.result = new ArrayList<RadioAccessSpecifier>();
1883 notifyRequester(request);
1884 }
1885 break;
1886 }
1887 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1888 ar = (AsyncResult) msg.obj;
1889 request = (MainThreadRequest) ar.userObj;
1890 if (ar.exception == null && ar.result != null) {
1891 request.result = ar.result;
1892 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001893 request.result = new IllegalStateException(
1894 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001895 if (ar.result == null) {
1896 loge("getSystemSelectionChannels: Empty response");
1897 } else {
1898 loge("getSystemSelectionChannels: Unknown exception");
1899 }
1900 }
1901 notifyRequester(request);
1902 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001903 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1904 ar = (AsyncResult) msg.obj;
1905 request = (MainThreadRequest) ar.userObj;
1906 if (ar.exception == null && ar.result != null) {
1907 request.result = ar.result;
1908 } else {
1909 request.result = -1;
1910 loge("Failed to set Forbidden Plmns");
1911 if (ar.result == null) {
1912 loge("setForbidenPlmns: Empty response");
1913 } else if (ar.exception != null) {
1914 loge("setForbiddenPlmns: Exception: " + ar.exception);
1915 request.result = -1;
1916 } else {
1917 loge("setForbiddenPlmns: Unknown exception");
1918 }
1919 }
1920 notifyRequester(request);
1921 break;
1922 case CMD_SET_FORBIDDEN_PLMNS:
1923 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001924 uiccPort = getUiccPortFromRequest(request);
1925 if (uiccPort == null) {
1926 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001927 request.result = -1;
1928 notifyRequester(request);
1929 break;
1930 }
1931 Pair<Integer, List<String>> setFplmnsArgs =
1932 (Pair<Integer, List<String>>) request.argument;
1933 appType = setFplmnsArgs.first;
1934 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001935 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001936 if (uiccApp == null) {
1937 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1938 request.result = -1;
1939 loge("Failed to get UICC App");
1940 notifyRequester(request);
1941 } else {
1942 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1943 ((SIMRecords) uiccApp.getIccRecords())
1944 .setForbiddenPlmns(onCompleted, fplmns);
1945 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001946 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001947 case CMD_ERASE_MODEM_CONFIG:
1948 request = (MainThreadRequest) msg.obj;
1949 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1950 defaultPhone.eraseModemConfig(onCompleted);
1951 break;
1952 case EVENT_ERASE_MODEM_CONFIG_DONE:
1953 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001954 break;
zoey chene02881a2019-12-30 16:11:23 +08001955
Kai Shif70f46f2021-03-03 13:59:46 -08001956 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1957 request = (MainThreadRequest) msg.obj;
1958 request.result = defaultPhone.eraseDataInSharedPreferences();
1959 notifyRequester(request);
1960 break;
1961
zoey chene02881a2019-12-30 16:11:23 +08001962 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1963 request = (MainThreadRequest) msg.obj;
1964 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1965 Pair<String, String> changed = (Pair<String, String>) request.argument;
1966 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1967 changed.first, changed.second, onCompleted);
1968 break;
1969 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1970 ar = (AsyncResult) msg.obj;
1971 request = (MainThreadRequest) ar.userObj;
1972 if (ar.exception == null) {
1973 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001974 // If the operation is successful, update the PIN storage
1975 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1976 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001977 UiccController.getInstance().getPinStorage()
1978 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001979 } else {
1980 request.result = msg.arg1;
1981 }
1982 notifyRequester(request);
1983 break;
1984
Michele Berionne5e411512020-11-13 02:36:59 +00001985 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001986 request = (MainThreadRequest) msg.obj;
1987 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1988 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1989 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1990 enabled.first, enabled.second, onCompleted);
1991 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001992 }
zoey chene02881a2019-12-30 16:11:23 +08001993 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1994 ar = (AsyncResult) msg.obj;
1995 request = (MainThreadRequest) ar.userObj;
1996 if (ar.exception == null) {
1997 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001998 // If the operation is successful, update the PIN storage
1999 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2000 int phoneId = getPhoneFromRequest(request).getPhoneId();
2001 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002002 UiccController.getInstance().getPinStorage()
2003 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002004 } else {
2005 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2006 }
zoey chene02881a2019-12-30 16:11:23 +08002007 } else {
2008 request.result = msg.arg1;
2009 }
Michele Berionne5e411512020-11-13 02:36:59 +00002010
2011
zoey chene02881a2019-12-30 16:11:23 +08002012 notifyRequester(request);
2013 break;
2014
Peter Wangdafb9ac2020-01-15 14:13:38 -08002015 case MSG_NOTIFY_USER_ACTIVITY:
2016 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002017 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002018 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2019 getDefaultPhone().getContext().sendBroadcastAsUser(
2020 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2021 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002022
2023 case CMD_SET_DATA_THROTTLING: {
2024 request = (MainThreadRequest) msg.obj;
2025 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2026 DataThrottlingRequest dataThrottlingRequest =
2027 (DataThrottlingRequest) request.argument;
2028 Phone phone = getPhoneFromRequest(request);
2029 if (phone != null) {
2030 phone.setDataThrottling(onCompleted,
2031 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2032 dataThrottlingRequest.getCompletionDurationMillis());
2033 } else {
2034 loge("setDataThrottling: No phone object");
2035 request.result =
2036 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2037 notifyRequester(request);
2038 }
2039
2040 break;
2041 }
2042 case EVENT_SET_DATA_THROTTLING_DONE:
2043 ar = (AsyncResult) msg.obj;
2044 request = (MainThreadRequest) ar.userObj;
2045
2046 if (ar.exception == null) {
2047 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2048 } else if (ar.exception instanceof CommandException) {
2049 loge("setDataThrottling: CommandException: " + ar.exception);
2050 CommandException.Error error =
2051 ((CommandException) (ar.exception)).getCommandError();
2052
2053 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2054 request.result = TelephonyManager
2055 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2056 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2057 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002058 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2059 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002060 } else {
2061 request.result =
2062 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2063 }
2064 } else {
2065 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2066 }
2067 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2068 notifyRequester(request);
2069 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002070
2071 case CMD_SET_SIM_POWER: {
2072 request = (MainThreadRequest) msg.obj;
2073 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2074 request = (MainThreadRequest) msg.obj;
2075 int stateToSet =
2076 ((Pair<Integer, IIntegerConsumer>)
2077 request.argument).first;
2078 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2079 break;
2080 }
2081 case EVENT_SET_SIM_POWER_DONE: {
2082 ar = (AsyncResult) msg.obj;
2083 request = (MainThreadRequest) ar.userObj;
2084 IIntegerConsumer callback =
2085 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2086 if (ar.exception != null) {
2087 loge("setSimPower exception: " + ar.exception);
2088 int errorCode = TelephonyManager.CallForwardingInfoCallback
2089 .RESULT_ERROR_UNKNOWN;
2090 if (ar.exception instanceof CommandException) {
2091 CommandException.Error error =
2092 ((CommandException) (ar.exception)).getCommandError();
2093 if (error == CommandException.Error.SIM_ERR) {
2094 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2095 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2096 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2097 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2098 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2099 } else {
2100 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2101 }
2102 }
2103 try {
2104 callback.accept(errorCode);
2105 } catch (RemoteException e) {
2106 // Ignore if the remote process is no longer available to call back.
2107 Log.w(LOG_TAG, "setSimPower: callback not available.");
2108 }
2109 } else {
2110 try {
2111 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2112 } catch (RemoteException e) {
2113 // Ignore if the remote process is no longer available to call back.
2114 Log.w(LOG_TAG, "setSimPower: callback not available.");
2115 }
2116 }
2117 break;
2118 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002119 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2120 request = (MainThreadRequest) msg.obj;
2121
2122 final Phone phone = getPhoneFromRequest(request);
2123 if (phone == null || phone.getServiceStateTracker() == null) {
2124 request.result = new IllegalStateException("Phone or SST is null");
2125 notifyRequester(request);
2126 break;
2127 }
2128
2129 Pair<Integer, SignalStrengthUpdateRequest> pair =
2130 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2131 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2132 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002133 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002134 request.subId, pair.first /*callingUid*/,
2135 pair.second /*request*/, onCompleted);
2136 break;
2137 }
2138 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2139 ar = (AsyncResult) msg.obj;
2140 request = (MainThreadRequest) ar.userObj;
2141 // request.result will be the exception of ar if present, true otherwise.
2142 // Be cautious not to leave result null which will wait() forever
2143 request.result = ar.exception != null ? ar.exception : true;
2144 notifyRequester(request);
2145 break;
2146 }
2147 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2148 request = (MainThreadRequest) msg.obj;
2149
2150 Phone phone = getPhoneFromRequest(request);
2151 if (phone == null || phone.getServiceStateTracker() == null) {
2152 request.result = new IllegalStateException("Phone or SST is null");
2153 notifyRequester(request);
2154 break;
2155 }
2156
2157 Pair<Integer, SignalStrengthUpdateRequest> pair =
2158 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2159 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2160 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002161 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002162 request.subId, pair.first /*callingUid*/,
2163 pair.second /*request*/, onCompleted);
2164 break;
2165 }
2166 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2167 ar = (AsyncResult) msg.obj;
2168 request = (MainThreadRequest) ar.userObj;
2169 request.result = ar.exception != null ? ar.exception : true;
2170 notifyRequester(request);
2171 break;
2172 }
Jordan Liu109698e2020-11-24 14:50:34 -08002173
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002174 case CMD_GET_SLICING_CONFIG: {
2175 request = (MainThreadRequest) msg.obj;
2176 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2177 request.phone.getSlicingConfig(onCompleted);
2178 break;
2179 }
2180 case EVENT_GET_SLICING_CONFIG_DONE: {
2181 ar = (AsyncResult) msg.obj;
2182 request = (MainThreadRequest) ar.userObj;
2183 ResultReceiver result = (ResultReceiver) request.argument;
2184
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002185 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002186 Bundle bundle = new Bundle();
2187 int resultCode = 0;
2188 if (ar.exception != null) {
2189 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2190 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002191 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002192 } else if (ar.result == null) {
2193 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002194 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002195 } else {
2196 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002197 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2198 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002199 }
2200
2201 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002202 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002203 }
2204 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2205 result.send(resultCode, bundle);
2206 notifyRequester(request);
2207 break;
2208 }
2209
Sarah Chin71b3a852022-09-28 15:54:19 -07002210 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002211 request = (MainThreadRequest) msg.obj;
2212 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002213 PurchasePremiumCapabilityArgument arg =
2214 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002215 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chinb8218c22023-01-04 13:35:29 -08002216 arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002217 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002218 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002219
Sarah Chin71b3a852022-09-28 15:54:19 -07002220 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002221 ar = (AsyncResult) msg.obj;
2222 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002223 PurchasePremiumCapabilityArgument arg =
2224 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002225 try {
2226 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002227 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002228 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002229 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002230 + ", result= "
2231 + TelephonyManager.convertPurchaseResultToString(result));
2232 } catch (RemoteException e) {
2233 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002234 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002235 + " failed: " + e;
2236 if (DBG) log(logStr);
2237 AnomalyReporter.reportAnomaly(
2238 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2239 }
2240 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002241 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002242
Michele Berionne5e411512020-11-13 02:36:59 +00002243 case CMD_PREPARE_UNATTENDED_REBOOT:
2244 request = (MainThreadRequest) msg.obj;
2245 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002246 UiccController.getInstance().getPinStorage()
2247 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002248 notifyRequester(request);
2249 break;
2250
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002251 default:
2252 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2253 break;
2254 }
2255 }
Jake Hambye994d462014-02-03 13:10:13 -08002256
Pengquan Menga1bb6272018-09-06 09:59:22 -07002257 private void notifyRequester(MainThreadRequest request) {
2258 synchronized (request) {
2259 request.notifyAll();
2260 }
2261 }
2262
Jake Hambye994d462014-02-03 13:10:13 -08002263 private void handleNullReturnEvent(Message msg, String command) {
2264 AsyncResult ar = (AsyncResult) msg.obj;
2265 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2266 if (ar.exception == null) {
2267 request.result = true;
2268 } else {
2269 request.result = false;
2270 if (ar.exception instanceof CommandException) {
2271 loge(command + ": CommandException: " + ar.exception);
2272 } else {
2273 loge(command + ": Unknown exception");
2274 }
2275 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002276 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002277 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 }
2279
2280 /**
2281 * Posts the specified command to be executed on the main thread,
2282 * waits for the request to complete, and returns the result.
2283 * @see #sendRequestAsync
2284 */
2285 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002286 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2287 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002288 }
2289
2290 /**
2291 * Posts the specified command to be executed on the main thread,
2292 * waits for the request to complete, and returns the result.
2293 * @see #sendRequestAsync
2294 */
2295 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2296 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002297 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002298 }
2299
2300 /**
2301 * Posts the specified command to be executed on the main thread,
2302 * waits for the request to complete, and returns the result.
2303 * @see #sendRequestAsync
2304 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002305 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002306 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2307 }
2308
2309 /**
2310 * Posts the specified command to be executed on the main thread,
2311 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2312 * if not timeout or null otherwise.
2313 * @see #sendRequestAsync
2314 */
2315 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2316 long timeoutInMs) {
2317 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002318 }
2319
2320 /**
2321 * Posts the specified command to be executed on the main thread,
2322 * waits for the request to complete, and returns the result.
2323 * @see #sendRequestAsync
2324 */
Nathan Harold92bed182018-10-12 18:16:49 -07002325 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002326 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002327 }
2328
2329 /**
2330 * Posts the specified command to be executed on the main thread,
2331 * waits for the request to complete, and returns the result.
2332 * @see #sendRequestAsync
2333 */
2334 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002335 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2336 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002337 }
2338
2339 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002340 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2341 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2342 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002343 * @see #sendRequestAsync
2344 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002345 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2346 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002347 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2348 throw new RuntimeException("This method will deadlock if called from the main thread.");
2349 }
2350
Nathan Harold92bed182018-10-12 18:16:49 -07002351 MainThreadRequest request = null;
2352 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2353 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2354 } else if (phone != null) {
2355 request = new MainThreadRequest(argument, phone, workSource);
2356 } else {
2357 request = new MainThreadRequest(argument, subId, workSource);
2358 }
2359
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 Message msg = mMainThreadHandler.obtainMessage(command, request);
2361 msg.sendToTarget();
2362
Rambo Wang0f050d82021-02-12 11:43:36 -08002363
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002365 if (timeoutInMs >= 0) {
2366 // Wait for at least timeoutInMs before returning null request result
2367 long now = SystemClock.elapsedRealtime();
2368 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002369 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002370 try {
2371 request.wait(deadline - now);
2372 } catch (InterruptedException e) {
2373 // Do nothing, go back and check if request is completed or timeout
2374 } finally {
2375 now = SystemClock.elapsedRealtime();
2376 }
2377 }
2378 } else {
2379 // Wait for the request to complete
2380 while (request.result == null) {
2381 try {
2382 request.wait();
2383 } catch (InterruptedException e) {
2384 // Do nothing, go back and wait until the request is complete
2385 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002386 }
2387 }
2388 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002389 if (request.result == null) {
2390 Log.wtf(LOG_TAG,
2391 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2392 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393 return request.result;
2394 }
2395
2396 /**
2397 * Asynchronous ("fire and forget") version of sendRequest():
2398 * Posts the specified command to be executed on the main thread, and
2399 * returns immediately.
2400 * @see #sendRequest
2401 */
2402 private void sendRequestAsync(int command) {
2403 mMainThreadHandler.sendEmptyMessage(command);
2404 }
2405
2406 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002407 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002408 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002409 */
2410 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002411 sendRequestAsync(command, argument, null, null);
2412 }
2413
2414 /**
2415 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2416 * @see {@link #sendRequest(int,Object)}
2417 */
2418 private void sendRequestAsync(
2419 int command, Object argument, Phone phone, WorkSource workSource) {
2420 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002421 Message msg = mMainThreadHandler.obtainMessage(command, request);
2422 msg.sendToTarget();
2423 }
2424
2425 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002426 * Initialize the singleton PhoneInterfaceManager instance.
2427 * This is only done once, at startup, from PhoneApp.onCreate().
2428 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002429 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430 synchronized (PhoneInterfaceManager.class) {
2431 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002432 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002433 } else {
2434 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2435 }
2436 return sInstance;
2437 }
2438 }
2439
2440 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002441 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002442 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002444 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002445 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002446 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002447 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 mMainThreadHandler = new MainThreadHandler();
Jack Yue37dd262022-12-16 11:53:37 -08002449 if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) {
2450 mSubscriptionController = SubscriptionController.getInstance();
2451 } else {
2452 mSubscriptionController = null;
2453 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002454 mTelephonySharedPreferences =
2455 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002456 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002457 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002458 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002459 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002460 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukiermand6cae882022-12-29 12:02:31 -05002461 mTelephony2gUpdater = new Telephony2gUpdater(mApp);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002462 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 publish();
arunvoddud7401012022-12-15 16:08:12 +00002464 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 }
2466
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002467 @VisibleForTesting
2468 public SharedPreferences getSharedPreferences() {
2469 return mTelephonySharedPreferences;
2470 }
2471
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002472 /**
2473 * Get the default phone for this device.
2474 */
2475 @VisibleForTesting
2476 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002477 Phone thePhone = getPhone(getDefaultSubscription());
2478 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2479 }
2480
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481 private void publish() {
2482 if (DBG) log("publish: " + this);
2483
Peter Wangc035ce42020-01-08 21:00:22 -08002484 TelephonyFrameworkInitializer
2485 .getTelephonyServiceManager()
2486 .getTelephonyServiceRegisterer()
2487 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 }
2489
Stuart Scott584921c2015-01-15 17:10:34 -08002490 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002491 if (request.phone != null) {
2492 return request.phone;
2493 } else {
2494 return getPhoneFromSubId(request.subId);
2495 }
2496 }
2497
2498 private Phone getPhoneFromSubId(int subId) {
2499 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2500 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002501 }
2502
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002503 /**
2504 * Get phone object associated with a subscription.
2505 * Return default phone if phone object associated with subscription is null
2506 * @param subId - subscriptionId
2507 * @return phone object associated with a subscription or default phone if null.
2508 */
2509 private Phone getPhoneFromSubIdOrDefault(int subId) {
2510 Phone phone = getPhoneFromSubId(subId);
2511 if (phone == null) {
2512 phone = getDefaultPhone();
2513 }
2514 return phone;
2515 }
2516
Rambo Wange53e07d2022-05-10 13:01:13 -07002517 @Nullable
2518 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002519 Phone phone = getPhoneFromRequest(request);
2520 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002521 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002522 }
2523
Wink Saville36469e72014-06-11 15:17:00 -07002524 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002525 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002526 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002527 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002528
Kai Shif70f46f2021-03-03 13:59:46 -08002529 private void sendEraseModemConfig(@NonNull Phone phone) {
2530 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2531 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2532 }
2533
2534 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2535 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2536 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002537 }
2538
Peter Wang44b186e2020-01-13 23:33:09 -08002539 private boolean isImsAvailableOnDevice() {
2540 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2541 if (pm == null) {
2542 // For some reason package manger is not available.. This will fail internally anyway,
2543 // so do not throw error and allow.
2544 return true;
2545 }
2546 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2547 }
2548
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002549 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002550 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002551 }
2552
Wink Savilleb564aae2014-10-23 10:18:09 -07002553 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002554 if (DBG) log("dial: " + number);
2555 // No permission check needed here: This is just a wrapper around the
2556 // ACTION_DIAL intent, which is available to any app since it puts up
2557 // the UI before it does anything.
2558
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002559 final long identity = Binder.clearCallingIdentity();
2560 try {
2561 String url = createTelUrl(number);
2562 if (url == null) {
2563 return;
2564 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002565
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002566 // PENDING: should we just silently fail if phone is offhook or ringing?
2567 PhoneConstants.State state = mCM.getState(subId);
2568 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2569 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2570 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2571 mApp.startActivity(intent);
2572 }
2573 } finally {
2574 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002575 }
2576 }
2577
2578 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002579 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002580 }
2581
Wink Savilleb564aae2014-10-23 10:18:09 -07002582 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002583 if (DBG) log("call: " + number);
2584
2585 // This is just a wrapper around the ACTION_CALL intent, but we still
2586 // need to do a permission check since we're calling startActivity()
2587 // from the context of the phone app.
2588 enforceCallPermission();
2589
Jordan Liu1617b712019-07-10 15:06:26 -07002590 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002591 != AppOpsManager.MODE_ALLOWED) {
2592 return;
2593 }
2594
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595 final long identity = Binder.clearCallingIdentity();
2596 try {
2597 String url = createTelUrl(number);
2598 if (url == null) {
2599 return;
2600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002601
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602 boolean isValid = false;
2603 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2604 if (slist != null) {
2605 for (SubscriptionInfo subInfoRecord : slist) {
2606 if (subInfoRecord.getSubscriptionId() == subId) {
2607 isValid = true;
2608 break;
2609 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002610 }
Wink Saville08874612014-08-31 19:19:58 -07002611 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612 if (!isValid) {
2613 return;
2614 }
Wink Saville08874612014-08-31 19:19:58 -07002615
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002616 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2617 intent.putExtra(SUBSCRIPTION_KEY, subId);
2618 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2619 mApp.startActivity(intent);
2620 } finally {
2621 Binder.restoreCallingIdentity(identity);
2622 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002623 }
2624
Wink Savilleb564aae2014-10-23 10:18:09 -07002625 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002626 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002627 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2628 }
2629
Wink Savilleb564aae2014-10-23 10:18:09 -07002630 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002631 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002632 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2633 }
2634
Wink Savilleb564aae2014-10-23 10:18:09 -07002635 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002636 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002637
2638 final long identity = Binder.clearCallingIdentity();
2639 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002640 Phone phone = getPhone(subId);
2641 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642 checkSimPin.start();
2643 return checkSimPin.unlockSim(null, pin);
2644 } finally {
2645 Binder.restoreCallingIdentity(identity);
2646 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647 }
2648
Wink Savilleb564aae2014-10-23 10:18:09 -07002649 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002650 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651
2652 final long identity = Binder.clearCallingIdentity();
2653 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002654 Phone phone = getPhone(subId);
2655 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002656 checkSimPuk.start();
2657 return checkSimPuk.unlockSim(puk, pin);
2658 } finally {
2659 Binder.restoreCallingIdentity(identity);
2660 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002661 }
2662
2663 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002664 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665 * a synchronous one.
2666 */
2667 private static class UnlockSim extends Thread {
2668
2669 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002670 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002671
2672 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002673 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2674 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002675
2676 // For replies from SimCard interface
2677 private Handler mHandler;
2678
2679 // For async handler to identify request type
2680 private static final int SUPPLY_PIN_COMPLETE = 100;
2681
Michele Berionne5e411512020-11-13 02:36:59 +00002682 UnlockSim(int phoneId, IccCard simCard) {
2683 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002684 mSimCard = simCard;
2685 }
2686
2687 @Override
2688 public void run() {
2689 Looper.prepare();
2690 synchronized (UnlockSim.this) {
2691 mHandler = new Handler() {
2692 @Override
2693 public void handleMessage(Message msg) {
2694 AsyncResult ar = (AsyncResult) msg.obj;
2695 switch (msg.what) {
2696 case SUPPLY_PIN_COMPLETE:
2697 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2698 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002699 mRetryCount = msg.arg1;
2700 if (ar.exception != null) {
2701 if (ar.exception instanceof CommandException &&
2702 ((CommandException)(ar.exception)).getCommandError()
2703 == CommandException.Error.PASSWORD_INCORRECT) {
2704 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002705 } //When UiccCardApp dispose,handle message and return exception
2706 else if (ar.exception instanceof CommandException &&
2707 ((CommandException) (ar.exception)).getCommandError()
2708 == CommandException.Error.ABORTED) {
2709 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002710 } else {
2711 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2712 }
2713 } else {
2714 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2715 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716 mDone = true;
2717 UnlockSim.this.notifyAll();
2718 }
2719 break;
2720 }
2721 }
2722 };
2723 UnlockSim.this.notifyAll();
2724 }
2725 Looper.loop();
2726 }
2727
2728 /*
2729 * Use PIN or PUK to unlock SIM card
2730 *
2731 * If PUK is null, unlock SIM card with PIN
2732 *
2733 * If PUK is not null, unlock SIM card with PUK and set PIN code
2734 */
Wink Saville9de0f752013-10-22 19:04:03 -07002735 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002736
2737 while (mHandler == null) {
2738 try {
2739 wait();
2740 } catch (InterruptedException e) {
2741 Thread.currentThread().interrupt();
2742 }
2743 }
2744 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2745
2746 if (puk == null) {
2747 mSimCard.supplyPin(pin, callback);
2748 } else {
2749 mSimCard.supplyPuk(puk, pin, callback);
2750 }
2751
2752 while (!mDone) {
2753 try {
2754 Log.d(LOG_TAG, "wait for done");
2755 wait();
2756 } catch (InterruptedException e) {
2757 // Restore the interrupted status
2758 Thread.currentThread().interrupt();
2759 }
2760 }
2761 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002762 int[] resultArray = new int[2];
2763 resultArray[0] = mResult;
2764 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002765
2766 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002767 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002768 }
2769
Wink Saville9de0f752013-10-22 19:04:03 -07002770 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002771 }
2772 }
2773
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002774 /**
2775 * This method has been removed due to privacy and stability concerns.
2776 */
2777 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002779 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2780 return;
Wink Saville36469e72014-06-11 15:17:00 -07002781 }
2782
Nathan Harold1f889d82020-06-04 17:05:26 -07002783 @Override
2784 public void updateServiceLocationWithPackageName(String callingPackage) {
2785 mApp.getSystemService(AppOpsManager.class)
2786 .checkPackage(Binder.getCallingUid(), callingPackage);
2787
Nathan Haroldf096d982020-11-18 17:18:06 -08002788 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002789 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2790 // Callers targeting S have no business invoking this method.
2791 return;
2792 }
2793
2794 LocationAccessPolicy.LocationPermissionResult locationResult =
2795 LocationAccessPolicy.checkLocationPermission(mApp,
2796 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2797 .setCallingPackage(callingPackage)
2798 .setCallingFeatureId(null)
2799 .setCallingPid(Binder.getCallingPid())
2800 .setCallingUid(Binder.getCallingUid())
2801 .setMethod("updateServiceLocation")
2802 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2803 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2804 .build());
2805 // Apps that lack location permission have no business calling this method;
2806 // however, because no permission was declared in the public API, denials must
2807 // all be "soft".
2808 switch (locationResult) {
2809 case DENIED_HARD: /* fall through */
2810 case DENIED_SOFT:
2811 return;
2812 }
2813
2814 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002815 final long identity = Binder.clearCallingIdentity();
2816 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002817 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002818 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002819 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002820 }
2821 } finally {
2822 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002823 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002824 }
2825
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002826 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002827 @Override
2828 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002829 return isRadioOnWithFeature(callingPackage, null);
2830 }
2831
2832
2833 @Override
2834 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2835 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2836 callingFeatureId);
2837 }
2838
2839 @Deprecated
2840 @Override
2841 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2842 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002843 }
2844
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002845 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002846 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2847 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002848 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002849 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002850 return false;
2851 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852
2853 final long identity = Binder.clearCallingIdentity();
2854 try {
2855 return isRadioOnForSubscriber(subId);
2856 } finally {
2857 Binder.restoreCallingIdentity(identity);
2858 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002859 }
2860
2861 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862 final long identity = Binder.clearCallingIdentity();
2863 try {
2864 final Phone phone = getPhone(subId);
2865 if (phone != null) {
2866 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2867 } else {
2868 return false;
2869 }
2870 } finally {
2871 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002872 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002873 }
2874
2875 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002876 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002877 }
Wink Saville36469e72014-06-11 15:17:00 -07002878
Wink Savilleb564aae2014-10-23 10:18:09 -07002879 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002880 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002881
2882 final long identity = Binder.clearCallingIdentity();
2883 try {
2884 final Phone phone = getPhone(subId);
2885 if (phone != null) {
2886 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2887 }
2888 } finally {
2889 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002890 }
Wink Saville36469e72014-06-11 15:17:00 -07002891 }
2892
2893 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002894 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002895 }
2896
Wink Savilleb564aae2014-10-23 10:18:09 -07002897 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002898 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002899
2900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 final Phone phone = getPhone(subId);
2903 if (phone == null) {
2904 return false;
2905 }
2906 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2907 toggleRadioOnOffForSubscriber(subId);
2908 }
2909 return true;
2910 } finally {
2911 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002912 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002913 }
Wink Saville36469e72014-06-11 15:17:00 -07002914
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002915 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002916 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002917 /*
2918 * If any of the Radios are available, it will need to be
2919 * shutdown. So return true if any Radio is available.
2920 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002921 final long identity = Binder.clearCallingIdentity();
2922 try {
2923 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2924 Phone phone = PhoneFactory.getPhone(i);
2925 if (phone != null && phone.isRadioAvailable()) return true;
2926 }
2927 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2928 return false;
2929 } finally {
2930 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002931 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002932 }
2933
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002934 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002935 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002936 enforceModifyPermission();
2937
2938 final long identity = Binder.clearCallingIdentity();
2939 try {
2940 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2941 logv("Shutting down Phone " + i);
2942 shutdownRadioUsingPhoneId(i);
2943 }
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002946 }
2947 }
2948
2949 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002950 Phone phone = PhoneFactory.getPhone(phoneId);
2951 if (phone != null && phone.isRadioAvailable()) {
2952 phone.shutdownRadio();
2953 }
2954 }
2955
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002956 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002957 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002958
2959 final long identity = Binder.clearCallingIdentity();
2960 try {
2961 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2962 if (defaultPhone != null) {
2963 defaultPhone.setRadioPower(turnOn);
2964 return true;
2965 } else {
2966 loge("There's no default phone.");
2967 return false;
2968 }
2969 } finally {
2970 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002971 }
Wink Saville36469e72014-06-11 15:17:00 -07002972 }
2973
Wink Savilleb564aae2014-10-23 10:18:09 -07002974 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002975 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002976
2977 final long identity = Binder.clearCallingIdentity();
2978 try {
2979 final Phone phone = getPhone(subId);
2980 if (phone != null) {
2981 phone.setRadioPower(turnOn);
2982 return true;
2983 } else {
2984 return false;
2985 }
2986 } finally {
2987 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002988 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002989 }
2990
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002991 /**
2992 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2993 * no reason to power it off. When any of the voters want to power it off, it will be turned
2994 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2995 * powering it off, and these radio off votes will be cleared.
2996 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
2997 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
2998 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
2999 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3000 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3001 * check its vote.
3002 *
3003 * @param subId The subscription ID.
3004 * @param reason The reason for powering off radio.
3005 * @return true on success and false on failure.
3006 */
3007 public boolean requestRadioPowerOffForReason(int subId,
3008 @TelephonyManager.RadioPowerReason int reason) {
3009 enforceModifyPermission();
3010
3011 final long identity = Binder.clearCallingIdentity();
3012 try {
3013 final Phone phone = getPhone(subId);
3014 if (phone != null) {
3015 phone.setRadioPowerForReason(false, reason);
3016 return true;
3017 } else {
3018 return false;
3019 }
3020 } finally {
3021 Binder.restoreCallingIdentity(identity);
3022 }
3023 }
3024
3025 /**
3026 * Remove the vote on powering off the radio for a reason, as requested by
3027 * {@link requestRadioPowerOffForReason}.
3028 *
3029 * @param subId The subscription ID.
3030 * @param reason The reason for powering off radio.
3031 * @return true on success and false on failure.
3032 */
3033 public boolean clearRadioPowerOffForReason(int subId,
3034 @TelephonyManager.RadioPowerReason int reason) {
3035 enforceModifyPermission();
3036
3037 final long identity = Binder.clearCallingIdentity();
3038 try {
3039 final Phone phone = getPhone(subId);
3040 if (phone != null) {
3041 phone.setRadioPowerForReason(true, reason);
3042 return true;
3043 } else {
3044 return false;
3045 }
3046 } finally {
3047 Binder.restoreCallingIdentity(identity);
3048 }
3049 }
3050
3051 /**
3052 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3053 *
3054 * @param subId The subscription ID.
3055 * @param callingPackage The package making the call.
3056 * @param callingFeatureId The feature in the package.
3057 * @return List of reasons for powering off radio.
3058 */
3059 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3060 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3061
3062 final long identity = Binder.clearCallingIdentity();
3063 List result = new ArrayList();
3064 try {
3065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3066 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3067 return result;
3068 }
3069
3070 final Phone phone = getPhone(subId);
3071 if (phone != null) {
3072 result.addAll(phone.getRadioPowerOffReasons());
3073 }
3074 } finally {
3075 Binder.restoreCallingIdentity(identity);
3076 }
3077 return result;
3078 }
3079
Wink Saville36469e72014-06-11 15:17:00 -07003080 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003081 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003082 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003083 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003084
3085 final long identity = Binder.clearCallingIdentity();
3086 try {
Jack Yu285100e2022-12-02 22:48:35 -08003087 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003088 final Phone phone = getPhone(subId);
3089 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003090 phone.getDataSettingsManager().setDataEnabled(
3091 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003092 return true;
3093 } else {
3094 return false;
3095 }
3096 } finally {
3097 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003098 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003099 }
3100
Wink Saville36469e72014-06-11 15:17:00 -07003101 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003102 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003103 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003104 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003105
3106 final long identity = Binder.clearCallingIdentity();
3107 try {
Jack Yu285100e2022-12-02 22:48:35 -08003108 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003109 final Phone phone = getPhone(subId);
3110 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003111 phone.getDataSettingsManager().setDataEnabled(
3112 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003113 return true;
3114 } else {
3115 return false;
3116 }
3117 } finally {
3118 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003119 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003120 }
3121
Sanket Padawe356d7632015-06-22 14:03:32 -07003122 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003123 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003124 final long identity = Binder.clearCallingIdentity();
3125 try {
3126 final Phone phone = getPhone(subId);
3127 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003128 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003129 } else {
3130 return false;
3131 }
3132 } finally {
3133 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003134 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003135 }
3136
3137 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003138 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003139 }
3140
pkanwarae03a6b2016-11-06 20:37:09 -08003141 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003142 enforceCallPermission();
3143
3144 final long identity = Binder.clearCallingIdentity();
3145 try {
3146 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3147 return;
3148 }
3149 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3150 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3151 } finally {
3152 Binder.restoreCallingIdentity(identity);
3153 }
pkanwar32d516d2016-10-14 19:37:38 -07003154 };
3155
Wink Savilleb564aae2014-10-23 10:18:09 -07003156 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003157 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003158
3159 final long identity = Binder.clearCallingIdentity();
3160 try {
3161 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3162 return false;
3163 }
3164 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3165 } finally {
3166 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003167 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003168 }
3169
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003170 /**
3171 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3172 * tag on getCallState Binder call.
3173 */
3174 @Deprecated
3175 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003176 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003177 if (CompatChanges.isChangeEnabled(
3178 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3179 Binder.getCallingUid())) {
3180 // Do not allow this API to be called on API version 31+, it should only be
3181 // called on old apps using this Binder call directly.
3182 throw new SecurityException("This method can only be used for applications "
3183 + "targeting API version 30 or less.");
3184 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003185 final long identity = Binder.clearCallingIdentity();
3186 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003187 Phone phone = getPhone(getDefaultSubscription());
3188 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3189 PhoneConstantConversions.convertCallState(phone.getState());
3190 } finally {
3191 Binder.restoreCallingIdentity(identity);
3192 }
3193 }
3194
3195 @Override
3196 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3197 if (CompatChanges.isChangeEnabled(
3198 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3199 Binder.getCallingUid())) {
3200 // Check READ_PHONE_STATE for API version 31+
3201 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3202 featureId, "getCallStateForSubscription")) {
3203 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3204 + "targeting API level 31+.");
3205 }
3206 }
3207 final long identity = Binder.clearCallingIdentity();
3208 try {
3209 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003210 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3211 PhoneConstantConversions.convertCallState(phone.getState());
3212 } finally {
3213 Binder.restoreCallingIdentity(identity);
3214 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003215 }
3216
Sanket Padawe356d7632015-06-22 14:03:32 -07003217 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003218 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003219 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003220 }
3221
3222 @Override
3223 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003224 final long identity = Binder.clearCallingIdentity();
3225 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003226 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003227 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003228 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003229 } else {
3230 return PhoneConstantConversions.convertDataState(
3231 PhoneConstants.DataState.DISCONNECTED);
3232 }
3233 } finally {
3234 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003235 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003236 }
3237
Sanket Padawe356d7632015-06-22 14:03:32 -07003238 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003239 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003240 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003241 }
3242
3243 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003244 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003245 final long identity = Binder.clearCallingIdentity();
3246 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003247 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003248 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003249 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003250 } else {
3251 return TelephonyManager.DATA_ACTIVITY_NONE;
3252 }
3253 } finally {
3254 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003256 }
3257
3258 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003259 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003260 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003261 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003262
3263 LocationAccessPolicy.LocationPermissionResult locationResult =
3264 LocationAccessPolicy.checkLocationPermission(mApp,
3265 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3266 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003267 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003268 .setCallingPid(Binder.getCallingPid())
3269 .setCallingUid(Binder.getCallingUid())
3270 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003271 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003272 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3273 .build());
3274 switch (locationResult) {
3275 case DENIED_HARD:
3276 throw new SecurityException("Not allowed to access cell location");
3277 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003278 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3279 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003280 }
3281
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003282 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003283 final long identity = Binder.clearCallingIdentity();
3284 try {
3285 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003286 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003287 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003288 } finally {
3289 Binder.restoreCallingIdentity(identity);
3290 }
Svetoslav64fad262015-04-14 14:35:21 -07003291 }
3292
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003293 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003294 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003295 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3296 // registered cell info, so return a NULL country instead.
3297 final long identity = Binder.clearCallingIdentity();
3298 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003299 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3300 // Get default phone in this case.
3301 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3302 }
Jack Yu285100e2022-12-02 22:48:35 -08003303 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003304 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003305 if (phone == null) return "";
3306 ServiceStateTracker sst = phone.getServiceStateTracker();
3307 if (sst == null) return "";
3308 LocaleTracker lt = sst.getLocaleTracker();
3309 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003310 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003311 } finally {
3312 Binder.restoreCallingIdentity(identity);
3313 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003314 }
3315
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003316 /**
3317 * This method was removed due to potential issues caused by performing partial
3318 * updates of service state, and lack of a credible use case.
3319 *
3320 * This has the ability to break the telephony implementation by disabling notification of
3321 * changes in device connectivity. DO NOT USE THIS!
3322 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003323 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003324 public void enableLocationUpdates() {
3325 mApp.enforceCallingOrSelfPermission(
3326 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003327 }
3328
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003329 /**
3330 * This method was removed due to potential issues caused by performing partial
3331 * updates of service state, and lack of a credible use case.
3332 *
3333 * This has the ability to break the telephony implementation by disabling notification of
3334 * changes in device connectivity. DO NOT USE THIS!
3335 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003336 @Override
3337 public void disableLocationUpdates() {
3338 mApp.enforceCallingOrSelfPermission(
3339 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003340 }
3341
3342 @Override
3343 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003344 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3345 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003346 try {
3347 mApp.getSystemService(AppOpsManager.class)
3348 .checkPackage(Binder.getCallingUid(), callingPackage);
3349 } catch (SecurityException e) {
3350 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3351 throw e;
3352 }
3353
Nathan Haroldf096d982020-11-18 17:18:06 -08003354 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003355 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3356 throw new SecurityException(
3357 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3358 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003359
Jordan Liu1617b712019-07-10 15:06:26 -07003360 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003361 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3362 return null;
3363 }
Svetoslav64fad262015-04-14 14:35:21 -07003364
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003365 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003366
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003367 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003368 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003369
Nathan Haroldf180aac2018-06-01 18:43:55 -07003370 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3371 for (CellInfo ci : info) {
3372 if (ci instanceof CellInfoGsm) {
3373 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3374 } else if (ci instanceof CellInfoWcdma) {
3375 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3376 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003377 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003378 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003379 }
3380
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003381 private List<CellInfo> getCachedCellInfo() {
3382 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3383 for (Phone phone : PhoneFactory.getPhones()) {
3384 List<CellInfo> info = phone.getAllCellInfo();
3385 if (info != null) cellInfos.addAll(info);
3386 }
3387 return cellInfos;
3388 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003389
3390 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003391 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003392 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003393 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003394
3395 LocationAccessPolicy.LocationPermissionResult locationResult =
3396 LocationAccessPolicy.checkLocationPermission(mApp,
3397 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3398 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003399 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003400 .setCallingPid(Binder.getCallingPid())
3401 .setCallingUid(Binder.getCallingUid())
3402 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003403 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003404 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3405 .build());
3406 switch (locationResult) {
3407 case DENIED_HARD:
3408 throw new SecurityException("Not allowed to access cell info");
3409 case DENIED_SOFT:
3410 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003411 }
3412
Nathan Haroldf096d982020-11-18 17:18:06 -08003413 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003414 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3415 return getCachedCellInfo();
3416 }
3417
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003418 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003419 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003420 final long identity = Binder.clearCallingIdentity();
3421 try {
3422 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3423 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003424 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003425 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003426 if (info != null) cellInfos.addAll(info);
3427 }
3428 return cellInfos;
3429 } finally {
3430 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003431 }
3432 }
3433
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003434 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003435 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3436 String callingFeatureId) {
3437 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3438 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003439 }
3440
3441 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003442 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3443 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003444 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003445 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003446 }
3447
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003448 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3449 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003450 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003451 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003452
3453 LocationAccessPolicy.LocationPermissionResult locationResult =
3454 LocationAccessPolicy.checkLocationPermission(mApp,
3455 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3456 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003457 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003458 .setCallingPid(Binder.getCallingPid())
3459 .setCallingUid(Binder.getCallingUid())
3460 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003461 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3462 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003463 .build());
3464 switch (locationResult) {
3465 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003466 if (TelephonyPermissions
3467 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003468 // Safetynet logging for b/154934934
3469 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3470 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003471 throw new SecurityException("Not allowed to access cell info");
3472 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003473 if (TelephonyPermissions
3474 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003475 // Safetynet logging for b/154934934
3476 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3477 }
Nathan Harold5320c422019-05-09 10:26:08 -07003478 try {
3479 cb.onCellInfo(new ArrayList<CellInfo>());
3480 } catch (RemoteException re) {
3481 // Drop without consequences
3482 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003483 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003484 }
3485
Nathan Harolda939a962019-05-09 10:13:47 -07003486
3487 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003488 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3489
3490 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3491 }
3492
3493 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003494 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003495 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003496 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003497
3498 final long identity = Binder.clearCallingIdentity();
3499 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003500 Phone phone = getPhone(subId);
3501 if (phone == null) {
3502 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3503 } else {
3504 phone.setCellInfoListRate(rateInMillis, workSource);
3505 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003506 } finally {
3507 Binder.restoreCallingIdentity(identity);
3508 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003509 }
3510
Shishir Agrawala9f32182016-04-12 12:00:16 -07003511 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003512 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003513 Phone phone = PhoneFactory.getPhone(slotIndex);
3514 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003515 return null;
3516 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003517 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003518 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003519 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003520 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003521 return null;
3522 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003523
3524 final long identity = Binder.clearCallingIdentity();
3525 try {
3526 return phone.getImei();
3527 } finally {
3528 Binder.restoreCallingIdentity(identity);
3529 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003530 }
3531
3532 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003533 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3534 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3535 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3536 callingFeatureId, "getPrimaryImei")) {
3537 throw new SecurityException("Caller does not have permission");
3538 }
3539 final long identity = Binder.clearCallingIdentity();
3540 try {
3541 for (Phone phone : PhoneFactory.getPhones()) {
3542 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3543 return phone.getImei();
3544 }
3545 }
3546 throw new UnsupportedOperationException("Operation not supported");
3547 } finally {
3548 Binder.restoreCallingIdentity(identity);
3549 }
3550 }
3551
3552 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003553 public String getTypeAllocationCodeForSlot(int slotIndex) {
3554 Phone phone = PhoneFactory.getPhone(slotIndex);
3555 String tac = null;
3556 if (phone != null) {
3557 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003558 try {
3559 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3560 } catch (IndexOutOfBoundsException e) {
3561 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3562 return null;
3563 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003564 }
3565 return tac;
3566 }
3567
3568 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003569 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003570 try {
3571 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3572 } catch (SecurityException se) {
3573 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3574 throw new SecurityException("Package " + callingPackage + " does not belong to "
3575 + Binder.getCallingUid());
3576 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003577 Phone phone = PhoneFactory.getPhone(slotIndex);
3578 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003579 return null;
3580 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003581
Jeff Davidson913390f2018-02-23 17:11:49 -08003582 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003583 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003584 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003585 return null;
3586 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003587
3588 final long identity = Binder.clearCallingIdentity();
3589 try {
3590 return phone.getMeid();
3591 } finally {
3592 Binder.restoreCallingIdentity(identity);
3593 }
Jack Yu2af8d712017-03-15 17:14:14 -07003594 }
3595
3596 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003597 public String getManufacturerCodeForSlot(int slotIndex) {
3598 Phone phone = PhoneFactory.getPhone(slotIndex);
3599 String manufacturerCode = null;
3600 if (phone != null) {
3601 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003602 try {
3603 manufacturerCode =
3604 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3605 } catch (IndexOutOfBoundsException e) {
3606 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3607 return null;
3608 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003609 }
3610 return manufacturerCode;
3611 }
3612
3613 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003614 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3615 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003616 Phone phone = PhoneFactory.getPhone(slotIndex);
3617 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003618 return null;
3619 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003620 int subId = phone.getSubId();
3621 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003622 mApp, subId, callingPackage, callingFeatureId,
3623 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003624 return null;
3625 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003626
3627 final long identity = Binder.clearCallingIdentity();
3628 try {
3629 return phone.getDeviceSvn();
3630 } finally {
3631 Binder.restoreCallingIdentity(identity);
3632 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003633 }
3634
fionaxu43304da2017-11-27 22:51:16 -08003635 @Override
3636 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003637 final long identity = Binder.clearCallingIdentity();
3638 try {
3639 final Phone phone = getPhone(subId);
3640 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3641 } finally {
3642 Binder.restoreCallingIdentity(identity);
3643 }
fionaxu43304da2017-11-27 22:51:16 -08003644 }
3645
3646 @Override
3647 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003648 final long identity = Binder.clearCallingIdentity();
3649 try {
3650 final Phone phone = getPhone(subId);
3651 return phone == null ? null : phone.getCarrierName();
3652 } finally {
3653 Binder.restoreCallingIdentity(identity);
3654 }
fionaxu43304da2017-11-27 22:51:16 -08003655 }
3656
calvinpanffe225e2018-11-01 19:43:06 +08003657 @Override
chen xu0026ca62019-03-06 15:28:50 -08003658 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003659 final long identity = Binder.clearCallingIdentity();
3660 try {
3661 final Phone phone = getPhone(subId);
3662 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003663 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003664 } finally {
3665 Binder.restoreCallingIdentity(identity);
3666 }
3667 }
3668
3669 @Override
chen xu0026ca62019-03-06 15:28:50 -08003670 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003671 final long identity = Binder.clearCallingIdentity();
3672 try {
3673 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003674 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003675 } finally {
3676 Binder.restoreCallingIdentity(identity);
3677 }
3678 }
3679
chen xu651eec72018-11-11 19:03:44 -08003680 @Override
chen xu864e11c2018-12-06 22:10:03 -08003681 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3682 if (!isSubscriptionMccMnc) {
3683 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3684 }
chen xu651eec72018-11-11 19:03:44 -08003685 final Phone phone = PhoneFactory.getPhone(slotIndex);
3686 if (phone == null) {
3687 return TelephonyManager.UNKNOWN_CARRIER_ID;
3688 }
3689 final long identity = Binder.clearCallingIdentity();
3690 try {
3691 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3692 } finally {
3693 Binder.restoreCallingIdentity(identity);
3694 }
3695 }
3696
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003697 //
3698 // Internal helper methods.
3699 //
3700
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003701 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003702 * Make sure the caller is the calling package itself
3703 *
3704 * @throws SecurityException if the caller is not the calling package
3705 */
3706 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3707 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003708 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3709 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003710 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003711 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003712 } catch (PackageManager.NameNotFoundException e) {
3713 // packageUid is -1
3714 }
3715 if (packageUid != callingUid) {
3716 throw new SecurityException(message + ": Package " + callingPackage
3717 + " does not belong to " + callingUid);
3718 }
3719 }
3720
3721 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003722 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3723 *
3724 * @throws SecurityException if the caller does not have the required permission
3725 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003726 @VisibleForTesting
3727 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003728 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3729 }
3730
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003731 /**
arunvoddud7401012022-12-15 16:08:12 +00003732 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003733 *
3734 * @throws SecurityException if the caller does not have the required permission
3735 */
3736 @VisibleForTesting
3737 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003738 enforceReadPermission(null);
3739 }
3740
3741 /**
3742 * Make sure the caller has the READ_PHONE_STATE permissions.
3743 *
3744 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3745 */
3746 @VisibleForTesting
3747 public void enforceReadPermission(String msg) {
3748 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003749 }
3750
Shuo Qian3b6ee772019-11-13 17:43:31 -08003751 private void enforceActiveEmergencySessionPermission() {
3752 mApp.enforceCallingOrSelfPermission(
3753 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3754 }
3755
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003756 /**
3757 * Make sure the caller has the CALL_PHONE permission.
3758 *
3759 * @throws SecurityException if the caller does not have the required permission
3760 */
3761 private void enforceCallPermission() {
3762 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3763 }
3764
paulhu5a773602019-08-23 19:17:33 +08003765 private void enforceSettingsPermission() {
3766 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003767 }
3768
Michele Berionne5e411512020-11-13 02:36:59 +00003769 private void enforceRebootPermission() {
3770 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3771 }
3772
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003773 private String createTelUrl(String number) {
3774 if (TextUtils.isEmpty(number)) {
3775 return null;
3776 }
3777
Jake Hambye994d462014-02-03 13:10:13 -08003778 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003779 }
3780
Ihab Awadf9e92732013-12-05 18:02:52 -08003781 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003782 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3783 }
3784
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003785 private static void logv(String msg) {
3786 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3787 }
3788
Ihab Awadf9e92732013-12-05 18:02:52 -08003789 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003790 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3791 }
3792
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003793 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003794 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003795 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003796 }
3797
Sanket Padawe356d7632015-06-22 14:03:32 -07003798 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003799 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003800 final long identity = Binder.clearCallingIdentity();
3801 try {
3802 final Phone phone = PhoneFactory.getPhone(slotIndex);
3803 if (phone == null) {
3804 return PhoneConstants.PHONE_TYPE_NONE;
3805 } else {
3806 return phone.getPhoneType();
3807 }
3808 } finally {
3809 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003810 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003811 }
3812
3813 /**
3814 * Returns the CDMA ERI icon index to display
3815 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003816 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003817 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3818 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3819 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003820 }
3821
Sanket Padawe356d7632015-06-22 14:03:32 -07003822 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003823 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3824 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003825 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003826 mApp, subId, callingPackage, callingFeatureId,
3827 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003828 return -1;
3829 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003830
3831 final long identity = Binder.clearCallingIdentity();
3832 try {
3833 final Phone phone = getPhone(subId);
3834 if (phone != null) {
3835 return phone.getCdmaEriIconIndex();
3836 } else {
3837 return -1;
3838 }
3839 } finally {
3840 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003841 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003842 }
3843
3844 /**
3845 * Returns the CDMA ERI icon mode,
3846 * 0 - ON
3847 * 1 - FLASHING
3848 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003849 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003850 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3851 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3852 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003853 }
3854
Sanket Padawe356d7632015-06-22 14:03:32 -07003855 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003856 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3857 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003858 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003859 mApp, subId, callingPackage, callingFeatureId,
3860 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003861 return -1;
3862 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003863
3864 final long identity = Binder.clearCallingIdentity();
3865 try {
3866 final Phone phone = getPhone(subId);
3867 if (phone != null) {
3868 return phone.getCdmaEriIconMode();
3869 } else {
3870 return -1;
3871 }
3872 } finally {
3873 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003874 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003875 }
3876
3877 /**
3878 * Returns the CDMA ERI text,
3879 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003880 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003881 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3882 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3883 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003884 }
3885
Sanket Padawe356d7632015-06-22 14:03:32 -07003886 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003887 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3888 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003889 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003890 mApp, subId, callingPackage, callingFeatureId,
3891 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003892 return null;
3893 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003894
3895 final long identity = Binder.clearCallingIdentity();
3896 try {
3897 final Phone phone = getPhone(subId);
3898 if (phone != null) {
3899 return phone.getCdmaEriText();
3900 } else {
3901 return null;
3902 }
3903 } finally {
3904 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003905 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003906 }
3907
3908 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003909 * Returns the CDMA MDN.
3910 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003911 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003912 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3914 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003915
3916 final long identity = Binder.clearCallingIdentity();
3917 try {
3918 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003919 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003920 return phone.getLine1Number();
3921 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003922 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003923 return null;
3924 }
3925 } finally {
3926 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003927 }
3928 }
3929
3930 /**
3931 * Returns the CDMA MIN.
3932 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003933 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003934 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003935 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3936 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003937
3938 final long identity = Binder.clearCallingIdentity();
3939 try {
3940 final Phone phone = getPhone(subId);
3941 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3942 return phone.getCdmaMin();
3943 } else {
3944 return null;
3945 }
3946 } finally {
3947 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003948 }
3949 }
3950
Hall Liud892bec2018-11-30 14:51:45 -08003951 @Override
3952 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3953 INumberVerificationCallback callback, String callingPackage) {
3954 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3955 != PERMISSION_GRANTED) {
3956 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3957 }
3958 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3959
3960 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3961 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003962 throw new SecurityException("Calling package must be configured in the device config: "
3963 + "calling package: " + callingPackage
3964 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003965 }
3966
3967 if (range == null) {
3968 throw new NullPointerException("Range must be non-null");
3969 }
3970
3971 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003972 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003973
3974 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3975 }
3976
Junda Liuca05d5d2014-08-14 22:36:34 -07003977 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003978 * Returns true if CDMA provisioning needs to run.
3979 */
3980 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003981 final long identity = Binder.clearCallingIdentity();
3982 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003983 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003984 } finally {
3985 Binder.restoreCallingIdentity(identity);
3986 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003987 }
3988
3989 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003990 * Sets the voice mail number of a given subId.
3991 */
3992 @Override
3993 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003994 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3995 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003996
3997 final long identity = Binder.clearCallingIdentity();
3998 try {
3999 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4000 new Pair<String, String>(alphaTag, number), new Integer(subId));
4001 return success;
4002 } finally {
4003 Binder.restoreCallingIdentity(identity);
4004 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004005 }
4006
Ta-wei Yen87c49842016-05-13 21:19:52 -07004007 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004008 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4009 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004010 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4011 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004012 if (!TextUtils.equals(callingPackage, systemDialer)) {
4013 throw new SecurityException("caller must be system dialer");
4014 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004015
4016 final long identity = Binder.clearCallingIdentity();
4017 try {
4018 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4019 if (phoneAccountHandle == null) {
4020 return null;
4021 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004022 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004023 } finally {
4024 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004025 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004026 }
4027
4028 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004029 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4030 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004031 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004032 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004033 mApp, subId, callingPackage, callingFeatureId,
4034 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004035 return null;
4036 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004037
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004038 final long identity = Binder.clearCallingIdentity();
4039 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004040 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004041 } finally {
4042 Binder.restoreCallingIdentity(identity);
4043 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004044 }
4045
4046 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004047 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4048 VisualVoicemailSmsFilterSettings settings) {
4049 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004050
4051 final long identity = Binder.clearCallingIdentity();
4052 try {
4053 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004054 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004055 } finally {
4056 Binder.restoreCallingIdentity(identity);
4057 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004058 }
4059
4060 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004061 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4062 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004063
4064 final long identity = Binder.clearCallingIdentity();
4065 try {
4066 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004067 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004068 } finally {
4069 Binder.restoreCallingIdentity(identity);
4070 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004071 }
4072
4073 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004074 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4075 String callingPackage, int subId) {
4076 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004077
4078 final long identity = Binder.clearCallingIdentity();
4079 try {
4080 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004081 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004082 } finally {
4083 Binder.restoreCallingIdentity(identity);
4084 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004085 }
4086
4087 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004088 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004089 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004090
4091 final long identity = Binder.clearCallingIdentity();
4092 try {
4093 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004094 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004095 } finally {
4096 Binder.restoreCallingIdentity(identity);
4097 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004098 }
4099
4100 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004101 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4102 String callingAttributionTag, int subId, String number, int port, String text,
4103 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004104 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004105 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004106 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004107 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004108 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4109 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004110 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004111
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004112 /**
fionaxu0152e512016-11-14 13:36:14 -08004113 * Sets the voice activation state of a given subId.
4114 */
4115 @Override
4116 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004117 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4118 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004119
4120 final long identity = Binder.clearCallingIdentity();
4121 try {
4122 final Phone phone = getPhone(subId);
4123 if (phone != null) {
4124 phone.setVoiceActivationState(activationState);
4125 } else {
4126 loge("setVoiceActivationState fails with invalid subId: " + subId);
4127 }
4128 } finally {
4129 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004130 }
4131 }
4132
4133 /**
4134 * Sets the data activation state of a given subId.
4135 */
4136 @Override
4137 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004138 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4139 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004140
4141 final long identity = Binder.clearCallingIdentity();
4142 try {
4143 final Phone phone = getPhone(subId);
4144 if (phone != null) {
4145 phone.setDataActivationState(activationState);
4146 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004147 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004148 }
4149 } finally {
4150 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004151 }
4152 }
4153
4154 /**
4155 * Returns the voice activation state of a given subId.
4156 */
4157 @Override
4158 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004159 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004160
fionaxu0152e512016-11-14 13:36:14 -08004161 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004162 final long identity = Binder.clearCallingIdentity();
4163 try {
4164 if (phone != null) {
4165 return phone.getVoiceActivationState();
4166 } else {
4167 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4168 }
4169 } finally {
4170 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004171 }
4172 }
4173
4174 /**
4175 * Returns the data activation state of a given subId.
4176 */
4177 @Override
4178 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004179 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004180
fionaxu0152e512016-11-14 13:36:14 -08004181 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004182 final long identity = Binder.clearCallingIdentity();
4183 try {
4184 if (phone != null) {
4185 return phone.getDataActivationState();
4186 } else {
4187 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4188 }
4189 } finally {
4190 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004191 }
4192 }
4193
4194 /**
Wink Saville36469e72014-06-11 15:17:00 -07004195 * Returns the unread count of voicemails for a subId
4196 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004197 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004198 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4199 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004200 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004201 mApp, subId, callingPackage, callingFeatureId,
4202 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004203 return 0;
4204 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004205 final long identity = Binder.clearCallingIdentity();
4206 try {
4207 final Phone phone = getPhone(subId);
4208 if (phone != null) {
4209 return phone.getVoiceMessageCount();
4210 } else {
4211 return 0;
4212 }
4213 } finally {
4214 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004215 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004216 }
4217
4218 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004219 * returns true, if the device is in a state where both voice and data
4220 * are supported simultaneously. This can change based on location or network condition.
4221 */
4222 @Override
4223 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004224 final long identity = Binder.clearCallingIdentity();
4225 try {
4226 final Phone phone = getPhone(subId);
4227 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4228 } finally {
4229 Binder.restoreCallingIdentity(identity);
4230 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004231 }
4232
4233 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004234 * Send the dialer code if called from the current default dialer or the caller has
4235 * carrier privilege.
4236 * @param inputCode The dialer code to send
4237 */
4238 @Override
4239 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004240 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004241 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004242 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4243 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004244 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004245 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004246 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004247 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004248
4249 final long identity = Binder.clearCallingIdentity();
4250 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004251 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004252 } finally {
4253 Binder.restoreCallingIdentity(identity);
4254 }
fionaxu235cc5e2017-03-06 22:25:57 -08004255 }
4256
Pengquan Menga1bb6272018-09-06 09:59:22 -07004257 @Override
4258 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004259 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004260 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004261 mApp, subId, "getNetworkSelectionMode");
4262 final long identity = Binder.clearCallingIdentity();
4263 try {
4264 if (!isActiveSubscription(subId)) {
4265 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4266 }
4267 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4268 } finally {
4269 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004270 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004271 }
4272
Brad Ebinger35c841c2018-10-01 10:40:55 -07004273 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004274 public boolean isInEmergencySmsMode() {
4275 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4276 final long identity = Binder.clearCallingIdentity();
4277 try {
4278 for (Phone phone : PhoneFactory.getPhones()) {
4279 if (phone.isInEmergencySmsMode()) {
4280 return true;
4281 }
4282 }
4283 } finally {
4284 Binder.restoreCallingIdentity(identity);
4285 }
4286 return false;
4287 }
4288
shilu366312e2019-12-17 09:28:10 -08004289 /**
4290 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4291 * @param subId The subscription to use to check the configuration.
4292 * @param c The callback that will be used to send the result.
4293 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004294 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004295 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4296 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004297 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004298 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004299
4300 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4301 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4302 "IMS not available on device.");
4303 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004304 final long token = Binder.clearCallingIdentity();
4305 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004306 int slotId = getSlotIndexOrException(subId);
4307 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004308
4309 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4310 if (controller != null) {
4311 ImsManager imsManager = controller.getImsManager(subId);
4312 if (imsManager != null) {
4313 imsManager.addRegistrationCallbackForSubscription(c, subId);
4314 } else {
4315 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4316 }
4317 } else {
4318 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4319 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004320 } catch (ImsException e) {
4321 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004322 } finally {
4323 Binder.restoreCallingIdentity(token);
4324 }
4325 }
4326
shilu366312e2019-12-17 09:28:10 -08004327 /**
4328 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4329 * @param subId The subscription to use to check the configuration.
4330 * @param c The callback that will be used to send the result.
4331 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004332 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004333 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004334 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004335 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004336 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4337 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4338 }
Meng Wangafbc5852019-09-19 17:37:13 -07004339 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004340
Meng Wangafbc5852019-09-19 17:37:13 -07004341 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004342 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4343 if (controller != null) {
4344 ImsManager imsManager = controller.getImsManager(subId);
4345 if (imsManager != null) {
4346 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4347 } else {
4348 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4349 + "is inactive, ignoring unregister.");
4350 // If the ImsManager is not valid, just return, since the callback
4351 // will already have been removed internally.
4352 }
4353 }
Meng Wangafbc5852019-09-19 17:37:13 -07004354 } finally {
4355 Binder.restoreCallingIdentity(token);
4356 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004357 }
4358
Brad Ebingera34a6c22019-10-22 17:36:18 -07004359 /**
4360 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4361 */
4362 @Override
4363 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4364 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4365 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4366 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4367 "IMS not available on device.");
4368 }
4369 final long token = Binder.clearCallingIdentity();
4370 try {
4371 Phone phone = getPhone(subId);
4372 if (phone == null) {
4373 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4374 + subId + "'");
4375 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4376 }
4377 phone.getImsRegistrationState(regState -> {
4378 try {
4379 consumer.accept((regState == null)
4380 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4381 } catch (RemoteException e) {
4382 // Ignore if the remote process is no longer available to call back.
4383 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4384 }
4385 });
4386 } finally {
4387 Binder.restoreCallingIdentity(token);
4388 }
4389 }
4390
4391 /**
4392 * Get the transport type for the IMS service registration state.
4393 */
4394 @Override
4395 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004396 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004397 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004398 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4399 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4400 "IMS not available on device.");
4401 }
4402 final long token = Binder.clearCallingIdentity();
4403 try {
4404 Phone phone = getPhone(subId);
4405 if (phone == null) {
4406 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4407 + subId + "'");
4408 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4409 }
4410 phone.getImsRegistrationTech(regTech -> {
4411 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4412 int regTechConverted = (regTech == null)
4413 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4414 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4415 regTechConverted);
4416 try {
4417 consumer.accept(regTechConverted);
4418 } catch (RemoteException e) {
4419 // Ignore if the remote process is no longer available to call back.
4420 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4421 }
4422 });
4423 } finally {
4424 Binder.restoreCallingIdentity(token);
4425 }
4426 }
4427
shilu366312e2019-12-17 09:28:10 -08004428 /**
4429 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4430 * @param subId The subscription to use to check the configuration.
4431 * @param c The callback that will be used to send the result.
4432 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004433 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004434 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4435 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004436 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004437 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004438 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4439 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4440 "IMS not available on device.");
4441 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004442 final long token = Binder.clearCallingIdentity();
4443 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004444 int slotId = getSlotIndexOrException(subId);
4445 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004446
4447 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4448 if (controller != null) {
4449 ImsManager imsManager = controller.getImsManager(subId);
4450 if (imsManager != null) {
4451 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4452 } else {
4453 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4454 }
4455 } else {
4456 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4457 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004458 } catch (ImsException e) {
4459 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004460 } finally {
4461 Binder.restoreCallingIdentity(token);
4462 }
4463 }
4464
shilu366312e2019-12-17 09:28:10 -08004465 /**
4466 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4467 * @param subId The subscription to use to check the configuration.
4468 * @param c The callback that will be used to send the result.
4469 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004470 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004471 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004472 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004473 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004474 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4475 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4476 }
Meng Wangafbc5852019-09-19 17:37:13 -07004477
4478 final long token = Binder.clearCallingIdentity();
4479 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004480 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4481 if (controller != null) {
4482 ImsManager imsManager = controller.getImsManager(subId);
4483 if (imsManager != null) {
4484 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4485 } else {
4486 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4487 + " is inactive, ignoring unregister.");
4488 // If the ImsManager is not valid, just return, since the callback
4489 // will already have been removed internally.
4490 }
4491 }
Meng Wangafbc5852019-09-19 17:37:13 -07004492 } finally {
4493 Binder.restoreCallingIdentity(token);
4494 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004495 }
4496
4497 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004498 public boolean isCapable(int subId, int capability, int regTech) {
4499 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004500 final long token = Binder.clearCallingIdentity();
4501 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004502 int slotId = getSlotIndexOrException(subId);
4503 verifyImsMmTelConfiguredOrThrow(slotId);
4504 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4505 } catch (com.android.ims.ImsException e) {
4506 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4507 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004508 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004509 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4510 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004511 } finally {
4512 Binder.restoreCallingIdentity(token);
4513 }
4514 }
4515
4516 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004517 public boolean isAvailable(int subId, int capability, int regTech) {
4518 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004519 final long token = Binder.clearCallingIdentity();
4520 try {
4521 Phone phone = getPhone(subId);
4522 if (phone == null) return false;
4523 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004524 } catch (com.android.ims.ImsException e) {
4525 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4526 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004527 } finally {
4528 Binder.restoreCallingIdentity(token);
4529 }
4530 }
4531
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004532 /**
4533 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4534 * subscription.
4535 * @param subId The subscription to use to check the configuration.
4536 * @param callback The callback that will be used to send the result.
4537 * @param capability The MmTelFeature capability that will be used to send the result.
4538 * @param transportType The transport type of the MmTelFeature capability.
4539 */
4540 @Override
4541 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4542 int transportType) {
4543 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004544 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4545 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4546 "IMS not available on device.");
4547 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004548 final long token = Binder.clearCallingIdentity();
4549 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004550 int slotId = getSlotIndex(subId);
4551 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4552 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4553 + subId + "'");
4554 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4555 }
4556 verifyImsMmTelConfiguredOrThrow(slotId);
4557 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4558 transportType, aBoolean -> {
4559 try {
4560 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4561 } catch (RemoteException e) {
4562 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4563 + "running. Ignore");
4564 }
4565 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004566 } catch (ImsException e) {
4567 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004568 } finally {
4569 Binder.restoreCallingIdentity(token);
4570 }
4571 }
4572
shilu366312e2019-12-17 09:28:10 -08004573 /**
4574 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4575 * @param subId The subscription to use to check the configuration.
4576 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004577 @Override
4578 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004579 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004580 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004581
Brad Ebinger35c841c2018-10-01 10:40:55 -07004582 final long token = Binder.clearCallingIdentity();
4583 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004584 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004585 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004586 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004587 } catch (ImsException e) {
4588 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004589 } finally {
4590 Binder.restoreCallingIdentity(token);
4591 }
4592 }
4593
4594 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004595 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004597 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004598 final long identity = Binder.clearCallingIdentity();
4599 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004600 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004601 // This setting doesn't require an active ImsService connection, so do not verify. The
4602 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004603 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004604 } catch (ImsException e) {
4605 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004606 } finally {
4607 Binder.restoreCallingIdentity(identity);
4608 }
4609 }
4610
shilu366312e2019-12-17 09:28:10 -08004611 /**
4612 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4613 * @param subId The subscription to use to check the configuration.
4614 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004615 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004616 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004617 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004618 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004619 final long identity = Binder.clearCallingIdentity();
4620 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004621 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004622 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004623 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004624 } catch (ImsException e) {
4625 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004626 } finally {
4627 Binder.restoreCallingIdentity(identity);
4628 }
4629 }
4630
4631 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004632 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004634 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004635 final long identity = Binder.clearCallingIdentity();
4636 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004637 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004638 // This setting doesn't require an active ImsService connection, so do not verify. The
4639 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004640 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004641 } catch (ImsException e) {
4642 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004643 } finally {
4644 Binder.restoreCallingIdentity(identity);
4645 }
4646 }
4647
shilu366312e2019-12-17 09:28:10 -08004648 /**
4649 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4650 * @param subId The subscription to use to check the configuration.
4651 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004652 @Override
4653 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004654 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004655 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004656 final long identity = Binder.clearCallingIdentity();
4657 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004658 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004659 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004660 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004661 } catch (ImsException e) {
4662 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004663 } finally {
4664 Binder.restoreCallingIdentity(identity);
4665 }
4666 }
4667
4668 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004669 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004671 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004672 final long identity = Binder.clearCallingIdentity();
4673 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004674 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004675 // This setting doesn't require an active ImsService connection, so do not verify. The
4676 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004677 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004678 } catch (ImsException e) {
4679 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004680 } finally {
4681 Binder.restoreCallingIdentity(identity);
4682 }
4683 }
4684
shilu366312e2019-12-17 09:28:10 -08004685 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004686 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4687 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4688 * @param subId The subscription to use to check the configuration.
4689 */
4690 @Override
4691 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004692 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004693 mApp, subId, "isCrossSimCallingEnabledByUser");
4694 final long identity = Binder.clearCallingIdentity();
4695 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004696 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004697 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004698 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004699 } catch (ImsException e) {
4700 throw new ServiceSpecificException(e.getCode());
4701 } finally {
4702 Binder.restoreCallingIdentity(identity);
4703 }
4704 }
4705
4706 /**
4707 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4708 * Requires MODIFY_PHONE_STATE permission.
4709 * @param subId The subscription to use to check the configuration.
4710 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4711 * false otherwise
4712 */
4713 @Override
4714 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4716 "setCrossSimCallingEnabled");
4717 final long identity = Binder.clearCallingIdentity();
4718 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004719 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004720 // This setting doesn't require an active ImsService connection, so do not verify. The
4721 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004722 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004723 } catch (ImsException e) {
4724 throw new ServiceSpecificException(e.getCode());
4725 } finally {
4726 Binder.restoreCallingIdentity(identity);
4727 }
4728 }
4729
4730 /**
shilu366312e2019-12-17 09:28:10 -08004731 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4732 * @param subId The subscription to use to check the configuration.
4733 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004734 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004735
Brad Ebinger35c841c2018-10-01 10:40:55 -07004736 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004737 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004738 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004739 final long identity = Binder.clearCallingIdentity();
4740 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004741 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004742 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004743 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004744 } catch (ImsException e) {
4745 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004746 } finally {
4747 Binder.restoreCallingIdentity(identity);
4748 }
4749 }
4750
4751 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004752 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004753 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004754 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004755 final long identity = Binder.clearCallingIdentity();
4756 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004757 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004758 // This setting doesn't require an active ImsService connection, so do not verify. The
4759 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004760 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004761 } catch (ImsException e) {
4762 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004763 } finally {
4764 Binder.restoreCallingIdentity(identity);
4765 }
4766 }
4767
4768 @Override
4769 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4771 "setVoWiFiNonPersistent");
4772 final long identity = Binder.clearCallingIdentity();
4773 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004774 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004775 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004776 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004777 } catch (ImsException e) {
4778 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004779 } finally {
4780 Binder.restoreCallingIdentity(identity);
4781 }
4782 }
4783
shilu366312e2019-12-17 09:28:10 -08004784 /**
4785 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4786 * @param subId The subscription to use to check the configuration.
4787 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004788 @Override
4789 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004790 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004791 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004792 final long identity = Binder.clearCallingIdentity();
4793 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004794 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004795 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004796 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004797 } catch (ImsException e) {
4798 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004799 } finally {
4800 Binder.restoreCallingIdentity(identity);
4801 }
4802 }
4803
4804 @Override
4805 public void setVoWiFiModeSetting(int subId, int mode) {
4806 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4807 "setVoWiFiModeSetting");
4808 final long identity = Binder.clearCallingIdentity();
4809 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004810 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004811 // This setting doesn't require an active ImsService connection, so do not verify. The
4812 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004813 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004814 } catch (ImsException e) {
4815 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004816 } finally {
4817 Binder.restoreCallingIdentity(identity);
4818 }
4819 }
4820
4821 @Override
4822 public int getVoWiFiRoamingModeSetting(int subId) {
4823 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4824 final long identity = Binder.clearCallingIdentity();
4825 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004826 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004827 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004828 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004829 } catch (ImsException e) {
4830 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004831 } finally {
4832 Binder.restoreCallingIdentity(identity);
4833 }
4834 }
4835
4836 @Override
4837 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4839 "setVoWiFiRoamingModeSetting");
4840 final long identity = Binder.clearCallingIdentity();
4841 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004842 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004843 // This setting doesn't require an active ImsService connection, so do not verify. The
4844 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004845 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004846 } catch (ImsException e) {
4847 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004848 } finally {
4849 Binder.restoreCallingIdentity(identity);
4850 }
4851 }
4852
4853 @Override
4854 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4856 "setRttCapabilityEnabled");
4857 final long identity = Binder.clearCallingIdentity();
4858 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004859 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004860 // This setting doesn't require an active ImsService connection, so do not verify. The
4861 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004862 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004863 } catch (ImsException e) {
4864 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004865 } finally {
4866 Binder.restoreCallingIdentity(identity);
4867 }
4868 }
4869
shilu366312e2019-12-17 09:28:10 -08004870 /**
4871 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4872 * @param subId The subscription to use to check the configuration.
4873 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004874 @Override
4875 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004876 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004877 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004878 final long identity = Binder.clearCallingIdentity();
4879 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004880 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004881 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004882 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004883 } catch (ImsException e) {
4884 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004885 } finally {
4886 Binder.restoreCallingIdentity(identity);
4887 }
4888 }
4889
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004890 @Override
4891 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4892 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004893
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004894 final long identity = Binder.clearCallingIdentity();
4895 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004896 if (!isImsAvailableOnDevice()) {
4897 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4898 "IMS not available on device.");
4899 }
4900 int slotId = getSlotIndexOrException(subId);
4901 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004902
4903 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4904 if (controller != null) {
4905 ImsManager imsManager = controller.getImsManager(subId);
4906 if (imsManager != null) {
4907 imsManager.addProvisioningCallbackForSubscription(callback, subId);
4908 } else {
4909 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4910 }
4911 } else {
4912 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4913 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004914 } catch (ImsException e) {
4915 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004916 } finally {
4917 Binder.restoreCallingIdentity(identity);
4918 }
4919 }
4920
4921 @Override
4922 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4923 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004924
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004925 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004926 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4927 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4928 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004929 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004930 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4931 if (controller != null) {
4932 ImsManager imsManager = controller.getImsManager(subId);
4933 if (imsManager != null) {
4934 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
4935 } else {
4936 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4937 + " is inactive, ignoring unregister.");
4938 // If the ImsManager is not valid, just return, since the callback will already
4939 // have been removed internally.
4940 }
4941 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004942 } finally {
4943 Binder.restoreCallingIdentity(identity);
4944 }
4945 }
4946
joonhunshincffb7fc2021-11-28 07:32:01 +00004947 @Override
4948 public void registerFeatureProvisioningChangedCallback(int subId,
4949 IFeatureProvisioningCallback callback) {
4950 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4951 mApp, subId, "registerFeatureProvisioningChangedCallback");
4952
4953 final long identity = Binder.clearCallingIdentity();
4954 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4955 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4956 }
4957
joonhunshin91bc1952022-04-29 08:47:15 +00004958 try {
4959 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4960 if (controller == null) {
4961 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4962 "Device does not support IMS");
4963 }
4964 controller.addFeatureProvisioningChangedCallback(subId, callback);
4965 } finally {
4966 Binder.restoreCallingIdentity(identity);
4967 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004968 }
4969
4970 @Override
4971 public void unregisterFeatureProvisioningChangedCallback(int subId,
4972 IFeatureProvisioningCallback callback) {
4973 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4974 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4975
4976 final long identity = Binder.clearCallingIdentity();
4977 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4978 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4979 }
4980
joonhunshin91bc1952022-04-29 08:47:15 +00004981 try {
4982 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4983 if (controller == null) {
4984 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4985 return;
4986 }
4987 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4988 } finally {
4989 Binder.restoreCallingIdentity(identity);
4990 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004991 }
allenwtsu99c623b2020-01-03 18:24:23 +08004992
4993 private void checkModifyPhoneStatePermission(int subId, String message) {
4994 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4995 message);
4996 }
4997
allenwtsu99c623b2020-01-03 18:24:23 +08004998 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004999 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005000 boolean isProvisioned) {
5001 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5002
5003 final long identity = Binder.clearCallingIdentity();
5004 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005005 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5006 if (controller == null) {
5007 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5008 return;
5009 }
5010 controller.setRcsProvisioningStatusForCapability(
5011 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005012 } finally {
5013 Binder.restoreCallingIdentity(identity);
5014 }
allenwtsu99c623b2020-01-03 18:24:23 +08005015 }
5016
5017
5018 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005019 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5020 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5021 mApp, subId, "getRcsProvisioningStatusForCapability");
5022
allenwtsu99c623b2020-01-03 18:24:23 +08005023 final long identity = Binder.clearCallingIdentity();
5024 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005025 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5026 if (controller == null) {
5027 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5028
5029 // device does not support IMS, this method will return true always.
5030 return true;
5031 }
5032 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005033 } finally {
5034 Binder.restoreCallingIdentity(identity);
5035 }
5036 }
5037
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005038 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005039 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5040 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005041 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005042
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005043 final long identity = Binder.clearCallingIdentity();
5044 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005045 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5046 if (controller == null) {
5047 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5048 return;
5049 }
5050 controller.setImsProvisioningStatusForCapability(
5051 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005052 } finally {
5053 Binder.restoreCallingIdentity(identity);
5054 }
5055 }
5056
5057 @Override
5058 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005059 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5060 mApp, subId, "getProvisioningStatusForCapability");
5061
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005062 final long identity = Binder.clearCallingIdentity();
5063 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005064 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5065 if (controller == null) {
5066 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005067
joonhunshin91bc1952022-04-29 08:47:15 +00005068 // device does not support IMS, this method will return true always.
5069 return true;
5070 }
5071 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005072 } finally {
5073 Binder.restoreCallingIdentity(identity);
5074 }
5075 }
5076
5077 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005078 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5079 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5080 mApp, subId, "isProvisioningRequiredForCapability");
5081
5082 final long identity = Binder.clearCallingIdentity();
5083 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005084 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5085 if (controller == null) {
5086 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5087
5088 // device does not support IMS, this method will return false
5089 return false;
5090 }
5091 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005092 } finally {
5093 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005094 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005095 }
5096
5097 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005098 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5099 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5100 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005101
joonhunshincffb7fc2021-11-28 07:32:01 +00005102 final long identity = Binder.clearCallingIdentity();
5103 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005104 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5105 if (controller == null) {
5106 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5107
5108 // device does not support IMS, this method will return false
5109 return false;
5110 }
5111 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005112 } finally {
5113 Binder.restoreCallingIdentity(identity);
5114 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005115 }
5116
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005117 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005118 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005119 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5120 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5121 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005122 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5123 mApp, subId, "getImsProvisioningInt");
5124
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005125 final long identity = Binder.clearCallingIdentity();
5126 try {
5127 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005128 int slotId = getSlotIndex(subId);
5129 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5130 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5131 + subId + "' for key:" + key);
5132 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5133 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005134
joonhunshin91bc1952022-04-29 08:47:15 +00005135 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5136 if (controller == null) {
5137 loge("getImsProvisioningInt: Device does not support IMS");
5138
5139 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5140 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5141 }
5142 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005143 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5144 return retVal;
5145 }
5146
calvinpanb5a34062021-02-08 19:59:36 +08005147 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005148 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005149 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5150 + subId + "' for key:" + key);
5151 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005152 } finally {
5153 Binder.restoreCallingIdentity(identity);
5154 }
5155 }
5156
5157 @Override
5158 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005159 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5160 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5161 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005162 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5163 mApp, subId, "getImsProvisioningString");
5164
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005165 final long identity = Binder.clearCallingIdentity();
5166 try {
5167 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005168 int slotId = getSlotIndex(subId);
5169 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5170 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5171 + subId + "' for key:" + key);
5172 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5173 }
calvinpanb5a34062021-02-08 19:59:36 +08005174 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005175 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005176 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5177 + subId + "' for key:" + key);
5178 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005179 } finally {
5180 Binder.restoreCallingIdentity(identity);
5181 }
5182 }
5183
5184 @Override
5185 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005186 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5187 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5188 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005189 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5190 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005191
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005192 final long identity = Binder.clearCallingIdentity();
5193 try {
5194 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005195 int slotId = getSlotIndex(subId);
5196 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5197 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5198 + subId + "' for key:" + key);
5199 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5200 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005201
joonhunshin91bc1952022-04-29 08:47:15 +00005202 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5203 if (controller == null) {
5204 loge("setImsProvisioningInt: Device does not support IMS");
5205
5206 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5207 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5208 }
5209 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005210 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5211 return retVal;
5212 }
5213
calvinpanb5a34062021-02-08 19:59:36 +08005214 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5215 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005216 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005217 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005218 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005219 } finally {
5220 Binder.restoreCallingIdentity(identity);
5221 }
5222 }
5223
5224 @Override
5225 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005226 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5227 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5228 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005229 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5230 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005231 final long identity = Binder.clearCallingIdentity();
5232 try {
5233 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005234 int slotId = getSlotIndex(subId);
5235 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5236 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5237 + subId + "' for key:" + key);
5238 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5239 }
calvinpanb5a34062021-02-08 19:59:36 +08005240 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5241 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005242 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005243 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005244 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005245 } finally {
5246 Binder.restoreCallingIdentity(identity);
5247 }
5248 }
5249
Brad Ebinger919631e2021-06-02 17:46:35 -07005250 /**
5251 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5252 * for the given slot ID or no ImsResolver instance has been created.
5253 * @param slotId The slot ID that the IMS service is created for.
5254 * @throws ImsException If there is no ImsService configured for this slot.
5255 */
5256 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5257 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5258 ImsFeature.FEATURE_MMTEL)) {
5259 throw new ImsException("This subscription does not support MMTEL over IMS",
5260 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5261 }
5262 }
5263
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005264 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005265 int slotId = SubscriptionManager.getSlotIndex(subId);
5266 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005267 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5268 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005269 }
5270 return slotId;
5271 }
5272
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005273 private int getSlotIndex(int subId) {
5274 int slotId = SubscriptionManager.getSlotIndex(subId);
5275 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5276 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5277 }
5278 return slotId;
5279 }
5280
Wink Saville36469e72014-06-11 15:17:00 -07005281 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005282 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005283 */
5284 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005285 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5286 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005287 try {
5288 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5289 } catch (SecurityException se) {
5290 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5291 throw new SecurityException("Package " + callingPackage + " does not belong to "
5292 + Binder.getCallingUid());
5293 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005294 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005295 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005296 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005297 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005298 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005299 mApp, subId, callingPackage, callingFeatureId,
5300 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005301 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5302 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005303
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005304 final long identity = Binder.clearCallingIdentity();
5305 try {
5306 final Phone phone = getPhone(subId);
5307 if (phone != null) {
5308 return phone.getServiceState().getDataNetworkType();
5309 } else {
5310 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5311 }
5312 } finally {
5313 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005314 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005315 }
5316
5317 /**
5318 * Returns the data network type
5319 */
5320 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005321 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005322 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005323 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005324 }
5325
5326 /**
5327 * Returns the data network type for a subId
5328 */
5329 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005330 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5331 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005332 String functionName = "getDataNetworkTypeForSubscriber";
5333 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5334 mApp, functionName)) {
5335 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5336 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5337 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5338 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005339 }
5340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005341 final long identity = Binder.clearCallingIdentity();
5342 try {
5343 final Phone phone = getPhone(subId);
5344 if (phone != null) {
5345 return phone.getServiceState().getDataNetworkType();
5346 } else {
5347 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5348 }
5349 } finally {
5350 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005352 }
5353
5354 /**
Wink Saville36469e72014-06-11 15:17:00 -07005355 * Returns the Voice network type for a subId
5356 */
5357 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005358 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5359 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005360 String functionName = "getVoiceNetworkTypeForSubscriber";
5361 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5362 mApp, functionName)) {
5363 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5364 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5365 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5366 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005367 }
5368
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005369 final long identity = Binder.clearCallingIdentity();
5370 try {
5371 final Phone phone = getPhone(subId);
5372 if (phone != null) {
5373 return phone.getServiceState().getVoiceNetworkType();
5374 } else {
5375 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5376 }
5377 } finally {
5378 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005379 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005380 }
5381
5382 /**
5383 * @return true if a ICC card is present
5384 */
5385 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005386 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005387 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005388 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005389 }
5390
5391 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005392 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005393 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005394 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005395 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396 final long identity = Binder.clearCallingIdentity();
5397 try {
5398 final Phone phone = PhoneFactory.getPhone(slotIndex);
5399 if (phone != null) {
5400 return phone.getIccCard().hasIccCard();
5401 } else {
5402 return false;
5403 }
5404 } finally {
5405 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005407 }
5408
5409 /**
5410 * Return if the current radio is LTE on CDMA. This
5411 * is a tri-state return value as for a period of time
5412 * the mode may be unknown.
5413 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005414 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005415 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005416 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005417 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005418 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005419 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5420 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5421 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005422 }
5423
Sanket Padawe356d7632015-06-22 14:03:32 -07005424 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005425 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5426 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005427 try {
5428 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5429 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005430 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5431 }
5432
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005433 final long identity = Binder.clearCallingIdentity();
5434 try {
5435 final Phone phone = getPhone(subId);
5436 if (phone == null) {
5437 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5438 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005439 return TelephonyProperties.lte_on_cdma_device()
5440 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441 }
5442 } finally {
5443 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005444 }
Wink Saville36469e72014-06-11 15:17:00 -07005445 }
5446
Wink Saville36469e72014-06-11 15:17:00 -07005447 /**
5448 * {@hide}
5449 * Returns Default subId, 0 in the case of single standby.
5450 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005451 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005452 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005453 }
5454
Shishir Agrawala9f32182016-04-12 12:00:16 -07005455 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005456 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005457 }
5458
Wink Savilleb564aae2014-10-23 10:18:09 -07005459 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005460 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005461 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005462
Pengquan Menge92a50d2018-09-21 15:54:48 -07005463 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08005464 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
5465 return SubscriptionManagerService.getInstance().isActiveSubId(subId,
5466 mApp.getOpPackageName(), mApp.getFeatureId());
5467 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005468 return mSubscriptionController.isActiveSubId(subId);
5469 }
5470
Ihab Awadf2177b72013-11-25 13:33:23 -08005471 /**
5472 * @see android.telephony.TelephonyManager.WifiCallingChoices
5473 */
5474 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475 final long identity = Binder.clearCallingIdentity();
5476 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005477 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005478 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5479 getWhenToMakeWifiCallsDefaultPreference());
5480 } finally {
5481 Binder.restoreCallingIdentity(identity);
5482 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005483 }
5484
5485 /**
5486 * @see android.telephony.TelephonyManager.WifiCallingChoices
5487 */
5488 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005489 final long identity = Binder.clearCallingIdentity();
5490 try {
5491 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005492 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005493 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5494 } finally {
5495 Binder.restoreCallingIdentity(identity);
5496 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005497 }
5498
Sailesh Nepald1e68152013-12-12 19:08:02 -08005499 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005500 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005501 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005502 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005503
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005504 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5505 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5506 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005507 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005508 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5509 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005510 }
5511 return PhoneFactory.getPhone(phoneId);
5512 }
5513
Shishir Agrawal566b7612013-10-28 14:41:00 -07005514 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005515 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005516 @NonNull IccLogicalChannelRequest request) {
5517 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5518 /*message=*/ "iccOpenLogicalChannel");
5519
5520 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5521 // Verify that the callingPackage in the request belongs to the calling UID
5522 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5523
5524 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005525 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005526
Rambo Wanga1782702021-11-10 20:15:19 -08005527 private Phone getPhoneFromValidIccLogicalChannelRequest(
5528 @NonNull IccLogicalChannelRequest request, String message) {
5529 Phone phone;
5530 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5532 mApp, request.subId, message);
5533 phone = getPhoneFromSubId(request.subId);
5534 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5535 enforceModifyPermission();
5536 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5537 } else {
5538 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005539 }
Rambo Wanga1782702021-11-10 20:15:19 -08005540 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005541 }
5542
5543 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005544 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005545 final long identity = Binder.clearCallingIdentity();
5546 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005547 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005548 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005549 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5550 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005551 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5552 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005553 loge("The calling package is not allowed to access ISD-R.");
5554 throw new SecurityException(
5555 "The calling package is not allowed to access ISD-R.");
5556 }
Derek Tan740e1672017-06-27 14:56:27 -07005557 }
Derek Tan740e1672017-06-27 14:56:27 -07005558
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005559 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005560 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5561 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005562 return response;
5563 } finally {
5564 Binder.restoreCallingIdentity(identity);
5565 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005566 }
5567
5568 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005569 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5570 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5571 /*message=*/"iccCloseLogicalChannel");
5572
5573 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5574
5575 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005576 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005577
Rambo Wanga1782702021-11-10 20:15:19 -08005578 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5579 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005580 // before this feature is enabled, this API should only return false if
5581 // the operation fails instead of throwing runtime exception for
5582 // backward-compatibility.
5583 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5584 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005585 final long identity = Binder.clearCallingIdentity();
5586 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005587 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005588 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005589 }
Chen Xue9d737e2022-01-01 23:41:31 -08005590 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005591 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005592 Boolean success = false;
5593 if (result instanceof RuntimeException) {
5594 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005595 if (shouldThrowExceptionOnFailure) {
5596 throw (RuntimeException) result;
5597 } else {
5598 return false;
5599 }
Chen Xue9d737e2022-01-01 23:41:31 -08005600 } else if (result instanceof Boolean) {
5601 success = (Boolean) result;
5602 } else {
5603 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5604 }
Rambo Wanga1782702021-11-10 20:15:19 -08005605 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005606 return success;
5607 } finally {
5608 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005609 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005610 }
5611
5612 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005613 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005614 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5616 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005617 if (DBG) {
5618 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5619 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5620 + p3 + " data=" + data);
5621 }
5622 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5623 command, p1, p2, p3, data);
5624 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005625
Jordan Liu4c733742019-02-28 12:03:40 -08005626 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005627 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5628 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005629 enforceModifyPermission();
5630 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005631 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5632 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5633 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005634 }
5635 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005636 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5637 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005638 }
5639
5640 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5641 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642 final long identity = Binder.clearCallingIdentity();
5643 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005644 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005645 return "";
5646 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005647
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005648 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005649 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5650 null /* workSource */);
5651 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005652
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005653 // Append the returned status code to the end of the response payload.
5654 String s = Integer.toHexString(
5655 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5656 if (response.payload != null) {
5657 s = IccUtils.bytesToHexString(response.payload) + s;
5658 }
5659 return s;
5660 } finally {
5661 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005662 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005663 }
Jake Hambye994d462014-02-03 13:10:13 -08005664
Evan Charltonc66da362014-05-16 14:06:40 -07005665 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005666 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5667 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005668 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5669 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005670 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005671 if (DBG) {
5672 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5673 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5674 }
5675 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5676 cla, command, p1, p2, p3, data);
5677 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005678
Jordan Liu4c733742019-02-28 12:03:40 -08005679 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005680 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5681 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005682 enforceModifyPermission();
5683 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5684 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005685 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5686 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5687 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005688 }
5689
5690 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005691 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5692 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005693 }
5694
5695 // open APDU basic channel assuming the caller has sufficient permissions
5696 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5697 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005698 final long identity = Binder.clearCallingIdentity();
5699 try {
5700 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5701 && TextUtils.equals(ISDR_AID, data)) {
5702 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005703 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5704 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005705 if (bestComponent == null
5706 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5707 loge("The calling package is not allowed to select ISD-R.");
5708 throw new SecurityException(
5709 "The calling package is not allowed to select ISD-R.");
5710 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005711 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005712
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005713 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005714 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5715 null /* workSource */);
5716 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005717
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005718 // Append the returned status code to the end of the response payload.
5719 String s = Integer.toHexString(
5720 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5721 if (response.payload != null) {
5722 s = IccUtils.bytesToHexString(response.payload) + s;
5723 }
5724 return s;
5725 } finally {
5726 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005727 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005728 }
5729
5730 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005731 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005732 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5734 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005735
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736 final long identity = Binder.clearCallingIdentity();
5737 try {
5738 if (DBG) {
5739 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5740 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5741 }
5742
5743 IccIoResult response =
5744 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5745 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5746 subId);
5747
5748 if (DBG) {
5749 log("Exchange SIM_IO [R]" + response);
5750 }
5751
5752 byte[] result = null;
5753 int length = 2;
5754 if (response.payload != null) {
5755 length = 2 + response.payload.length;
5756 result = new byte[length];
5757 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5758 } else {
5759 result = new byte[length];
5760 }
5761
5762 result[length - 1] = (byte) response.sw2;
5763 result[length - 2] = (byte) response.sw1;
5764 return result;
5765 } finally {
5766 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005767 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005768 }
5769
Nathan Haroldb3014052017-01-25 15:57:32 -08005770 /**
5771 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5772 * on a particular subscription
5773 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005774 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5775 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005776 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005777 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005778 return null;
5779 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780
5781 final long identity = Binder.clearCallingIdentity();
5782 try {
5783 if (appType != TelephonyManager.APPTYPE_USIM
5784 && appType != TelephonyManager.APPTYPE_SIM) {
5785 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5786 return null;
5787 }
5788 Object response = sendRequest(
5789 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5790 if (response instanceof String[]) {
5791 return (String[]) response;
5792 }
yincheng zhao2737e882019-09-06 17:06:54 -07005793 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005794 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005795 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005796 } finally {
5797 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005798 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005799 }
5800
yincheng zhao2737e882019-09-06 17:06:54 -07005801 /**
5802 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5803 * subscription.
5804 *
5805 * @param subId the id of the subscription.
5806 * @param appType the uicc app type, must be USIM or SIM.
5807 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5808 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005809 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005810 * @return number of fplmns that is successfully written to the SIM.
5811 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005812 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5813 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005814 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5815 mApp, subId, "setForbiddenPlmns");
5816
yincheng zhao2737e882019-09-06 17:06:54 -07005817 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5818 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5819 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5820 }
5821 if (fplmns == null) {
5822 throw new IllegalArgumentException("Fplmn List provided is null");
5823 }
5824 for (String fplmn : fplmns) {
5825 if (!CellIdentity.isValidPlmn(fplmn)) {
5826 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5827 }
5828 }
5829 final long identity = Binder.clearCallingIdentity();
5830 try {
5831 Object response = sendRequest(
5832 CMD_SET_FORBIDDEN_PLMNS,
5833 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5834 subId);
5835 return (int) response;
5836 } finally {
5837 Binder.restoreCallingIdentity(identity);
5838 }
5839 }
5840
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005841 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005842 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5844 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005845
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005846 final long identity = Binder.clearCallingIdentity();
5847 try {
5848 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5849 if (response.payload == null) {
5850 return "";
5851 }
Evan Charltonc66da362014-05-16 14:06:40 -07005852
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005853 // Append the returned status code to the end of the response payload.
5854 String s = Integer.toHexString(
5855 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5856 s = IccUtils.bytesToHexString(response.payload) + s;
5857 return s;
5858 } finally {
5859 Binder.restoreCallingIdentity(identity);
5860 }
Evan Charltonc66da362014-05-16 14:06:40 -07005861 }
5862
Jake Hambye994d462014-02-03 13:10:13 -08005863 /**
5864 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5865 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5866 *
5867 * @param itemID the ID of the item to read
5868 * @return the NV item as a String, or null on error.
5869 */
5870 @Override
5871 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005872 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5874 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005875
5876 final long identity = Binder.clearCallingIdentity();
5877 try {
5878 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005879 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005880 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5881 return value;
5882 } finally {
5883 Binder.restoreCallingIdentity(identity);
5884 }
Jake Hambye994d462014-02-03 13:10:13 -08005885 }
5886
5887 /**
5888 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5889 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5890 *
5891 * @param itemID the ID of the item to read
5892 * @param itemValue the value to write, as a String
5893 * @return true on success; false on any failure
5894 */
5895 @Override
5896 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005897 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005898 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5899 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900
5901 final long identity = Binder.clearCallingIdentity();
5902 try {
5903 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5904 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005905 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005906 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5907 return success;
5908 } finally {
5909 Binder.restoreCallingIdentity(identity);
5910 }
Jake Hambye994d462014-02-03 13:10:13 -08005911 }
5912
5913 /**
5914 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5915 * Used for device configuration by some CDMA operators.
5916 *
5917 * @param preferredRoamingList byte array containing the new PRL
5918 * @return true on success; false on any failure
5919 */
5920 @Override
5921 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005922 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5923 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005924
5925 final long identity = Binder.clearCallingIdentity();
5926 try {
5927 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5928 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5929 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5930 return success;
5931 } finally {
5932 Binder.restoreCallingIdentity(identity);
5933 }
Jake Hambye994d462014-02-03 13:10:13 -08005934 }
5935
5936 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005937 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005938 * Used for device configuration by some CDMA operators.
5939 *
chen xu6dac5ab2018-10-26 17:39:23 -07005940 * @param slotIndex - device slot.
5941 *
Jake Hambye994d462014-02-03 13:10:13 -08005942 * @return true on success; false on any failure
5943 */
5944 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005945 public boolean resetModemConfig(int slotIndex) {
5946 Phone phone = PhoneFactory.getPhone(slotIndex);
5947 if (phone != null) {
5948 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5949 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005950
chen xu6dac5ab2018-10-26 17:39:23 -07005951 final long identity = Binder.clearCallingIdentity();
5952 try {
5953 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5954 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5955 return success;
5956 } finally {
5957 Binder.restoreCallingIdentity(identity);
5958 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005959 }
chen xu6dac5ab2018-10-26 17:39:23 -07005960 return false;
5961 }
5962
5963 /**
5964 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5965 *
5966 * @param slotIndex - device slot.
5967 *
5968 * @return true on success; false on any failure
5969 */
5970 @Override
5971 public boolean rebootModem(int slotIndex) {
5972 Phone phone = PhoneFactory.getPhone(slotIndex);
5973 if (phone != null) {
5974 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5975 mApp, phone.getSubId(), "rebootModem");
5976
5977 final long identity = Binder.clearCallingIdentity();
5978 try {
5979 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5980 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5981 return success;
5982 } finally {
5983 Binder.restoreCallingIdentity(identity);
5984 }
5985 }
5986 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005987 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005988
Brad Ebinger51f743a2017-01-23 13:50:20 -08005989 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005990 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5991 * {@link #disableIms(int)}.
5992 * @param slotIndex device slot.
5993 */
5994 public void resetIms(int slotIndex) {
5995 enforceModifyPermission();
5996
5997 final long identity = Binder.clearCallingIdentity();
5998 try {
5999 if (mImsResolver == null) {
6000 // may happen if the does not support IMS.
6001 return;
6002 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006003 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006004 } finally {
6005 Binder.restoreCallingIdentity(identity);
6006 }
6007 }
6008
6009 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006010 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6011 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006012 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006013 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006014 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015
6016 final long identity = Binder.clearCallingIdentity();
6017 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006018 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006019 // may happen if the device does not support IMS.
6020 return;
6021 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006022 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006023 } finally {
6024 Binder.restoreCallingIdentity(identity);
6025 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006026 }
6027
6028 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006029 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6030 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006031 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006032 public void disableIms(int slotId) {
6033 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006034
6035 final long identity = Binder.clearCallingIdentity();
6036 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006037 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006038 // may happen if the device does not support IMS.
6039 return;
6040 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006041 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042 } finally {
6043 Binder.restoreCallingIdentity(identity);
6044 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006045 }
6046
6047 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006048 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6049 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006050 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006051 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006052 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006053 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006054
6055 final long identity = Binder.clearCallingIdentity();
6056 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006057 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006058 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6059 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006060 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006061 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006062 } finally {
6063 Binder.restoreCallingIdentity(identity);
6064 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006065 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006066 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006067 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6068 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006069 @Override
6070 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006071 enforceModifyPermission();
6072
6073 final long identity = Binder.clearCallingIdentity();
6074 try {
6075 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006076 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006077 } finally {
6078 Binder.restoreCallingIdentity(identity);
6079 }
6080 }
6081
6082 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006083 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006084 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006085 */
6086 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6087 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006088
6089 final long identity = Binder.clearCallingIdentity();
6090 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006091 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006092 // may happen if the device does not support IMS.
6093 return null;
6094 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006095 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006096 } finally {
6097 Binder.restoreCallingIdentity(identity);
6098 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006099 }
6100
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006101 /**
6102 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006103 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006104 */
6105 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6106 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107
6108 final long identity = Binder.clearCallingIdentity();
6109 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006110 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006111 // may happen if the device does not support IMS.
6112 return null;
6113 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006114 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006115 } finally {
6116 Binder.restoreCallingIdentity(identity);
6117 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006118 }
6119
Brad Ebinger884c07b2018-02-15 16:17:40 -08006120 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006121 * Sets the ImsService Package Name that Telephony will bind to.
6122 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006123 * @param slotIndex the slot ID that the ImsService should bind for.
6124 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006125 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006126 * @param featureTypes An integer array of feature types associated with a packageName.
6127 * @param packageName The name of the package that the current configuration will be replaced
6128 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006129 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006130 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006131 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6132 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006133 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006135 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006136
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137 final long identity = Binder.clearCallingIdentity();
6138 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006139 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006140 // may happen if the device does not support IMS.
6141 return false;
6142 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006143 Map<Integer, String> featureConfig = new HashMap<>();
6144 for (int featureType : featureTypes) {
6145 featureConfig.put(featureType, packageName);
6146 }
6147 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6148 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006149 } finally {
6150 Binder.restoreCallingIdentity(identity);
6151 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006152 }
6153
6154 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006155 * Clears any carrier ImsService overrides for the slot index specified that were previously
6156 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6157 *
6158 * This should only be used for testing.
6159 *
6160 * @param slotIndex the slot ID that the ImsService should bind for.
6161 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6162 */
6163 @Override
6164 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006165 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6166 "clearCarrierImsServiceOverride");
6167 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006168 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006169
6170 final long identity = Binder.clearCallingIdentity();
6171 try {
6172 if (mImsResolver == null) {
6173 // may happen if the device does not support IMS.
6174 return false;
6175 }
6176 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6177 } finally {
6178 Binder.restoreCallingIdentity(identity);
6179 }
6180 }
6181
6182 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006183 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006184 *
6185 * @param slotId The slot that the ImsService is associated with.
6186 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6187 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006188 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006189 * @return the package name of the ImsService configuration.
6190 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006191 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6192 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006193 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006194 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6195 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006196
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006197 final long identity = Binder.clearCallingIdentity();
6198 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006199 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006200 // may happen if the device does not support IMS.
6201 return "";
6202 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006203 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006204 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6205 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006206 } finally {
6207 Binder.restoreCallingIdentity(identity);
6208 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006209 }
6210
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006211 /**
6212 * Get the MmTelFeature state associated with the requested subscription id.
6213 * @param subId The subscription that the MmTelFeature is associated with.
6214 * @param callback A callback with an integer containing the
6215 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6216 */
6217 @Override
6218 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6219 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006220 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6221 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6222 "IMS not available on device.");
6223 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006224 final long token = Binder.clearCallingIdentity();
6225 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006226 int slotId = getSlotIndex(subId);
6227 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6228 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6229 + subId + "'");
6230 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6231 }
6232 verifyImsMmTelConfiguredOrThrow(slotId);
6233 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6234 try {
6235 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6236 } catch (RemoteException e) {
6237 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6238 + "Ignore");
6239 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006240 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006241 } catch (ImsException e) {
6242 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006243 } finally {
6244 Binder.restoreCallingIdentity(token);
6245 }
6246 }
6247
Daniel Brightbb5840b2021-01-12 15:48:18 -08006248 /**
6249 * Sets the ims registration state on all valid {@link Phone}s.
6250 */
6251 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006252 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006253
6254 final long identity = Binder.clearCallingIdentity();
6255 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006256 // NOTE: Before S, this method only set the default phone.
6257 for (final Phone phone : PhoneFactory.getPhones()) {
6258 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6259 phone.setImsRegistrationState(registered);
6260 }
6261 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006262 } finally {
6263 Binder.restoreCallingIdentity(identity);
6264 }
Wink Saville36469e72014-06-11 15:17:00 -07006265 }
6266
6267 /**
Stuart Scott54788802015-03-30 13:18:01 -07006268 * Set the network selection mode to automatic.
6269 *
6270 */
6271 @Override
6272 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6274 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006275
6276 final long identity = Binder.clearCallingIdentity();
6277 try {
shilufc958392020-01-20 11:36:01 -08006278 if (!isActiveSubscription(subId)) {
6279 return;
6280 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006281 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006282 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6283 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006284 } finally {
6285 Binder.restoreCallingIdentity(identity);
6286 }
Stuart Scott54788802015-03-30 13:18:01 -07006287 }
6288
Jack Yud10cdd42020-09-28 20:28:01 -07006289 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006290 * Ask the radio to connect to the input network and change selection mode to manual.
6291 *
6292 * @param subId the id of the subscription.
6293 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6294 * the operator to attach to.
6295 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6296 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6297 * normal network selection next time.
6298 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006299 */
6300 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006301 public boolean setNetworkSelectionModeManual(
6302 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6304 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006305
Jack Yu285100e2022-12-02 22:48:35 -08006306 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006307 if (!isActiveSubscription(subId)) {
6308 return false;
6309 }
6310
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006311 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006312 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006313 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006314 if (DBG) {
6315 log("setNetworkSelectionModeManual: subId: " + subId
6316 + " operator: " + operatorInfo);
6317 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006318 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6319 } finally {
6320 Binder.restoreCallingIdentity(identity);
6321 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006322 }
shilu84f6e8b2019-12-19 13:58:01 -08006323 /**
6324 * Get the manual network selection
6325 *
6326 * @param subId the id of the subscription.
6327 *
6328 * @return the previously saved user selected PLMN
6329 */
6330 @Override
6331 public String getManualNetworkSelectionPlmn(int subId) {
6332 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006333 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006334 mApp, subId, "getManualNetworkSelectionPlmn");
6335
6336 final long identity = Binder.clearCallingIdentity();
6337 try {
6338 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006339 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006340 }
6341
6342 final Phone phone = getPhone(subId);
6343 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006344 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006345 }
6346 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6347 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6348 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6349 } finally {
6350 Binder.restoreCallingIdentity(identity);
6351 }
6352 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006353
6354 /**
6355 * Scans for available networks.
6356 */
6357 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006358 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6359 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6361 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006362 LocationAccessPolicy.LocationPermissionResult locationResult =
6363 LocationAccessPolicy.checkLocationPermission(mApp,
6364 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6365 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006366 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006367 .setCallingPid(Binder.getCallingPid())
6368 .setCallingUid(Binder.getCallingUid())
6369 .setMethod("getCellNetworkScanResults")
6370 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006371 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6372 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006373 .build());
6374 switch (locationResult) {
6375 case DENIED_HARD:
6376 throw new SecurityException("Not allowed to access scan results -- location");
6377 case DENIED_SOFT:
6378 return null;
6379 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006380
Pengquan Menga1bb6272018-09-06 09:59:22 -07006381 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006382 try {
6383 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006384 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006385 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006386 } finally {
6387 Binder.restoreCallingIdentity(identity);
6388 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006389 }
6390
6391 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006392 * Get the call forwarding info, given the call forwarding reason.
6393 */
6394 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006395 public void getCallForwarding(int subId, int callForwardingReason,
6396 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006397 enforceReadPrivilegedPermission("getCallForwarding");
6398 long identity = Binder.clearCallingIdentity();
6399 try {
6400 if (DBG) {
6401 log("getCallForwarding: subId " + subId
6402 + " callForwardingReason" + callForwardingReason);
6403 }
Hall Liu27d24262020-09-18 19:04:59 -07006404
6405 Phone phone = getPhone(subId);
6406 if (phone == null) {
6407 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006408 callback.onError(
6409 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006410 } catch (RemoteException e) {
6411 // ignore
6412 }
6413 return;
6414 }
6415
6416 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6417 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6418 @Override
6419 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6420 try {
6421 callback.onCallForwardingInfoAvailable(info);
6422 } catch (RemoteException e) {
6423 // ignore
6424 }
6425 }
6426
6427 @Override
6428 public void onError(int error) {
6429 try {
6430 callback.onError(error);
6431 } catch (RemoteException e) {
6432 // ignore
6433 }
6434 }
6435 });
6436 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006437 } finally {
6438 Binder.restoreCallingIdentity(identity);
6439 }
6440 }
6441
6442 /**
6443 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6444 * reason, the number to forward, and the timeout before the forwarding is attempted.
6445 */
6446 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006447 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6448 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006449 enforceModifyPermission();
6450 long identity = Binder.clearCallingIdentity();
6451 try {
6452 if (DBG) {
6453 log("setCallForwarding: subId " + subId
6454 + " callForwardingInfo" + callForwardingInfo);
6455 }
Hall Liu27d24262020-09-18 19:04:59 -07006456
6457 Phone phone = getPhone(subId);
6458 if (phone == null) {
6459 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006460 callback.accept(
6461 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006462 } catch (RemoteException e) {
6463 // ignore
6464 }
6465 return;
6466 }
6467
6468 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6469 FunctionalUtils.ignoreRemoteException(callback::accept));
6470
6471 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006472 } finally {
6473 Binder.restoreCallingIdentity(identity);
6474 }
6475 }
6476
6477 /**
Hall Liu27d24262020-09-18 19:04:59 -07006478 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006479 */
6480 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006481 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006482 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006483 long identity = Binder.clearCallingIdentity();
6484 try {
Hall Liu27d24262020-09-18 19:04:59 -07006485 Phone phone = getPhone(subId);
6486 if (phone == null) {
6487 try {
6488 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6489 } catch (RemoteException e) {
6490 // ignore
6491 }
6492 return;
6493 }
SongFerngWang0e767992021-03-31 22:08:45 +08006494 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6495 PersistableBundle c = configManager.getConfigForSubId(subId);
6496 boolean requireUssd = c.getBoolean(
6497 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006498
Shuo Qian4a594052020-01-23 11:59:30 -08006499 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006500 if (requireUssd) {
6501 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6502 getSubscriptionCarrierId(subId));
6503 String newUssdCommand = "";
6504 try {
6505 newUssdCommand = carrierXmlParser.getFeature(
6506 CarrierXmlParser.FEATURE_CALL_WAITING)
6507 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6508 } catch (NullPointerException e) {
6509 loge("Failed to generate USSD number" + e);
6510 }
6511 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6512 mMainThreadHandler, callback, carrierXmlParser,
6513 CarrierXmlParser.SsEntry.SSAction.QUERY);
6514 final String ussdCommand = newUssdCommand;
6515 Executors.newSingleThreadExecutor().execute(() -> {
6516 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6517 });
6518 } else {
6519 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6520 callback::accept);
6521 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6522 }
Shuo Qian4a594052020-01-23 11:59:30 -08006523 } finally {
6524 Binder.restoreCallingIdentity(identity);
6525 }
6526 }
6527
6528 /**
Hall Liu27d24262020-09-18 19:04:59 -07006529 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006530 */
6531 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006532 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006533 enforceModifyPermission();
6534 long identity = Binder.clearCallingIdentity();
6535 try {
Hall Liu27d24262020-09-18 19:04:59 -07006536 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6537
6538 Phone phone = getPhone(subId);
6539 if (phone == null) {
6540 try {
6541 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6542 } catch (RemoteException e) {
6543 // ignore
6544 }
6545 return;
6546 }
6547
SongFerngWang0e767992021-03-31 22:08:45 +08006548 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6549 PersistableBundle c = configManager.getConfigForSubId(subId);
6550 boolean requireUssd = c.getBoolean(
6551 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006552
SongFerngWang0e767992021-03-31 22:08:45 +08006553 if (DBG) log("getCallWaitingStatus: subId " + subId);
6554 if (requireUssd) {
6555 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6556 getSubscriptionCarrierId(subId));
6557 CarrierXmlParser.SsEntry.SSAction ssAction =
6558 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6559 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6560 String newUssdCommand = "";
6561 try {
6562 newUssdCommand = carrierXmlParser.getFeature(
6563 CarrierXmlParser.FEATURE_CALL_WAITING)
6564 .makeCommand(ssAction, null);
6565 } catch (NullPointerException e) {
6566 loge("Failed to generate USSD number" + e);
6567 }
6568 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6569 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6570 final String ussdCommand = newUssdCommand;
6571 Executors.newSingleThreadExecutor().execute(() -> {
6572 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6573 });
6574 } else {
6575 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6576 FunctionalUtils.ignoreRemoteException(callback::accept));
6577
6578 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6579 }
Shuo Qian4a594052020-01-23 11:59:30 -08006580 } finally {
6581 Binder.restoreCallingIdentity(identity);
6582 }
6583 }
6584
6585 /**
yinxub1bed742017-04-17 11:45:04 -07006586 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006587 *
yinxub1bed742017-04-17 11:45:04 -07006588 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006589 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6590 * location related information which will be sent if the caller already possess
6591 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006592 * @param request contains the radio access networks with bands/channels to scan
6593 * @param messenger callback messenger for scan results or errors
6594 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006595 * @return the id of the requested scan which can be used to stop the scan.
6596 */
6597 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006598 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6599 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006600 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6602 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006603 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006604 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6605 if (!renounceFineLocationAccess) {
6606 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6607 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6608 .setCallingPackage(callingPackage)
6609 .setCallingFeatureId(callingFeatureId)
6610 .setCallingPid(Binder.getCallingPid())
6611 .setCallingUid(Binder.getCallingUid())
6612 .setMethod("requestNetworkScan")
6613 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6614 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6615 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6616 .build());
6617 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006618 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006619 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6620 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006621 if (e != null) {
6622 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6623 throw e;
6624 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006625 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006626 return TelephonyScanManager.INVALID_SCAN_ID;
6627 }
6628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006629 }
Hall Liu912dfd32019-04-25 14:02:26 -07006630 int callingUid = Binder.getCallingUid();
6631 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006632 final long identity = Binder.clearCallingIdentity();
6633 try {
6634 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006635 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006636 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006637 } finally {
6638 Binder.restoreCallingIdentity(identity);
6639 }
yinxu504e1392017-04-12 16:03:22 -07006640 }
6641
Hall Liub2ac8ef2019-02-28 15:56:23 -08006642 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006643 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006644 boolean hasCarrierPriv;
6645 final long identity = Binder.clearCallingIdentity();
6646 try {
6647 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6648 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6649 } finally {
6650 Binder.restoreCallingIdentity(identity);
6651 }
Hall Liu558027f2019-05-15 19:14:05 -07006652 boolean hasNetworkScanPermission =
6653 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6654 == PERMISSION_GRANTED;
6655
6656 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6657 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6658 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006659 }
6660
6661 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6662 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006663 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6664 return new SecurityException("Specific channels must not be"
6665 + " scanned without location access.");
6666 }
6667 }
6668 }
6669
Hall Liub2ac8ef2019-02-28 15:56:23 -08006670 return null;
6671 }
6672
yinxu504e1392017-04-12 16:03:22 -07006673 /**
6674 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006675 *
6676 * @param subId id of the subscription
6677 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006678 */
6679 @Override
6680 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6682 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006683
Hall Liu912dfd32019-04-25 14:02:26 -07006684 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006685 final long identity = Binder.clearCallingIdentity();
6686 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006687 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006688 } finally {
6689 Binder.restoreCallingIdentity(identity);
6690 }
yinxu504e1392017-04-12 16:03:22 -07006691 }
6692
6693 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006694 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006695 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006696 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006697 */
6698 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006699 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006700 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006701 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006702 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006703
6704 final long identity = Binder.clearCallingIdentity();
6705 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006706 if (DBG) log("getAllowedNetworkTypesBitmask");
6707 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6708 int networkTypesBitmask = (result != null ? result[0] : -1);
6709 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6710 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006711 } finally {
6712 Binder.restoreCallingIdentity(identity);
6713 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006714 }
6715
6716 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006717 * Get the allowed network types for certain reason.
6718 *
6719 * @param subId the id of the subscription.
6720 * @param reason the reason the allowed network type change is taking place
6721 * @return the allowed network types.
6722 */
6723 @Override
6724 public long getAllowedNetworkTypesForReason(int subId,
6725 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006726 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006727 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006728 final long identity = Binder.clearCallingIdentity();
6729 try {
6730 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6731 } finally {
6732 Binder.restoreCallingIdentity(identity);
6733 }
6734 }
6735
6736 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006737 * Enable/Disable E-UTRA-NR Dual Connectivity
6738 * @param subId subscription id of the sim card
6739 * @param nrDualConnectivityState expected NR dual connectivity state
6740 * This can be passed following states
6741 * <ol>
6742 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6743 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6744 * <li>Disable NR dual connectivity and force secondary cell to be released
6745 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6746 * </ol>
6747 * @return operation result.
6748 */
6749 @Override
6750 public int setNrDualConnectivityState(int subId,
6751 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6753 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006754 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006755 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6756 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6757 }
6758
Sooraj Sasindran37444802020-08-11 10:40:43 -07006759 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6760 final long identity = Binder.clearCallingIdentity();
6761 try {
6762 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6763 nrDualConnectivityState, subId,
6764 workSource);
6765 if (DBG) log("enableNRDualConnectivity result: " + result);
6766 return result;
6767 } finally {
6768 Binder.restoreCallingIdentity(identity);
6769 }
6770 }
6771
6772 /**
6773 * Is E-UTRA-NR Dual Connectivity enabled
6774 * @return true if dual connectivity is enabled else false
6775 */
6776 @Override
6777 public boolean isNrDualConnectivityEnabled(int subId) {
6778 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006779 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006780 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006781 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006782 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6783 return false;
6784 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006785 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6786 final long identity = Binder.clearCallingIdentity();
6787 try {
6788 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6789 null, subId, workSource);
6790 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6791 return isEnabled;
6792 } finally {
6793 Binder.restoreCallingIdentity(identity);
6794 }
6795 }
6796
6797 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006798 * Set the allowed network types of the device and
6799 * provide the reason triggering the allowed network change.
6800 *
6801 * @param subId the id of the subscription.
6802 * @param reason the reason the allowed network type change is taking place
6803 * @param allowedNetworkTypes the allowed network types.
6804 * @return true on success; false on any failure.
6805 */
6806 @Override
6807 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006808 @TelephonyManager.AllowedNetworkTypesReason int reason,
6809 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006810 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6811 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006812 // If the caller only has carrier privileges, then they should not be able to override
6813 // any network types which were set for security reasons.
6814 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6815 != PERMISSION_GRANTED
6816 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6817 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6818 throw new SecurityException(
6819 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6820 + " reason "
Jack Yu5b494332023-01-23 18:18:04 +00006821 + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006822 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006823 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006824 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08006825 return false;
6826 }
6827 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6828 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006829 return false;
6830 }
6831
Jack Yu5b494332023-01-23 18:18:04 +00006832 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
6833 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006834
Jack Yue37dd262022-12-16 11:53:37 -08006835 Phone phone = getPhone(subId);
6836 if (phone == null) {
6837 return false;
6838 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006839
Jack Yue37dd262022-12-16 11:53:37 -08006840 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006841 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006842 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006843 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006844
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006845 final long identity = Binder.clearCallingIdentity();
6846 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006847 Boolean success = (Boolean) sendRequest(
6848 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6849 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6850
6851 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6852 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006853 } finally {
6854 Binder.restoreCallingIdentity(identity);
6855 }
6856 }
6857
6858 /**
Miaoa84611c2019-03-15 09:21:10 +08006859 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006860 *
Miaoa84611c2019-03-15 09:21:10 +08006861 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006862 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006863 * @hide
6864 */
6865 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006866 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006867 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006868 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006869 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006870 try {
Miaoa84611c2019-03-15 09:21:10 +08006871 if (phone != null) {
6872 return phone.hasMatchedTetherApnSetting();
6873 } else {
6874 return false;
6875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006876 } finally {
6877 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006878 }
Junda Liu475951f2014-11-07 16:45:03 -08006879 }
6880
6881 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006882 * Get the user enabled state of Mobile Data.
6883 *
6884 * TODO: remove and use isUserDataEnabled.
6885 * This can't be removed now because some vendor codes
6886 * calls through ITelephony directly while they should
6887 * use TelephonyManager.
6888 *
6889 * @return true on enabled
6890 */
6891 @Override
6892 public boolean getDataEnabled(int subId) {
6893 return isUserDataEnabled(subId);
6894 }
6895
6896 /**
6897 * Get whether mobile data is enabled per user setting.
6898 *
6899 * There are other factors deciding whether mobile data is actually enabled, but they are
6900 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006901 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006902 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6903 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006904 *
6905 * @return {@code true} if data is enabled else {@code false}
6906 */
6907 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006908 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006909 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006910 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006911 try {
6912 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6913 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006914 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006915 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6916 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006917 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006919 mApp, subId, functionName);
6920
Robert Greenwalt646120a2014-05-23 11:54:03 -07006921 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006922
6923 final long identity = Binder.clearCallingIdentity();
6924 try {
Jack Yu285100e2022-12-02 22:48:35 -08006925 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006926 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6927 Phone phone = PhoneFactory.getPhone(phoneId);
6928 if (phone != null) {
6929 boolean retVal = phone.isUserDataEnabled();
6930 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6931 return retVal;
6932 } else {
6933 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6934 return false;
6935 }
6936 } finally {
6937 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006938 }
6939 }
6940
6941 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006942 * Checks if the device is capable of mobile data by considering whether whether the
6943 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6944 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006945 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006946 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006947 */
6948 @Override
6949 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006950 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006951 try {
6952 try {
6953 mApp.enforceCallingOrSelfPermission(
6954 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006955 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006956 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006957 try {
6958 mApp.enforceCallingOrSelfPermission(
6959 android.Manifest.permission.READ_PHONE_STATE,
6960 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006961 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006962 mApp.enforceCallingOrSelfPermission(
6963 permission.READ_BASIC_PHONE_STATE, functionName);
6964 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006965 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006966 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006967 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006968 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006969
6970 final long identity = Binder.clearCallingIdentity();
6971 try {
Jack Yu285100e2022-12-02 22:48:35 -08006972 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006973 Phone phone = PhoneFactory.getPhone(phoneId);
6974 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006975 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006976 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006977 return retVal;
6978 } else {
6979 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6980 return false;
6981 }
6982 } finally {
6983 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006984 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006985 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006986
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006987 /**
6988 * Check if data is enabled for a specific reason
6989 * @param subId Subscription index
6990 * @param reason the reason the data enable change is taking place
6991 * @return {@code true} if the overall data is enabled; {@code false} if not.
6992 */
6993 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006994 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006995 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006996 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006997 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006998 try {
6999 mApp.enforceCallingOrSelfPermission(
7000 android.Manifest.permission.ACCESS_NETWORK_STATE,
7001 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007002 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007003 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7004 functionName);
7005 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007006 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007007 try {
7008 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007009 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007010 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007012 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007013 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007014 }
7015
7016
7017 final long identity = Binder.clearCallingIdentity();
7018 try {
Jack Yu285100e2022-12-02 22:48:35 -08007019 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007020 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007021 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007022 + " reason=" + reason);
7023 }
7024 Phone phone = PhoneFactory.getPhone(phoneId);
7025 if (phone != null) {
7026 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007027 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007028 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007029 return retVal;
7030 } else {
7031 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007032 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007033 + subId + " retVal=false");
7034 }
7035 return false;
7036 }
7037 } finally {
7038 Binder.restoreCallingIdentity(identity);
7039 }
7040 }
7041
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007042 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007043 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007044 // No permission needed; this only lets the caller inspect their own status.
7045 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007046 }
Junda Liu29340342014-07-10 15:23:27 -07007047
7048 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007049 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007050 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007051 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7052 }
7053
7054 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7055 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007056 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007057 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007058 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7059 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007060 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7061 if (cpt == null) {
7062 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007063 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7064 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007065 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007066 }
7067
7068 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007069 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007070 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007071 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007072 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007073 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007074 Phone phone = getPhone(subId);
7075 if (phone == null) {
7076 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7077 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7078 }
7079 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7080 if (cpt == null) {
7081 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007082 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7083 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007084 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007085 }
7086
7087 @Override
7088 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007089 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007090 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7091 }
7092
7093 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007094 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007095 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007096 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007097 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007098 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7099 Phone phone = PhoneFactory.getPhone(phoneId);
7100 if (phone == null) {
7101 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007102 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007103 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7104 if (cpt == null) {
7105 continue;
7106 }
7107 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007108 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7109 break;
7110 }
7111 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007112 return result;
Junda Liu29340342014-07-10 15:23:27 -07007113 }
Derek Tan89e89d42014-07-08 17:00:10 -07007114
7115 @Override
Junda Liue64de782015-04-16 17:19:16 -07007116 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007117 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007118 Phone phone = PhoneFactory.getPhone(phoneId);
7119 if (phone == null) {
7120 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007121 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007122 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7123 if (cpt == null) {
7124 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007125 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007126 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007127 }
7128
Amith Yamasani6e118872016-02-19 12:53:51 -08007129 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007130 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007131 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007132 Phone phone = PhoneFactory.getPhone(phoneId);
7133 if (phone == null) {
7134 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007135 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007136 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7137 if (cpt == null) {
7138 return Collections.emptyList();
7139 }
7140 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007141 }
7142
chen xuf7e9fe82019-05-09 19:31:02 -07007143 @Override
7144 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007145 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007146 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007147 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007148 try {
7149 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7150 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7151 }
7152 } finally {
7153 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007154 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007155 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007156 }
7157
Rambo Wang6812ffb2022-03-15 16:54:17 -07007158 @Override
7159 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7160 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7161
7162 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7163 if (phone == null) {
7164 return null;
7165 }
7166 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7167 if (cpt == null) {
7168 return null;
7169 }
7170 return cpt.getCarrierServicePackageName();
7171 }
7172
Wink Savilleb564aae2014-10-23 10:18:09 -07007173 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007174 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007175 UiccPort port = phone == null ? null : phone.getUiccPort();
7176 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007177 return null;
7178 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007179 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007180 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007181 return null;
7182 }
7183 return iccId;
7184 }
7185
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007186 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007187 public void setCallComposerStatus(int subId, int status) {
7188 enforceModifyPermission();
7189
7190 final long identity = Binder.clearCallingIdentity();
7191 try {
7192 Phone phone = getPhone(subId);
7193 if (phone != null) {
7194 Phone defaultPhone = phone.getImsPhone();
7195 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7196 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7197 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007198 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7199 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007200 }
7201 }
Shuo Qian284ae752020-12-22 19:10:14 -08007202 } catch (ImsException e) {
7203 throw new ServiceSpecificException(e.getCode());
7204 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007205 Binder.restoreCallingIdentity(identity);
7206 }
7207 }
7208
7209 @Override
7210 public int getCallComposerStatus(int subId) {
7211 enforceReadPrivilegedPermission("getCallComposerStatus");
7212
7213 final long identity = Binder.clearCallingIdentity();
7214 try {
7215 Phone phone = getPhone(subId);
7216 if (phone != null) {
7217 Phone defaultPhone = phone.getImsPhone();
7218 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7219 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7220 return imsPhone.getCallComposerStatus();
7221 }
7222 }
7223 } finally {
7224 Binder.restoreCallingIdentity(identity);
7225 }
7226 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7227 }
7228
7229 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007230 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7231 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007232 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007233 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007234
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235 final long identity = Binder.clearCallingIdentity();
7236 try {
7237 final String iccId = getIccId(subId);
7238 final Phone phone = getPhone(subId);
7239 if (phone == null) {
7240 return false;
7241 }
7242 final String subscriberId = phone.getSubscriberId();
7243
7244 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007245 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007246 + subscriberId + " to " + number);
7247 }
7248
7249 if (TextUtils.isEmpty(iccId)) {
7250 return false;
7251 }
7252
7253 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7254
7255 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7256 if (alphaTag == null) {
7257 editor.remove(alphaTagPrefKey);
7258 } else {
7259 editor.putString(alphaTagPrefKey, alphaTag);
7260 }
7261
7262 // Record both the line number and IMSI for this ICCID, since we need to
7263 // track all merged IMSIs based on line number
7264 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7265 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7266 if (number == null) {
7267 editor.remove(numberPrefKey);
7268 editor.remove(subscriberPrefKey);
7269 } else {
7270 editor.putString(numberPrefKey, number);
7271 editor.putString(subscriberPrefKey, subscriberId);
7272 }
7273
7274 editor.commit();
7275 return true;
7276 } finally {
7277 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007278 }
Derek Tan7226c842014-07-02 17:42:23 -07007279 }
7280
7281 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007282 public String getLine1NumberForDisplay(int subId, String callingPackage,
7283 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007284 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007285 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007286 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007287 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007288 return null;
7289 }
Derek Tan97ebb422014-09-05 16:55:38 -07007290
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007291 final long identity = Binder.clearCallingIdentity();
7292 try {
7293 String iccId = getIccId(subId);
7294 if (iccId != null) {
7295 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7296 if (DBG_MERGE) {
7297 log("getLine1NumberForDisplay returning "
7298 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7299 }
7300 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007301 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007302 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7303 return null;
7304 } finally {
7305 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007306 }
Derek Tan7226c842014-07-02 17:42:23 -07007307 }
7308
7309 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007310 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7311 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007312 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007313 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007314 return null;
7315 }
Derek Tan97ebb422014-09-05 16:55:38 -07007316
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007317 final long identity = Binder.clearCallingIdentity();
7318 try {
7319 String iccId = getIccId(subId);
7320 if (iccId != null) {
7321 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7322 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7323 }
7324 return null;
7325 } finally {
7326 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007327 }
Derek Tan7226c842014-07-02 17:42:23 -07007328 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007329
7330 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007331 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7332 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007333 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7334 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007335 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007336 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007337 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007338 return null;
7339 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007340
Jordan Liub49b04b2019-05-06 14:45:15 -07007341 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7342 // the process, where TelephonyManager was instantiated.
7343 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007344 final long identity = Binder.clearCallingIdentity();
7345 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007346 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007347 final TelephonyManager tele = TelephonyManager.from(context);
7348 final SubscriptionManager sub = SubscriptionManager.from(context);
7349
7350 // Figure out what subscribers are currently active
7351 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007352
Jordan Liub49b04b2019-05-06 14:45:15 -07007353 // Only consider subs which match the current subId
7354 // This logic can be simplified. See b/131189269 for progress.
7355 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007356 activeSubscriberIds.add(tele.getSubscriberId(subId));
7357 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007358
7359 // First pass, find a number override for an active subscriber
7360 String mergeNumber = null;
7361 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7362 for (String key : prefs.keySet()) {
7363 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7364 final String subscriberId = (String) prefs.get(key);
7365 if (activeSubscriberIds.contains(subscriberId)) {
7366 final String iccId = key.substring(
7367 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7368 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7369 mergeNumber = (String) prefs.get(numberKey);
7370 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007371 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007372 + " for active subscriber " + subscriberId);
7373 }
7374 if (!TextUtils.isEmpty(mergeNumber)) {
7375 break;
7376 }
7377 }
7378 }
7379 }
7380
7381 // Shortcut when no active merged subscribers
7382 if (TextUtils.isEmpty(mergeNumber)) {
7383 return null;
7384 }
7385
7386 // Second pass, find all subscribers under that line override
7387 final ArraySet<String> result = new ArraySet<>();
7388 for (String key : prefs.keySet()) {
7389 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7390 final String number = (String) prefs.get(key);
7391 if (mergeNumber.equals(number)) {
7392 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7393 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7394 final String subscriberId = (String) prefs.get(subscriberKey);
7395 if (!TextUtils.isEmpty(subscriberId)) {
7396 result.add(subscriberId);
7397 }
7398 }
7399 }
7400 }
7401
7402 final String[] resultArray = result.toArray(new String[result.size()]);
7403 Arrays.sort(resultArray);
7404 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007405 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007406 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7407 }
7408 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007409 } finally {
7410 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007411 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007412 }
7413
7414 @Override
zoey chen38003472019-12-13 17:16:31 +08007415 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7416 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007417
7418 final long identity = Binder.clearCallingIdentity();
7419 try {
7420 final TelephonyManager telephonyManager = mApp.getSystemService(
7421 TelephonyManager.class);
7422 String subscriberId = telephonyManager.getSubscriberId(subId);
7423 if (subscriberId == null) {
7424 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007425 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007426 + subId);
7427 }
7428 return null;
7429 }
7430
Jack Yu285100e2022-12-02 22:48:35 -08007431 ParcelUuid groupUuid;
7432 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7433 final SubscriptionInfo info = SubscriptionManagerService.getInstance()
7434 .getSubscriptionInfo(subId);
7435 groupUuid = info.getGroupUuid();
7436 } else {
7437 final SubscriptionInfo info = mSubscriptionController
7438 .getSubscriptionInfo(subId);
7439 groupUuid = info.getGroupUuid();
7440 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007441 // If it doesn't belong to any group, return just subscriberId of itself.
7442 if (groupUuid == null) {
7443 return new String[]{subscriberId};
7444 }
7445
7446 // Get all subscriberIds from the group.
7447 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007448 List<SubscriptionInfo> groupInfos;
7449 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7450 groupInfos = SubscriptionManagerService.getInstance()
7451 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7452 mApp.getAttributionTag());
7453 } else {
7454 groupInfos = mSubscriptionController
7455 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7456 mApp.getAttributionTag());
7457 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007458 for (SubscriptionInfo subInfo : groupInfos) {
7459 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7460 if (subscriberId != null) {
7461 mergedSubscriberIds.add(subscriberId);
7462 }
7463 }
7464
7465 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7466 } finally {
7467 Binder.restoreCallingIdentity(identity);
7468
7469 }
7470 }
7471
7472 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007473 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007474 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007475 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007476
7477 final long identity = Binder.clearCallingIdentity();
7478 try {
7479 final Phone phone = getPhone(subId);
7480 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7481 } finally {
7482 Binder.restoreCallingIdentity(identity);
7483 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007484 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007485
7486 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007487 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007488 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7489 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007490 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7491 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007492
7493 final long identity = Binder.clearCallingIdentity();
7494 try {
7495 final Phone phone = getPhone(subId);
7496 if (phone == null) {
7497 return false;
7498 }
7499 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7500 cdmaNonRoamingList);
7501 } finally {
7502 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007503 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007504 }
7505
7506 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007507 @Deprecated
7508 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7509 enforceModifyPermission();
7510
7511 int returnValue = 0;
7512 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007513 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007514 if(result.exception == null) {
7515 if (result.result != null) {
7516 byte[] responseData = (byte[])(result.result);
7517 if(responseData.length > oemResp.length) {
7518 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7519 responseData.length + "bytes. Buffer Size is " +
7520 oemResp.length + "bytes.");
7521 }
7522 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7523 returnValue = responseData.length;
7524 }
7525 } else {
7526 CommandException ex = (CommandException) result.exception;
7527 returnValue = ex.getCommandError().ordinal();
7528 if(returnValue > 0) returnValue *= -1;
7529 }
7530 } catch (RuntimeException e) {
7531 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7532 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7533 if(returnValue > 0) returnValue *= -1;
7534 }
7535
7536 return returnValue;
7537 }
7538
7539 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007540 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007541 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007542 try {
7543 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007544 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007545 mApp, phone.getSubId(), "getRadioAccessFamily");
7546 } catch (SecurityException e) {
7547 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7548 throw e;
7549 }
chen xub97461a2018-10-26 14:17:57 -07007550 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007551 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007552 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007553 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007554 final long identity = Binder.clearCallingIdentity();
7555 try {
chen xub97461a2018-10-26 14:17:57 -07007556 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007557 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007558 mApp, phone.getSubId(), "getRadioAccessFamily");
7559 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007560 } finally {
7561 Binder.restoreCallingIdentity(identity);
7562 }
chen xub97461a2018-10-26 14:17:57 -07007563 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007564 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007565
7566 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007567 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007568 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007569 try {
7570 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7571 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007572 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007573 }
7574 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007575 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007576 }
7577 RoleManager rm = mApp.getSystemService(RoleManager.class);
7578 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7579 if (!dialerRoleHolders.contains(callingPackage)) {
7580 throw new SecurityException("App must be the dialer role holder to"
7581 + " upload a call composer pic");
7582 }
7583
7584 Executors.newSingleThreadExecutor().execute(() -> {
7585 ByteArrayOutputStream output = new ByteArrayOutputStream(
7586 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7587 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7588 boolean readUntilEnd = false;
7589 int totalBytesRead = 0;
7590 byte[] buffer = new byte[16 * 1024];
7591 while (true) {
7592 int numRead;
7593 try {
7594 numRead = input.read(buffer);
7595 } catch (IOException e) {
7596 try {
7597 fd.checkError();
7598 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7599 null);
7600 } catch (IOException e1) {
7601 // This means that the other side closed explicitly with an error. If this
7602 // happens, log and ignore.
7603 loge("Remote end of call composer picture pipe closed: " + e1);
7604 }
7605 break;
7606 }
7607 if (numRead == -1) {
7608 readUntilEnd = true;
7609 break;
7610 }
7611 totalBytesRead += numRead;
7612 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7613 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7614 try {
7615 input.close();
7616 } catch (IOException e) {
7617 // ignore
7618 }
7619 break;
7620 }
7621 output.write(buffer, 0, numRead);
7622 }
7623 // Generally, the remote end will close the file descriptors. The only case where we
7624 // close is above, where the picture size is too big.
7625
7626 try {
7627 fd.checkError();
7628 } catch (IOException e) {
7629 loge("Remote end for call composer closed with an error: " + e);
7630 return;
7631 }
7632
Hall Liuaa4211e2021-01-20 15:43:39 -08007633 if (!readUntilEnd) {
7634 loge("Did not finish reading entire image; aborting");
7635 return;
7636 }
Hall Liu82694d52020-12-11 18:22:04 -08007637
Hall Liuaa4211e2021-01-20 15:43:39 -08007638 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7639 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7640 new CallComposerPictureTransfer.Factory() {},
7641 imageData,
7642 (result) -> {
7643 if (result.first != null) {
7644 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7645 Bundle outputResult = new Bundle();
7646 outputResult.putParcelable(
7647 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7648 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7649 outputResult);
7650 } else {
7651 callback.send(result.second, null);
7652 }
7653 }
7654 );
Hall Liu82694d52020-12-11 18:22:04 -08007655 });
7656 }
7657
7658 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007659 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007660 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007661 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007662
7663 final long identity = Binder.clearCallingIdentity();
7664 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007665 ImsManager.getInstance(defaultPhone.getContext(),
7666 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007667 } finally {
7668 Binder.restoreCallingIdentity(identity);
7669 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007670 }
7671
7672 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007673 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007674 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007675 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7676 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007677 return false;
7678 }
Svet Ganovb320e182015-04-16 12:30:10 -07007679
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007680 final long identity = Binder.clearCallingIdentity();
7681 try {
7682 // Check the user preference and the system-level IMS setting. Even if the user has
7683 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7684 // In the long run, we may instead need to check if there exists a connection service
7685 // which can support video calling.
7686 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007687 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007688 return imsManager.isVtEnabledByPlatform()
7689 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7690 && imsManager.isVtEnabledByUser();
7691 } finally {
7692 Binder.restoreCallingIdentity(identity);
7693 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007694 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007695
Andrew Leea1239f22015-03-02 17:44:07 -08007696 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007697 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7698 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007699 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007700 mApp, subId, callingPackage, callingFeatureId,
7701 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007702 return false;
7703 }
7704
7705 final long identity = Binder.clearCallingIdentity();
7706 try {
7707 CarrierConfigManager configManager =
7708 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007709 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007710 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7711 } finally {
7712 Binder.restoreCallingIdentity(identity);
7713 }
Andrew Leea1239f22015-03-02 17:44:07 -08007714 }
7715
7716 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007717 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007718 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007719 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007720 return false;
7721 }
7722
7723 final long identity = Binder.clearCallingIdentity();
7724 try {
7725 CarrierConfigManager configManager =
7726 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007727 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007728 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7729 } finally {
7730 Binder.restoreCallingIdentity(identity);
7731 }
Andrew Leea1239f22015-03-02 17:44:07 -08007732 }
7733
Andrew Lee9431b832015-03-09 18:46:45 -07007734 @Override
7735 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007736 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007737 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007738 }
7739
7740 @Override
7741 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007742 final long identity = Binder.clearCallingIdentity();
7743 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007744 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007745 } finally {
7746 Binder.restoreCallingIdentity(identity);
7747 }
Andrew Lee9431b832015-03-09 18:46:45 -07007748 }
7749
Hall Liuf6668912018-10-31 17:05:23 -07007750 /**
7751 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7752 * support for the feature and device firmware support.
7753 *
7754 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7755 */
7756 @Override
7757 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007758 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007759 final Phone phone = getPhone(subscriptionId);
7760 if (phone == null) {
7761 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7762 return false;
7763 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007764 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007765 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007766 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7767 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007768 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007769 return isCarrierSupported && isDeviceSupported;
7770 } finally {
7771 Binder.restoreCallingIdentity(identity);
7772 }
Hall Liu98187582018-01-22 19:15:32 -08007773 }
7774
Hall Liuf6668912018-10-31 17:05:23 -07007775 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007776 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7777 * RTT setting, will return true if the device and carrier both support RTT.
7778 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007779 */
7780 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007781 final long identity = Binder.clearCallingIdentity();
7782 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007783 boolean isRttSupported = isRttSupported(subscriptionId);
7784 boolean isUserRttSettingOn = Settings.Secure.getInt(
7785 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7786 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7787 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7788 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007789 } finally {
7790 Binder.restoreCallingIdentity(identity);
7791 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007792 }
7793
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007794 @Deprecated
7795 @Override
7796 public String getDeviceId(String callingPackage) {
7797 return getDeviceIdWithFeature(callingPackage, null);
7798 }
7799
Sanket Padawe7310cc72015-01-14 09:53:20 -08007800 /**
7801 * Returns the unique device ID of phone, for example, the IMEI for
7802 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7803 *
7804 * <p>Requires Permission:
7805 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7806 */
7807 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007808 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007809 try {
7810 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7811 } catch (SecurityException se) {
7812 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7813 throw new SecurityException("Package " + callingPackage + " does not belong to "
7814 + Binder.getCallingUid());
7815 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007816 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007817 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007818 return null;
7819 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007820 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007821 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007822 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007823 return null;
7824 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007825
7826 final long identity = Binder.clearCallingIdentity();
7827 try {
7828 return phone.getDeviceId();
7829 } finally {
7830 Binder.restoreCallingIdentity(identity);
7831 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007832 }
7833
Ping Sunc67b7c22016-03-02 19:16:45 +08007834 /**
7835 * {@hide}
7836 * Returns the IMS Registration Status on a particular subid
7837 *
7838 * @param subId
7839 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007840 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007841 Phone phone = getPhone(subId);
7842 if (phone != null) {
7843 return phone.isImsRegistered();
7844 } else {
7845 return false;
7846 }
7847 }
7848
Santos Cordon7a1885b2015-02-03 11:15:19 -08007849 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007850 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007851 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007852 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007853 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007854 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7855 }
7856 final long identity = Binder.clearCallingIdentity();
7857 try {
7858 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7859 } finally {
7860 Binder.restoreCallingIdentity(identity);
7861 }
7862 }
7863
7864 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007865 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007866 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007867 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007868 mApp,
7869 subscriptionId,
7870 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007871 final long identity = Binder.clearCallingIdentity();
7872 try {
7873 Phone phone = getPhone(subscriptionId);
7874 if (phone == null) {
7875 return null;
7876 }
7877 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7878 } finally {
7879 Binder.restoreCallingIdentity(identity);
7880 }
7881 }
7882
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007883 /**
7884 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007885 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007886 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007887 final long identity = Binder.clearCallingIdentity();
7888 try {
7889 Phone phone = getPhone(subId);
7890 if (phone != null) {
7891 return phone.isWifiCallingEnabled();
7892 } else {
7893 return false;
7894 }
7895 } finally {
7896 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007897 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007898 }
7899
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007900 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007901 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007902 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007903 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007904 final long identity = Binder.clearCallingIdentity();
7905 try {
7906 Phone phone = getPhone(subId);
7907 if (phone != null) {
7908 return phone.isVideoEnabled();
7909 } else {
7910 return false;
7911 }
7912 } finally {
7913 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007914 }
7915 }
7916
7917 /**
7918 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7919 * defined in {@link ImsRegistrationImplBase}.
7920 */
7921 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007922 final long identity = Binder.clearCallingIdentity();
7923 try {
7924 Phone phone = getPhone(subId);
7925 if (phone != null) {
7926 return phone.getImsRegistrationTech();
7927 } else {
7928 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7929 }
7930 } finally {
7931 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007932 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007933 }
7934
Stuart Scott8eef64f2015-04-08 15:13:54 -07007935 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007936 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007937 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007938 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7939 return;
7940 }
Kai Shif70f46f2021-03-03 13:59:46 -08007941 Phone defaultPhone = getDefaultPhone();
7942 if (defaultPhone != null) {
7943 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7944 mApp, getDefaultPhone().getSubId(), "factoryReset");
7945 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007946 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007947
Svet Ganovcc087f82015-05-12 20:35:54 -07007948 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007949 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7950 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007951 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007952 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007953 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007954 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007955 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007956 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007957 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007958 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007959 // There has been issues when Sms raw table somehow stores orphan
7960 // fragments. They lead to garbled message when new fragments come
7961 // in and combined with those stale ones. In case this happens again,
7962 // user can reset all network settings which will clean up this table.
7963 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007964 // Clean up IMS settings as well here.
7965 int slotId = getSlotIndex(subId);
7966 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7967 ImsManager.getInstance(mApp, slotId).factoryReset();
7968 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007969
Kai Shif70f46f2021-03-03 13:59:46 -08007970 if (defaultPhone == null) {
7971 return;
7972 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007973 // Erase modem config if erase modem on network setting is enabled.
7974 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7975 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7976 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007977 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007978 }
Kai Shif70f46f2021-03-03 13:59:46 -08007979
7980 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007981 } finally {
7982 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007983 }
7984 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007985
SongFerngWangfd89b102021-05-27 22:44:54 +08007986 @VisibleForTesting
7987 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7988 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7989 return;
7990 }
7991 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7992 RILConstants.PREFERRED_NETWORK_MODE);
7993 SubscriptionManager.setSubscriptionProperty(subId,
7994 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7995 "user=" + defaultNetworkType);
7996 phone.loadAllowedNetworksFromSubscriptionDatabase();
7997 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7998 defaultNetworkType, null);
7999 }
8000
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008001 private void cleanUpSmsRawTable(Context context) {
8002 ContentResolver resolver = context.getContentResolver();
8003 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8004 resolver.delete(uri, null, null);
8005 }
8006
Narayan Kamath1c496c22015-04-16 14:40:19 +01008007 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008008 public String getSimLocaleForSubscriber(int subId) {
8009 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8010 final Phone phone = getPhone(subId);
8011 if (phone == null) {
8012 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008013 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008014 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008015 final long identity = Binder.clearCallingIdentity();
8016 try {
Jack Yu285100e2022-12-02 22:48:35 -08008017 SubscriptionInfo info;
8018 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8019 info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId,
8020 phone.getContext().getOpPackageName(),
8021 phone.getContext().getAttributionTag());
8022 if (info == null) {
8023 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8024 return null;
8025 }
8026 } else {
8027 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
8028 phone.getContext().getOpPackageName(),
8029 phone.getContext().getAttributionTag());
8030 if (info == null) {
8031 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8032 return null;
8033 }
chen xu6291c472019-02-04 12:55:53 -08008034 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008035 // Try and fetch the locale from the carrier properties or from the SIM language
8036 // preferences (EF-PL and EF-LI)...
8037 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008038 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008039 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8040 if (localeFromDefaultSim != null) {
8041 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8042 if (DBG) log("Using locale from subId: " + subId + " locale: "
8043 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008044 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008045 } else {
8046 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008047 }
8048 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008049
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008050 // The SIM language preferences only store a language (e.g. fr = French), not an
8051 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8052 // the SIM and carrier preferences does not include a country we add the country
8053 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008054 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008055 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008056 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008057 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008058 }
8059
8060 if (DBG) log("No locale found - returning null");
8061 return null;
8062 } finally {
8063 Binder.restoreCallingIdentity(identity);
8064 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008065 }
8066
tom hsu0b59d292022-09-29 23:49:21 +08008067 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008068 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008069 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008070 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008071 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008072 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8073 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008074 Locale.forLanguageTag(localeTag).getCountry())) {
8075 return localeTag;
8076 }
8077 }
8078 return inputLocale.toLanguageTag();
8079 }
8080
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008081 /**
8082 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8083 */
8084 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08008085 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8086 return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList(
8087 mApp.getOpPackageName(), mApp.getAttributionTag());
8088 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008089 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08008090 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008091 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008092
Gary Jian3aa9a762022-01-24 16:41:19 +08008093 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8094 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008095
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008096 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008097 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8098 * representing the state of the modem.
8099 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008100 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8101 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008102 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008103 */
8104 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008105 public void requestModemActivityInfo(ResultReceiver result) {
8106 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008107 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008108
8109 final long identity = Binder.clearCallingIdentity();
8110 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008111 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008112 } finally {
8113 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008114 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008115 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008116
Gary Jian76280a42022-12-07 16:18:33 +08008117 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008118 // less than total activity duration.
8119 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8120 if (info == null) {
8121 return false;
8122 }
8123 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008124 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008125 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8126
Hall Liu49656c02020-10-09 19:00:11 -07008127 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8128
Siddharth Rayb8114062018-06-17 15:02:38 -07008129 return (info.isValid()
8130 && (info.getSleepTimeMillis() <= activityDurationMs)
Gary Jian76280a42022-12-07 16:18:33 +08008131 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008132 }
8133
Gary Jian3aa9a762022-01-24 16:41:19 +08008134 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8135 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8136 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8137 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8138
8139 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8140 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8141 }
8142
8143 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8144 mLastModemActivityInfo.setReceiveTimeMillis(
8145 rat,
8146 freq,
8147 info.getReceiveTimeMillis(rat, freq)
8148 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8149 }
8150
8151 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8152 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8153 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8154 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8155
8156 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8157 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8158 }
8159 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8160 mLastModemActivityInfo.setReceiveTimeMillis(
8161 rat,
8162 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8163 }
8164
8165 /**
8166 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8167 * @param info recent ModemActivityInfo
8168 */
8169 private void mergeModemActivityInfo(ModemActivityInfo info) {
8170 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008171 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008172 boolean matched;
8173 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8174 matched = false;
8175 int rat = info.getSpecificInfoRat(i);
8176 int freq = info.getSpecificInfoFrequencyRange(i);
8177 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8178 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8179 //if it already exists
8180 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8181 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8182 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8183 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8184 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8185 updateLastModemActivityInfo(info, rat, freq);
8186 matched = true;
8187 }
8188 } else {
8189 updateLastModemActivityInfo(info, rat);
8190 matched = true;
8191 }
8192 }
8193 }
8194
8195 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008196 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008197 new ActivityStatsTechSpecificInfo(
8198 rat,
8199 freq,
8200 info.getTransmitTimeMillis(rat, freq),
8201 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008202 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008203 }
8204 }
8205 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8206 mLastModemActivitySpecificInfo =
8207 new ActivityStatsTechSpecificInfo[merged.size()];
8208 merged.toArray(mLastModemActivitySpecificInfo);
8209
8210 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8211 mLastModemActivityInfo.setSleepTimeMillis(
8212 info.getSleepTimeMillis()
8213 + mLastModemActivityInfo.getSleepTimeMillis());
8214 mLastModemActivityInfo.setIdleTimeMillis(
8215 info.getIdleTimeMillis()
8216 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008217
8218 mLastModemActivityInfo =
8219 new ModemActivityInfo(
8220 mLastModemActivityInfo.getTimestampMillis(),
8221 mLastModemActivityInfo.getSleepTimeMillis(),
8222 mLastModemActivityInfo.getIdleTimeMillis(),
8223 mLastModemActivitySpecificInfo);
8224 }
8225
8226 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8227 ActivityStatsTechSpecificInfo[] info) {
8228 int infoSize = info.length;
8229 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8230 for (int i = 0; i < infoSize; i++) {
8231 ret[i] = new ActivityStatsTechSpecificInfo(
8232 info[i].getRat(), info[i].getFrequencyRange(),
8233 info[i].getTransmitTimeMillis(),
8234 (int) info[i].getReceiveTimeMillis());
8235 }
8236 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008237 }
8238
Jack Yu85bd38a2015-11-09 11:34:32 -08008239 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008240 * Returns the service state information on specified subscription.
8241 */
8242 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008243 public ServiceState getServiceStateForSubscriber(int subId,
8244 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8245 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008246 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008247 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008248 return null;
8249 }
8250
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008251 boolean hasFinePermission = false;
8252 boolean hasCoarsePermission = false;
8253 if (!renounceFineLocationAccess) {
8254 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8255 LocationAccessPolicy.checkLocationPermission(mApp,
8256 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8257 .setCallingPackage(callingPackage)
8258 .setCallingFeatureId(callingFeatureId)
8259 .setCallingPid(Binder.getCallingPid())
8260 .setCallingUid(Binder.getCallingUid())
8261 .setMethod("getServiceStateForSubscriber")
8262 .setLogAsInfo(true)
8263 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8264 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8265 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8266 .build());
8267 hasFinePermission =
8268 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8269 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008270
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008271 if (!renounceCoarseLocationAccess) {
8272 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8273 LocationAccessPolicy.checkLocationPermission(mApp,
8274 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8275 .setCallingPackage(callingPackage)
8276 .setCallingFeatureId(callingFeatureId)
8277 .setCallingPid(Binder.getCallingPid())
8278 .setCallingUid(Binder.getCallingUid())
8279 .setMethod("getServiceStateForSubscriber")
8280 .setLogAsInfo(true)
8281 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8282 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8283 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8284 .build());
8285 hasCoarsePermission =
8286 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8287 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008288
Jack Yu479f40e2020-10-27 21:29:25 -07008289 final Phone phone = getPhone(subId);
8290 if (phone == null) {
8291 return null;
8292 }
8293
Jordan Liu0f2bc442020-11-18 16:47:37 -08008294 final long identity = Binder.clearCallingIdentity();
8295
Jack Yu479f40e2020-10-27 21:29:25 -07008296 boolean isCallingPackageDataService = phone.getDataServicePackages()
8297 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008298 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008299 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008300 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8301 SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance()
8302 .getSubscriptionInfoInternal(subId);
8303 if (subInfo == null || !subInfo.isActive()) {
8304 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8305 + "subId=" + subId);
8306 return null;
8307 }
8308 } else {
8309 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8310 callingFeatureId)) {
8311 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8312 + "subId=" + subId);
8313 return null;
8314 }
Jordan Liuc437b192020-08-17 10:59:12 -07008315 }
8316
Hall Liuf19c44f2018-11-27 14:38:17 -08008317 ServiceState ss = phone.getServiceState();
8318
8319 // Scrub out the location info in ServiceState depending on what level of access
8320 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008321 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008322 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8323 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008324 } finally {
8325 Binder.restoreCallingIdentity(identity);
8326 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008327 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008328
8329 /**
8330 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8331 *
8332 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8333 * voicemail ringtone.
8334 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8335 * PhoneAccount.
8336 */
8337 @Override
8338 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008339 final long identity = Binder.clearCallingIdentity();
8340 try {
8341 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8342 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008343 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008344 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008345
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008346 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8347 } finally {
8348 Binder.restoreCallingIdentity(identity);
8349 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008350 }
8351
8352 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008353 * Sets the per-account voicemail ringtone.
8354 *
8355 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8356 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8357 *
8358 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8359 * voicemail ringtone.
8360 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8361 * PhoneAccount.
8362 */
8363 @Override
8364 public void setVoicemailRingtoneUri(String callingPackage,
8365 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008366 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008367 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008368 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8369 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8371 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8372 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008373 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008374
8375 final long identity = Binder.clearCallingIdentity();
8376 try {
8377 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8378 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008379 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008380 }
8381 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8382 } finally {
8383 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008384 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008385 }
8386
8387 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008388 * Returns whether vibration is set for voicemail notification in Phone settings.
8389 *
8390 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8391 * voicemail vibration setting.
8392 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8393 */
8394 @Override
8395 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008396 final long identity = Binder.clearCallingIdentity();
8397 try {
8398 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8399 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008400 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008401 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008402
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008403 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8404 } finally {
8405 Binder.restoreCallingIdentity(identity);
8406 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008407 }
8408
Youhan Wange64578a2016-05-02 15:32:42 -07008409 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008410 * Sets the per-account voicemail vibration.
8411 *
8412 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8413 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8414 *
8415 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8416 * voicemail vibration setting.
8417 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8418 * specific PhoneAccount.
8419 */
8420 @Override
8421 public void setVoicemailVibrationEnabled(String callingPackage,
8422 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008423 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008424 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008425 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8426 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8428 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8429 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008430 }
8431
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008432 final long identity = Binder.clearCallingIdentity();
8433 try {
8434 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8435 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008436 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008437 }
8438 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8439 } finally {
8440 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008441 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008442 }
8443
8444 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008445 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8446 *
8447 * @throws SecurityException if the caller does not have the required permission
8448 */
arunvoddud7401012022-12-15 16:08:12 +00008449 @VisibleForTesting
8450 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008451 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008452 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008453 }
8454
8455 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008456 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8457 * permission.
8458 *
8459 * @throws SecurityException if the caller does not have the required permission
8460 */
8461 private void enforceSendSmsPermission() {
8462 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8463 }
8464
8465 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008466 * Make sure either called from same process as self (phone) or IPC caller has interact across
8467 * users permission.
8468 *
8469 * @throws SecurityException if the caller does not have the required permission
8470 */
8471 private void enforceInteractAcrossUsersPermission(String message) {
8472 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8473 }
8474
8475 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008476 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008477 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008478 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008479 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008480 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008481 final long identity = Binder.clearCallingIdentity();
8482 try {
8483 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008484 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008485 if (componentName == null) {
8486 throw new SecurityException(
8487 "Caller not current active visual voicemail package[null]");
8488 }
8489 String vvmPackage = componentName.getPackageName();
8490 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008491 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008492 }
8493 } finally {
8494 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008495 }
8496 }
8497
8498 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008499 * Return the application ID for the app type.
8500 *
8501 * @param subId the subscription ID that this request applies to.
8502 * @param appType the uicc app type.
8503 * @return Application ID for specificied app type, or null if no uicc.
8504 */
8505 @Override
8506 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008507 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008508 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008509
8510 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008511 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008512 if (phone == null) {
8513 return null;
8514 }
8515 String aid = null;
8516 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008517 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008518 .getApplicationByType(appType).getAid();
8519 } catch (Exception e) {
8520 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8521 }
8522 return aid;
8523 } finally {
8524 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008525 }
Youhan Wange64578a2016-05-02 15:32:42 -07008526 }
8527
Youhan Wang4001d252016-05-11 10:29:41 -07008528 /**
8529 * Return the Electronic Serial Number.
8530 *
8531 * @param subId the subscription ID that this request applies to.
8532 * @return ESN or null if error.
8533 */
8534 @Override
8535 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008536 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008537 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008538
8539 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008540 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008541 if (phone == null) {
8542 return null;
8543 }
8544 String esn = null;
8545 try {
8546 esn = phone.getEsn();
8547 } catch (Exception e) {
8548 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8549 }
8550 return esn;
8551 } finally {
8552 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008553 }
Youhan Wang4001d252016-05-11 10:29:41 -07008554 }
8555
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008556 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008557 * Return the Preferred Roaming List Version.
8558 *
8559 * @param subId the subscription ID that this request applies to.
8560 * @return PRLVersion or null if error.
8561 */
8562 @Override
8563 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008564 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008565 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008566
8567 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008568 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008569 if (phone == null) {
8570 return null;
8571 }
8572 String cdmaPrlVersion = null;
8573 try {
8574 cdmaPrlVersion = phone.getCdmaPrlVersion();
8575 } catch (Exception e) {
8576 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8577 }
8578 return cdmaPrlVersion;
8579 } finally {
8580 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008581 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008582 }
8583
8584 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008585 * Get snapshot of Telephony histograms
8586 * @return List of Telephony histograms
8587 * @hide
8588 */
8589 @Override
8590 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8592 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008593
8594 final long identity = Binder.clearCallingIdentity();
8595 try {
8596 return RIL.getTelephonyRILTimingHistograms();
8597 } finally {
8598 Binder.restoreCallingIdentity(identity);
8599 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008600 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008601
8602 /**
8603 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008604 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8605 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008606 * Require system privileges. In the future we may add this to carrier APIs.
8607 *
Michele Berionne482f8202018-11-27 18:57:59 -08008608 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008609 */
8610 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008611 @TelephonyManager.SetCarrierRestrictionResult
8612 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008613 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008614 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008615
Michele Berionne482f8202018-11-27 18:57:59 -08008616 if (carrierRestrictionRules == null) {
8617 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008618 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008619
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008620 final long identity = Binder.clearCallingIdentity();
8621 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008622 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008623 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008624 } finally {
8625 Binder.restoreCallingIdentity(identity);
8626 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008627 }
8628
8629 /**
8630 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008631 * Get the allowed carrier list and the excluded carrier list, including the priority between
8632 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008633 * Require system privileges. In the future we may add this to carrier APIs.
8634 *
Michele Berionne482f8202018-11-27 18:57:59 -08008635 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008636 */
8637 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008638 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008639 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008640 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008641
8642 final long identity = Binder.clearCallingIdentity();
8643 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008644 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8645 if (response instanceof CarrierRestrictionRules) {
8646 return (CarrierRestrictionRules) response;
8647 }
8648 // Response is an Exception of some kind,
8649 // which is signalled to the user as a NULL retval
8650 return null;
8651 } catch (Exception e) {
8652 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8653 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008654 } finally {
8655 Binder.restoreCallingIdentity(identity);
8656 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008657 }
8658
fionaxu59545b42016-05-25 15:53:37 -07008659 /**
arunvoddud7401012022-12-15 16:08:12 +00008660 * Fetches the carrier restriction status of the device and sends the status to the caller
8661 * through the callback.
8662 *
8663 * @param callback The callback that will be used to send the result.
8664 * @throws SecurityException if the caller does not have the required permission/privileges or
8665 * the caller is not allowlisted.
8666 */
8667 @Override
8668 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8669 enforceReadPermission("getCarrierRestrictionStatus");
8670 int carrierId = validateCallerAndGetCarrierId(packageName);
8671 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8672 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8673 throw new SecurityException("Not an authorized caller");
8674 }
8675 final long identity = Binder.clearCallingIdentity();
8676 try {
8677 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8678 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8679 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8680 } finally {
8681 Binder.restoreCallingIdentity(identity);
8682 }
8683 }
8684
8685 @VisibleForTesting
8686 public int validateCallerAndGetCarrierId(String packageName) {
8687 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8688 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8689 }
8690
8691 /**
fionaxu59545b42016-05-25 15:53:37 -07008692 * Action set from carrier signalling broadcast receivers to enable/disable radio
8693 * @param subId the subscription ID that this action applies to.
8694 * @param enabled control enable or disable radio.
8695 * {@hide}
8696 */
8697 @Override
8698 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8699 enforceModifyPermission();
8700 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008701
8702 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008703 if (phone == null) {
8704 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8705 return;
8706 }
8707 try {
8708 phone.carrierActionSetRadioEnabled(enabled);
8709 } catch (Exception e) {
8710 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008711 } finally {
8712 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008713 }
8714 }
8715
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008716 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008717 * Enable or disable Voice over NR (VoNR)
8718 * @param subId the subscription ID that this action applies to.
8719 * @param enabled enable or disable VoNR.
8720 * @return operation result.
8721 */
8722 @Override
8723 public int setVoNrEnabled(int subId, boolean enabled) {
8724 enforceModifyPermission();
8725 final Phone phone = getPhone(subId);
8726
8727 final long identity = Binder.clearCallingIdentity();
8728 if (phone == null) {
8729 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8730 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8731 }
8732
8733 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8734 try {
8735 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8736 workSource);
8737 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008738
8739 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8740 if (DBG) {
8741 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8742 }
8743 SubscriptionManager.setSubscriptionProperty(
8744 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8745 (enabled ? "1" : "0"));
8746 }
8747
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008748 return result;
8749 } finally {
8750 Binder.restoreCallingIdentity(identity);
8751 }
8752 }
8753
8754 /**
8755 * Is voice over NR enabled
8756 * @return true if VoNR is enabled else false
8757 */
8758 @Override
8759 public boolean isVoNrEnabled(int subId) {
8760 enforceReadPrivilegedPermission("isVoNrEnabled");
8761 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8762 final long identity = Binder.clearCallingIdentity();
8763 try {
8764 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8765 null, subId, workSource);
8766 if (DBG) log("isVoNrEnabled: " + isEnabled);
8767 return isEnabled;
8768 } finally {
8769 Binder.restoreCallingIdentity(identity);
8770 }
8771 }
8772
8773 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008774 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8775 * network status based on which carrier apps could apply actions accordingly,
8776 * enable/disable default url handler for example.
8777 *
8778 * @param subId the subscription ID that this action applies to.
8779 * @param report control start/stop reporting the default network status.
8780 * {@hide}
8781 */
8782 @Override
8783 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8784 enforceModifyPermission();
8785 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008786
8787 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008788 if (phone == null) {
8789 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8790 return;
8791 }
8792 try {
8793 phone.carrierActionReportDefaultNetworkStatus(report);
8794 } catch (Exception e) {
8795 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008796 } finally {
8797 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008798 }
8799 }
8800
8801 /**
fionaxud9622282017-07-17 17:51:30 -07008802 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8803 * @param subId the subscription ID that this action applies to.
8804 * {@hide}
8805 */
8806 @Override
8807 public void carrierActionResetAll(int subId) {
8808 enforceModifyPermission();
8809 final Phone phone = getPhone(subId);
8810 if (phone == null) {
8811 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8812 return;
8813 }
8814 try {
8815 phone.carrierActionResetAll();
8816 } catch (Exception e) {
8817 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8818 }
8819 }
8820
8821 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008822 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8823 * bug report is being generated.
8824 */
8825 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008826 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008827 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8828 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008829 writer.println("Permission Denial: can't dump Phone from pid="
8830 + Binder.getCallingPid()
8831 + ", uid=" + Binder.getCallingUid()
8832 + "without permission "
8833 + android.Manifest.permission.DUMP);
8834 return;
8835 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008836 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008837 }
Jack Yueb89b242016-06-22 13:27:47 -07008838
Brad Ebingerdac2f002018-04-03 15:17:52 -07008839 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008840 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8841 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8842 @NonNull String[] args) {
8843 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8844 this, in.getFileDescriptor(), out.getFileDescriptor(),
8845 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008846 }
8847
Jack Yueb89b242016-06-22 13:27:47 -07008848 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008849 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008850 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008851 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008852 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008853 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008854 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008855 */
8856 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008857 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008858 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008859 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8860 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8861 try {
8862 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008863 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008864 } catch (SecurityException se) {
8865 enforceModifyPermission();
8866 }
8867 } else {
8868 enforceModifyPermission();
8869 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008870
8871 final long identity = Binder.clearCallingIdentity();
8872 try {
8873 Phone phone = getPhone(subId);
8874 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008875 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8876 phone.carrierActionSetMeteredApnsEnabled(enabled);
8877 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008878 phone.getDataSettingsManager().setDataEnabled(
8879 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008880 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008881 }
8882 } finally {
8883 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008884 }
8885 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008886
8887 /**
8888 * Get Client request stats
8889 * @return List of Client Request Stats
8890 * @hide
8891 */
8892 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008893 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8894 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008895 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008896 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008897 return null;
8898 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008899 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008900
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008901 final long identity = Binder.clearCallingIdentity();
8902 try {
8903 if (phone != null) {
8904 return phone.getClientRequestStats();
8905 }
8906
8907 return null;
8908 } finally {
8909 Binder.restoreCallingIdentity(identity);
8910 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008911 }
8912
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008913 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008914 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008915 if (uid == Process.ROOT_UID && packageName == null) {
8916 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8917 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8918 // exception. ROOT_UID seems not to have a valid package name returned by
8919 // PackageManager, so just fake it here to avoid issues when running telephony shell
8920 // commands that plumb through the RIL as root, like so:
8921 // $ adb root
8922 // $ adb shell cmd phone ...
8923 packageName = "root";
8924 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008925 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008926 }
Jack Yueb4124c2017-02-16 15:32:43 -08008927
8928 /**
Grace Chen70990072017-03-24 17:21:30 -07008929 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008930 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008931 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008932 * @param state State of SIM (power down, power up, pass through)
8933 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8934 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8935 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008936 *
8937 **/
8938 @Override
Grace Chen70990072017-03-24 17:21:30 -07008939 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008940 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008941 Phone phone = PhoneFactory.getPhone(slotIndex);
8942
vagdeviaf9a5b92018-08-15 16:01:53 -07008943 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8944
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008945 final long identity = Binder.clearCallingIdentity();
8946 try {
8947 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008948 phone.setSimPowerState(state, null, workSource);
8949 }
8950 } finally {
8951 Binder.restoreCallingIdentity(identity);
8952 }
8953 }
8954
8955 /**
8956 * Set SIM card power state.
8957 *
8958 * @param slotIndex SIM slot id.
8959 * @param state State of SIM (power down, power up, pass through)
8960 * @param callback callback to trigger after success or failure
8961 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8962 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8963 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8964 *
8965 **/
8966 @Override
8967 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8968 IIntegerConsumer callback) {
8969 enforceModifyPermission();
8970 Phone phone = PhoneFactory.getPhone(slotIndex);
8971
8972 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8973
8974 final long identity = Binder.clearCallingIdentity();
8975 try {
8976 if (phone != null) {
8977 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8978 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008979 }
8980 } finally {
8981 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008982 }
8983 }
Shuo Qiandd210312017-04-12 22:11:33 +00008984
Tyler Gunn65d45c22017-06-05 11:22:26 -07008985 private boolean isUssdApiAllowed(int subId) {
8986 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008987 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008988 if (configManager == null) {
8989 return false;
8990 }
8991 PersistableBundle pb = configManager.getConfigForSubId(subId);
8992 if (pb == null) {
8993 return false;
8994 }
8995 return pb.getBoolean(
8996 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8997 }
8998
Shuo Qiandd210312017-04-12 22:11:33 +00008999 /**
9000 * Check if phone is in emergency callback mode
9001 * @return true if phone is in emergency callback mode
9002 * @param subId sub id
9003 */
goneil9c5f4872017-12-05 14:07:56 -08009004 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009005 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009006 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00009007 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009008
9009 final long identity = Binder.clearCallingIdentity();
9010 try {
9011 if (phone != null) {
9012 return phone.isInEcm();
9013 } else {
9014 return false;
9015 }
9016 } finally {
9017 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009018 }
9019 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009020
9021 /**
9022 * Get the current signal strength information for the given subscription.
9023 * Because this information is not updated when the device is in a low power state
9024 * it should not be relied-upon to be current.
9025 * @param subId Subscription index
9026 * @return the most recent cached signal strength info from the modem
9027 */
9028 @Override
9029 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009030 final long identity = Binder.clearCallingIdentity();
9031 try {
9032 Phone p = getPhone(subId);
9033 if (p == null) {
9034 return null;
9035 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009036
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009037 return p.getSignalStrength();
9038 } finally {
9039 Binder.restoreCallingIdentity(identity);
9040 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009041 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009042
Pengquan Meng77b7f132018-08-22 14:49:57 -07009043 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009044 * Get the current modem radio state for the given slot.
9045 * @param slotIndex slot index.
9046 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009047 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009048 * @return the current radio power state from the modem
9049 */
9050 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009051 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009052 Phone phone = PhoneFactory.getPhone(slotIndex);
9053 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009054 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9055 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009056 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9057 }
9058
9059 final long identity = Binder.clearCallingIdentity();
9060 try {
9061 return phone.getRadioPowerState();
9062 } finally {
9063 Binder.restoreCallingIdentity(identity);
9064 }
9065 }
9066 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9067 }
9068
9069 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009070 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9071 *
9072 * <p>Requires one of the following permissions:
9073 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009074 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009075 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9076 * privileges.
9077 *
9078 * @param subId subscription id
9079 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9080 * {@code false}.
9081 */
9082 @Override
9083 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009084 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009085 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009086 try {
9087 mApp.enforceCallingOrSelfPermission(
9088 android.Manifest.permission.ACCESS_NETWORK_STATE,
9089 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009090 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009091 mApp.enforceCallingOrSelfPermission(
9092 permission.READ_BASIC_PHONE_STATE, functionName);
9093 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009094 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009095 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009096 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009097 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009098
Pengquan Menga1bb6272018-09-06 09:59:22 -07009099 boolean isEnabled = false;
9100 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009101 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009102 Phone phone = getPhone(subId);
9103 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009104 } finally {
9105 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009106 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009107 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009108 }
9109
9110
9111 /**
9112 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9113 *
9114 * <p> Requires permission:
9115 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9116 * privileges.
9117 *
9118 * @param subId subscription id
9119 * @param isEnabled {@code true} means enable, {@code false} means disable.
9120 */
9121 @Override
9122 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009123 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9124 mApp, subId, "setDataRoamingEnabled");
9125
Pengquan Menga1bb6272018-09-06 09:59:22 -07009126 final long identity = Binder.clearCallingIdentity();
9127 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009128 Phone phone = getPhone(subId);
9129 if (phone != null) {
9130 phone.setDataRoamingEnabled(isEnabled);
9131 }
9132 } finally {
9133 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009134 }
9135 }
9136
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009137 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009138 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009139 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009140 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07009141 mApp, subId, "isManualNetworkSelectionAllowed");
9142
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009143 boolean isAllowed = true;
9144 final long identity = Binder.clearCallingIdentity();
9145 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009146 Phone phone = getPhone(subId);
9147 if (phone != null) {
9148 isAllowed = phone.isCspPlmnEnabled();
9149 }
9150 } finally {
9151 Binder.restoreCallingIdentity(identity);
9152 }
9153 return isAllowed;
9154 }
9155
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009156 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9157 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009158 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009159 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009160 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009161 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9162 if (phone == null) {
9163 return false;
9164 }
9165 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9166 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9167 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009168 }
9169
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009170 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009171 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009172 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009173 mApp.getSystemService(AppOpsManager.class)
9174 .checkPackage(Binder.getCallingUid(), callingPackage);
9175
Jordan Liu1e142fc2019-04-22 15:10:43 -07009176 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009177 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009178 try {
9179 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009180 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009181 } catch (SecurityException e) {
9182 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9183 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009184 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08009185 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009186 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009187 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009188 }
sandeepjsb6c87872021-09-27 15:34:44 +00009189 // checking compatibility, if calling app's target SDK is T and beyond.
9190 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9191 Binder.getCallingUid())) {
9192 isIccIdAccessRestricted = true;
9193 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009194 final long identity = Binder.clearCallingIdentity();
9195 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009196 UiccController uiccController = UiccController.getInstance();
9197 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009198 if (hasReadPermission) {
9199 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009200 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009201
9202 // Remove private info if the caller doesn't have access
9203 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9204 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009205 //setting the value after compatibility check
9206 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009207 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9208 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009209 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009210 if (card == null) {
9211 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009212 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009213 continue;
9214 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009215 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9216 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009217 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009218 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009219 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009220 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9221 for (UiccPortInfo portInfo : portInfos) {
9222 UiccPort port = uiccController.getUiccPortForSlot(
9223 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9224 if (port == null) {
9225 // assume no access if port is null
9226 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9227 continue;
9228 }
9229 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9230 uiccPortInfos.add(portInfo);
9231 } else {
9232 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9233 }
9234 }
9235 filteredInfos.add(new UiccCardInfo(
9236 cardInfo.isEuicc(),
9237 cardInfo.getCardId(),
9238 null,
9239 cardInfo.getPhysicalSlotIndex(),
9240 cardInfo.isRemovable(),
9241 cardInfo.isMultipleEnabledProfilesSupported(),
9242 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009243 }
9244 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009245 } finally {
9246 Binder.restoreCallingIdentity(identity);
9247 }
9248 }
9249
sandeepjsb6c87872021-09-27 15:34:44 +00009250 /**
9251 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9252 * generally private and require carrier privileges to view.
9253 *
9254 * @hide
9255 */
9256 @NonNull
9257 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9258 List<UiccPortInfo> portinfo = new ArrayList<>();
9259 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9260 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9261 }
9262 return new UiccCardInfo(
9263 cardInfo.isEuicc(),
9264 cardInfo.getCardId(),
9265 null,
9266 cardInfo.getPhysicalSlotIndex(),
9267 cardInfo.isRemovable(),
9268 cardInfo.isMultipleEnabledProfilesSupported(),
9269 portinfo
9270 );
9271 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009272
sandeepjsb6c87872021-09-27 15:34:44 +00009273 /**
9274 * @hide
9275 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9276 * These values are generally private and require carrier privileges to view.
9277 */
9278 @NonNull
9279 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9280 return new UiccPortInfo(
9281 UiccPortInfo.ICCID_REDACTED,
9282 portInfo.getPortIndex(),
9283 portInfo.getLogicalSlotIndex(),
9284 portInfo.isActive()
9285 );
9286 }
9287 @Override
9288 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009289 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009290 mApp.getSystemService(AppOpsManager.class)
9291 .checkPackage(Binder.getCallingUid(), callingPackage);
9292
sandeepjsb6c87872021-09-27 15:34:44 +00009293 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009294
Aman Guptaf3c90b32022-03-17 04:54:16 +00009295 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9296 // we are reading iccId which is PII data.
9297 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009298
9299 // checking compatibility, if calling app's target SDK is T and beyond.
9300 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9301 Binder.getCallingUid())) {
9302 isLogicalSlotAccessRestricted = true;
9303 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009304 final long identity = Binder.clearCallingIdentity();
9305 try {
9306 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009307 if (slots == null || slots.length == 0) {
9308 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009309 return null;
9310 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009311 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9312 for (int i = 0; i < slots.length; i++) {
9313 UiccSlot slot = slots[i];
9314 if (slot == null) {
9315 continue;
9316 }
9317
Jordan Liu7be7e652019-05-06 18:55:02 +00009318 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009319 UiccCard card = slot.getUiccCard();
9320 if (card != null) {
9321 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009322 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009323 cardId = slot.getEid();
9324 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009325 // If cardId is null, use iccId of default port as cardId.
9326 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009327 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009328 }
9329
Jordan Liu857451f2019-05-09 16:35:35 -07009330 if (cardId != null) {
9331 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9332 // if cardId is an EID, it's all digits so this is fine
9333 cardId = IccUtils.stripTrailingFs(cardId);
9334 }
9335
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009336 int cardState = 0;
9337 switch (slot.getCardState()) {
9338 case CARDSTATE_ABSENT:
9339 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9340 break;
9341 case CARDSTATE_PRESENT:
9342 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9343 break;
9344 case CARDSTATE_ERROR:
9345 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9346 break;
9347 case CARDSTATE_RESTRICTED:
9348 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9349 break;
9350 default:
9351 break;
9352
9353 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009354 List<UiccPortInfo> portInfos = new ArrayList<>();
9355 int[] portIndexes = slot.getPortList();
9356 for (int portIdx : portIndexes) {
9357 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009358 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009359 portInfos.add(new UiccPortInfo(iccId, portIdx,
9360 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009361 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009362 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009363 slot.isEuicc(),
9364 cardId,
9365 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009366 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009367 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009368 //setting the value after compatibility check
9369 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009370 }
9371 return infos;
9372 } finally {
9373 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009374 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009375 }
9376
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009377 /* Returns null if doesn't have read permission or carrier privilege access. */
9378 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9379 boolean hasReadPermission) {
9380 String iccId = slot.getIccId(portIndex);
9381 if (hasReadPermission) { // if has read permission
9382 return iccId;
9383 } else {
9384 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9385 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9386 // if no read permission, checking carrier privilege access
9387 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9388 return iccId;
9389 }
9390 }
9391 }
9392 // No read permission or carrier privilege access.
9393 return UiccPortInfo.ICCID_REDACTED;
9394 }
9395
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009396 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009397 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009398 public boolean switchSlots(int[] physicalSlots) {
9399 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009400
9401 final long identity = Binder.clearCallingIdentity();
9402 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009403 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9404 for (int i = 0; i < physicalSlots.length; i++) {
9405 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9406 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9407 physicalSlots[i], i));
9408 }
9409 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009410 } finally {
9411 Binder.restoreCallingIdentity(identity);
9412 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009413 }
Jack Yu4c988042018-02-27 15:30:01 -08009414
9415 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009416 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9417 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9418 enforceModifyPermission();
9419
9420 final long identity = Binder.clearCallingIdentity();
9421 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009422 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009423 } finally {
9424 Binder.restoreCallingIdentity(identity);
9425 }
9426 }
9427
9428 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009429 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009430 final long identity = Binder.clearCallingIdentity();
9431 try {
9432 return UiccController.getInstance().getCardIdForDefaultEuicc();
9433 } finally {
9434 Binder.restoreCallingIdentity(identity);
9435 }
9436 }
9437
Pengquan Meng85728fb2018-03-12 16:31:21 -07009438 /**
goneil47ffb6e2018-04-06 15:40:58 -07009439 * A test API to reload the UICC profile.
9440 *
9441 * <p>Requires that the calling app has permission
9442 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9443 * @hide
9444 */
9445 @Override
9446 public void refreshUiccProfile(int subId) {
9447 enforceModifyPermission();
9448
9449 final long identity = Binder.clearCallingIdentity();
9450 try {
9451 Phone phone = getPhone(subId);
9452 if (phone == null) {
9453 return;
9454 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009455 UiccPort uiccPort = phone.getUiccPort();
9456 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009457 return;
9458 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009459 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009460 if (uiccProfile == null) {
9461 return;
9462 }
9463 uiccProfile.refresh();
9464 } finally {
9465 Binder.restoreCallingIdentity(identity);
9466 }
9467 }
9468
9469 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009470 * Returns false if the mobile data is disabled by default, otherwise return true.
9471 */
9472 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009473 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009474 }
9475
9476 /**
9477 * Returns true if the data roaming is enabled by default, i.e the system property
9478 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9479 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9480 */
9481 private boolean getDefaultDataRoamingEnabled(int subId) {
9482 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009483 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009484 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009485 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9486 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9487 return isDataRoamingEnabled;
9488 }
9489
9490 /**
9491 * Returns the default network type for the given {@code subId}, if the default network type is
9492 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9493 */
9494 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009495 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009496 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009497 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9498 return list.get(phoneId);
9499 }
9500 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009501 }
fionaxua13278b2018-03-21 00:08:13 -07009502
9503 @Override
9504 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009505 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009506 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009507
9508 final long identity = Binder.clearCallingIdentity();
9509 try {
9510 final Phone phone = getPhone(subId);
9511 if (phone == null) {
9512 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9513 return;
9514 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009515 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9516 if (cpt != null) {
9517 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9518 }
9519 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009520 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9521 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009522 if (carrierPrivilegeRules == null) {
9523 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9524 } else {
9525 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9526 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009527 } finally {
9528 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009529 }
fionaxua13278b2018-03-21 00:08:13 -07009530 }
9531
9532 @Override
9533 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009534 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009535
9536 final long identity = Binder.clearCallingIdentity();
9537 try {
9538 final Phone phone = getPhone(subId);
9539 if (phone == null) {
9540 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9541 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9542 }
9543 return phone.getCarrierIdListVersion();
9544 } finally {
9545 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009546 }
fionaxua13278b2018-03-21 00:08:13 -07009547 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009548
9549 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009550 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9551 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009552 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009553 mApp, subId, callingPackage, callingFeatureId,
9554 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009555 return -1;
9556 }
9557
9558 final long identity = Binder.clearCallingIdentity();
9559 try {
9560 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9561 } finally {
9562 Binder.restoreCallingIdentity(identity);
9563 }
9564 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009565
9566 @Override
9567 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009568 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009569 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009570 mApp, subId, "getCdmaRoamingMode");
9571
9572 final long identity = Binder.clearCallingIdentity();
9573 try {
9574 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9575 } finally {
9576 Binder.restoreCallingIdentity(identity);
9577 }
9578 }
9579
9580 @Override
9581 public boolean setCdmaRoamingMode(int subId, int mode) {
9582 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9583 mApp, subId, "setCdmaRoamingMode");
9584
9585 final long identity = Binder.clearCallingIdentity();
9586 try {
9587 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9588 } finally {
9589 Binder.restoreCallingIdentity(identity);
9590 }
9591 }
9592
9593 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009594 public int getCdmaSubscriptionMode(int subId) {
9595 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009596 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009597 mApp, subId, "getCdmaSubscriptionMode");
9598
9599 final long identity = Binder.clearCallingIdentity();
9600 try {
9601 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9602 } finally {
9603 Binder.restoreCallingIdentity(identity);
9604 }
9605 }
9606
9607 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009608 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9609 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9610 mApp, subId, "setCdmaSubscriptionMode");
9611
9612 final long identity = Binder.clearCallingIdentity();
9613 try {
9614 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9615 } finally {
9616 Binder.restoreCallingIdentity(identity);
9617 }
9618 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009619
sqianc5eccab2018-10-19 18:46:41 -07009620 @Override
sqian8c685422019-02-22 15:55:18 -08009621 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009622 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009623 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009624 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9625 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009626 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9627 }
9628 final long identity = Binder.clearCallingIdentity();
9629 try {
sqian854d44b2018-12-12 16:48:18 -08009630 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9631 for (Phone phone: PhoneFactory.getPhones()) {
9632 if (phone.getEmergencyNumberTracker() != null
9633 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9634 emergencyNumberListInternal.put(
9635 phone.getSubId(),
9636 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9637 }
sqian11b7a0e2018-12-05 18:48:28 -08009638 }
sqian854d44b2018-12-12 16:48:18 -08009639 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009640 } finally {
9641 Binder.restoreCallingIdentity(identity);
9642 }
sqianc5eccab2018-10-19 18:46:41 -07009643 }
9644
9645 @Override
sqian8c685422019-02-22 15:55:18 -08009646 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009647 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009648 if (!exactMatch) {
9649 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009650 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009651 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009652 }
9653 final long identity = Binder.clearCallingIdentity();
9654 try {
sqian854d44b2018-12-12 16:48:18 -08009655 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009656 //Note: we ignore passed in param exactMatch. We can remove it once
9657 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009658 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009659 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009660 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009661 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009662 }
sqian11b7a0e2018-12-05 18:48:28 -08009663 }
9664 return false;
9665 } finally {
9666 Binder.restoreCallingIdentity(identity);
9667 }
9668 }
9669
sqianf4ca7ed2019-01-15 18:32:07 -08009670 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009671 * Start emergency callback mode for GsmCdmaPhone for testing.
9672 */
9673 @Override
9674 public void startEmergencyCallbackMode() {
9675 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9676 "startEmergencyCallbackMode");
9677 enforceModifyPermission();
9678 final long identity = Binder.clearCallingIdentity();
9679 try {
9680 for (Phone phone : PhoneFactory.getPhones()) {
9681 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9682 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9683 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9684 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9685 gsmCdmaPhone.obtainMessage(
9686 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9687 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9688 }
9689 }
9690 } finally {
9691 Binder.restoreCallingIdentity(identity);
9692 }
9693 }
9694
9695 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009696 * Update emergency number list for test mode.
9697 */
9698 @Override
9699 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9700 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9701 "updateEmergencyNumberListTestMode");
9702
9703 final long identity = Binder.clearCallingIdentity();
9704 try {
9705 for (Phone phone: PhoneFactory.getPhones()) {
9706 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9707 if (tracker != null) {
9708 tracker.executeEmergencyNumberTestModeCommand(action, num);
9709 }
9710 }
9711 } finally {
9712 Binder.restoreCallingIdentity(identity);
9713 }
9714 }
9715
9716 /**
9717 * Get the full emergency number list for test mode.
9718 */
9719 @Override
9720 public List<String> getEmergencyNumberListTestMode() {
9721 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9722 "getEmergencyNumberListTestMode");
9723
9724 final long identity = Binder.clearCallingIdentity();
9725 try {
9726 Set<String> emergencyNumbers = new HashSet<>();
9727 for (Phone phone: PhoneFactory.getPhones()) {
9728 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9729 if (tracker != null) {
9730 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9731 emergencyNumbers.add(num.getNumber());
9732 }
9733 }
9734 }
9735 return new ArrayList<>(emergencyNumbers);
9736 } finally {
9737 Binder.restoreCallingIdentity(identity);
9738 }
9739 }
9740
chen xud6b45bd2018-10-30 22:27:10 -07009741 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009742 public int getEmergencyNumberDbVersion(int subId) {
9743 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9744
9745 final long identity = Binder.clearCallingIdentity();
9746 try {
9747 final Phone phone = getPhone(subId);
9748 if (phone == null) {
9749 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9750 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9751 }
9752 return phone.getEmergencyNumberDbVersion();
9753 } finally {
9754 Binder.restoreCallingIdentity(identity);
9755 }
9756 }
9757
9758 @Override
9759 public void notifyOtaEmergencyNumberDbInstalled() {
9760 enforceModifyPermission();
9761
9762 final long identity = Binder.clearCallingIdentity();
9763 try {
9764 for (Phone phone: PhoneFactory.getPhones()) {
9765 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9766 if (tracker != null) {
9767 tracker.updateOtaEmergencyNumberDatabase();
9768 }
9769 }
9770 } finally {
9771 Binder.restoreCallingIdentity(identity);
9772 }
9773 }
9774
9775 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009776 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009777 enforceActiveEmergencySessionPermission();
9778
9779 final long identity = Binder.clearCallingIdentity();
9780 try {
9781 for (Phone phone: PhoneFactory.getPhones()) {
9782 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9783 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009784 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9785 }
9786 }
9787 } finally {
9788 Binder.restoreCallingIdentity(identity);
9789 }
9790 }
9791
9792 @Override
9793 public void resetOtaEmergencyNumberDbFilePath() {
9794 enforceActiveEmergencySessionPermission();
9795
9796 final long identity = Binder.clearCallingIdentity();
9797 try {
9798 for (Phone phone: PhoneFactory.getPhones()) {
9799 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9800 if (tracker != null) {
9801 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009802 }
9803 }
9804 } finally {
9805 Binder.restoreCallingIdentity(identity);
9806 }
9807 }
9808
9809 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009810 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9811 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9812 Phone phone = getPhone(subId);
9813 if (phone == null) {
9814 return null;
9815 }
9816 final long identity = Binder.clearCallingIdentity();
9817 try {
9818 UiccProfile profile = UiccController.getInstance()
9819 .getUiccProfileForPhone(phone.getPhoneId());
9820 if (profile != null) {
9821 return profile.getCertsFromCarrierPrivilegeAccessRules();
9822 }
9823 } finally {
9824 Binder.restoreCallingIdentity(identity);
9825 }
9826 return null;
9827 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009828
9829 /**
9830 * Enable or disable a modem stack.
9831 */
9832 @Override
9833 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9834 enforceModifyPermission();
9835
9836 final long identity = Binder.clearCallingIdentity();
9837 try {
9838 Phone phone = PhoneFactory.getPhone(slotIndex);
9839 if (phone == null) {
9840 return false;
9841 } else {
9842 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9843 }
9844 } finally {
9845 Binder.restoreCallingIdentity(identity);
9846 }
9847 }
Michelecea4cf22018-12-21 15:00:11 -08009848
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009849 /**
9850 * Whether a modem stack is enabled or not.
9851 */
9852 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009853 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9854 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009855 Phone phone = PhoneFactory.getPhone(slotIndex);
9856 if (phone == null) return false;
9857
9858 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009859 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9860 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009861 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9862 }
9863
9864 final long identity = Binder.clearCallingIdentity();
9865 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009866 try {
9867 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9868 } catch (NoSuchElementException ex) {
9869 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9870 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009871 } finally {
9872 Binder.restoreCallingIdentity(identity);
9873 }
9874 }
9875
Michelecea4cf22018-12-21 15:00:11 -08009876 @Override
Michele0ea7d782019-03-19 14:58:42 -07009877 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009878 enforceModifyPermission();
9879
9880 final long identity = Binder.clearCallingIdentity();
9881 try {
9882 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009883 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009884 .commit();
9885 } finally {
9886 Binder.restoreCallingIdentity(identity);
9887 }
9888 }
9889
9890 @Override
Michele0ea7d782019-03-19 14:58:42 -07009891 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009892 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009893 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009894 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9895 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009896 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009897 }
Michelecea4cf22018-12-21 15:00:11 -08009898
9899 final long identity = Binder.clearCallingIdentity();
9900 try {
Michele0ea7d782019-03-19 14:58:42 -07009901 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009902 } finally {
9903 Binder.restoreCallingIdentity(identity);
9904 }
9905 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009906
Michele0ea7d782019-03-19 14:58:42 -07009907 @TelephonyManager.IsMultiSimSupportedResult
9908 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009909 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9910 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9911 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009912 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9913 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009914 }
9915 // Check if the hardware supports multisim functionality. If usage of multisim is not
9916 // supported by the modem, indicate that it is restricted.
9917 PhoneCapability staticCapability =
9918 mPhoneConfigurationManager.getStaticPhoneCapability();
9919 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009920 loge("isMultiSimSupportedInternal: no static configuration available");
9921 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009922 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009923 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009924 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9925 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009926 }
9927 // Check if support of multiple SIMs is restricted by carrier
9928 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009929 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009930 }
9931
Michele0ea7d782019-03-19 14:58:42 -07009932 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009933 }
9934
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009935 /**
9936 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009937 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9938 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9939 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009940 * @param numOfSims number of active sims we want to switch to
9941 */
9942 @Override
9943 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009944 if (numOfSims == 1) {
9945 enforceModifyPermission();
9946 } else {
9947 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9948 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9949 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009950 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009951
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009952 try {
Michele30b57b22019-03-01 12:01:14 -08009953 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009954 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009955 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9956 return;
9957 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009958 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9959 } finally {
9960 Binder.restoreCallingIdentity(identity);
9961 }
9962 }
9963
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009964 @Override
9965 public boolean isApplicationOnUicc(int subId, int appType) {
9966 enforceReadPrivilegedPermission("isApplicationOnUicc");
9967 Phone phone = getPhone(subId);
9968 if (phone == null) {
9969 return false;
9970 }
9971 final long identity = Binder.clearCallingIdentity();
9972 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009973 UiccPort uiccPort = phone.getUiccPort();
9974 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009975 return false;
9976 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009977 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009978 if (uiccProfile == null) {
9979 return false;
9980 }
9981 if (TelephonyManager.APPTYPE_SIM <= appType
9982 && appType <= TelephonyManager.APPTYPE_ISIM) {
9983 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9984 }
9985 return false;
9986 } finally {
9987 Binder.restoreCallingIdentity(identity);
9988 }
9989 }
9990
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009991 /**
chen xub4baa772019-04-03 10:23:41 -07009992 * Get whether making changes to modem configurations will trigger reboot.
9993 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009994 */
9995 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009996 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9997 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009998 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009999 mApp, subId, callingPackage, callingFeatureId,
10000 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010001 return false;
10002 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010003 final long identity = Binder.clearCallingIdentity();
10004 try {
10005 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10006 } finally {
10007 Binder.restoreCallingIdentity(identity);
10008 }
10009 }
10010
Nathan Harold29f5f052019-02-15 13:41:57 -080010011 private void updateModemStateMetrics() {
10012 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10013 // TODO: check the state for each modem if the api is ready.
10014 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10015 }
10016
Pengquan Meng3889a572019-01-23 11:16:29 -080010017 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010018 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010019 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010020 // Verify that the callingPackage belongs to the calling UID
10021 mApp.getSystemService(AppOpsManager.class)
10022 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010023 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010024 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010025 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010026 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10027 if (slotInfos != null) {
10028 for (int i = 0; i < slotInfos.length; i++) {
10029 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10030 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10031 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10032 portInfo.getLogicalSlotIndex()));
10033 }
10034 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010035 }
10036 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010037 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010038 } finally {
10039 Binder.restoreCallingIdentity(identity);
10040 }
10041 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010042
10043 /**
10044 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010045 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010046 */
jimsunf9ec1622022-09-13 21:18:43 +080010047 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010048 @Override
10049 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010050 return getHalVersion(HAL_SERVICE_RADIO);
10051 }
10052
10053 /**
10054 * Get the HAL Version of a specific service
10055 */
10056 @Override
10057 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010058 Phone phone = getDefaultPhone();
10059 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010060 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010061 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10062 return hv.major * 100 + hv.minor;
10063 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010064
10065 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010066 * Get the current calling package name.
10067 * @return the current calling package name
10068 */
10069 @Override
10070 public String getCurrentPackageName() {
10071 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10072 }
10073
10074 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010075 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10076 * corresponding network requests on a subId.
10077 *
10078 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010079 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010080 * 2) APN is un-metered for this subscription, or
10081 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010082 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010083 *
10084 * @return whether data is allowed for a apn type.
10085 *
10086 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010087 */
10088 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010089 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010090 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10091 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010092
10093 // Now that all security checks passes, perform the operation as ourselves.
10094 final long identity = Binder.clearCallingIdentity();
10095 try {
10096 Phone phone = getPhone(subId);
10097 if (phone == null) return false;
10098
Jack Yu27422a52022-03-21 10:38:05 -070010099 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010100 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010101 isMetered = phone.getDataNetworkController().getDataConfigManager()
10102 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10103 phone.getServiceState().getDataRoaming());
10104 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010105 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010106 } finally {
10107 Binder.restoreCallingIdentity(identity);
10108 }
10109 }
10110
10111 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010112 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010113 enforceReadPrivilegedPermission("isApnMetered");
10114
10115 // Now that all security checks passes, perform the operation as ourselves.
10116 final long identity = Binder.clearCallingIdentity();
10117 try {
10118 Phone phone = getPhone(subId);
10119 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010120 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10121 DataUtils.apnTypeToNetworkCapability(apnType),
10122 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010123 } finally {
10124 Binder.restoreCallingIdentity(identity);
10125 }
10126 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010127
10128 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010129 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10130 int subscriptionId, IBooleanConsumer resultCallback) {
10131 enforceModifyPermission();
10132 long token = Binder.clearCallingIdentity();
10133 try {
10134 Phone phone = getPhone(subscriptionId);
10135 if (phone == null) {
10136 try {
10137 if (resultCallback != null) {
10138 resultCallback.accept(false);
10139 }
10140 } catch (RemoteException e) {
10141 // ignore
10142 }
10143 return;
10144 }
10145 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10146 Pair.create(specifiers, (x) -> {
10147 try {
10148 if (resultCallback != null) {
10149 resultCallback.accept(x);
10150 }
10151 } catch (RemoteException e) {
10152 // ignore
10153 }
10154 });
10155 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10156 } finally {
10157 Binder.restoreCallingIdentity(token);
10158 }
10159 }
10160
10161 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010162 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10163 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010164 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010165 mApp, subId, "getSystemSelectionChannels");
10166 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10167 final long identity = Binder.clearCallingIdentity();
10168 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010169 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10170 if (result instanceof IllegalStateException) {
10171 throw (IllegalStateException) result;
10172 }
10173 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010174 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10175 return specifiers;
10176 } finally {
10177 Binder.restoreCallingIdentity(identity);
10178 }
10179 }
10180
10181 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010182 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010183 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010184 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010185 }
10186
10187 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010188 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10189 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010190 if (callingPackage == null) {
10191 callingPackage = getCurrentPackageName();
10192 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010193 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10194 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010195 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10196 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010197 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10198 }
10199 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10200 Intent intent = new Intent();
10201 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10202 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10203 // Bring up choose default SMS subscription dialog right now
10204 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10205 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10206 mApp.startActivity(intent);
10207 }
chen xud5ca2d52019-05-28 15:20:57 -070010208
10209 @Override
10210 public String getMmsUAProfUrl(int subId) {
10211 //TODO investigate if this API should require proper permission check in R b/133791609
10212 final long identity = Binder.clearCallingIdentity();
10213 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010214 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10215 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10216 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10217 return carrierUAProfUrl;
10218 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010219 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10220 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010221 } finally {
10222 Binder.restoreCallingIdentity(identity);
10223 }
10224 }
10225
10226 @Override
10227 public String getMmsUserAgent(int subId) {
10228 //TODO investigate if this API should require proper permission check in R b/133791609
10229 final long identity = Binder.clearCallingIdentity();
10230 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010231 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10232 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10233 if (!TextUtils.isEmpty(carrierUserAgent)) {
10234 return carrierUserAgent;
10235 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010236 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10237 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010238 } finally {
10239 Binder.restoreCallingIdentity(identity);
10240 }
10241 }
Jack Yub07d4972019-05-28 16:12:25 -070010242
10243 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010244 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10245 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010246
Jack Yub07d4972019-05-28 16:12:25 -070010247 final long identity = Binder.clearCallingIdentity();
10248 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010249 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010250 if (phone == null) return false;
10251
Ling Maf188d502022-09-16 15:22:36 -070010252 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010253 } finally {
10254 Binder.restoreCallingIdentity(identity);
10255 }
10256 }
10257
10258 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010259 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010260 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010261 enforceModifyPermission();
10262
changbettyd5c246e2019-12-24 15:40:37 +080010263 final long identity = Binder.clearCallingIdentity();
10264 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010265 Phone phone = getPhone(subscriptionId);
10266 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010267
Ling Maf188d502022-09-16 15:22:36 -070010268 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010269 } finally {
10270 Binder.restoreCallingIdentity(identity);
10271 }
10272 }
10273
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010274 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010275 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010276 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10277 * otherwise.
10278 */
10279 @Override
10280 public void setCepEnabled(boolean isCepEnabled) {
10281 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10282
10283 final long identity = Binder.clearCallingIdentity();
10284 try {
10285 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10286 for (Phone phone : PhoneFactory.getPhones()) {
10287 Phone defaultPhone = phone.getImsPhone();
10288 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10289 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10290 ImsPhoneCallTracker imsPhoneCallTracker =
10291 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10292 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10293 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10294 + imsPhone.getMsisdn());
10295 }
10296 }
10297 } finally {
10298 Binder.restoreCallingIdentity(identity);
10299 }
10300 }
allenwtsu46dcc572020-01-08 18:24:03 +080010301
10302 /**
10303 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10304 *
10305 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10306 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10307 * before being read.
10308 */
10309 @Override
10310 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10311 isCompressed) {
10312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10313 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010314 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10315 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10316 }
10317 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010318 // ProvisioningManager can not handle ServiceSpecificException.
10319 // Throw the IllegalStateException and annotate ProvisioningManager.
10320 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010321 }
10322
10323 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010324 try {
Hui Wang761a6682020-10-31 05:12:53 +000010325 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10326 } finally {
10327 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010328 }
10329 }
zoey chene02881a2019-12-30 16:11:23 +080010330
10331 @Override
10332 public boolean isIccLockEnabled(int subId) {
10333 enforceReadPrivilegedPermission("isIccLockEnabled");
10334
10335 // Now that all security checks passes, perform the operation as ourselves.
10336 final long identity = Binder.clearCallingIdentity();
10337 try {
10338 Phone phone = getPhone(subId);
10339 if (phone != null && phone.getIccCard() != null) {
10340 return phone.getIccCard().getIccLockEnabled();
10341 } else {
10342 return false;
10343 }
10344 } finally {
10345 Binder.restoreCallingIdentity(identity);
10346 }
10347 }
10348
10349 /**
10350 * Set the ICC pin lock enabled or disabled.
10351 *
10352 * @return an integer representing the status of IccLock enabled or disabled in the following
10353 * three cases:
10354 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10355 * successfully.
10356 * - Positive number and zero for remaining password attempts.
10357 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10358 *
10359 */
10360 @Override
10361 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10362 enforceModifyPermission();
10363
10364 Phone phone = getPhone(subId);
10365 if (phone == null) {
10366 return 0;
10367 }
10368 // Now that all security checks passes, perform the operation as ourselves.
10369 final long identity = Binder.clearCallingIdentity();
10370 try {
10371 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10372 new Pair<Boolean, String>(enabled, password), phone, null);
10373 return attemptsRemaining;
10374
10375 } catch (Exception e) {
10376 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10377 } finally {
10378 Binder.restoreCallingIdentity(identity);
10379 }
10380 return 0;
10381 }
10382
10383 /**
10384 * Change the ICC password used in ICC pin lock.
10385 *
10386 * @return an integer representing the status of IccLock changed in the following three cases:
10387 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10388 * - Positive number and zero for remaining password attempts.
10389 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10390 *
10391 */
10392 @Override
10393 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10394 enforceModifyPermission();
10395
10396 Phone phone = getPhone(subId);
10397 if (phone == null) {
10398 return 0;
10399 }
10400 // Now that all security checks passes, perform the operation as ourselves.
10401 final long identity = Binder.clearCallingIdentity();
10402 try {
10403 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10404 new Pair<String, String>(oldPassword, newPassword), phone, null);
10405 return attemptsRemaining;
10406
10407 } catch (Exception e) {
10408 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10409 } finally {
10410 Binder.restoreCallingIdentity(identity);
10411 }
10412 return 0;
10413 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010414
10415 /**
10416 * Request for receiving user activity notification
10417 */
10418 @Override
10419 public void requestUserActivityNotification() {
10420 if (!mNotifyUserActivity.get()
10421 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10422 mNotifyUserActivity.set(true);
10423 }
10424 }
10425
10426 /**
10427 * Called when userActivity is signalled in the power manager.
10428 * This is safe to call from any thread, with any window manager locks held or not.
10429 */
10430 @Override
10431 public void userActivity() {
10432 // ***************************************
10433 // * Inherited from PhoneWindowManager *
10434 // ***************************************
10435 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10436 // WITH ITS LOCKS HELD.
10437 //
10438 // This code must be VERY careful about the locks
10439 // it acquires.
10440 // In fact, the current code acquires way too many,
10441 // and probably has lurking deadlocks.
10442
10443 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10444 throw new SecurityException("Only the OS may call notifyUserActivity()");
10445 }
10446
10447 if (mNotifyUserActivity.getAndSet(false)) {
10448 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10449 USER_ACTIVITY_NOTIFICATION_DELAY);
10450 }
10451 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010452
10453 @Override
10454 public boolean canConnectTo5GInDsdsMode() {
10455 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10456 }
Jack Yud10cdd42020-09-28 20:28:01 -070010457
10458 @Override
10459 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10460 String callingFeatureId) {
10461 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10462 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10463 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10464 }
10465
10466 Phone phone = getPhone(subId);
10467 if (phone == null) {
10468 throw new RuntimeException("phone is not available");
10469 }
10470 // Now that all security checks passes, perform the operation as ourselves.
10471 final long identity = Binder.clearCallingIdentity();
10472 try {
10473 return phone.getEquivalentHomePlmns();
10474 } finally {
10475 Binder.restoreCallingIdentity(identity);
10476 }
10477 }
Daniel Bright59e67312020-11-13 11:49:37 -080010478
10479 @Override
10480 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010481 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10482 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010483 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010484 if (radioInterfaceCapabilities == null) {
10485 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010486 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010487 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010488 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010489
Hui Wang641e81c2020-10-12 12:14:23 -070010490 @Override
10491 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10492 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010493 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10494 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10495 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10496 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10497 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010498 if (DBG) {
10499 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10500 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10501 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10502 }
10503
10504 if (!SubscriptionManager.isValidSubscriptionId(subId)
10505 || appType < TelephonyManager.APPTYPE_UNKNOWN
10506 || appType > TelephonyManager.APPTYPE_ISIM
10507 || nafUrl == null || securityProtocol == null || callback == null) {
10508 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10509 if (callback != null) {
10510 try {
10511 callback.onAuthenticationFailure(
10512 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10513 } catch (RemoteException exception) {
10514 log("Fail to notify onAuthenticationFailure due to " + exception);
10515 }
10516 return;
10517 }
10518 }
10519
10520 final long token = Binder.clearCallingIdentity();
10521 try {
10522 getGbaManager(subId).bootstrapAuthenticationRequest(
10523 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10524 forceBootStrapping, callback));
10525 } finally {
10526 Binder.restoreCallingIdentity(token);
10527 }
10528 }
10529
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010530 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010531 * Attempts to set the radio power state for all phones for thermal reason.
10532 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010533 * requested radio power state will actually be set. See {@link
10534 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10535 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010536 * @param enable {@code true} if trying to turn radio on.
10537 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10538 * false}.
10539 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010540 private boolean setRadioPowerForThermal(boolean enable) {
10541 boolean isPhoneAvailable = false;
10542 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10543 Phone phone = PhoneFactory.getPhone(i);
10544 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010545 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010546 isPhoneAvailable = true;
10547 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010548 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010549
10550 // return true if successfully informed the phone object about the thermal radio power
10551 // request.
10552 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010553 }
10554
10555 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010556 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010557 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10558 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10559 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10560 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10561 throw new IllegalArgumentException("modem does not support data throttling");
10562 }
10563
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010564 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10565 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010566 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010567 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10568 }
10569
Sarah Chinecc78c42022-03-31 21:16:48 -070010570 setDataEnabledForReason(
10571 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010572
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010573 if (isDataThrottlingSupported) {
10574 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010575 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010576 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10577 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10578 } else if (thermalMitigationResult
10579 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010580 log("Modem likely does not support data throttling on secondary carrier. Data " +
10581 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10582 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010583 }
10584 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010585 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010586
10587 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010588 }
10589
Jack Nudelman644b91a2021-03-12 14:09:48 -080010590 private static List<String> getThermalMitigationAllowlist(Context context) {
10591 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10592 for (String pckg : context.getResources()
10593 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10594 sThermalMitigationAllowlistedPackages.add(pckg);
10595 }
10596 }
10597
10598 return sThermalMitigationAllowlistedPackages;
10599 }
10600
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010601 private boolean isAnyPhoneInEmergencyState() {
10602 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10603 if (tm.isInEmergencyCall()) {
10604 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10605 return true;
10606 }
10607 for (Phone phone : PhoneFactory.getPhones()) {
10608 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10609 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10610 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10611 + phone.isInEcm());
10612 return true;
10613 }
10614 }
10615
10616 return false;
10617 }
10618
Jack Nudelman644b91a2021-03-12 14:09:48 -080010619 /**
10620 * Used by shell commands to add an authorized package name for thermal mitigation.
10621 * @param packageName name of package to be allowlisted
10622 * @param context
10623 */
10624 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10625 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10626 sThermalMitigationAllowlistedPackages.add(packageName);
10627 }
10628
10629 /**
10630 * Used by shell commands to remove an authorized package name for thermal mitigation.
10631 * @param packageName name of package to remove from allowlist
10632 * @param context
10633 */
10634 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10635 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10636 sThermalMitigationAllowlistedPackages.remove(packageName);
10637 }
10638
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010639 /**
10640 * Thermal mitigation request to control functionalities at modem.
10641 *
10642 * @param subId the id of the subscription.
10643 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010644 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010645 *
10646 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10647 */
10648 @Override
10649 @ThermalMitigationResult
10650 public int sendThermalMitigationRequest(
10651 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010652 ThermalMitigationRequest thermalMitigationRequest,
10653 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010654 enforceModifyPermission();
10655
Jack Nudelman644b91a2021-03-12 14:09:48 -080010656 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10657 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10658 .contains(callingPackage)) {
10659 throw new SecurityException("Calling package must be configured in the device config. "
10660 + "calling package: " + callingPackage);
10661 }
10662
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010663 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10664 final long identity = Binder.clearCallingIdentity();
10665
10666 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10667 try {
10668 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10669 switch (thermalMitigationAction) {
10670 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10671 thermalMitigationResult =
10672 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010673 thermalMitigationRequest.getDataThrottlingRequest(),
10674 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010675 break;
10676 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10677 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10678 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10679 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10680 }
10681
10682 // Ensure that radio is on. If not able to power on due to phone being
10683 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010684 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010685 thermalMitigationResult =
10686 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10687 break;
10688 }
10689
10690 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010691 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010692 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10693 break;
10694 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10695 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10696 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10697 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10698 }
10699
10700 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10701 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010702 Phone phone = getPhone(subId);
10703 if (phone == null) {
10704 thermalMitigationResult =
10705 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10706 break;
10707 }
10708
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010709 TelephonyConnectionService service =
10710 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010711 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010712 Log.e(LOG_TAG, "An emergency call is pending");
10713 thermalMitigationResult =
10714 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10715 break;
10716 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010717 thermalMitigationResult =
10718 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10719 break;
10720 }
10721 } else {
10722 thermalMitigationResult =
10723 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10724 break;
10725 }
10726
10727 // Turn radio off. If not able to power off due to phone being unavailable,
10728 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010729 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010730 thermalMitigationResult =
10731 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10732 break;
10733 }
10734 thermalMitigationResult =
10735 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10736 break;
10737 default:
10738 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10739 + "not exist. Requested action: " + thermalMitigationAction);
10740 }
10741 } catch (IllegalArgumentException e) {
10742 throw e;
10743 } catch (Exception e) {
10744 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10745 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10746 } finally {
10747 Binder.restoreCallingIdentity(identity);
10748 }
10749
10750 if (DBG) {
10751 log("thermalMitigationRequest returning with thermalMitigationResult: "
10752 + thermalMitigationResult);
10753 }
10754
10755 return thermalMitigationResult;
10756 }
Hui Wang641e81c2020-10-12 12:14:23 -070010757
10758 /**
10759 * Set the GbaService Package Name that Telephony will bind to.
10760 *
10761 * @param subId The sim that the GbaService is associated with.
10762 * @param packageName The name of the package to be replaced with.
10763 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10764 */
10765 @Override
10766 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10767 enforceModifyPermission();
10768
10769 final long identity = Binder.clearCallingIdentity();
10770 try {
10771 return getGbaManager(subId).overrideServicePackage(packageName);
10772 } finally {
10773 Binder.restoreCallingIdentity(identity);
10774 }
10775 }
10776
10777 /**
10778 * Return the package name of the currently bound GbaService.
10779 *
10780 * @param subId The sim that the GbaService is associated with.
10781 * @return the package name of the GbaService configuration, null if GBA is not supported.
10782 */
10783 @Override
10784 public String getBoundGbaService(int subId) {
10785 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10786
10787 final long identity = Binder.clearCallingIdentity();
10788 try {
10789 return getGbaManager(subId).getServicePackage();
10790 } finally {
10791 Binder.restoreCallingIdentity(identity);
10792 }
10793 }
10794
10795 /**
10796 * Set the release time for telephony to unbind GbaService.
10797 *
10798 * @param subId The sim that the GbaService is associated with.
10799 * @param interval The release time to unbind GbaService by millisecond.
10800 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10801 */
10802 @Override
10803 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10804 enforceModifyPermission();
10805
10806 final long identity = Binder.clearCallingIdentity();
10807 try {
10808 return getGbaManager(subId).overrideReleaseTime(interval);
10809 } finally {
10810 Binder.restoreCallingIdentity(identity);
10811 }
10812 }
10813
10814 /**
10815 * Return the release time for telephony to unbind GbaService.
10816 *
10817 * @param subId The sim that the GbaService is associated with.
10818 * @return The release time to unbind GbaService by millisecond.
10819 */
10820 @Override
10821 public int getGbaReleaseTime(int subId) {
10822 enforceReadPrivilegedPermission("getGbaReleaseTime");
10823
10824 final long identity = Binder.clearCallingIdentity();
10825 try {
10826 return getGbaManager(subId).getReleaseTime();
10827 } finally {
10828 Binder.restoreCallingIdentity(identity);
10829 }
10830 }
10831
10832 private GbaManager getGbaManager(int subId) {
10833 GbaManager instance = GbaManager.getInstance(subId);
10834 if (instance == null) {
10835 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10836 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10837 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10838 }
10839 return instance;
10840 }
Hui Wang761a6682020-10-31 05:12:53 +000010841
10842 /**
10843 * indicate whether the device and the carrier can support
10844 * RCS VoLTE single registration.
10845 */
10846 @Override
10847 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010848 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10849 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10850 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10851 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010852
10853 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10854 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10855 }
10856
10857 final long identity = Binder.clearCallingIdentity();
10858 try {
10859 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10860 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010861 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10862 if (isCapable != null) {
10863 return isCapable;
10864 }
Hui Wang761a6682020-10-31 05:12:53 +000010865 }
Hui Wang67af90e2021-06-04 16:57:15 -070010866 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10867 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010868 } finally {
10869 Binder.restoreCallingIdentity(identity);
10870 }
10871 }
10872
10873 /**
10874 * Register RCS provisioning callback.
10875 */
10876 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010877 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010878 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010879 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010880 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010881 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10882 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010883
10884 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10885 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10886 }
10887 if (!isImsAvailableOnDevice()) {
10888 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10889 "IMS not available on device.");
10890 }
10891
10892 final long identity = Binder.clearCallingIdentity();
10893 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010894 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010895 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010896 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10897 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010898 }
Hui Wang761a6682020-10-31 05:12:53 +000010899 } finally {
10900 Binder.restoreCallingIdentity(identity);
10901 }
10902 }
10903
10904 /**
10905 * Unregister RCS provisioning callback.
10906 */
10907 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010908 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010909 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010910 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010911 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010912 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10913 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010914
10915 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10916 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10917 }
10918 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010919 // operation failed silently
10920 Rlog.w(LOG_TAG, "IMS not available on device.");
10921 return;
Hui Wang761a6682020-10-31 05:12:53 +000010922 }
10923
10924 final long identity = Binder.clearCallingIdentity();
10925 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010926 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010927 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010928 } finally {
10929 Binder.restoreCallingIdentity(identity);
10930 }
10931 }
10932
10933 /**
10934 * trigger RCS reconfiguration.
10935 */
10936 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010937 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10938 "triggerRcsReconfiguration",
10939 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010940
10941 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10942 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10943 }
10944 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010945 // ProvisioningManager can not handle ServiceSpecificException.
10946 // Throw the IllegalStateException and annotate ProvisioningManager.
10947 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010948 }
10949
10950 final long identity = Binder.clearCallingIdentity();
10951 try {
10952 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10953 } finally {
10954 Binder.restoreCallingIdentity(identity);
10955 }
10956 }
10957
10958 /**
10959 * Provide the client configuration parameters of the RCS application.
10960 */
10961 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010962 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10963 "setRcsClientConfiguration",
10964 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010965
10966 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10967 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10968 }
10969 if (!isImsAvailableOnDevice()) {
10970 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10971 "IMS not available on device.");
10972 }
10973
10974 final long identity = Binder.clearCallingIdentity();
10975
10976 try {
10977 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10978 if (configBinder == null) {
10979 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010980 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10981 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010982 } else {
10983 configBinder.setRcsClientConfiguration(rcc);
10984 }
joonhunshin3e154242021-09-17 06:33:39 +000010985
10986 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10987 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010988 } catch (RemoteException e) {
10989 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010990 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10991 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010992 } finally {
10993 Binder.restoreCallingIdentity(identity);
10994 }
10995 }
10996
10997 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010998 * Enables or disables the test mode for RCS VoLTE single registration.
10999 */
11000 @Override
11001 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11002 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11003 "setRcsSingleRegistrationTestModeEnabled");
11004
11005 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11006 }
11007
11008 /**
11009 * Gets the test mode for RCS VoLTE single registration.
11010 */
11011 @Override
11012 public boolean getRcsSingleRegistrationTestModeEnabled() {
11013 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11014 "getRcsSingleRegistrationTestModeEnabled");
11015
11016 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11017 }
11018
11019 /**
Hui Wang761a6682020-10-31 05:12:53 +000011020 * Overrides the config of RCS VoLTE single registration enabled for the device.
11021 */
11022 @Override
11023 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11024 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11025 "setDeviceSingleRegistrationEnabledOverride");
11026 enforceModifyPermission();
11027
11028 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11029 : Boolean.parseBoolean(enabledStr);
11030 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011031 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011032 }
11033
11034 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011035 * Sends a device to device communication message. Only usable via shell.
11036 * @param message message to send.
11037 * @param value message value.
11038 */
11039 @Override
11040 public void sendDeviceToDeviceMessage(int message, int value) {
11041 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011042 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011043 enforceModifyPermission();
11044
11045 final long identity = Binder.clearCallingIdentity();
11046 try {
11047 TelephonyConnectionService service =
11048 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11049 if (service == null) {
11050 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11051 return;
11052 }
11053 service.sendTestDeviceToDeviceMessage(message, value);
11054 } finally {
11055 Binder.restoreCallingIdentity(identity);
11056 }
11057 }
11058
Tyler Gunnbabbda02021-02-10 11:05:02 -080011059 /**
11060 * Sets the specified device to device transport active.
11061 * @param transport The transport to set active.
11062 */
11063 @Override
11064 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11065 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11066 "setActiveDeviceToDeviceTransport");
11067 enforceModifyPermission();
11068
11069 final long identity = Binder.clearCallingIdentity();
11070 try {
11071 TelephonyConnectionService service =
11072 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11073 if (service == null) {
11074 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11075 return;
11076 }
11077 service.setActiveDeviceToDeviceTransport(transport);
11078 } finally {
11079 Binder.restoreCallingIdentity(identity);
11080 }
11081 }
Tyler Gunn92479152021-01-20 16:30:10 -080011082
Tyler Gunnd4339262021-05-03 14:46:49 -070011083 @Override
11084 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11085 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11086 "setDeviceToDeviceForceEnabled");
11087
11088 final long identity = Binder.clearCallingIdentity();
11089 try {
11090 Arrays.stream(PhoneFactory.getPhones()).forEach(
11091 p -> {
11092 Phone thePhone = p.getImsPhone();
11093 if (thePhone != null && thePhone instanceof ImsPhone) {
11094 ImsPhone imsPhone = (ImsPhone) thePhone;
11095 CallTracker tracker = imsPhone.getCallTracker();
11096 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11097 ImsPhoneCallTracker imsPhoneCallTracker =
11098 (ImsPhoneCallTracker) tracker;
11099 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11100 }
11101 }
11102 }
11103 );
11104 } finally {
11105 Binder.restoreCallingIdentity(identity);
11106 }
11107 }
11108
Tyler Gunn92479152021-01-20 16:30:10 -080011109 /**
Hui Wang761a6682020-10-31 05:12:53 +000011110 * Gets the config of RCS VoLTE single registration enabled for the device.
11111 */
11112 @Override
11113 public boolean getDeviceSingleRegistrationEnabled() {
11114 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11115 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11116 }
11117
11118 /**
11119 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11120 */
11121 @Override
11122 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11123 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11124 "setCarrierSingleRegistrationEnabledOverride");
11125 enforceModifyPermission();
11126
11127 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11128 : Boolean.parseBoolean(enabledStr);
11129 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11130 subId, enabled);
11131 }
11132
11133 /**
11134 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11135 */
11136 @Override
11137 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11138 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11139 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11140 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011141
11142 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011143 * Overrides the ims feature validation result
11144 */
11145 @Override
11146 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11147 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11148 "setImsFeatureValidationOverride");
11149
11150 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11151 : Boolean.parseBoolean(enabledStr);
11152 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11153 subId, enabled);
11154 }
11155
11156 /**
11157 * Gets the ims feature validation override value
11158 */
11159 @Override
11160 public boolean getImsFeatureValidationOverride(int subId) {
11161 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11162 "getImsFeatureValidationOverride");
11163 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11164 }
11165
11166 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011167 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11168 * their mobile plan.
11169 */
11170 @Override
11171 public String getMobileProvisioningUrl() {
11172 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11173 final long identity = Binder.clearCallingIdentity();
11174 try {
11175 return getDefaultPhone().getMobileProvisioningUrl();
11176 } finally {
11177 Binder.restoreCallingIdentity(identity);
11178 }
11179 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011180
James.cf Linbcdf8b32021-01-14 16:44:13 +080011181 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011182 * Get the EAB contact from the EAB database.
11183 */
11184 @Override
11185 public String getContactFromEab(String contact) {
11186 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11187 enforceModifyPermission();
11188 final long identity = Binder.clearCallingIdentity();
11189 try {
11190 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11191 } finally {
11192 Binder.restoreCallingIdentity(identity);
11193 }
11194 }
11195
11196 /**
Calvin Pana1434322021-07-01 19:27:01 +080011197 * Get the EAB capability from the EAB database.
11198 */
11199 @Override
11200 public String getCapabilityFromEab(String contact) {
11201 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11202 enforceModifyPermission();
11203 final long identity = Binder.clearCallingIdentity();
11204 try {
11205 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11206 } finally {
11207 Binder.restoreCallingIdentity(identity);
11208 }
11209 }
11210
11211 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011212 * Remove the EAB contacts from the EAB database.
11213 */
11214 @Override
11215 public int removeContactFromEab(int subId, String contacts) {
11216 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11217 enforceModifyPermission();
11218 final long identity = Binder.clearCallingIdentity();
11219 try {
11220 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11221 } finally {
11222 Binder.restoreCallingIdentity(identity);
11223 }
11224 }
11225
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011226 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011227 public boolean getDeviceUceEnabled() {
11228 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11229 final long identity = Binder.clearCallingIdentity();
11230 try {
11231 return mApp.getDeviceUceEnabled();
11232 } finally {
11233 Binder.restoreCallingIdentity(identity);
11234 }
11235 }
11236
11237 @Override
11238 public void setDeviceUceEnabled(boolean isEnabled) {
11239 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11240 final long identity = Binder.clearCallingIdentity();
11241 try {
11242 mApp.setDeviceUceEnabled(isEnabled);
11243 } finally {
11244 Binder.restoreCallingIdentity(identity);
11245 }
11246 }
11247
Brad Ebinger14d467f2021-02-12 06:18:28 +000011248 /**
11249 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11250 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11251 */
11252 // Used for SHELL command only right now.
11253 @Override
11254 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11255 List<String> featureTags) {
11256 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11257 "addUceRegistrationOverrideShell");
11258 final long identity = Binder.clearCallingIdentity();
11259 try {
11260 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11261 new ArraySet<>(featureTags));
11262 } catch (ImsException e) {
11263 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11264 } finally {
11265 Binder.restoreCallingIdentity(identity);
11266 }
11267 }
11268
11269 /**
11270 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11271 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11272 */
11273 // Used for SHELL command only right now.
11274 @Override
11275 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11276 List<String> featureTags) {
11277 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11278 "removeUceRegistrationOverrideShell");
11279 final long identity = Binder.clearCallingIdentity();
11280 try {
11281 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11282 new ArraySet<>(featureTags));
11283 } catch (ImsException e) {
11284 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11285 } finally {
11286 Binder.restoreCallingIdentity(identity);
11287 }
11288 }
11289
11290 /**
11291 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11292 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11293 */
11294 // Used for SHELL command only right now.
11295 @Override
11296 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11297 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11298 "clearUceRegistrationOverrideShell");
11299 final long identity = Binder.clearCallingIdentity();
11300 try {
11301 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11302 } catch (ImsException e) {
11303 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11304 } finally {
11305 Binder.restoreCallingIdentity(identity);
11306 }
11307 }
11308
11309 /**
11310 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11311 */
11312 // Used for SHELL command only right now.
11313 @Override
11314 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11315 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11316 "getLatestRcsContactUceCapabilityShell");
11317 final long identity = Binder.clearCallingIdentity();
11318 try {
11319 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11320 } catch (ImsException e) {
11321 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11322 } finally {
11323 Binder.restoreCallingIdentity(identity);
11324 }
11325 }
11326
11327 /**
11328 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11329 * device does not have an active PUBLISH.
11330 */
11331 // Used for SHELL command only right now.
11332 @Override
11333 public String getLastUcePidfXmlShell(int subId) {
11334 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11335 final long identity = Binder.clearCallingIdentity();
11336 try {
11337 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11338 } catch (ImsException e) {
11339 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11340 } finally {
11341 Binder.restoreCallingIdentity(identity);
11342 }
11343 }
11344
James.cf Line8713a42021-04-29 16:04:26 +080011345 /**
11346 * Remove UCE requests cannot be sent to the network status.
11347 */
11348 // Used for SHELL command only right now.
11349 @Override
11350 public boolean removeUceRequestDisallowedStatus(int subId) {
11351 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11352 final long identity = Binder.clearCallingIdentity();
11353 try {
11354 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11355 } catch (ImsException e) {
11356 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11357 } finally {
11358 Binder.restoreCallingIdentity(identity);
11359 }
11360 }
11361
James.cf Lin18bb9002021-05-25 01:37:38 +080011362 /**
11363 * Remove UCE requests cannot be sent to the network status.
11364 */
11365 // Used for SHELL command only.
11366 @Override
11367 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11368 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11369 final long identity = Binder.clearCallingIdentity();
11370 try {
11371 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11372 } catch (ImsException e) {
11373 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11374 } finally {
11375 Binder.restoreCallingIdentity(identity);
11376 }
11377 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011378
James.cf Lin4b784aa2021-01-31 03:25:15 +080011379 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011380 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11381 String callingPackage) {
11382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11383 mApp, subId, "setSignalStrengthUpdateRequest");
11384
11385 final int callingUid = Binder.getCallingUid();
11386 // Verify that tha callingPackage belongs to the calling UID
11387 mApp.getSystemService(AppOpsManager.class)
11388 .checkPackage(callingUid, callingPackage);
11389
Rambo Wang3607f502021-02-01 21:51:40 -080011390 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011391
11392 final long identity = Binder.clearCallingIdentity();
11393 try {
11394 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11395 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11396
11397 if (result instanceof IllegalStateException) {
11398 throw (IllegalStateException) result;
11399 }
11400 } finally {
11401 Binder.restoreCallingIdentity(identity);
11402 }
11403 }
11404
11405 @Override
11406 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11407 String callingPackage) {
11408 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11409 mApp, subId, "clearSignalStrengthUpdateRequest");
11410
11411 final int callingUid = Binder.getCallingUid();
11412 // Verify that tha callingPackage belongs to the calling UID
11413 mApp.getSystemService(AppOpsManager.class)
11414 .checkPackage(callingUid, callingPackage);
11415
11416 final long identity = Binder.clearCallingIdentity();
11417 try {
11418 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11419 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11420
11421 if (result instanceof IllegalStateException) {
11422 throw (IllegalStateException) result;
11423 }
11424 } finally {
11425 Binder.restoreCallingIdentity(identity);
11426 }
11427 }
11428
Rambo Wang3607f502021-02-01 21:51:40 -080011429 private static void validateSignalStrengthUpdateRequest(Context context,
11430 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011431 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11432 // phone/system process do not have further restriction on request
11433 return;
11434 }
11435
11436 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011437 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011438 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011439 context.enforceCallingOrSelfPermission(
11440 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11441 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011442 }
11443
11444 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011445 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011446 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011447 || info.isEnabled()) {
11448 throw new IllegalArgumentException(
11449 "Only system can set hide fields in SignalThresholdInfo");
11450 }
11451
11452 // Thresholds length for each RAN need in range. This has been validated in
11453 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11454 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11455 final int[] thresholds = info.getThresholds();
11456 Objects.requireNonNull(thresholds);
11457 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11458 || thresholds.length
11459 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11460 throw new IllegalArgumentException(
11461 "thresholds length is out of range: " + thresholds.length);
11462 }
11463 }
11464 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011465
11466 /**
11467 * Gets the current phone capability.
11468 *
11469 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11470 * @return the PhoneCapability which describes the data connection capability of modem.
11471 * It's used to evaluate possible phone config change, for example from single
11472 * SIM device to multi-SIM device.
11473 */
11474 @Override
11475 public PhoneCapability getPhoneCapability() {
11476 enforceReadPrivilegedPermission("getPhoneCapability");
11477 final long identity = Binder.clearCallingIdentity();
11478 try {
11479 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11480 } finally {
11481 Binder.restoreCallingIdentity(identity);
11482 }
11483 }
Michele Berionne5e411512020-11-13 02:36:59 +000011484
11485 /**
11486 * Prepare TelephonyManager for an unattended reboot. The reboot is
11487 * required to be done shortly after the API is invoked.
11488 */
11489 @Override
11490 @TelephonyManager.PrepareUnattendedRebootResult
11491 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011492 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011493 enforceRebootPermission();
11494
11495 final long identity = Binder.clearCallingIdentity();
11496 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011497 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011498 } finally {
11499 Binder.restoreCallingIdentity(identity);
11500 }
11501 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011502
11503 /**
11504 * Request to get the current slicing configuration including URSP rules and
11505 * NSSAIs (configured, allowed and rejected).
11506 *
11507 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11508 */
11509 @Override
11510 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011511 TelephonyPermissions
11512 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11513 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011514
11515 final long identity = Binder.clearCallingIdentity();
11516 try {
11517 Phone phone = getDefaultPhone();
11518 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11519 } finally {
11520 Binder.restoreCallingIdentity(identity);
11521 }
11522 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011523
11524 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011525 * Check whether the given premium capability is available for purchase from the carrier.
11526 *
11527 * @param capability The premium capability to check.
11528 * @param subId The subId to check the premium capability for.
11529 *
11530 * @return Whether the given premium capability is available to purchase.
11531 */
11532 @Override
11533 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11534 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11535 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11536 log("Premium capability "
11537 + TelephonyManager.convertPremiumCapabilityToString(capability)
11538 + " is not available for purchase due to missing permissions.");
11539 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11540 + "permission READ_BASIC_PHONE_STATE.");
11541 }
11542
11543 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011544 if (phone == null) {
11545 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11546 return false;
11547 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011548 final long identity = Binder.clearCallingIdentity();
11549 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011550 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011551 .isPremiumCapabilityAvailableForPurchase(capability);
11552 } finally {
11553 Binder.restoreCallingIdentity(identity);
11554 }
11555 }
11556
11557 /**
11558 * Purchase the given premium capability from the carrier.
11559 *
11560 * @param capability The premium capability to purchase.
11561 * @param callback The result of the purchase request.
11562 * @param subId The subId to purchase the premium capability for.
11563 */
11564 @Override
11565 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11566 log("purchasePremiumCapability: capability="
11567 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11568 + getCurrentPackageName());
11569
11570 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11571 mApp, "purchasePremiumCapability")) {
11572 log("purchasePremiumCapability "
11573 + TelephonyManager.convertPremiumCapabilityToString(capability)
11574 + " failed due to missing permissions.");
11575 throw new SecurityException("purchasePremiumCapability requires permission "
11576 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011577 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11578 mApp, "purchasePremiumCapability")) {
11579 log("purchasePremiumCapability "
11580 + TelephonyManager.convertPremiumCapabilityToString(capability)
11581 + " failed due to missing permissions.");
11582 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011583 }
11584
11585 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011586 if (phone == null) {
11587 try {
11588 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11589 callback.accept(result);
11590 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11591 } catch (RemoteException e) {
11592 String logStr = "Purchase premium capability "
11593 + TelephonyManager.convertPremiumCapabilityToString(capability)
11594 + " failed due to RemoteException handling null phone: " + e;
11595 if (DBG) log(logStr);
11596 AnomalyReporter.reportAnomaly(
11597 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11598 }
11599 return;
11600 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011601
11602 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011603 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011604 callingProcess = mApp.getPackageManager().getApplicationInfo(
11605 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011606 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011607 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011608 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011609
11610 boolean isVisible = false;
11611 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11612 if (am != null) {
11613 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11614 if (processes != null) {
11615 for (ActivityManager.RunningAppProcessInfo process : processes) {
11616 log("purchasePremiumCapability: process " + process.processName
11617 + "has importance " + process.importance);
11618 if (process.processName.equals(callingProcess) && process.importance
11619 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11620 isVisible = true;
11621 break;
11622 }
11623 }
11624 }
11625 }
11626
11627 if (!isVisible) {
11628 try {
11629 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11630 callback.accept(result);
11631 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11632 } catch (RemoteException e) {
11633 String logStr = "Purchase premium capability "
11634 + TelephonyManager.convertPremiumCapabilityToString(capability)
11635 + " failed due to RemoteException handling background application: " + e;
11636 if (DBG) log(logStr);
11637 AnomalyReporter.reportAnomaly(
11638 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11639 }
11640 return;
11641 }
11642
Sarah Chin71b3a852022-09-28 15:54:19 -070011643 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011644 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011645 }
11646
11647 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011648 * Register an IMS connection state callback
11649 */
11650 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011651 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11652 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011653 if (feature == ImsFeature.FEATURE_MMTEL) {
11654 // ImsMmTelManager
11655 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11656 TelephonyPermissions
11657 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11658 mApp, subId, "registerImsStateCallback");
11659 } else if (feature == ImsFeature.FEATURE_RCS) {
11660 // ImsRcsManager or SipDelegateManager
11661 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11662 Binder.getCallingUid(), "registerImsStateCallback",
11663 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11664 Manifest.permission.READ_PRECISE_PHONE_STATE,
11665 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11666 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11667 }
11668
11669 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11670 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11671 "IMS not available on device.");
11672 }
11673
11674 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11675 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11676 }
11677
11678 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11679 if (controller == null) {
11680 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11681 "IMS not available on device.");
11682 }
11683
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011684 if (callingPackage == null) {
11685 callingPackage = getCurrentPackageName();
11686 }
11687
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011688 final long token = Binder.clearCallingIdentity();
11689 try {
11690 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011691 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011692 } catch (ImsException e) {
11693 throw new ServiceSpecificException(e.getCode());
11694 } finally {
11695 Binder.restoreCallingIdentity(token);
11696 }
11697 }
11698
11699 /**
11700 * Unregister an IMS connection state callback
11701 */
11702 @Override
11703 public void unregisterImsStateCallback(IImsStateCallback cb) {
11704 final long token = Binder.clearCallingIdentity();
11705 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11706 if (controller == null) {
11707 return;
11708 }
11709 try {
11710 controller.unregisterImsStateCallback(cb);
11711 } finally {
11712 Binder.restoreCallingIdentity(token);
11713 }
11714 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011715
11716 /**
11717 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11718 *
11719 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11720 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11721 * SecurityException.
11722 * If there is current registered network this value will be same as the registered cell
11723 * identity. If the device goes out of service the previous cell identity is cached and
11724 * will be returned. If the cache age of the Cell identity is more than 24 hours
11725 * it will be cleared and null will be returned.
11726 *
11727 */
11728 @Override
11729 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11730 String callingFeatureId) {
11731 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11732 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11733 LocationAccessPolicy.checkLocationPermission(mApp,
11734 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11735 .setCallingPackage(callingPackage)
11736 .setCallingFeatureId(callingFeatureId)
11737 .setCallingPid(Binder.getCallingPid())
11738 .setCallingUid(Binder.getCallingUid())
11739 .setMethod("getLastKnownCellIdentity")
11740 .setLogAsInfo(true)
11741 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11742 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11743 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11744 .build());
11745
11746 boolean hasFinePermission =
11747 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11748 if (!hasFinePermission
11749 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11750 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011751 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011752 }
11753
11754 final long identity = Binder.clearCallingIdentity();
11755 try {
11756 Phone phone = getPhone(subId);
11757 if (phone == null) return null;
11758 ServiceStateTracker sst = phone.getServiceStateTracker();
11759 if (sst == null) return null;
11760 return sst.getLastKnownCellIdentity();
11761 } finally {
11762 Binder.restoreCallingIdentity(identity);
11763 }
11764 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011765
jimsun3b9ccac2021-10-26 15:01:23 +080011766 /**
11767 * Sets the modem service class Name that Telephony will bind to.
11768 *
11769 * @param serviceName The class name of the modem service.
11770 * @return true if the operation is succeed, otherwise false.
11771 */
11772 public boolean setModemService(String serviceName) {
11773 Log.d(LOG_TAG, "setModemService - " + serviceName);
11774 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11776 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11777 "setModemService");
11778 return mPhoneConfigurationManager.setModemService(serviceName);
11779 }
11780
11781 /**
11782 * Return the class name of the currently bounded modem service.
11783 *
11784 * @return the class name of the modem service.
11785 */
11786 public String getModemService() {
11787 String result;
11788 Log.d(LOG_TAG, "getModemService");
11789 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11790 TelephonyPermissions
11791 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11792 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11793 "getModemService");
11794 result = mPhoneConfigurationManager.getModemService();
11795 Log.d(LOG_TAG, "result = " + result);
11796 return result;
11797 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011798
11799 @Override
11800 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11801 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11802 mApp.enforceCallingOrSelfPermission(
11803 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11804 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11805
11806 final long identity = Binder.clearCallingIdentity();
11807 try {
11808 Phone phone = getPhone(subId);
11809 if (phone == null) return;
11810 phone.setVoiceServiceStateOverride(hasService);
11811 } finally {
11812 Binder.restoreCallingIdentity(identity);
11813 }
11814 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011815
11816 /**
11817 * set removable eSIM as default eUICC.
11818 *
11819 * @hide
11820 */
11821 @Override
11822 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11823 enforceModifyPermission();
11824 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11825
11826 final long identity = Binder.clearCallingIdentity();
11827 try {
11828 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11829 } finally {
11830 Binder.restoreCallingIdentity(identity);
11831 }
11832 }
11833
11834 /**
11835 * Returns whether the removable eSIM is default eUICC or not.
11836 *
11837 * @hide
11838 */
11839 @Override
11840 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11841 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11842 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11843
11844 final long identity = Binder.clearCallingIdentity();
11845 try {
11846 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11847 } finally {
11848 Binder.restoreCallingIdentity(identity);
11849 }
11850 }
11851
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011852 /**
11853 * Get the component name of the default app to direct respond-via-message intent for the
11854 * user associated with this subscription, update the cache if there is no respond-via-message
11855 * application currently configured for this user.
11856 * @return component name of the app and class to direct Respond Via Message intent to, or
11857 * {@code null} if the functionality is not supported.
11858 * @hide
11859 */
11860 @Override
11861 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11862 boolean updateIfNeeded) {
11863 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011864
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000011865 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
11866
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011867 UserHandle userHandle = null;
11868 final long identity = Binder.clearCallingIdentity();
11869 try {
11870 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11871 } finally {
11872 Binder.restoreCallingIdentity(identity);
11873 }
11874 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11875 updateIfNeeded, userHandle);
11876 }
Jack Yuf5badd92022-12-08 00:50:53 -080011877
11878 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011879 * Set whether the device is able to connect with null ciphering or integrity
11880 * algorithms. This is a global setting and will apply to all active subscriptions
11881 * and all new subscriptions after this.
11882 *
11883 * @param enabled when true, null cipher and integrity algorithms are allowed.
11884 * @hide
11885 */
11886 @Override
11887 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11888 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11889 enforceModifyPermission();
11890 checkForNullCipherAndIntegritySupport();
11891
11892 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11893 // for listening to these preference changes and applying them immediately.
11894 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11895 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11896 editor.apply();
11897
11898 for (Phone phone: PhoneFactory.getPhones()) {
11899 phone.handleNullCipherEnabledChange();
11900 }
11901 }
11902
11903
11904 /**
11905 * Get whether the device is able to connect with null ciphering or integrity
11906 * algorithms. Note that this retrieves the phone-global preference and not
11907 * the state of the radio.
11908 *
11909 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11910 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11911 * version for this feature.
11912 * @hide
11913 */
11914 @Override
11915 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11916 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11917 enforceReadPermission();
11918 checkForNullCipherAndIntegritySupport();
11919 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11920 }
11921
11922 private void checkForNullCipherAndIntegritySupport() {
11923 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11924 throw new UnsupportedOperationException(
11925 "Null cipher and integrity operations require HAL 2.1 or above");
11926 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000011927 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
11928 throw new UnsupportedOperationException(
11929 "Null cipher and integrity operations unsupported by modem");
11930 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011931 }
11932
11933 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011934 * Get the SIM state for the slot index.
11935 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11936 *
11937 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11938 */
11939 @Override
11940 @SimState
11941 public int getSimStateForSlotIndex(int slotIndex) {
11942 IccCardConstants.State simState;
11943 if (slotIndex < 0) {
11944 simState = IccCardConstants.State.UNKNOWN;
11945 } else {
11946 Phone phone = null;
11947 try {
11948 phone = PhoneFactory.getPhone(slotIndex);
11949 } catch (IllegalStateException e) {
11950 // ignore
11951 }
11952 if (phone == null) {
11953 simState = IccCardConstants.State.UNKNOWN;
11954 } else {
11955 IccCard icc = phone.getIccCard();
11956 if (icc == null) {
11957 simState = IccCardConstants.State.UNKNOWN;
11958 } else {
11959 simState = icc.getState();
11960 }
11961 }
11962 }
11963 return simState.ordinal();
11964 }
Hui Wang9b5793a2022-12-05 14:38:06 -060011965
11966 /**
11967 * Get current cell broadcast ranges.
11968 */
11969 @Override
11970 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
11971 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
11972 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
11973 "getCellBroadcastIdRanges");
11974 final long identity = Binder.clearCallingIdentity();
11975 try {
11976 return getPhone(subId).getCellBroadcastIdRanges();
11977 } finally {
11978 Binder.restoreCallingIdentity(identity);
11979 }
11980 }
11981
11982 /**
11983 * Set reception of cell broadcast messages with the list of the given ranges
11984 *
11985 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
11986 */
11987 @Override
11988 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
11989 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
11990 @Nullable IIntegerConsumer callback) {
11991 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
11992 "setCellBroadcastIdRanges");
11993 final long identity = Binder.clearCallingIdentity();
11994 try {
11995 Phone phone = getPhoneFromSubId(subId);
11996 if (DBG) {
11997 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
11998 }
11999 phone.setCellBroadcastIdRanges(ranges, result -> {
12000 if (callback != null) {
12001 try {
12002 callback.accept(result);
12003 } catch (RemoteException e) {
12004 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12005 }
12006 }
12007 });
12008 } finally {
12009 Binder.restoreCallingIdentity(identity);
12010 }
12011 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012012
12013 /**
12014 * Returns whether the device supports the domain selection service.
12015 *
12016 * @return {@code true} if the device supports the domain selection service.
12017 */
12018 @Override
12019 public boolean isDomainSelectionSupported() {
12020 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12021 "isDomainSelectionSupported");
12022
12023 final long identity = Binder.clearCallingIdentity();
12024 try {
12025 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12026 } finally {
12027 Binder.restoreCallingIdentity(identity);
12028 }
12029 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012030
12031 /**
12032 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12033 *
12034 * <p>This method behaves in one of the following ways:
12035 * <ul>
12036 * <li>return true : if the calling package has the appop permission {@link
12037 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12038 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12039 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12040 * Owner device identifier access check, or the calling package has carrier privileges</>
12041 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12042 * </ul>
12043 */
12044 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12045 String callingPackage, @Nullable String callingFeatureId, String message) {
12046 for (Phone phone : PhoneFactory.getPhones()) {
12047 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12048 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12049 return true;
12050 }
12051 }
12052 return false;
12053 }
arunvoddud7401012022-12-15 16:08:12 +000012054
12055 /**
12056 * Class binds the consumer[callback] and carrierId.
12057 */
12058 private static class CallerCallbackInfo {
12059 private final Consumer<Integer> mConsumer;
12060 private final int mCarrierId;
12061
12062 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12063 mConsumer = consumer;
12064 mCarrierId = carrierId;
12065 }
12066
12067 public Consumer<Integer> getConsumer() {
12068 return mConsumer;
12069 }
12070
12071 public int getCarrierId() {
12072 return mCarrierId;
12073 }
12074 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012075}