blob: 8b8267542d15dc1ed48dd2e59c74dbfdebc55b20 [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 Yu95e933d2023-01-14 12:42:30 -08006821 + TelephonyManager.allowedNetworkTypesReasonToString(reason));
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006822 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006823 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu95e933d2023-01-14 12:42:30 -08006824 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: "
6825 + TelephonyManager.allowedNetworkTypesReasonToString(reason));
SongFerngWang7ffc2732021-04-15 19:46:33 +08006826 return false;
6827 }
6828 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6829 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006830 return false;
6831 }
6832
Jack Yu95e933d2023-01-14 12:42:30 -08006833 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason="
6834 + TelephonyManager.allowedNetworkTypesReasonToString(reason) + ", network types: "
6835 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)
6836 + ", callingPackage=" + getCurrentPackageName());
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006837
Jack Yue37dd262022-12-16 11:53:37 -08006838 Phone phone = getPhone(subId);
6839 if (phone == null) {
6840 return false;
6841 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006842
Jack Yue37dd262022-12-16 11:53:37 -08006843 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu95e933d2023-01-14 12:42:30 -08006844 log("setAllowedNetworkTypesForReason: "
6845 + TelephonyManager.allowedNetworkTypesReasonToString(reason)
6846 + " already has the specified network types.");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006847 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006848 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006849
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006850 final long identity = Binder.clearCallingIdentity();
6851 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006852 Boolean success = (Boolean) sendRequest(
6853 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6854 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6855
6856 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6857 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006858 } finally {
6859 Binder.restoreCallingIdentity(identity);
6860 }
6861 }
6862
6863 /**
Miaoa84611c2019-03-15 09:21:10 +08006864 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006865 *
Miaoa84611c2019-03-15 09:21:10 +08006866 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006867 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006868 * @hide
6869 */
6870 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006871 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006872 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006873 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006874 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006875 try {
Miaoa84611c2019-03-15 09:21:10 +08006876 if (phone != null) {
6877 return phone.hasMatchedTetherApnSetting();
6878 } else {
6879 return false;
6880 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006881 } finally {
6882 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006883 }
Junda Liu475951f2014-11-07 16:45:03 -08006884 }
6885
6886 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006887 * Get the user enabled state of Mobile Data.
6888 *
6889 * TODO: remove and use isUserDataEnabled.
6890 * This can't be removed now because some vendor codes
6891 * calls through ITelephony directly while they should
6892 * use TelephonyManager.
6893 *
6894 * @return true on enabled
6895 */
6896 @Override
6897 public boolean getDataEnabled(int subId) {
6898 return isUserDataEnabled(subId);
6899 }
6900
6901 /**
6902 * Get whether mobile data is enabled per user setting.
6903 *
6904 * There are other factors deciding whether mobile data is actually enabled, but they are
6905 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006906 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006907 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6908 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006909 *
6910 * @return {@code true} if data is enabled else {@code false}
6911 */
6912 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006913 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006914 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006915 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006916 try {
6917 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6918 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006919 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006920 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6921 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006922 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006923 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006924 mApp, subId, functionName);
6925
Robert Greenwalt646120a2014-05-23 11:54:03 -07006926 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006927
6928 final long identity = Binder.clearCallingIdentity();
6929 try {
Jack Yu285100e2022-12-02 22:48:35 -08006930 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006931 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6932 Phone phone = PhoneFactory.getPhone(phoneId);
6933 if (phone != null) {
6934 boolean retVal = phone.isUserDataEnabled();
6935 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6936 return retVal;
6937 } else {
6938 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6939 return false;
6940 }
6941 } finally {
6942 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006943 }
6944 }
6945
6946 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006947 * Checks if the device is capable of mobile data by considering whether whether the
6948 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6949 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006950 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006951 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006952 */
6953 @Override
6954 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006955 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006956 try {
6957 try {
6958 mApp.enforceCallingOrSelfPermission(
6959 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006960 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006961 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006962 try {
6963 mApp.enforceCallingOrSelfPermission(
6964 android.Manifest.permission.READ_PHONE_STATE,
6965 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006966 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006967 mApp.enforceCallingOrSelfPermission(
6968 permission.READ_BASIC_PHONE_STATE, functionName);
6969 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006970 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006971 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006972 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006973 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006974
6975 final long identity = Binder.clearCallingIdentity();
6976 try {
Jack Yu285100e2022-12-02 22:48:35 -08006977 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006978 Phone phone = PhoneFactory.getPhone(phoneId);
6979 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006980 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006981 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006982 return retVal;
6983 } else {
6984 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6985 return false;
6986 }
6987 } finally {
6988 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006989 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006990 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006991
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006992 /**
6993 * Check if data is enabled for a specific reason
6994 * @param subId Subscription index
6995 * @param reason the reason the data enable change is taking place
6996 * @return {@code true} if the overall data is enabled; {@code false} if not.
6997 */
6998 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006999 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007000 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007001 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007002 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007003 try {
7004 mApp.enforceCallingOrSelfPermission(
7005 android.Manifest.permission.ACCESS_NETWORK_STATE,
7006 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007007 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007008 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7009 functionName);
7010 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007011 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007012 try {
7013 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007014 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007015 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007016 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007017 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007018 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007019 }
7020
7021
7022 final long identity = Binder.clearCallingIdentity();
7023 try {
Jack Yu285100e2022-12-02 22:48:35 -08007024 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007025 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007026 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007027 + " reason=" + reason);
7028 }
7029 Phone phone = PhoneFactory.getPhone(phoneId);
7030 if (phone != null) {
7031 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007032 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007033 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007034 return retVal;
7035 } else {
7036 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007037 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007038 + subId + " retVal=false");
7039 }
7040 return false;
7041 }
7042 } finally {
7043 Binder.restoreCallingIdentity(identity);
7044 }
7045 }
7046
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007047 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007048 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007049 // No permission needed; this only lets the caller inspect their own status.
7050 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007051 }
Junda Liu29340342014-07-10 15:23:27 -07007052
7053 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007054 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007055 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007056 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7057 }
7058
7059 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7060 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007061 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007062 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007063 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7064 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007065 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7066 if (cpt == null) {
7067 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007068 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7069 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007070 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007071 }
7072
7073 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007074 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007075 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007076 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007077 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007078 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007079 Phone phone = getPhone(subId);
7080 if (phone == null) {
7081 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7082 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7083 }
7084 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7085 if (cpt == null) {
7086 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007087 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7088 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007089 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007090 }
7091
7092 @Override
7093 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007094 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007095 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7096 }
7097
7098 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007099 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007100 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007101 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007102 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007103 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7104 Phone phone = PhoneFactory.getPhone(phoneId);
7105 if (phone == null) {
7106 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007107 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007108 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7109 if (cpt == null) {
7110 continue;
7111 }
7112 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007113 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7114 break;
7115 }
7116 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007117 return result;
Junda Liu29340342014-07-10 15:23:27 -07007118 }
Derek Tan89e89d42014-07-08 17:00:10 -07007119
7120 @Override
Junda Liue64de782015-04-16 17:19:16 -07007121 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007122 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007123 Phone phone = PhoneFactory.getPhone(phoneId);
7124 if (phone == null) {
7125 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007126 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007127 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7128 if (cpt == null) {
7129 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007130 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007131 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007132 }
7133
Amith Yamasani6e118872016-02-19 12:53:51 -08007134 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007135 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007136 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007137 Phone phone = PhoneFactory.getPhone(phoneId);
7138 if (phone == null) {
7139 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007140 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007141 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7142 if (cpt == null) {
7143 return Collections.emptyList();
7144 }
7145 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007146 }
7147
chen xuf7e9fe82019-05-09 19:31:02 -07007148 @Override
7149 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007150 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007151 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007152 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007153 try {
7154 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7155 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7156 }
7157 } finally {
7158 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007159 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007160 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007161 }
7162
Rambo Wang6812ffb2022-03-15 16:54:17 -07007163 @Override
7164 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7165 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7166
7167 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7168 if (phone == null) {
7169 return null;
7170 }
7171 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7172 if (cpt == null) {
7173 return null;
7174 }
7175 return cpt.getCarrierServicePackageName();
7176 }
7177
Wink Savilleb564aae2014-10-23 10:18:09 -07007178 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007179 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007180 UiccPort port = phone == null ? null : phone.getUiccPort();
7181 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007182 return null;
7183 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007184 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007185 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007186 return null;
7187 }
7188 return iccId;
7189 }
7190
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007191 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007192 public void setCallComposerStatus(int subId, int status) {
7193 enforceModifyPermission();
7194
7195 final long identity = Binder.clearCallingIdentity();
7196 try {
7197 Phone phone = getPhone(subId);
7198 if (phone != null) {
7199 Phone defaultPhone = phone.getImsPhone();
7200 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7201 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7202 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007203 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7204 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007205 }
7206 }
Shuo Qian284ae752020-12-22 19:10:14 -08007207 } catch (ImsException e) {
7208 throw new ServiceSpecificException(e.getCode());
7209 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007210 Binder.restoreCallingIdentity(identity);
7211 }
7212 }
7213
7214 @Override
7215 public int getCallComposerStatus(int subId) {
7216 enforceReadPrivilegedPermission("getCallComposerStatus");
7217
7218 final long identity = Binder.clearCallingIdentity();
7219 try {
7220 Phone phone = getPhone(subId);
7221 if (phone != null) {
7222 Phone defaultPhone = phone.getImsPhone();
7223 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7224 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7225 return imsPhone.getCallComposerStatus();
7226 }
7227 }
7228 } finally {
7229 Binder.restoreCallingIdentity(identity);
7230 }
7231 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7232 }
7233
7234 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007235 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7236 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007237 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007238 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007239
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007240 final long identity = Binder.clearCallingIdentity();
7241 try {
7242 final String iccId = getIccId(subId);
7243 final Phone phone = getPhone(subId);
7244 if (phone == null) {
7245 return false;
7246 }
7247 final String subscriberId = phone.getSubscriberId();
7248
7249 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007250 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007251 + subscriberId + " to " + number);
7252 }
7253
7254 if (TextUtils.isEmpty(iccId)) {
7255 return false;
7256 }
7257
7258 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7259
7260 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7261 if (alphaTag == null) {
7262 editor.remove(alphaTagPrefKey);
7263 } else {
7264 editor.putString(alphaTagPrefKey, alphaTag);
7265 }
7266
7267 // Record both the line number and IMSI for this ICCID, since we need to
7268 // track all merged IMSIs based on line number
7269 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7270 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7271 if (number == null) {
7272 editor.remove(numberPrefKey);
7273 editor.remove(subscriberPrefKey);
7274 } else {
7275 editor.putString(numberPrefKey, number);
7276 editor.putString(subscriberPrefKey, subscriberId);
7277 }
7278
7279 editor.commit();
7280 return true;
7281 } finally {
7282 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007283 }
Derek Tan7226c842014-07-02 17:42:23 -07007284 }
7285
7286 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007287 public String getLine1NumberForDisplay(int subId, String callingPackage,
7288 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007289 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007290 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007291 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007292 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007293 return null;
7294 }
Derek Tan97ebb422014-09-05 16:55:38 -07007295
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007296 final long identity = Binder.clearCallingIdentity();
7297 try {
7298 String iccId = getIccId(subId);
7299 if (iccId != null) {
7300 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7301 if (DBG_MERGE) {
7302 log("getLine1NumberForDisplay returning "
7303 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7304 }
7305 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007306 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007307 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7308 return null;
7309 } finally {
7310 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007311 }
Derek Tan7226c842014-07-02 17:42:23 -07007312 }
7313
7314 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007315 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7316 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007317 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007318 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007319 return null;
7320 }
Derek Tan97ebb422014-09-05 16:55:38 -07007321
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007322 final long identity = Binder.clearCallingIdentity();
7323 try {
7324 String iccId = getIccId(subId);
7325 if (iccId != null) {
7326 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7327 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7328 }
7329 return null;
7330 } finally {
7331 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007332 }
Derek Tan7226c842014-07-02 17:42:23 -07007333 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007334
7335 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007336 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7337 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007338 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7339 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007340 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007341 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007342 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007343 return null;
7344 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007345
Jordan Liub49b04b2019-05-06 14:45:15 -07007346 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7347 // the process, where TelephonyManager was instantiated.
7348 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007349 final long identity = Binder.clearCallingIdentity();
7350 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007351 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007352 final TelephonyManager tele = TelephonyManager.from(context);
7353 final SubscriptionManager sub = SubscriptionManager.from(context);
7354
7355 // Figure out what subscribers are currently active
7356 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007357
Jordan Liub49b04b2019-05-06 14:45:15 -07007358 // Only consider subs which match the current subId
7359 // This logic can be simplified. See b/131189269 for progress.
7360 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007361 activeSubscriberIds.add(tele.getSubscriberId(subId));
7362 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007363
7364 // First pass, find a number override for an active subscriber
7365 String mergeNumber = null;
7366 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7367 for (String key : prefs.keySet()) {
7368 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7369 final String subscriberId = (String) prefs.get(key);
7370 if (activeSubscriberIds.contains(subscriberId)) {
7371 final String iccId = key.substring(
7372 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7373 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7374 mergeNumber = (String) prefs.get(numberKey);
7375 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007376 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007377 + " for active subscriber " + subscriberId);
7378 }
7379 if (!TextUtils.isEmpty(mergeNumber)) {
7380 break;
7381 }
7382 }
7383 }
7384 }
7385
7386 // Shortcut when no active merged subscribers
7387 if (TextUtils.isEmpty(mergeNumber)) {
7388 return null;
7389 }
7390
7391 // Second pass, find all subscribers under that line override
7392 final ArraySet<String> result = new ArraySet<>();
7393 for (String key : prefs.keySet()) {
7394 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7395 final String number = (String) prefs.get(key);
7396 if (mergeNumber.equals(number)) {
7397 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7398 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7399 final String subscriberId = (String) prefs.get(subscriberKey);
7400 if (!TextUtils.isEmpty(subscriberId)) {
7401 result.add(subscriberId);
7402 }
7403 }
7404 }
7405 }
7406
7407 final String[] resultArray = result.toArray(new String[result.size()]);
7408 Arrays.sort(resultArray);
7409 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007410 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007411 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7412 }
7413 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007414 } finally {
7415 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007416 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007417 }
7418
7419 @Override
zoey chen38003472019-12-13 17:16:31 +08007420 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7421 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007422
7423 final long identity = Binder.clearCallingIdentity();
7424 try {
7425 final TelephonyManager telephonyManager = mApp.getSystemService(
7426 TelephonyManager.class);
7427 String subscriberId = telephonyManager.getSubscriberId(subId);
7428 if (subscriberId == null) {
7429 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007430 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007431 + subId);
7432 }
7433 return null;
7434 }
7435
Jack Yu285100e2022-12-02 22:48:35 -08007436 ParcelUuid groupUuid;
7437 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7438 final SubscriptionInfo info = SubscriptionManagerService.getInstance()
7439 .getSubscriptionInfo(subId);
7440 groupUuid = info.getGroupUuid();
7441 } else {
7442 final SubscriptionInfo info = mSubscriptionController
7443 .getSubscriptionInfo(subId);
7444 groupUuid = info.getGroupUuid();
7445 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007446 // If it doesn't belong to any group, return just subscriberId of itself.
7447 if (groupUuid == null) {
7448 return new String[]{subscriberId};
7449 }
7450
7451 // Get all subscriberIds from the group.
7452 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007453 List<SubscriptionInfo> groupInfos;
7454 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7455 groupInfos = SubscriptionManagerService.getInstance()
7456 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7457 mApp.getAttributionTag());
7458 } else {
7459 groupInfos = mSubscriptionController
7460 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7461 mApp.getAttributionTag());
7462 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007463 for (SubscriptionInfo subInfo : groupInfos) {
7464 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7465 if (subscriberId != null) {
7466 mergedSubscriberIds.add(subscriberId);
7467 }
7468 }
7469
7470 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7471 } finally {
7472 Binder.restoreCallingIdentity(identity);
7473
7474 }
7475 }
7476
7477 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007478 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007479 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007480 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007481
7482 final long identity = Binder.clearCallingIdentity();
7483 try {
7484 final Phone phone = getPhone(subId);
7485 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7486 } finally {
7487 Binder.restoreCallingIdentity(identity);
7488 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007489 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007490
7491 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007492 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007493 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7494 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007495 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7496 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007497
7498 final long identity = Binder.clearCallingIdentity();
7499 try {
7500 final Phone phone = getPhone(subId);
7501 if (phone == null) {
7502 return false;
7503 }
7504 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7505 cdmaNonRoamingList);
7506 } finally {
7507 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007508 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007509 }
7510
7511 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007512 @Deprecated
7513 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7514 enforceModifyPermission();
7515
7516 int returnValue = 0;
7517 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007518 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007519 if(result.exception == null) {
7520 if (result.result != null) {
7521 byte[] responseData = (byte[])(result.result);
7522 if(responseData.length > oemResp.length) {
7523 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7524 responseData.length + "bytes. Buffer Size is " +
7525 oemResp.length + "bytes.");
7526 }
7527 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7528 returnValue = responseData.length;
7529 }
7530 } else {
7531 CommandException ex = (CommandException) result.exception;
7532 returnValue = ex.getCommandError().ordinal();
7533 if(returnValue > 0) returnValue *= -1;
7534 }
7535 } catch (RuntimeException e) {
7536 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7537 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7538 if(returnValue > 0) returnValue *= -1;
7539 }
7540
7541 return returnValue;
7542 }
7543
7544 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007545 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007546 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007547 try {
7548 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007549 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007550 mApp, phone.getSubId(), "getRadioAccessFamily");
7551 } catch (SecurityException e) {
7552 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7553 throw e;
7554 }
chen xub97461a2018-10-26 14:17:57 -07007555 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007556 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007557 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007558 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007559 final long identity = Binder.clearCallingIdentity();
7560 try {
chen xub97461a2018-10-26 14:17:57 -07007561 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007562 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007563 mApp, phone.getSubId(), "getRadioAccessFamily");
7564 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007565 } finally {
7566 Binder.restoreCallingIdentity(identity);
7567 }
chen xub97461a2018-10-26 14:17:57 -07007568 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007569 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007570
7571 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007572 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007573 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007574 try {
7575 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7576 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007577 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007578 }
7579 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007580 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007581 }
7582 RoleManager rm = mApp.getSystemService(RoleManager.class);
7583 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7584 if (!dialerRoleHolders.contains(callingPackage)) {
7585 throw new SecurityException("App must be the dialer role holder to"
7586 + " upload a call composer pic");
7587 }
7588
7589 Executors.newSingleThreadExecutor().execute(() -> {
7590 ByteArrayOutputStream output = new ByteArrayOutputStream(
7591 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7592 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7593 boolean readUntilEnd = false;
7594 int totalBytesRead = 0;
7595 byte[] buffer = new byte[16 * 1024];
7596 while (true) {
7597 int numRead;
7598 try {
7599 numRead = input.read(buffer);
7600 } catch (IOException e) {
7601 try {
7602 fd.checkError();
7603 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7604 null);
7605 } catch (IOException e1) {
7606 // This means that the other side closed explicitly with an error. If this
7607 // happens, log and ignore.
7608 loge("Remote end of call composer picture pipe closed: " + e1);
7609 }
7610 break;
7611 }
7612 if (numRead == -1) {
7613 readUntilEnd = true;
7614 break;
7615 }
7616 totalBytesRead += numRead;
7617 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7618 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7619 try {
7620 input.close();
7621 } catch (IOException e) {
7622 // ignore
7623 }
7624 break;
7625 }
7626 output.write(buffer, 0, numRead);
7627 }
7628 // Generally, the remote end will close the file descriptors. The only case where we
7629 // close is above, where the picture size is too big.
7630
7631 try {
7632 fd.checkError();
7633 } catch (IOException e) {
7634 loge("Remote end for call composer closed with an error: " + e);
7635 return;
7636 }
7637
Hall Liuaa4211e2021-01-20 15:43:39 -08007638 if (!readUntilEnd) {
7639 loge("Did not finish reading entire image; aborting");
7640 return;
7641 }
Hall Liu82694d52020-12-11 18:22:04 -08007642
Hall Liuaa4211e2021-01-20 15:43:39 -08007643 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7644 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7645 new CallComposerPictureTransfer.Factory() {},
7646 imageData,
7647 (result) -> {
7648 if (result.first != null) {
7649 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7650 Bundle outputResult = new Bundle();
7651 outputResult.putParcelable(
7652 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7653 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7654 outputResult);
7655 } else {
7656 callback.send(result.second, null);
7657 }
7658 }
7659 );
Hall Liu82694d52020-12-11 18:22:04 -08007660 });
7661 }
7662
7663 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007664 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007665 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007666 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007667
7668 final long identity = Binder.clearCallingIdentity();
7669 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007670 ImsManager.getInstance(defaultPhone.getContext(),
7671 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007672 } finally {
7673 Binder.restoreCallingIdentity(identity);
7674 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007675 }
7676
7677 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007678 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007679 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007680 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7681 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007682 return false;
7683 }
Svet Ganovb320e182015-04-16 12:30:10 -07007684
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007685 final long identity = Binder.clearCallingIdentity();
7686 try {
7687 // Check the user preference and the system-level IMS setting. Even if the user has
7688 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7689 // In the long run, we may instead need to check if there exists a connection service
7690 // which can support video calling.
7691 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007692 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007693 return imsManager.isVtEnabledByPlatform()
7694 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7695 && imsManager.isVtEnabledByUser();
7696 } finally {
7697 Binder.restoreCallingIdentity(identity);
7698 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007699 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007700
Andrew Leea1239f22015-03-02 17:44:07 -08007701 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007702 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7703 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007704 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007705 mApp, subId, callingPackage, callingFeatureId,
7706 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007707 return false;
7708 }
7709
7710 final long identity = Binder.clearCallingIdentity();
7711 try {
7712 CarrierConfigManager configManager =
7713 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007714 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007715 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7716 } finally {
7717 Binder.restoreCallingIdentity(identity);
7718 }
Andrew Leea1239f22015-03-02 17:44:07 -08007719 }
7720
7721 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007722 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007723 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007724 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007725 return false;
7726 }
7727
7728 final long identity = Binder.clearCallingIdentity();
7729 try {
7730 CarrierConfigManager configManager =
7731 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007732 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007733 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7734 } finally {
7735 Binder.restoreCallingIdentity(identity);
7736 }
Andrew Leea1239f22015-03-02 17:44:07 -08007737 }
7738
Andrew Lee9431b832015-03-09 18:46:45 -07007739 @Override
7740 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007741 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007742 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007743 }
7744
7745 @Override
7746 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007747 final long identity = Binder.clearCallingIdentity();
7748 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007749 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007750 } finally {
7751 Binder.restoreCallingIdentity(identity);
7752 }
Andrew Lee9431b832015-03-09 18:46:45 -07007753 }
7754
Hall Liuf6668912018-10-31 17:05:23 -07007755 /**
7756 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7757 * support for the feature and device firmware support.
7758 *
7759 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7760 */
7761 @Override
7762 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007763 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007764 final Phone phone = getPhone(subscriptionId);
7765 if (phone == null) {
7766 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7767 return false;
7768 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007769 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007770 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007771 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7772 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007773 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007774 return isCarrierSupported && isDeviceSupported;
7775 } finally {
7776 Binder.restoreCallingIdentity(identity);
7777 }
Hall Liu98187582018-01-22 19:15:32 -08007778 }
7779
Hall Liuf6668912018-10-31 17:05:23 -07007780 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007781 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7782 * RTT setting, will return true if the device and carrier both support RTT.
7783 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007784 */
7785 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007786 final long identity = Binder.clearCallingIdentity();
7787 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007788 boolean isRttSupported = isRttSupported(subscriptionId);
7789 boolean isUserRttSettingOn = Settings.Secure.getInt(
7790 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7791 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7792 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7793 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007794 } finally {
7795 Binder.restoreCallingIdentity(identity);
7796 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007797 }
7798
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007799 @Deprecated
7800 @Override
7801 public String getDeviceId(String callingPackage) {
7802 return getDeviceIdWithFeature(callingPackage, null);
7803 }
7804
Sanket Padawe7310cc72015-01-14 09:53:20 -08007805 /**
7806 * Returns the unique device ID of phone, for example, the IMEI for
7807 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7808 *
7809 * <p>Requires Permission:
7810 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7811 */
7812 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007813 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007814 try {
7815 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7816 } catch (SecurityException se) {
7817 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7818 throw new SecurityException("Package " + callingPackage + " does not belong to "
7819 + Binder.getCallingUid());
7820 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007821 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007822 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007823 return null;
7824 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007825 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007826 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007827 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007828 return null;
7829 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007830
7831 final long identity = Binder.clearCallingIdentity();
7832 try {
7833 return phone.getDeviceId();
7834 } finally {
7835 Binder.restoreCallingIdentity(identity);
7836 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007837 }
7838
Ping Sunc67b7c22016-03-02 19:16:45 +08007839 /**
7840 * {@hide}
7841 * Returns the IMS Registration Status on a particular subid
7842 *
7843 * @param subId
7844 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007845 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007846 Phone phone = getPhone(subId);
7847 if (phone != null) {
7848 return phone.isImsRegistered();
7849 } else {
7850 return false;
7851 }
7852 }
7853
Santos Cordon7a1885b2015-02-03 11:15:19 -08007854 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007855 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007856 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007857 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007858 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007859 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7860 }
7861 final long identity = Binder.clearCallingIdentity();
7862 try {
7863 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7864 } finally {
7865 Binder.restoreCallingIdentity(identity);
7866 }
7867 }
7868
7869 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007870 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007871 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007872 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007873 mApp,
7874 subscriptionId,
7875 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007876 final long identity = Binder.clearCallingIdentity();
7877 try {
7878 Phone phone = getPhone(subscriptionId);
7879 if (phone == null) {
7880 return null;
7881 }
7882 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7883 } finally {
7884 Binder.restoreCallingIdentity(identity);
7885 }
7886 }
7887
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007888 /**
7889 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007890 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007891 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007892 final long identity = Binder.clearCallingIdentity();
7893 try {
7894 Phone phone = getPhone(subId);
7895 if (phone != null) {
7896 return phone.isWifiCallingEnabled();
7897 } else {
7898 return false;
7899 }
7900 } finally {
7901 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007902 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007903 }
7904
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007905 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007906 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007907 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007908 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007909 final long identity = Binder.clearCallingIdentity();
7910 try {
7911 Phone phone = getPhone(subId);
7912 if (phone != null) {
7913 return phone.isVideoEnabled();
7914 } else {
7915 return false;
7916 }
7917 } finally {
7918 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007919 }
7920 }
7921
7922 /**
7923 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7924 * defined in {@link ImsRegistrationImplBase}.
7925 */
7926 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007927 final long identity = Binder.clearCallingIdentity();
7928 try {
7929 Phone phone = getPhone(subId);
7930 if (phone != null) {
7931 return phone.getImsRegistrationTech();
7932 } else {
7933 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7934 }
7935 } finally {
7936 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007937 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007938 }
7939
Stuart Scott8eef64f2015-04-08 15:13:54 -07007940 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007941 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007942 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007943 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7944 return;
7945 }
Kai Shif70f46f2021-03-03 13:59:46 -08007946 Phone defaultPhone = getDefaultPhone();
7947 if (defaultPhone != null) {
7948 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7949 mApp, getDefaultPhone().getSubId(), "factoryReset");
7950 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007951 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007952
Svet Ganovcc087f82015-05-12 20:35:54 -07007953 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007954 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7955 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007956 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007957 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007958 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007959 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007960 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007961 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007962 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007963 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007964 // There has been issues when Sms raw table somehow stores orphan
7965 // fragments. They lead to garbled message when new fragments come
7966 // in and combined with those stale ones. In case this happens again,
7967 // user can reset all network settings which will clean up this table.
7968 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007969 // Clean up IMS settings as well here.
7970 int slotId = getSlotIndex(subId);
7971 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7972 ImsManager.getInstance(mApp, slotId).factoryReset();
7973 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007974
Kai Shif70f46f2021-03-03 13:59:46 -08007975 if (defaultPhone == null) {
7976 return;
7977 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007978 // Erase modem config if erase modem on network setting is enabled.
7979 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7980 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7981 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007982 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007983 }
Kai Shif70f46f2021-03-03 13:59:46 -08007984
7985 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007986 } finally {
7987 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007988 }
7989 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007990
SongFerngWangfd89b102021-05-27 22:44:54 +08007991 @VisibleForTesting
7992 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7993 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7994 return;
7995 }
7996 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7997 RILConstants.PREFERRED_NETWORK_MODE);
7998 SubscriptionManager.setSubscriptionProperty(subId,
7999 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8000 "user=" + defaultNetworkType);
8001 phone.loadAllowedNetworksFromSubscriptionDatabase();
8002 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8003 defaultNetworkType, null);
8004 }
8005
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008006 private void cleanUpSmsRawTable(Context context) {
8007 ContentResolver resolver = context.getContentResolver();
8008 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8009 resolver.delete(uri, null, null);
8010 }
8011
Narayan Kamath1c496c22015-04-16 14:40:19 +01008012 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008013 public String getSimLocaleForSubscriber(int subId) {
8014 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8015 final Phone phone = getPhone(subId);
8016 if (phone == null) {
8017 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008018 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008019 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008020 final long identity = Binder.clearCallingIdentity();
8021 try {
Jack Yu285100e2022-12-02 22:48:35 -08008022 SubscriptionInfo info;
8023 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8024 info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId,
8025 phone.getContext().getOpPackageName(),
8026 phone.getContext().getAttributionTag());
8027 if (info == null) {
8028 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8029 return null;
8030 }
8031 } else {
8032 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
8033 phone.getContext().getOpPackageName(),
8034 phone.getContext().getAttributionTag());
8035 if (info == null) {
8036 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8037 return null;
8038 }
chen xu6291c472019-02-04 12:55:53 -08008039 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008040 // Try and fetch the locale from the carrier properties or from the SIM language
8041 // preferences (EF-PL and EF-LI)...
8042 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008043 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008044 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8045 if (localeFromDefaultSim != null) {
8046 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8047 if (DBG) log("Using locale from subId: " + subId + " locale: "
8048 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008049 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008050 } else {
8051 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008052 }
8053 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008054
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008055 // The SIM language preferences only store a language (e.g. fr = French), not an
8056 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8057 // the SIM and carrier preferences does not include a country we add the country
8058 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008059 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008060 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008061 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008062 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008063 }
8064
8065 if (DBG) log("No locale found - returning null");
8066 return null;
8067 } finally {
8068 Binder.restoreCallingIdentity(identity);
8069 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008070 }
8071
tom hsu0b59d292022-09-29 23:49:21 +08008072 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008073 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008074 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008075 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008076 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008077 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8078 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008079 Locale.forLanguageTag(localeTag).getCountry())) {
8080 return localeTag;
8081 }
8082 }
8083 return inputLocale.toLanguageTag();
8084 }
8085
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008086 /**
8087 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8088 */
8089 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08008090 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8091 return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList(
8092 mApp.getOpPackageName(), mApp.getAttributionTag());
8093 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008094 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08008095 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008096 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008097
Gary Jian3aa9a762022-01-24 16:41:19 +08008098 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8099 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008100
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008101 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008102 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8103 * representing the state of the modem.
8104 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008105 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8106 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008107 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008108 */
8109 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008110 public void requestModemActivityInfo(ResultReceiver result) {
8111 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008112 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008113
8114 final long identity = Binder.clearCallingIdentity();
8115 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008116 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008117 } finally {
8118 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008119 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008120 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008121
Gary Jian76280a42022-12-07 16:18:33 +08008122 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008123 // less than total activity duration.
8124 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8125 if (info == null) {
8126 return false;
8127 }
8128 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008129 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008130 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8131
Hall Liu49656c02020-10-09 19:00:11 -07008132 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8133
Siddharth Rayb8114062018-06-17 15:02:38 -07008134 return (info.isValid()
8135 && (info.getSleepTimeMillis() <= activityDurationMs)
Gary Jian76280a42022-12-07 16:18:33 +08008136 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008137 }
8138
Gary Jian3aa9a762022-01-24 16:41:19 +08008139 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8140 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8141 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8142 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8143
8144 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8145 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8146 }
8147
8148 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8149 mLastModemActivityInfo.setReceiveTimeMillis(
8150 rat,
8151 freq,
8152 info.getReceiveTimeMillis(rat, freq)
8153 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8154 }
8155
8156 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8157 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8158 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8159 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8160
8161 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8162 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8163 }
8164 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8165 mLastModemActivityInfo.setReceiveTimeMillis(
8166 rat,
8167 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8168 }
8169
8170 /**
8171 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8172 * @param info recent ModemActivityInfo
8173 */
8174 private void mergeModemActivityInfo(ModemActivityInfo info) {
8175 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008176 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008177 boolean matched;
8178 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8179 matched = false;
8180 int rat = info.getSpecificInfoRat(i);
8181 int freq = info.getSpecificInfoFrequencyRange(i);
8182 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8183 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8184 //if it already exists
8185 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8186 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8187 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8188 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8189 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8190 updateLastModemActivityInfo(info, rat, freq);
8191 matched = true;
8192 }
8193 } else {
8194 updateLastModemActivityInfo(info, rat);
8195 matched = true;
8196 }
8197 }
8198 }
8199
8200 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008201 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008202 new ActivityStatsTechSpecificInfo(
8203 rat,
8204 freq,
8205 info.getTransmitTimeMillis(rat, freq),
8206 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008207 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008208 }
8209 }
8210 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8211 mLastModemActivitySpecificInfo =
8212 new ActivityStatsTechSpecificInfo[merged.size()];
8213 merged.toArray(mLastModemActivitySpecificInfo);
8214
8215 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8216 mLastModemActivityInfo.setSleepTimeMillis(
8217 info.getSleepTimeMillis()
8218 + mLastModemActivityInfo.getSleepTimeMillis());
8219 mLastModemActivityInfo.setIdleTimeMillis(
8220 info.getIdleTimeMillis()
8221 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008222
8223 mLastModemActivityInfo =
8224 new ModemActivityInfo(
8225 mLastModemActivityInfo.getTimestampMillis(),
8226 mLastModemActivityInfo.getSleepTimeMillis(),
8227 mLastModemActivityInfo.getIdleTimeMillis(),
8228 mLastModemActivitySpecificInfo);
8229 }
8230
8231 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8232 ActivityStatsTechSpecificInfo[] info) {
8233 int infoSize = info.length;
8234 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8235 for (int i = 0; i < infoSize; i++) {
8236 ret[i] = new ActivityStatsTechSpecificInfo(
8237 info[i].getRat(), info[i].getFrequencyRange(),
8238 info[i].getTransmitTimeMillis(),
8239 (int) info[i].getReceiveTimeMillis());
8240 }
8241 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008242 }
8243
Jack Yu85bd38a2015-11-09 11:34:32 -08008244 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008245 * Returns the service state information on specified subscription.
8246 */
8247 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008248 public ServiceState getServiceStateForSubscriber(int subId,
8249 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8250 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008251 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008252 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008253 return null;
8254 }
8255
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008256 boolean hasFinePermission = false;
8257 boolean hasCoarsePermission = false;
8258 if (!renounceFineLocationAccess) {
8259 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8260 LocationAccessPolicy.checkLocationPermission(mApp,
8261 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8262 .setCallingPackage(callingPackage)
8263 .setCallingFeatureId(callingFeatureId)
8264 .setCallingPid(Binder.getCallingPid())
8265 .setCallingUid(Binder.getCallingUid())
8266 .setMethod("getServiceStateForSubscriber")
8267 .setLogAsInfo(true)
8268 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8269 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8270 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8271 .build());
8272 hasFinePermission =
8273 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8274 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008275
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008276 if (!renounceCoarseLocationAccess) {
8277 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8278 LocationAccessPolicy.checkLocationPermission(mApp,
8279 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8280 .setCallingPackage(callingPackage)
8281 .setCallingFeatureId(callingFeatureId)
8282 .setCallingPid(Binder.getCallingPid())
8283 .setCallingUid(Binder.getCallingUid())
8284 .setMethod("getServiceStateForSubscriber")
8285 .setLogAsInfo(true)
8286 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8287 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8288 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8289 .build());
8290 hasCoarsePermission =
8291 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8292 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008293
Jack Yu479f40e2020-10-27 21:29:25 -07008294 final Phone phone = getPhone(subId);
8295 if (phone == null) {
8296 return null;
8297 }
8298
Jordan Liu0f2bc442020-11-18 16:47:37 -08008299 final long identity = Binder.clearCallingIdentity();
8300
Jack Yu479f40e2020-10-27 21:29:25 -07008301 boolean isCallingPackageDataService = phone.getDataServicePackages()
8302 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008303 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008304 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008305 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8306 SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance()
8307 .getSubscriptionInfoInternal(subId);
8308 if (subInfo == null || !subInfo.isActive()) {
8309 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8310 + "subId=" + subId);
8311 return null;
8312 }
8313 } else {
8314 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8315 callingFeatureId)) {
8316 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8317 + "subId=" + subId);
8318 return null;
8319 }
Jordan Liuc437b192020-08-17 10:59:12 -07008320 }
8321
Hall Liuf19c44f2018-11-27 14:38:17 -08008322 ServiceState ss = phone.getServiceState();
8323
8324 // Scrub out the location info in ServiceState depending on what level of access
8325 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008326 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008327 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8328 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008329 } finally {
8330 Binder.restoreCallingIdentity(identity);
8331 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008332 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008333
8334 /**
8335 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8336 *
8337 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8338 * voicemail ringtone.
8339 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8340 * PhoneAccount.
8341 */
8342 @Override
8343 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008344 final long identity = Binder.clearCallingIdentity();
8345 try {
8346 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8347 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008348 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008349 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008350
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008351 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8352 } finally {
8353 Binder.restoreCallingIdentity(identity);
8354 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008355 }
8356
8357 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008358 * Sets the per-account voicemail ringtone.
8359 *
8360 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8361 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8362 *
8363 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8364 * voicemail ringtone.
8365 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8366 * PhoneAccount.
8367 */
8368 @Override
8369 public void setVoicemailRingtoneUri(String callingPackage,
8370 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008371 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008372 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008373 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8374 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008375 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8376 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8377 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008378 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008379
8380 final long identity = Binder.clearCallingIdentity();
8381 try {
8382 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8383 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008384 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008385 }
8386 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8387 } finally {
8388 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008389 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008390 }
8391
8392 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008393 * Returns whether vibration is set for voicemail notification in Phone settings.
8394 *
8395 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8396 * voicemail vibration setting.
8397 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8398 */
8399 @Override
8400 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008401 final long identity = Binder.clearCallingIdentity();
8402 try {
8403 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8404 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008405 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008406 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008407
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008408 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8409 } finally {
8410 Binder.restoreCallingIdentity(identity);
8411 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008412 }
8413
Youhan Wange64578a2016-05-02 15:32:42 -07008414 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008415 * Sets the per-account voicemail vibration.
8416 *
8417 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8418 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8419 *
8420 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8421 * voicemail vibration setting.
8422 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8423 * specific PhoneAccount.
8424 */
8425 @Override
8426 public void setVoicemailVibrationEnabled(String callingPackage,
8427 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008428 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008429 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008430 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8431 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8433 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8434 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008435 }
8436
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008437 final long identity = Binder.clearCallingIdentity();
8438 try {
8439 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8440 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008441 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008442 }
8443 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8444 } finally {
8445 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008446 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008447 }
8448
8449 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008450 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8451 *
8452 * @throws SecurityException if the caller does not have the required permission
8453 */
arunvoddud7401012022-12-15 16:08:12 +00008454 @VisibleForTesting
8455 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008456 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008457 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008458 }
8459
8460 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008461 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8462 * permission.
8463 *
8464 * @throws SecurityException if the caller does not have the required permission
8465 */
8466 private void enforceSendSmsPermission() {
8467 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8468 }
8469
8470 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008471 * Make sure either called from same process as self (phone) or IPC caller has interact across
8472 * users permission.
8473 *
8474 * @throws SecurityException if the caller does not have the required permission
8475 */
8476 private void enforceInteractAcrossUsersPermission(String message) {
8477 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8478 }
8479
8480 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008481 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008482 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008483 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008484 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008485 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008486 final long identity = Binder.clearCallingIdentity();
8487 try {
8488 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008489 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008490 if (componentName == null) {
8491 throw new SecurityException(
8492 "Caller not current active visual voicemail package[null]");
8493 }
8494 String vvmPackage = componentName.getPackageName();
8495 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008496 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008497 }
8498 } finally {
8499 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008500 }
8501 }
8502
8503 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008504 * Return the application ID for the app type.
8505 *
8506 * @param subId the subscription ID that this request applies to.
8507 * @param appType the uicc app type.
8508 * @return Application ID for specificied app type, or null if no uicc.
8509 */
8510 @Override
8511 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008512 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008513 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008514
8515 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008516 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008517 if (phone == null) {
8518 return null;
8519 }
8520 String aid = null;
8521 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008522 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008523 .getApplicationByType(appType).getAid();
8524 } catch (Exception e) {
8525 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8526 }
8527 return aid;
8528 } finally {
8529 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008530 }
Youhan Wange64578a2016-05-02 15:32:42 -07008531 }
8532
Youhan Wang4001d252016-05-11 10:29:41 -07008533 /**
8534 * Return the Electronic Serial Number.
8535 *
8536 * @param subId the subscription ID that this request applies to.
8537 * @return ESN or null if error.
8538 */
8539 @Override
8540 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008541 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008542 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008543
8544 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008545 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008546 if (phone == null) {
8547 return null;
8548 }
8549 String esn = null;
8550 try {
8551 esn = phone.getEsn();
8552 } catch (Exception e) {
8553 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8554 }
8555 return esn;
8556 } finally {
8557 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008558 }
Youhan Wang4001d252016-05-11 10:29:41 -07008559 }
8560
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008561 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008562 * Return the Preferred Roaming List Version.
8563 *
8564 * @param subId the subscription ID that this request applies to.
8565 * @return PRLVersion or null if error.
8566 */
8567 @Override
8568 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008569 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008570 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008571
8572 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008573 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008574 if (phone == null) {
8575 return null;
8576 }
8577 String cdmaPrlVersion = null;
8578 try {
8579 cdmaPrlVersion = phone.getCdmaPrlVersion();
8580 } catch (Exception e) {
8581 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8582 }
8583 return cdmaPrlVersion;
8584 } finally {
8585 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008586 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008587 }
8588
8589 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008590 * Get snapshot of Telephony histograms
8591 * @return List of Telephony histograms
8592 * @hide
8593 */
8594 @Override
8595 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8597 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008598
8599 final long identity = Binder.clearCallingIdentity();
8600 try {
8601 return RIL.getTelephonyRILTimingHistograms();
8602 } finally {
8603 Binder.restoreCallingIdentity(identity);
8604 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008605 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008606
8607 /**
8608 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008609 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8610 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008611 * Require system privileges. In the future we may add this to carrier APIs.
8612 *
Michele Berionne482f8202018-11-27 18:57:59 -08008613 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008614 */
8615 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008616 @TelephonyManager.SetCarrierRestrictionResult
8617 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008618 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008619 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008620
Michele Berionne482f8202018-11-27 18:57:59 -08008621 if (carrierRestrictionRules == null) {
8622 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008623 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008624
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008625 final long identity = Binder.clearCallingIdentity();
8626 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008627 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008628 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008629 } finally {
8630 Binder.restoreCallingIdentity(identity);
8631 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008632 }
8633
8634 /**
8635 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008636 * Get the allowed carrier list and the excluded carrier list, including the priority between
8637 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008638 * Require system privileges. In the future we may add this to carrier APIs.
8639 *
Michele Berionne482f8202018-11-27 18:57:59 -08008640 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008641 */
8642 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008643 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008644 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008645 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008646
8647 final long identity = Binder.clearCallingIdentity();
8648 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008649 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8650 if (response instanceof CarrierRestrictionRules) {
8651 return (CarrierRestrictionRules) response;
8652 }
8653 // Response is an Exception of some kind,
8654 // which is signalled to the user as a NULL retval
8655 return null;
8656 } catch (Exception e) {
8657 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8658 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008659 } finally {
8660 Binder.restoreCallingIdentity(identity);
8661 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008662 }
8663
fionaxu59545b42016-05-25 15:53:37 -07008664 /**
arunvoddud7401012022-12-15 16:08:12 +00008665 * Fetches the carrier restriction status of the device and sends the status to the caller
8666 * through the callback.
8667 *
8668 * @param callback The callback that will be used to send the result.
8669 * @throws SecurityException if the caller does not have the required permission/privileges or
8670 * the caller is not allowlisted.
8671 */
8672 @Override
8673 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8674 enforceReadPermission("getCarrierRestrictionStatus");
8675 int carrierId = validateCallerAndGetCarrierId(packageName);
8676 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8677 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8678 throw new SecurityException("Not an authorized caller");
8679 }
8680 final long identity = Binder.clearCallingIdentity();
8681 try {
8682 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8683 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8684 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8685 } finally {
8686 Binder.restoreCallingIdentity(identity);
8687 }
8688 }
8689
8690 @VisibleForTesting
8691 public int validateCallerAndGetCarrierId(String packageName) {
8692 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8693 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8694 }
8695
8696 /**
fionaxu59545b42016-05-25 15:53:37 -07008697 * Action set from carrier signalling broadcast receivers to enable/disable radio
8698 * @param subId the subscription ID that this action applies to.
8699 * @param enabled control enable or disable radio.
8700 * {@hide}
8701 */
8702 @Override
8703 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8704 enforceModifyPermission();
8705 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008706
8707 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008708 if (phone == null) {
8709 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8710 return;
8711 }
8712 try {
8713 phone.carrierActionSetRadioEnabled(enabled);
8714 } catch (Exception e) {
8715 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008716 } finally {
8717 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008718 }
8719 }
8720
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008721 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008722 * Enable or disable Voice over NR (VoNR)
8723 * @param subId the subscription ID that this action applies to.
8724 * @param enabled enable or disable VoNR.
8725 * @return operation result.
8726 */
8727 @Override
8728 public int setVoNrEnabled(int subId, boolean enabled) {
8729 enforceModifyPermission();
8730 final Phone phone = getPhone(subId);
8731
8732 final long identity = Binder.clearCallingIdentity();
8733 if (phone == null) {
8734 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8735 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8736 }
8737
8738 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8739 try {
8740 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8741 workSource);
8742 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008743
8744 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8745 if (DBG) {
8746 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8747 }
8748 SubscriptionManager.setSubscriptionProperty(
8749 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8750 (enabled ? "1" : "0"));
8751 }
8752
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008753 return result;
8754 } finally {
8755 Binder.restoreCallingIdentity(identity);
8756 }
8757 }
8758
8759 /**
8760 * Is voice over NR enabled
8761 * @return true if VoNR is enabled else false
8762 */
8763 @Override
8764 public boolean isVoNrEnabled(int subId) {
8765 enforceReadPrivilegedPermission("isVoNrEnabled");
8766 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8767 final long identity = Binder.clearCallingIdentity();
8768 try {
8769 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8770 null, subId, workSource);
8771 if (DBG) log("isVoNrEnabled: " + isEnabled);
8772 return isEnabled;
8773 } finally {
8774 Binder.restoreCallingIdentity(identity);
8775 }
8776 }
8777
8778 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008779 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8780 * network status based on which carrier apps could apply actions accordingly,
8781 * enable/disable default url handler for example.
8782 *
8783 * @param subId the subscription ID that this action applies to.
8784 * @param report control start/stop reporting the default network status.
8785 * {@hide}
8786 */
8787 @Override
8788 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8789 enforceModifyPermission();
8790 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008791
8792 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008793 if (phone == null) {
8794 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8795 return;
8796 }
8797 try {
8798 phone.carrierActionReportDefaultNetworkStatus(report);
8799 } catch (Exception e) {
8800 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008801 } finally {
8802 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008803 }
8804 }
8805
8806 /**
fionaxud9622282017-07-17 17:51:30 -07008807 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8808 * @param subId the subscription ID that this action applies to.
8809 * {@hide}
8810 */
8811 @Override
8812 public void carrierActionResetAll(int subId) {
8813 enforceModifyPermission();
8814 final Phone phone = getPhone(subId);
8815 if (phone == null) {
8816 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8817 return;
8818 }
8819 try {
8820 phone.carrierActionResetAll();
8821 } catch (Exception e) {
8822 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8823 }
8824 }
8825
8826 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008827 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8828 * bug report is being generated.
8829 */
8830 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008831 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008832 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8833 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008834 writer.println("Permission Denial: can't dump Phone from pid="
8835 + Binder.getCallingPid()
8836 + ", uid=" + Binder.getCallingUid()
8837 + "without permission "
8838 + android.Manifest.permission.DUMP);
8839 return;
8840 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008841 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008842 }
Jack Yueb89b242016-06-22 13:27:47 -07008843
Brad Ebingerdac2f002018-04-03 15:17:52 -07008844 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008845 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8846 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8847 @NonNull String[] args) {
8848 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8849 this, in.getFileDescriptor(), out.getFileDescriptor(),
8850 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008851 }
8852
Jack Yueb89b242016-06-22 13:27:47 -07008853 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008854 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008855 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008856 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008857 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008858 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008859 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008860 */
8861 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008862 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008863 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008864 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8865 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8866 try {
8867 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008868 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008869 } catch (SecurityException se) {
8870 enforceModifyPermission();
8871 }
8872 } else {
8873 enforceModifyPermission();
8874 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008875
8876 final long identity = Binder.clearCallingIdentity();
8877 try {
8878 Phone phone = getPhone(subId);
8879 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008880 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8881 phone.carrierActionSetMeteredApnsEnabled(enabled);
8882 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008883 phone.getDataSettingsManager().setDataEnabled(
8884 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008885 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008886 }
8887 } finally {
8888 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008889 }
8890 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008891
8892 /**
8893 * Get Client request stats
8894 * @return List of Client Request Stats
8895 * @hide
8896 */
8897 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008898 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8899 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008900 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008901 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008902 return null;
8903 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008904 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008905
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008906 final long identity = Binder.clearCallingIdentity();
8907 try {
8908 if (phone != null) {
8909 return phone.getClientRequestStats();
8910 }
8911
8912 return null;
8913 } finally {
8914 Binder.restoreCallingIdentity(identity);
8915 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008916 }
8917
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008918 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008919 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008920 if (uid == Process.ROOT_UID && packageName == null) {
8921 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8922 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8923 // exception. ROOT_UID seems not to have a valid package name returned by
8924 // PackageManager, so just fake it here to avoid issues when running telephony shell
8925 // commands that plumb through the RIL as root, like so:
8926 // $ adb root
8927 // $ adb shell cmd phone ...
8928 packageName = "root";
8929 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008930 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008931 }
Jack Yueb4124c2017-02-16 15:32:43 -08008932
8933 /**
Grace Chen70990072017-03-24 17:21:30 -07008934 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008935 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008936 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008937 * @param state State of SIM (power down, power up, pass through)
8938 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8939 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8940 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008941 *
8942 **/
8943 @Override
Grace Chen70990072017-03-24 17:21:30 -07008944 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008945 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008946 Phone phone = PhoneFactory.getPhone(slotIndex);
8947
vagdeviaf9a5b92018-08-15 16:01:53 -07008948 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8949
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008950 final long identity = Binder.clearCallingIdentity();
8951 try {
8952 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008953 phone.setSimPowerState(state, null, workSource);
8954 }
8955 } finally {
8956 Binder.restoreCallingIdentity(identity);
8957 }
8958 }
8959
8960 /**
8961 * Set SIM card power state.
8962 *
8963 * @param slotIndex SIM slot id.
8964 * @param state State of SIM (power down, power up, pass through)
8965 * @param callback callback to trigger after success or failure
8966 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8967 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8968 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8969 *
8970 **/
8971 @Override
8972 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8973 IIntegerConsumer callback) {
8974 enforceModifyPermission();
8975 Phone phone = PhoneFactory.getPhone(slotIndex);
8976
8977 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8978
8979 final long identity = Binder.clearCallingIdentity();
8980 try {
8981 if (phone != null) {
8982 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8983 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008984 }
8985 } finally {
8986 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008987 }
8988 }
Shuo Qiandd210312017-04-12 22:11:33 +00008989
Tyler Gunn65d45c22017-06-05 11:22:26 -07008990 private boolean isUssdApiAllowed(int subId) {
8991 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008992 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008993 if (configManager == null) {
8994 return false;
8995 }
8996 PersistableBundle pb = configManager.getConfigForSubId(subId);
8997 if (pb == null) {
8998 return false;
8999 }
9000 return pb.getBoolean(
9001 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9002 }
9003
Shuo Qiandd210312017-04-12 22:11:33 +00009004 /**
9005 * Check if phone is in emergency callback mode
9006 * @return true if phone is in emergency callback mode
9007 * @param subId sub id
9008 */
goneil9c5f4872017-12-05 14:07:56 -08009009 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009010 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009011 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00009012 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009013
9014 final long identity = Binder.clearCallingIdentity();
9015 try {
9016 if (phone != null) {
9017 return phone.isInEcm();
9018 } else {
9019 return false;
9020 }
9021 } finally {
9022 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009023 }
9024 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009025
9026 /**
9027 * Get the current signal strength information for the given subscription.
9028 * Because this information is not updated when the device is in a low power state
9029 * it should not be relied-upon to be current.
9030 * @param subId Subscription index
9031 * @return the most recent cached signal strength info from the modem
9032 */
9033 @Override
9034 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009035 final long identity = Binder.clearCallingIdentity();
9036 try {
9037 Phone p = getPhone(subId);
9038 if (p == null) {
9039 return null;
9040 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009041
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009042 return p.getSignalStrength();
9043 } finally {
9044 Binder.restoreCallingIdentity(identity);
9045 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009046 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009047
Pengquan Meng77b7f132018-08-22 14:49:57 -07009048 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009049 * Get the current modem radio state for the given slot.
9050 * @param slotIndex slot index.
9051 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009052 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009053 * @return the current radio power state from the modem
9054 */
9055 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009056 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009057 Phone phone = PhoneFactory.getPhone(slotIndex);
9058 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009059 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9060 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009061 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9062 }
9063
9064 final long identity = Binder.clearCallingIdentity();
9065 try {
9066 return phone.getRadioPowerState();
9067 } finally {
9068 Binder.restoreCallingIdentity(identity);
9069 }
9070 }
9071 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9072 }
9073
9074 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009075 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9076 *
9077 * <p>Requires one of the following permissions:
9078 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009079 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009080 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9081 * privileges.
9082 *
9083 * @param subId subscription id
9084 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9085 * {@code false}.
9086 */
9087 @Override
9088 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009089 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009090 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009091 try {
9092 mApp.enforceCallingOrSelfPermission(
9093 android.Manifest.permission.ACCESS_NETWORK_STATE,
9094 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009095 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009096 mApp.enforceCallingOrSelfPermission(
9097 permission.READ_BASIC_PHONE_STATE, functionName);
9098 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009099 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009100 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009101 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009102 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009103
Pengquan Menga1bb6272018-09-06 09:59:22 -07009104 boolean isEnabled = false;
9105 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009106 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009107 Phone phone = getPhone(subId);
9108 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009109 } finally {
9110 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009111 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009112 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009113 }
9114
9115
9116 /**
9117 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9118 *
9119 * <p> Requires permission:
9120 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9121 * privileges.
9122 *
9123 * @param subId subscription id
9124 * @param isEnabled {@code true} means enable, {@code false} means disable.
9125 */
9126 @Override
9127 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009128 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9129 mApp, subId, "setDataRoamingEnabled");
9130
Pengquan Menga1bb6272018-09-06 09:59:22 -07009131 final long identity = Binder.clearCallingIdentity();
9132 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009133 Phone phone = getPhone(subId);
9134 if (phone != null) {
9135 phone.setDataRoamingEnabled(isEnabled);
9136 }
9137 } finally {
9138 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009139 }
9140 }
9141
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009142 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009143 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009144 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009145 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07009146 mApp, subId, "isManualNetworkSelectionAllowed");
9147
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009148 boolean isAllowed = true;
9149 final long identity = Binder.clearCallingIdentity();
9150 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009151 Phone phone = getPhone(subId);
9152 if (phone != null) {
9153 isAllowed = phone.isCspPlmnEnabled();
9154 }
9155 } finally {
9156 Binder.restoreCallingIdentity(identity);
9157 }
9158 return isAllowed;
9159 }
9160
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009161 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9162 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009163 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009164 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009165 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009166 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9167 if (phone == null) {
9168 return false;
9169 }
9170 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9171 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9172 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009173 }
9174
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009175 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009176 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009177 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009178 mApp.getSystemService(AppOpsManager.class)
9179 .checkPackage(Binder.getCallingUid(), callingPackage);
9180
Jordan Liu1e142fc2019-04-22 15:10:43 -07009181 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009182 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009183 try {
9184 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009185 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009186 } catch (SecurityException e) {
9187 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9188 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009189 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08009190 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009191 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009192 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009193 }
sandeepjsb6c87872021-09-27 15:34:44 +00009194 // checking compatibility, if calling app's target SDK is T and beyond.
9195 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9196 Binder.getCallingUid())) {
9197 isIccIdAccessRestricted = true;
9198 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009199 final long identity = Binder.clearCallingIdentity();
9200 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009201 UiccController uiccController = UiccController.getInstance();
9202 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009203 if (hasReadPermission) {
9204 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009205 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009206
9207 // Remove private info if the caller doesn't have access
9208 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9209 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009210 //setting the value after compatibility check
9211 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009212 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9213 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009214 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009215 if (card == null) {
9216 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009217 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009218 continue;
9219 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009220 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9221 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009222 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009223 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009224 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009225 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9226 for (UiccPortInfo portInfo : portInfos) {
9227 UiccPort port = uiccController.getUiccPortForSlot(
9228 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9229 if (port == null) {
9230 // assume no access if port is null
9231 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9232 continue;
9233 }
9234 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9235 uiccPortInfos.add(portInfo);
9236 } else {
9237 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9238 }
9239 }
9240 filteredInfos.add(new UiccCardInfo(
9241 cardInfo.isEuicc(),
9242 cardInfo.getCardId(),
9243 null,
9244 cardInfo.getPhysicalSlotIndex(),
9245 cardInfo.isRemovable(),
9246 cardInfo.isMultipleEnabledProfilesSupported(),
9247 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009248 }
9249 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009250 } finally {
9251 Binder.restoreCallingIdentity(identity);
9252 }
9253 }
9254
sandeepjsb6c87872021-09-27 15:34:44 +00009255 /**
9256 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9257 * generally private and require carrier privileges to view.
9258 *
9259 * @hide
9260 */
9261 @NonNull
9262 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9263 List<UiccPortInfo> portinfo = new ArrayList<>();
9264 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9265 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9266 }
9267 return new UiccCardInfo(
9268 cardInfo.isEuicc(),
9269 cardInfo.getCardId(),
9270 null,
9271 cardInfo.getPhysicalSlotIndex(),
9272 cardInfo.isRemovable(),
9273 cardInfo.isMultipleEnabledProfilesSupported(),
9274 portinfo
9275 );
9276 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009277
sandeepjsb6c87872021-09-27 15:34:44 +00009278 /**
9279 * @hide
9280 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9281 * These values are generally private and require carrier privileges to view.
9282 */
9283 @NonNull
9284 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9285 return new UiccPortInfo(
9286 UiccPortInfo.ICCID_REDACTED,
9287 portInfo.getPortIndex(),
9288 portInfo.getLogicalSlotIndex(),
9289 portInfo.isActive()
9290 );
9291 }
9292 @Override
9293 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009294 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009295 mApp.getSystemService(AppOpsManager.class)
9296 .checkPackage(Binder.getCallingUid(), callingPackage);
9297
sandeepjsb6c87872021-09-27 15:34:44 +00009298 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009299
Aman Guptaf3c90b32022-03-17 04:54:16 +00009300 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9301 // we are reading iccId which is PII data.
9302 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009303
9304 // checking compatibility, if calling app's target SDK is T and beyond.
9305 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9306 Binder.getCallingUid())) {
9307 isLogicalSlotAccessRestricted = true;
9308 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009309 final long identity = Binder.clearCallingIdentity();
9310 try {
9311 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009312 if (slots == null || slots.length == 0) {
9313 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009314 return null;
9315 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009316 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9317 for (int i = 0; i < slots.length; i++) {
9318 UiccSlot slot = slots[i];
9319 if (slot == null) {
9320 continue;
9321 }
9322
Jordan Liu7be7e652019-05-06 18:55:02 +00009323 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009324 UiccCard card = slot.getUiccCard();
9325 if (card != null) {
9326 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009327 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009328 cardId = slot.getEid();
9329 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009330 // If cardId is null, use iccId of default port as cardId.
9331 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009332 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009333 }
9334
Jordan Liu857451f2019-05-09 16:35:35 -07009335 if (cardId != null) {
9336 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9337 // if cardId is an EID, it's all digits so this is fine
9338 cardId = IccUtils.stripTrailingFs(cardId);
9339 }
9340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009341 int cardState = 0;
9342 switch (slot.getCardState()) {
9343 case CARDSTATE_ABSENT:
9344 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9345 break;
9346 case CARDSTATE_PRESENT:
9347 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9348 break;
9349 case CARDSTATE_ERROR:
9350 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9351 break;
9352 case CARDSTATE_RESTRICTED:
9353 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9354 break;
9355 default:
9356 break;
9357
9358 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009359 List<UiccPortInfo> portInfos = new ArrayList<>();
9360 int[] portIndexes = slot.getPortList();
9361 for (int portIdx : portIndexes) {
9362 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009363 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009364 portInfos.add(new UiccPortInfo(iccId, portIdx,
9365 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009366 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009367 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009368 slot.isEuicc(),
9369 cardId,
9370 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009371 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009372 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009373 //setting the value after compatibility check
9374 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009375 }
9376 return infos;
9377 } finally {
9378 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009379 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009380 }
9381
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009382 /* Returns null if doesn't have read permission or carrier privilege access. */
9383 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9384 boolean hasReadPermission) {
9385 String iccId = slot.getIccId(portIndex);
9386 if (hasReadPermission) { // if has read permission
9387 return iccId;
9388 } else {
9389 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9390 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9391 // if no read permission, checking carrier privilege access
9392 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9393 return iccId;
9394 }
9395 }
9396 }
9397 // No read permission or carrier privilege access.
9398 return UiccPortInfo.ICCID_REDACTED;
9399 }
9400
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009401 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009402 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009403 public boolean switchSlots(int[] physicalSlots) {
9404 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009405
9406 final long identity = Binder.clearCallingIdentity();
9407 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009408 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9409 for (int i = 0; i < physicalSlots.length; i++) {
9410 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9411 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9412 physicalSlots[i], i));
9413 }
9414 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009415 } finally {
9416 Binder.restoreCallingIdentity(identity);
9417 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009418 }
Jack Yu4c988042018-02-27 15:30:01 -08009419
9420 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009421 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9422 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9423 enforceModifyPermission();
9424
9425 final long identity = Binder.clearCallingIdentity();
9426 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009427 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009428 } finally {
9429 Binder.restoreCallingIdentity(identity);
9430 }
9431 }
9432
9433 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009434 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009435 final long identity = Binder.clearCallingIdentity();
9436 try {
9437 return UiccController.getInstance().getCardIdForDefaultEuicc();
9438 } finally {
9439 Binder.restoreCallingIdentity(identity);
9440 }
9441 }
9442
Pengquan Meng85728fb2018-03-12 16:31:21 -07009443 /**
goneil47ffb6e2018-04-06 15:40:58 -07009444 * A test API to reload the UICC profile.
9445 *
9446 * <p>Requires that the calling app has permission
9447 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9448 * @hide
9449 */
9450 @Override
9451 public void refreshUiccProfile(int subId) {
9452 enforceModifyPermission();
9453
9454 final long identity = Binder.clearCallingIdentity();
9455 try {
9456 Phone phone = getPhone(subId);
9457 if (phone == null) {
9458 return;
9459 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009460 UiccPort uiccPort = phone.getUiccPort();
9461 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009462 return;
9463 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009464 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009465 if (uiccProfile == null) {
9466 return;
9467 }
9468 uiccProfile.refresh();
9469 } finally {
9470 Binder.restoreCallingIdentity(identity);
9471 }
9472 }
9473
9474 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009475 * Returns false if the mobile data is disabled by default, otherwise return true.
9476 */
9477 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009478 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009479 }
9480
9481 /**
9482 * Returns true if the data roaming is enabled by default, i.e the system property
9483 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9484 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9485 */
9486 private boolean getDefaultDataRoamingEnabled(int subId) {
9487 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009488 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009489 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009490 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9491 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9492 return isDataRoamingEnabled;
9493 }
9494
9495 /**
9496 * Returns the default network type for the given {@code subId}, if the default network type is
9497 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9498 */
9499 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009500 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009501 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009502 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9503 return list.get(phoneId);
9504 }
9505 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009506 }
fionaxua13278b2018-03-21 00:08:13 -07009507
9508 @Override
9509 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009510 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009511 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009512
9513 final long identity = Binder.clearCallingIdentity();
9514 try {
9515 final Phone phone = getPhone(subId);
9516 if (phone == null) {
9517 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9518 return;
9519 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009520 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9521 if (cpt != null) {
9522 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9523 }
9524 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009525 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9526 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009527 if (carrierPrivilegeRules == null) {
9528 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9529 } else {
9530 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9531 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009532 } finally {
9533 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009534 }
fionaxua13278b2018-03-21 00:08:13 -07009535 }
9536
9537 @Override
9538 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009539 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009540
9541 final long identity = Binder.clearCallingIdentity();
9542 try {
9543 final Phone phone = getPhone(subId);
9544 if (phone == null) {
9545 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9546 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9547 }
9548 return phone.getCarrierIdListVersion();
9549 } finally {
9550 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009551 }
fionaxua13278b2018-03-21 00:08:13 -07009552 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009553
9554 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009555 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9556 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009557 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009558 mApp, subId, callingPackage, callingFeatureId,
9559 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009560 return -1;
9561 }
9562
9563 final long identity = Binder.clearCallingIdentity();
9564 try {
9565 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9566 } finally {
9567 Binder.restoreCallingIdentity(identity);
9568 }
9569 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009570
9571 @Override
9572 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009573 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009574 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009575 mApp, subId, "getCdmaRoamingMode");
9576
9577 final long identity = Binder.clearCallingIdentity();
9578 try {
9579 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9580 } finally {
9581 Binder.restoreCallingIdentity(identity);
9582 }
9583 }
9584
9585 @Override
9586 public boolean setCdmaRoamingMode(int subId, int mode) {
9587 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9588 mApp, subId, "setCdmaRoamingMode");
9589
9590 final long identity = Binder.clearCallingIdentity();
9591 try {
9592 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9593 } finally {
9594 Binder.restoreCallingIdentity(identity);
9595 }
9596 }
9597
9598 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009599 public int getCdmaSubscriptionMode(int subId) {
9600 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009601 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009602 mApp, subId, "getCdmaSubscriptionMode");
9603
9604 final long identity = Binder.clearCallingIdentity();
9605 try {
9606 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9607 } finally {
9608 Binder.restoreCallingIdentity(identity);
9609 }
9610 }
9611
9612 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009613 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9615 mApp, subId, "setCdmaSubscriptionMode");
9616
9617 final long identity = Binder.clearCallingIdentity();
9618 try {
9619 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9620 } finally {
9621 Binder.restoreCallingIdentity(identity);
9622 }
9623 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009624
sqianc5eccab2018-10-19 18:46:41 -07009625 @Override
sqian8c685422019-02-22 15:55:18 -08009626 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009627 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009628 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009629 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9630 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009631 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9632 }
9633 final long identity = Binder.clearCallingIdentity();
9634 try {
sqian854d44b2018-12-12 16:48:18 -08009635 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9636 for (Phone phone: PhoneFactory.getPhones()) {
9637 if (phone.getEmergencyNumberTracker() != null
9638 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9639 emergencyNumberListInternal.put(
9640 phone.getSubId(),
9641 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9642 }
sqian11b7a0e2018-12-05 18:48:28 -08009643 }
sqian854d44b2018-12-12 16:48:18 -08009644 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009645 } finally {
9646 Binder.restoreCallingIdentity(identity);
9647 }
sqianc5eccab2018-10-19 18:46:41 -07009648 }
9649
9650 @Override
sqian8c685422019-02-22 15:55:18 -08009651 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009652 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009653 if (!exactMatch) {
9654 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009655 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009656 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009657 }
9658 final long identity = Binder.clearCallingIdentity();
9659 try {
sqian854d44b2018-12-12 16:48:18 -08009660 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009661 //Note: we ignore passed in param exactMatch. We can remove it once
9662 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009663 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009664 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009665 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009666 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009667 }
sqian11b7a0e2018-12-05 18:48:28 -08009668 }
9669 return false;
9670 } finally {
9671 Binder.restoreCallingIdentity(identity);
9672 }
9673 }
9674
sqianf4ca7ed2019-01-15 18:32:07 -08009675 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009676 * Start emergency callback mode for GsmCdmaPhone for testing.
9677 */
9678 @Override
9679 public void startEmergencyCallbackMode() {
9680 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9681 "startEmergencyCallbackMode");
9682 enforceModifyPermission();
9683 final long identity = Binder.clearCallingIdentity();
9684 try {
9685 for (Phone phone : PhoneFactory.getPhones()) {
9686 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9687 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9688 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9689 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9690 gsmCdmaPhone.obtainMessage(
9691 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9692 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9693 }
9694 }
9695 } finally {
9696 Binder.restoreCallingIdentity(identity);
9697 }
9698 }
9699
9700 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009701 * Update emergency number list for test mode.
9702 */
9703 @Override
9704 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9705 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9706 "updateEmergencyNumberListTestMode");
9707
9708 final long identity = Binder.clearCallingIdentity();
9709 try {
9710 for (Phone phone: PhoneFactory.getPhones()) {
9711 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9712 if (tracker != null) {
9713 tracker.executeEmergencyNumberTestModeCommand(action, num);
9714 }
9715 }
9716 } finally {
9717 Binder.restoreCallingIdentity(identity);
9718 }
9719 }
9720
9721 /**
9722 * Get the full emergency number list for test mode.
9723 */
9724 @Override
9725 public List<String> getEmergencyNumberListTestMode() {
9726 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9727 "getEmergencyNumberListTestMode");
9728
9729 final long identity = Binder.clearCallingIdentity();
9730 try {
9731 Set<String> emergencyNumbers = new HashSet<>();
9732 for (Phone phone: PhoneFactory.getPhones()) {
9733 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9734 if (tracker != null) {
9735 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9736 emergencyNumbers.add(num.getNumber());
9737 }
9738 }
9739 }
9740 return new ArrayList<>(emergencyNumbers);
9741 } finally {
9742 Binder.restoreCallingIdentity(identity);
9743 }
9744 }
9745
chen xud6b45bd2018-10-30 22:27:10 -07009746 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009747 public int getEmergencyNumberDbVersion(int subId) {
9748 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9749
9750 final long identity = Binder.clearCallingIdentity();
9751 try {
9752 final Phone phone = getPhone(subId);
9753 if (phone == null) {
9754 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9755 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9756 }
9757 return phone.getEmergencyNumberDbVersion();
9758 } finally {
9759 Binder.restoreCallingIdentity(identity);
9760 }
9761 }
9762
9763 @Override
9764 public void notifyOtaEmergencyNumberDbInstalled() {
9765 enforceModifyPermission();
9766
9767 final long identity = Binder.clearCallingIdentity();
9768 try {
9769 for (Phone phone: PhoneFactory.getPhones()) {
9770 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9771 if (tracker != null) {
9772 tracker.updateOtaEmergencyNumberDatabase();
9773 }
9774 }
9775 } finally {
9776 Binder.restoreCallingIdentity(identity);
9777 }
9778 }
9779
9780 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009781 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009782 enforceActiveEmergencySessionPermission();
9783
9784 final long identity = Binder.clearCallingIdentity();
9785 try {
9786 for (Phone phone: PhoneFactory.getPhones()) {
9787 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9788 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009789 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9790 }
9791 }
9792 } finally {
9793 Binder.restoreCallingIdentity(identity);
9794 }
9795 }
9796
9797 @Override
9798 public void resetOtaEmergencyNumberDbFilePath() {
9799 enforceActiveEmergencySessionPermission();
9800
9801 final long identity = Binder.clearCallingIdentity();
9802 try {
9803 for (Phone phone: PhoneFactory.getPhones()) {
9804 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9805 if (tracker != null) {
9806 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009807 }
9808 }
9809 } finally {
9810 Binder.restoreCallingIdentity(identity);
9811 }
9812 }
9813
9814 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009815 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9816 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9817 Phone phone = getPhone(subId);
9818 if (phone == null) {
9819 return null;
9820 }
9821 final long identity = Binder.clearCallingIdentity();
9822 try {
9823 UiccProfile profile = UiccController.getInstance()
9824 .getUiccProfileForPhone(phone.getPhoneId());
9825 if (profile != null) {
9826 return profile.getCertsFromCarrierPrivilegeAccessRules();
9827 }
9828 } finally {
9829 Binder.restoreCallingIdentity(identity);
9830 }
9831 return null;
9832 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009833
9834 /**
9835 * Enable or disable a modem stack.
9836 */
9837 @Override
9838 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9839 enforceModifyPermission();
9840
9841 final long identity = Binder.clearCallingIdentity();
9842 try {
9843 Phone phone = PhoneFactory.getPhone(slotIndex);
9844 if (phone == null) {
9845 return false;
9846 } else {
9847 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9848 }
9849 } finally {
9850 Binder.restoreCallingIdentity(identity);
9851 }
9852 }
Michelecea4cf22018-12-21 15:00:11 -08009853
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009854 /**
9855 * Whether a modem stack is enabled or not.
9856 */
9857 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009858 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9859 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009860 Phone phone = PhoneFactory.getPhone(slotIndex);
9861 if (phone == null) return false;
9862
9863 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009864 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9865 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009866 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9867 }
9868
9869 final long identity = Binder.clearCallingIdentity();
9870 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009871 try {
9872 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9873 } catch (NoSuchElementException ex) {
9874 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9875 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009876 } finally {
9877 Binder.restoreCallingIdentity(identity);
9878 }
9879 }
9880
Michelecea4cf22018-12-21 15:00:11 -08009881 @Override
Michele0ea7d782019-03-19 14:58:42 -07009882 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009883 enforceModifyPermission();
9884
9885 final long identity = Binder.clearCallingIdentity();
9886 try {
9887 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009888 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009889 .commit();
9890 } finally {
9891 Binder.restoreCallingIdentity(identity);
9892 }
9893 }
9894
9895 @Override
Michele0ea7d782019-03-19 14:58:42 -07009896 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009897 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009898 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009899 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9900 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009901 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009902 }
Michelecea4cf22018-12-21 15:00:11 -08009903
9904 final long identity = Binder.clearCallingIdentity();
9905 try {
Michele0ea7d782019-03-19 14:58:42 -07009906 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009907 } finally {
9908 Binder.restoreCallingIdentity(identity);
9909 }
9910 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009911
Michele0ea7d782019-03-19 14:58:42 -07009912 @TelephonyManager.IsMultiSimSupportedResult
9913 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009914 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9915 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9916 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009917 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9918 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009919 }
9920 // Check if the hardware supports multisim functionality. If usage of multisim is not
9921 // supported by the modem, indicate that it is restricted.
9922 PhoneCapability staticCapability =
9923 mPhoneConfigurationManager.getStaticPhoneCapability();
9924 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009925 loge("isMultiSimSupportedInternal: no static configuration available");
9926 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009927 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009928 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009929 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9930 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009931 }
9932 // Check if support of multiple SIMs is restricted by carrier
9933 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009934 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009935 }
9936
Michele0ea7d782019-03-19 14:58:42 -07009937 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009938 }
9939
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009940 /**
9941 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009942 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9943 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9944 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009945 * @param numOfSims number of active sims we want to switch to
9946 */
9947 @Override
9948 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009949 if (numOfSims == 1) {
9950 enforceModifyPermission();
9951 } else {
9952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9953 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9954 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009955 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009956
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009957 try {
Michele30b57b22019-03-01 12:01:14 -08009958 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009959 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009960 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9961 return;
9962 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009963 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9964 } finally {
9965 Binder.restoreCallingIdentity(identity);
9966 }
9967 }
9968
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009969 @Override
9970 public boolean isApplicationOnUicc(int subId, int appType) {
9971 enforceReadPrivilegedPermission("isApplicationOnUicc");
9972 Phone phone = getPhone(subId);
9973 if (phone == null) {
9974 return false;
9975 }
9976 final long identity = Binder.clearCallingIdentity();
9977 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009978 UiccPort uiccPort = phone.getUiccPort();
9979 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009980 return false;
9981 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009982 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009983 if (uiccProfile == null) {
9984 return false;
9985 }
9986 if (TelephonyManager.APPTYPE_SIM <= appType
9987 && appType <= TelephonyManager.APPTYPE_ISIM) {
9988 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9989 }
9990 return false;
9991 } finally {
9992 Binder.restoreCallingIdentity(identity);
9993 }
9994 }
9995
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009996 /**
chen xub4baa772019-04-03 10:23:41 -07009997 * Get whether making changes to modem configurations will trigger reboot.
9998 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009999 */
10000 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010001 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10002 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010003 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010004 mApp, subId, callingPackage, callingFeatureId,
10005 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010006 return false;
10007 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010008 final long identity = Binder.clearCallingIdentity();
10009 try {
10010 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10011 } finally {
10012 Binder.restoreCallingIdentity(identity);
10013 }
10014 }
10015
Nathan Harold29f5f052019-02-15 13:41:57 -080010016 private void updateModemStateMetrics() {
10017 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10018 // TODO: check the state for each modem if the api is ready.
10019 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10020 }
10021
Pengquan Meng3889a572019-01-23 11:16:29 -080010022 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010023 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010024 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010025 // Verify that the callingPackage belongs to the calling UID
10026 mApp.getSystemService(AppOpsManager.class)
10027 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010028 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010029 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010030 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010031 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10032 if (slotInfos != null) {
10033 for (int i = 0; i < slotInfos.length; i++) {
10034 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10035 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10036 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10037 portInfo.getLogicalSlotIndex()));
10038 }
10039 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010040 }
10041 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010042 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010043 } finally {
10044 Binder.restoreCallingIdentity(identity);
10045 }
10046 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010047
10048 /**
10049 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010050 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010051 */
jimsunf9ec1622022-09-13 21:18:43 +080010052 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010053 @Override
10054 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010055 return getHalVersion(HAL_SERVICE_RADIO);
10056 }
10057
10058 /**
10059 * Get the HAL Version of a specific service
10060 */
10061 @Override
10062 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010063 Phone phone = getDefaultPhone();
10064 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010065 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010066 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10067 return hv.major * 100 + hv.minor;
10068 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010069
10070 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010071 * Get the current calling package name.
10072 * @return the current calling package name
10073 */
10074 @Override
10075 public String getCurrentPackageName() {
10076 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10077 }
10078
10079 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010080 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10081 * corresponding network requests on a subId.
10082 *
10083 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010084 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010085 * 2) APN is un-metered for this subscription, or
10086 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010087 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010088 *
10089 * @return whether data is allowed for a apn type.
10090 *
10091 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010092 */
10093 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010094 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010095 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10096 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010097
10098 // Now that all security checks passes, perform the operation as ourselves.
10099 final long identity = Binder.clearCallingIdentity();
10100 try {
10101 Phone phone = getPhone(subId);
10102 if (phone == null) return false;
10103
Jack Yu27422a52022-03-21 10:38:05 -070010104 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010105 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010106 isMetered = phone.getDataNetworkController().getDataConfigManager()
10107 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10108 phone.getServiceState().getDataRoaming());
10109 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010110 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010111 } finally {
10112 Binder.restoreCallingIdentity(identity);
10113 }
10114 }
10115
10116 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010117 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010118 enforceReadPrivilegedPermission("isApnMetered");
10119
10120 // Now that all security checks passes, perform the operation as ourselves.
10121 final long identity = Binder.clearCallingIdentity();
10122 try {
10123 Phone phone = getPhone(subId);
10124 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010125 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10126 DataUtils.apnTypeToNetworkCapability(apnType),
10127 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010128 } finally {
10129 Binder.restoreCallingIdentity(identity);
10130 }
10131 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010132
10133 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010134 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10135 int subscriptionId, IBooleanConsumer resultCallback) {
10136 enforceModifyPermission();
10137 long token = Binder.clearCallingIdentity();
10138 try {
10139 Phone phone = getPhone(subscriptionId);
10140 if (phone == null) {
10141 try {
10142 if (resultCallback != null) {
10143 resultCallback.accept(false);
10144 }
10145 } catch (RemoteException e) {
10146 // ignore
10147 }
10148 return;
10149 }
10150 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10151 Pair.create(specifiers, (x) -> {
10152 try {
10153 if (resultCallback != null) {
10154 resultCallback.accept(x);
10155 }
10156 } catch (RemoteException e) {
10157 // ignore
10158 }
10159 });
10160 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10161 } finally {
10162 Binder.restoreCallingIdentity(token);
10163 }
10164 }
10165
10166 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010167 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10168 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010169 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010170 mApp, subId, "getSystemSelectionChannels");
10171 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10172 final long identity = Binder.clearCallingIdentity();
10173 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010174 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10175 if (result instanceof IllegalStateException) {
10176 throw (IllegalStateException) result;
10177 }
10178 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010179 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10180 return specifiers;
10181 } finally {
10182 Binder.restoreCallingIdentity(identity);
10183 }
10184 }
10185
10186 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010187 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010188 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010189 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010190 }
10191
10192 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010193 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10194 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010195 if (callingPackage == null) {
10196 callingPackage = getCurrentPackageName();
10197 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010198 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10199 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010200 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10201 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010202 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10203 }
10204 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10205 Intent intent = new Intent();
10206 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10207 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10208 // Bring up choose default SMS subscription dialog right now
10209 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10210 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10211 mApp.startActivity(intent);
10212 }
chen xud5ca2d52019-05-28 15:20:57 -070010213
10214 @Override
10215 public String getMmsUAProfUrl(int subId) {
10216 //TODO investigate if this API should require proper permission check in R b/133791609
10217 final long identity = Binder.clearCallingIdentity();
10218 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010219 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10220 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10221 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10222 return carrierUAProfUrl;
10223 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010224 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10225 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010226 } finally {
10227 Binder.restoreCallingIdentity(identity);
10228 }
10229 }
10230
10231 @Override
10232 public String getMmsUserAgent(int subId) {
10233 //TODO investigate if this API should require proper permission check in R b/133791609
10234 final long identity = Binder.clearCallingIdentity();
10235 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010236 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10237 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10238 if (!TextUtils.isEmpty(carrierUserAgent)) {
10239 return carrierUserAgent;
10240 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010241 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10242 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010243 } finally {
10244 Binder.restoreCallingIdentity(identity);
10245 }
10246 }
Jack Yub07d4972019-05-28 16:12:25 -070010247
10248 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010249 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10250 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010251
Jack Yub07d4972019-05-28 16:12:25 -070010252 final long identity = Binder.clearCallingIdentity();
10253 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010254 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010255 if (phone == null) return false;
10256
Ling Maf188d502022-09-16 15:22:36 -070010257 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010258 } finally {
10259 Binder.restoreCallingIdentity(identity);
10260 }
10261 }
10262
10263 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010264 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010265 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010266 enforceModifyPermission();
10267
changbettyd5c246e2019-12-24 15:40:37 +080010268 final long identity = Binder.clearCallingIdentity();
10269 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010270 Phone phone = getPhone(subscriptionId);
10271 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010272
Ling Maf188d502022-09-16 15:22:36 -070010273 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010274 } finally {
10275 Binder.restoreCallingIdentity(identity);
10276 }
10277 }
10278
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010279 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010280 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010281 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10282 * otherwise.
10283 */
10284 @Override
10285 public void setCepEnabled(boolean isCepEnabled) {
10286 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10287
10288 final long identity = Binder.clearCallingIdentity();
10289 try {
10290 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10291 for (Phone phone : PhoneFactory.getPhones()) {
10292 Phone defaultPhone = phone.getImsPhone();
10293 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10294 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10295 ImsPhoneCallTracker imsPhoneCallTracker =
10296 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10297 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10298 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10299 + imsPhone.getMsisdn());
10300 }
10301 }
10302 } finally {
10303 Binder.restoreCallingIdentity(identity);
10304 }
10305 }
allenwtsu46dcc572020-01-08 18:24:03 +080010306
10307 /**
10308 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10309 *
10310 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10311 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10312 * before being read.
10313 */
10314 @Override
10315 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10316 isCompressed) {
10317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10318 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010319 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10320 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10321 }
10322 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010323 // ProvisioningManager can not handle ServiceSpecificException.
10324 // Throw the IllegalStateException and annotate ProvisioningManager.
10325 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010326 }
10327
10328 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010329 try {
Hui Wang761a6682020-10-31 05:12:53 +000010330 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10331 } finally {
10332 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010333 }
10334 }
zoey chene02881a2019-12-30 16:11:23 +080010335
10336 @Override
10337 public boolean isIccLockEnabled(int subId) {
10338 enforceReadPrivilegedPermission("isIccLockEnabled");
10339
10340 // Now that all security checks passes, perform the operation as ourselves.
10341 final long identity = Binder.clearCallingIdentity();
10342 try {
10343 Phone phone = getPhone(subId);
10344 if (phone != null && phone.getIccCard() != null) {
10345 return phone.getIccCard().getIccLockEnabled();
10346 } else {
10347 return false;
10348 }
10349 } finally {
10350 Binder.restoreCallingIdentity(identity);
10351 }
10352 }
10353
10354 /**
10355 * Set the ICC pin lock enabled or disabled.
10356 *
10357 * @return an integer representing the status of IccLock enabled or disabled in the following
10358 * three cases:
10359 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10360 * successfully.
10361 * - Positive number and zero for remaining password attempts.
10362 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10363 *
10364 */
10365 @Override
10366 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10367 enforceModifyPermission();
10368
10369 Phone phone = getPhone(subId);
10370 if (phone == null) {
10371 return 0;
10372 }
10373 // Now that all security checks passes, perform the operation as ourselves.
10374 final long identity = Binder.clearCallingIdentity();
10375 try {
10376 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10377 new Pair<Boolean, String>(enabled, password), phone, null);
10378 return attemptsRemaining;
10379
10380 } catch (Exception e) {
10381 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10382 } finally {
10383 Binder.restoreCallingIdentity(identity);
10384 }
10385 return 0;
10386 }
10387
10388 /**
10389 * Change the ICC password used in ICC pin lock.
10390 *
10391 * @return an integer representing the status of IccLock changed in the following three cases:
10392 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10393 * - Positive number and zero for remaining password attempts.
10394 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10395 *
10396 */
10397 @Override
10398 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10399 enforceModifyPermission();
10400
10401 Phone phone = getPhone(subId);
10402 if (phone == null) {
10403 return 0;
10404 }
10405 // Now that all security checks passes, perform the operation as ourselves.
10406 final long identity = Binder.clearCallingIdentity();
10407 try {
10408 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10409 new Pair<String, String>(oldPassword, newPassword), phone, null);
10410 return attemptsRemaining;
10411
10412 } catch (Exception e) {
10413 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10414 } finally {
10415 Binder.restoreCallingIdentity(identity);
10416 }
10417 return 0;
10418 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010419
10420 /**
10421 * Request for receiving user activity notification
10422 */
10423 @Override
10424 public void requestUserActivityNotification() {
10425 if (!mNotifyUserActivity.get()
10426 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10427 mNotifyUserActivity.set(true);
10428 }
10429 }
10430
10431 /**
10432 * Called when userActivity is signalled in the power manager.
10433 * This is safe to call from any thread, with any window manager locks held or not.
10434 */
10435 @Override
10436 public void userActivity() {
10437 // ***************************************
10438 // * Inherited from PhoneWindowManager *
10439 // ***************************************
10440 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10441 // WITH ITS LOCKS HELD.
10442 //
10443 // This code must be VERY careful about the locks
10444 // it acquires.
10445 // In fact, the current code acquires way too many,
10446 // and probably has lurking deadlocks.
10447
10448 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10449 throw new SecurityException("Only the OS may call notifyUserActivity()");
10450 }
10451
10452 if (mNotifyUserActivity.getAndSet(false)) {
10453 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10454 USER_ACTIVITY_NOTIFICATION_DELAY);
10455 }
10456 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010457
10458 @Override
10459 public boolean canConnectTo5GInDsdsMode() {
10460 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10461 }
Jack Yud10cdd42020-09-28 20:28:01 -070010462
10463 @Override
10464 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10465 String callingFeatureId) {
10466 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10467 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10468 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10469 }
10470
10471 Phone phone = getPhone(subId);
10472 if (phone == null) {
10473 throw new RuntimeException("phone is not available");
10474 }
10475 // Now that all security checks passes, perform the operation as ourselves.
10476 final long identity = Binder.clearCallingIdentity();
10477 try {
10478 return phone.getEquivalentHomePlmns();
10479 } finally {
10480 Binder.restoreCallingIdentity(identity);
10481 }
10482 }
Daniel Bright59e67312020-11-13 11:49:37 -080010483
10484 @Override
10485 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010486 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10487 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010488 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010489 if (radioInterfaceCapabilities == null) {
10490 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010491 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010492 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010493 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010494
Hui Wang641e81c2020-10-12 12:14:23 -070010495 @Override
10496 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10497 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010498 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10499 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10500 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10501 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10502 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010503 if (DBG) {
10504 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10505 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10506 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10507 }
10508
10509 if (!SubscriptionManager.isValidSubscriptionId(subId)
10510 || appType < TelephonyManager.APPTYPE_UNKNOWN
10511 || appType > TelephonyManager.APPTYPE_ISIM
10512 || nafUrl == null || securityProtocol == null || callback == null) {
10513 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10514 if (callback != null) {
10515 try {
10516 callback.onAuthenticationFailure(
10517 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10518 } catch (RemoteException exception) {
10519 log("Fail to notify onAuthenticationFailure due to " + exception);
10520 }
10521 return;
10522 }
10523 }
10524
10525 final long token = Binder.clearCallingIdentity();
10526 try {
10527 getGbaManager(subId).bootstrapAuthenticationRequest(
10528 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10529 forceBootStrapping, callback));
10530 } finally {
10531 Binder.restoreCallingIdentity(token);
10532 }
10533 }
10534
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010535 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010536 * Attempts to set the radio power state for all phones for thermal reason.
10537 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010538 * requested radio power state will actually be set. See {@link
10539 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10540 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010541 * @param enable {@code true} if trying to turn radio on.
10542 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10543 * false}.
10544 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010545 private boolean setRadioPowerForThermal(boolean enable) {
10546 boolean isPhoneAvailable = false;
10547 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10548 Phone phone = PhoneFactory.getPhone(i);
10549 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010550 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010551 isPhoneAvailable = true;
10552 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010553 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010554
10555 // return true if successfully informed the phone object about the thermal radio power
10556 // request.
10557 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010558 }
10559
10560 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010561 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010562 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10563 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10564 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10565 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10566 throw new IllegalArgumentException("modem does not support data throttling");
10567 }
10568
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010569 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10570 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010571 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010572 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10573 }
10574
Sarah Chinecc78c42022-03-31 21:16:48 -070010575 setDataEnabledForReason(
10576 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010577
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010578 if (isDataThrottlingSupported) {
10579 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010580 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010581 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10582 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10583 } else if (thermalMitigationResult
10584 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010585 log("Modem likely does not support data throttling on secondary carrier. Data " +
10586 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10587 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010588 }
10589 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010590 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010591
10592 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010593 }
10594
Jack Nudelman644b91a2021-03-12 14:09:48 -080010595 private static List<String> getThermalMitigationAllowlist(Context context) {
10596 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10597 for (String pckg : context.getResources()
10598 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10599 sThermalMitigationAllowlistedPackages.add(pckg);
10600 }
10601 }
10602
10603 return sThermalMitigationAllowlistedPackages;
10604 }
10605
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010606 private boolean isAnyPhoneInEmergencyState() {
10607 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10608 if (tm.isInEmergencyCall()) {
10609 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10610 return true;
10611 }
10612 for (Phone phone : PhoneFactory.getPhones()) {
10613 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10614 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10615 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10616 + phone.isInEcm());
10617 return true;
10618 }
10619 }
10620
10621 return false;
10622 }
10623
Jack Nudelman644b91a2021-03-12 14:09:48 -080010624 /**
10625 * Used by shell commands to add an authorized package name for thermal mitigation.
10626 * @param packageName name of package to be allowlisted
10627 * @param context
10628 */
10629 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10630 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10631 sThermalMitigationAllowlistedPackages.add(packageName);
10632 }
10633
10634 /**
10635 * Used by shell commands to remove an authorized package name for thermal mitigation.
10636 * @param packageName name of package to remove from allowlist
10637 * @param context
10638 */
10639 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10640 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10641 sThermalMitigationAllowlistedPackages.remove(packageName);
10642 }
10643
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010644 /**
10645 * Thermal mitigation request to control functionalities at modem.
10646 *
10647 * @param subId the id of the subscription.
10648 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010649 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010650 *
10651 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10652 */
10653 @Override
10654 @ThermalMitigationResult
10655 public int sendThermalMitigationRequest(
10656 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010657 ThermalMitigationRequest thermalMitigationRequest,
10658 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010659 enforceModifyPermission();
10660
Jack Nudelman644b91a2021-03-12 14:09:48 -080010661 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10662 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10663 .contains(callingPackage)) {
10664 throw new SecurityException("Calling package must be configured in the device config. "
10665 + "calling package: " + callingPackage);
10666 }
10667
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010668 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10669 final long identity = Binder.clearCallingIdentity();
10670
10671 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10672 try {
10673 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10674 switch (thermalMitigationAction) {
10675 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10676 thermalMitigationResult =
10677 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010678 thermalMitigationRequest.getDataThrottlingRequest(),
10679 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010680 break;
10681 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10682 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10683 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10684 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10685 }
10686
10687 // Ensure that radio is on. If not able to power on due to phone being
10688 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010689 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010690 thermalMitigationResult =
10691 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10692 break;
10693 }
10694
10695 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010696 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010697 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10698 break;
10699 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10700 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10701 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10702 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10703 }
10704
10705 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10706 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010707 Phone phone = getPhone(subId);
10708 if (phone == null) {
10709 thermalMitigationResult =
10710 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10711 break;
10712 }
10713
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010714 TelephonyConnectionService service =
10715 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010716 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010717 Log.e(LOG_TAG, "An emergency call is pending");
10718 thermalMitigationResult =
10719 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10720 break;
10721 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010722 thermalMitigationResult =
10723 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10724 break;
10725 }
10726 } else {
10727 thermalMitigationResult =
10728 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10729 break;
10730 }
10731
10732 // Turn radio off. If not able to power off due to phone being unavailable,
10733 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010734 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010735 thermalMitigationResult =
10736 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10737 break;
10738 }
10739 thermalMitigationResult =
10740 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10741 break;
10742 default:
10743 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10744 + "not exist. Requested action: " + thermalMitigationAction);
10745 }
10746 } catch (IllegalArgumentException e) {
10747 throw e;
10748 } catch (Exception e) {
10749 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10750 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10751 } finally {
10752 Binder.restoreCallingIdentity(identity);
10753 }
10754
10755 if (DBG) {
10756 log("thermalMitigationRequest returning with thermalMitigationResult: "
10757 + thermalMitigationResult);
10758 }
10759
10760 return thermalMitigationResult;
10761 }
Hui Wang641e81c2020-10-12 12:14:23 -070010762
10763 /**
10764 * Set the GbaService Package Name that Telephony will bind to.
10765 *
10766 * @param subId The sim that the GbaService is associated with.
10767 * @param packageName The name of the package to be replaced with.
10768 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10769 */
10770 @Override
10771 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10772 enforceModifyPermission();
10773
10774 final long identity = Binder.clearCallingIdentity();
10775 try {
10776 return getGbaManager(subId).overrideServicePackage(packageName);
10777 } finally {
10778 Binder.restoreCallingIdentity(identity);
10779 }
10780 }
10781
10782 /**
10783 * Return the package name of the currently bound GbaService.
10784 *
10785 * @param subId The sim that the GbaService is associated with.
10786 * @return the package name of the GbaService configuration, null if GBA is not supported.
10787 */
10788 @Override
10789 public String getBoundGbaService(int subId) {
10790 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10791
10792 final long identity = Binder.clearCallingIdentity();
10793 try {
10794 return getGbaManager(subId).getServicePackage();
10795 } finally {
10796 Binder.restoreCallingIdentity(identity);
10797 }
10798 }
10799
10800 /**
10801 * Set the release time for telephony to unbind GbaService.
10802 *
10803 * @param subId The sim that the GbaService is associated with.
10804 * @param interval The release time to unbind GbaService by millisecond.
10805 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10806 */
10807 @Override
10808 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10809 enforceModifyPermission();
10810
10811 final long identity = Binder.clearCallingIdentity();
10812 try {
10813 return getGbaManager(subId).overrideReleaseTime(interval);
10814 } finally {
10815 Binder.restoreCallingIdentity(identity);
10816 }
10817 }
10818
10819 /**
10820 * Return the release time for telephony to unbind GbaService.
10821 *
10822 * @param subId The sim that the GbaService is associated with.
10823 * @return The release time to unbind GbaService by millisecond.
10824 */
10825 @Override
10826 public int getGbaReleaseTime(int subId) {
10827 enforceReadPrivilegedPermission("getGbaReleaseTime");
10828
10829 final long identity = Binder.clearCallingIdentity();
10830 try {
10831 return getGbaManager(subId).getReleaseTime();
10832 } finally {
10833 Binder.restoreCallingIdentity(identity);
10834 }
10835 }
10836
10837 private GbaManager getGbaManager(int subId) {
10838 GbaManager instance = GbaManager.getInstance(subId);
10839 if (instance == null) {
10840 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10841 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10842 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10843 }
10844 return instance;
10845 }
Hui Wang761a6682020-10-31 05:12:53 +000010846
10847 /**
10848 * indicate whether the device and the carrier can support
10849 * RCS VoLTE single registration.
10850 */
10851 @Override
10852 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010853 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10854 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10855 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10856 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010857
10858 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10859 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10860 }
10861
10862 final long identity = Binder.clearCallingIdentity();
10863 try {
10864 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10865 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010866 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10867 if (isCapable != null) {
10868 return isCapable;
10869 }
Hui Wang761a6682020-10-31 05:12:53 +000010870 }
Hui Wang67af90e2021-06-04 16:57:15 -070010871 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10872 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010873 } finally {
10874 Binder.restoreCallingIdentity(identity);
10875 }
10876 }
10877
10878 /**
10879 * Register RCS provisioning callback.
10880 */
10881 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010882 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010883 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010884 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010885 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010886 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10887 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010888
10889 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10890 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10891 }
10892 if (!isImsAvailableOnDevice()) {
10893 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10894 "IMS not available on device.");
10895 }
10896
10897 final long identity = Binder.clearCallingIdentity();
10898 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010899 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010900 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010901 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10902 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010903 }
Hui Wang761a6682020-10-31 05:12:53 +000010904 } finally {
10905 Binder.restoreCallingIdentity(identity);
10906 }
10907 }
10908
10909 /**
10910 * Unregister RCS provisioning callback.
10911 */
10912 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010913 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010914 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010915 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010916 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010917 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10918 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010919
10920 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10921 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10922 }
10923 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010924 // operation failed silently
10925 Rlog.w(LOG_TAG, "IMS not available on device.");
10926 return;
Hui Wang761a6682020-10-31 05:12:53 +000010927 }
10928
10929 final long identity = Binder.clearCallingIdentity();
10930 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010931 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010932 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010933 } finally {
10934 Binder.restoreCallingIdentity(identity);
10935 }
10936 }
10937
10938 /**
10939 * trigger RCS reconfiguration.
10940 */
10941 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010942 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10943 "triggerRcsReconfiguration",
10944 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010945
10946 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10947 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10948 }
10949 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010950 // ProvisioningManager can not handle ServiceSpecificException.
10951 // Throw the IllegalStateException and annotate ProvisioningManager.
10952 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010953 }
10954
10955 final long identity = Binder.clearCallingIdentity();
10956 try {
10957 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10958 } finally {
10959 Binder.restoreCallingIdentity(identity);
10960 }
10961 }
10962
10963 /**
10964 * Provide the client configuration parameters of the RCS application.
10965 */
10966 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010967 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10968 "setRcsClientConfiguration",
10969 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010970
10971 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10972 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10973 }
10974 if (!isImsAvailableOnDevice()) {
10975 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10976 "IMS not available on device.");
10977 }
10978
10979 final long identity = Binder.clearCallingIdentity();
10980
10981 try {
10982 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10983 if (configBinder == null) {
10984 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010985 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10986 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010987 } else {
10988 configBinder.setRcsClientConfiguration(rcc);
10989 }
joonhunshin3e154242021-09-17 06:33:39 +000010990
10991 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10992 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010993 } catch (RemoteException e) {
10994 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010995 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10996 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010997 } finally {
10998 Binder.restoreCallingIdentity(identity);
10999 }
11000 }
11001
11002 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011003 * Enables or disables the test mode for RCS VoLTE single registration.
11004 */
11005 @Override
11006 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11007 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11008 "setRcsSingleRegistrationTestModeEnabled");
11009
11010 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11011 }
11012
11013 /**
11014 * Gets the test mode for RCS VoLTE single registration.
11015 */
11016 @Override
11017 public boolean getRcsSingleRegistrationTestModeEnabled() {
11018 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11019 "getRcsSingleRegistrationTestModeEnabled");
11020
11021 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11022 }
11023
11024 /**
Hui Wang761a6682020-10-31 05:12:53 +000011025 * Overrides the config of RCS VoLTE single registration enabled for the device.
11026 */
11027 @Override
11028 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11029 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11030 "setDeviceSingleRegistrationEnabledOverride");
11031 enforceModifyPermission();
11032
11033 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11034 : Boolean.parseBoolean(enabledStr);
11035 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011036 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011037 }
11038
11039 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011040 * Sends a device to device communication message. Only usable via shell.
11041 * @param message message to send.
11042 * @param value message value.
11043 */
11044 @Override
11045 public void sendDeviceToDeviceMessage(int message, int value) {
11046 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011047 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011048 enforceModifyPermission();
11049
11050 final long identity = Binder.clearCallingIdentity();
11051 try {
11052 TelephonyConnectionService service =
11053 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11054 if (service == null) {
11055 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11056 return;
11057 }
11058 service.sendTestDeviceToDeviceMessage(message, value);
11059 } finally {
11060 Binder.restoreCallingIdentity(identity);
11061 }
11062 }
11063
Tyler Gunnbabbda02021-02-10 11:05:02 -080011064 /**
11065 * Sets the specified device to device transport active.
11066 * @param transport The transport to set active.
11067 */
11068 @Override
11069 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11070 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11071 "setActiveDeviceToDeviceTransport");
11072 enforceModifyPermission();
11073
11074 final long identity = Binder.clearCallingIdentity();
11075 try {
11076 TelephonyConnectionService service =
11077 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11078 if (service == null) {
11079 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11080 return;
11081 }
11082 service.setActiveDeviceToDeviceTransport(transport);
11083 } finally {
11084 Binder.restoreCallingIdentity(identity);
11085 }
11086 }
Tyler Gunn92479152021-01-20 16:30:10 -080011087
Tyler Gunnd4339262021-05-03 14:46:49 -070011088 @Override
11089 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11090 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11091 "setDeviceToDeviceForceEnabled");
11092
11093 final long identity = Binder.clearCallingIdentity();
11094 try {
11095 Arrays.stream(PhoneFactory.getPhones()).forEach(
11096 p -> {
11097 Phone thePhone = p.getImsPhone();
11098 if (thePhone != null && thePhone instanceof ImsPhone) {
11099 ImsPhone imsPhone = (ImsPhone) thePhone;
11100 CallTracker tracker = imsPhone.getCallTracker();
11101 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11102 ImsPhoneCallTracker imsPhoneCallTracker =
11103 (ImsPhoneCallTracker) tracker;
11104 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11105 }
11106 }
11107 }
11108 );
11109 } finally {
11110 Binder.restoreCallingIdentity(identity);
11111 }
11112 }
11113
Tyler Gunn92479152021-01-20 16:30:10 -080011114 /**
Hui Wang761a6682020-10-31 05:12:53 +000011115 * Gets the config of RCS VoLTE single registration enabled for the device.
11116 */
11117 @Override
11118 public boolean getDeviceSingleRegistrationEnabled() {
11119 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11120 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11121 }
11122
11123 /**
11124 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11125 */
11126 @Override
11127 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11128 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11129 "setCarrierSingleRegistrationEnabledOverride");
11130 enforceModifyPermission();
11131
11132 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11133 : Boolean.parseBoolean(enabledStr);
11134 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11135 subId, enabled);
11136 }
11137
11138 /**
11139 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11140 */
11141 @Override
11142 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11143 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11144 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11145 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011146
11147 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011148 * Overrides the ims feature validation result
11149 */
11150 @Override
11151 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11152 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11153 "setImsFeatureValidationOverride");
11154
11155 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11156 : Boolean.parseBoolean(enabledStr);
11157 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11158 subId, enabled);
11159 }
11160
11161 /**
11162 * Gets the ims feature validation override value
11163 */
11164 @Override
11165 public boolean getImsFeatureValidationOverride(int subId) {
11166 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11167 "getImsFeatureValidationOverride");
11168 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11169 }
11170
11171 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011172 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11173 * their mobile plan.
11174 */
11175 @Override
11176 public String getMobileProvisioningUrl() {
11177 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11178 final long identity = Binder.clearCallingIdentity();
11179 try {
11180 return getDefaultPhone().getMobileProvisioningUrl();
11181 } finally {
11182 Binder.restoreCallingIdentity(identity);
11183 }
11184 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011185
James.cf Linbcdf8b32021-01-14 16:44:13 +080011186 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011187 * Get the EAB contact from the EAB database.
11188 */
11189 @Override
11190 public String getContactFromEab(String contact) {
11191 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11192 enforceModifyPermission();
11193 final long identity = Binder.clearCallingIdentity();
11194 try {
11195 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11196 } finally {
11197 Binder.restoreCallingIdentity(identity);
11198 }
11199 }
11200
11201 /**
Calvin Pana1434322021-07-01 19:27:01 +080011202 * Get the EAB capability from the EAB database.
11203 */
11204 @Override
11205 public String getCapabilityFromEab(String contact) {
11206 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11207 enforceModifyPermission();
11208 final long identity = Binder.clearCallingIdentity();
11209 try {
11210 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11211 } finally {
11212 Binder.restoreCallingIdentity(identity);
11213 }
11214 }
11215
11216 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011217 * Remove the EAB contacts from the EAB database.
11218 */
11219 @Override
11220 public int removeContactFromEab(int subId, String contacts) {
11221 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11222 enforceModifyPermission();
11223 final long identity = Binder.clearCallingIdentity();
11224 try {
11225 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11226 } finally {
11227 Binder.restoreCallingIdentity(identity);
11228 }
11229 }
11230
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011231 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011232 public boolean getDeviceUceEnabled() {
11233 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11234 final long identity = Binder.clearCallingIdentity();
11235 try {
11236 return mApp.getDeviceUceEnabled();
11237 } finally {
11238 Binder.restoreCallingIdentity(identity);
11239 }
11240 }
11241
11242 @Override
11243 public void setDeviceUceEnabled(boolean isEnabled) {
11244 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11245 final long identity = Binder.clearCallingIdentity();
11246 try {
11247 mApp.setDeviceUceEnabled(isEnabled);
11248 } finally {
11249 Binder.restoreCallingIdentity(identity);
11250 }
11251 }
11252
Brad Ebinger14d467f2021-02-12 06:18:28 +000011253 /**
11254 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11255 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11256 */
11257 // Used for SHELL command only right now.
11258 @Override
11259 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11260 List<String> featureTags) {
11261 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11262 "addUceRegistrationOverrideShell");
11263 final long identity = Binder.clearCallingIdentity();
11264 try {
11265 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11266 new ArraySet<>(featureTags));
11267 } catch (ImsException e) {
11268 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11269 } finally {
11270 Binder.restoreCallingIdentity(identity);
11271 }
11272 }
11273
11274 /**
11275 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11276 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11277 */
11278 // Used for SHELL command only right now.
11279 @Override
11280 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11281 List<String> featureTags) {
11282 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11283 "removeUceRegistrationOverrideShell");
11284 final long identity = Binder.clearCallingIdentity();
11285 try {
11286 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11287 new ArraySet<>(featureTags));
11288 } catch (ImsException e) {
11289 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11290 } finally {
11291 Binder.restoreCallingIdentity(identity);
11292 }
11293 }
11294
11295 /**
11296 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11297 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11298 */
11299 // Used for SHELL command only right now.
11300 @Override
11301 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11302 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11303 "clearUceRegistrationOverrideShell");
11304 final long identity = Binder.clearCallingIdentity();
11305 try {
11306 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11307 } catch (ImsException e) {
11308 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11309 } finally {
11310 Binder.restoreCallingIdentity(identity);
11311 }
11312 }
11313
11314 /**
11315 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11316 */
11317 // Used for SHELL command only right now.
11318 @Override
11319 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11320 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11321 "getLatestRcsContactUceCapabilityShell");
11322 final long identity = Binder.clearCallingIdentity();
11323 try {
11324 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11325 } catch (ImsException e) {
11326 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11327 } finally {
11328 Binder.restoreCallingIdentity(identity);
11329 }
11330 }
11331
11332 /**
11333 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11334 * device does not have an active PUBLISH.
11335 */
11336 // Used for SHELL command only right now.
11337 @Override
11338 public String getLastUcePidfXmlShell(int subId) {
11339 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11340 final long identity = Binder.clearCallingIdentity();
11341 try {
11342 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11343 } catch (ImsException e) {
11344 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11345 } finally {
11346 Binder.restoreCallingIdentity(identity);
11347 }
11348 }
11349
James.cf Line8713a42021-04-29 16:04:26 +080011350 /**
11351 * Remove UCE requests cannot be sent to the network status.
11352 */
11353 // Used for SHELL command only right now.
11354 @Override
11355 public boolean removeUceRequestDisallowedStatus(int subId) {
11356 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11357 final long identity = Binder.clearCallingIdentity();
11358 try {
11359 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11360 } catch (ImsException e) {
11361 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11362 } finally {
11363 Binder.restoreCallingIdentity(identity);
11364 }
11365 }
11366
James.cf Lin18bb9002021-05-25 01:37:38 +080011367 /**
11368 * Remove UCE requests cannot be sent to the network status.
11369 */
11370 // Used for SHELL command only.
11371 @Override
11372 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11373 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11374 final long identity = Binder.clearCallingIdentity();
11375 try {
11376 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11377 } catch (ImsException e) {
11378 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11379 } finally {
11380 Binder.restoreCallingIdentity(identity);
11381 }
11382 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011383
James.cf Lin4b784aa2021-01-31 03:25:15 +080011384 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011385 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11386 String callingPackage) {
11387 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11388 mApp, subId, "setSignalStrengthUpdateRequest");
11389
11390 final int callingUid = Binder.getCallingUid();
11391 // Verify that tha callingPackage belongs to the calling UID
11392 mApp.getSystemService(AppOpsManager.class)
11393 .checkPackage(callingUid, callingPackage);
11394
Rambo Wang3607f502021-02-01 21:51:40 -080011395 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011396
11397 final long identity = Binder.clearCallingIdentity();
11398 try {
11399 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11400 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11401
11402 if (result instanceof IllegalStateException) {
11403 throw (IllegalStateException) result;
11404 }
11405 } finally {
11406 Binder.restoreCallingIdentity(identity);
11407 }
11408 }
11409
11410 @Override
11411 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11412 String callingPackage) {
11413 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11414 mApp, subId, "clearSignalStrengthUpdateRequest");
11415
11416 final int callingUid = Binder.getCallingUid();
11417 // Verify that tha callingPackage belongs to the calling UID
11418 mApp.getSystemService(AppOpsManager.class)
11419 .checkPackage(callingUid, callingPackage);
11420
11421 final long identity = Binder.clearCallingIdentity();
11422 try {
11423 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11424 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11425
11426 if (result instanceof IllegalStateException) {
11427 throw (IllegalStateException) result;
11428 }
11429 } finally {
11430 Binder.restoreCallingIdentity(identity);
11431 }
11432 }
11433
Rambo Wang3607f502021-02-01 21:51:40 -080011434 private static void validateSignalStrengthUpdateRequest(Context context,
11435 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011436 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11437 // phone/system process do not have further restriction on request
11438 return;
11439 }
11440
11441 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011442 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011443 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011444 context.enforceCallingOrSelfPermission(
11445 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11446 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011447 }
11448
11449 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011450 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011451 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011452 || info.isEnabled()) {
11453 throw new IllegalArgumentException(
11454 "Only system can set hide fields in SignalThresholdInfo");
11455 }
11456
11457 // Thresholds length for each RAN need in range. This has been validated in
11458 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11459 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11460 final int[] thresholds = info.getThresholds();
11461 Objects.requireNonNull(thresholds);
11462 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11463 || thresholds.length
11464 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11465 throw new IllegalArgumentException(
11466 "thresholds length is out of range: " + thresholds.length);
11467 }
11468 }
11469 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011470
11471 /**
11472 * Gets the current phone capability.
11473 *
11474 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11475 * @return the PhoneCapability which describes the data connection capability of modem.
11476 * It's used to evaluate possible phone config change, for example from single
11477 * SIM device to multi-SIM device.
11478 */
11479 @Override
11480 public PhoneCapability getPhoneCapability() {
11481 enforceReadPrivilegedPermission("getPhoneCapability");
11482 final long identity = Binder.clearCallingIdentity();
11483 try {
11484 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11485 } finally {
11486 Binder.restoreCallingIdentity(identity);
11487 }
11488 }
Michele Berionne5e411512020-11-13 02:36:59 +000011489
11490 /**
11491 * Prepare TelephonyManager for an unattended reboot. The reboot is
11492 * required to be done shortly after the API is invoked.
11493 */
11494 @Override
11495 @TelephonyManager.PrepareUnattendedRebootResult
11496 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011497 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011498 enforceRebootPermission();
11499
11500 final long identity = Binder.clearCallingIdentity();
11501 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011502 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011503 } finally {
11504 Binder.restoreCallingIdentity(identity);
11505 }
11506 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011507
11508 /**
11509 * Request to get the current slicing configuration including URSP rules and
11510 * NSSAIs (configured, allowed and rejected).
11511 *
11512 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11513 */
11514 @Override
11515 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011516 TelephonyPermissions
11517 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11518 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011519
11520 final long identity = Binder.clearCallingIdentity();
11521 try {
11522 Phone phone = getDefaultPhone();
11523 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11524 } finally {
11525 Binder.restoreCallingIdentity(identity);
11526 }
11527 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011528
11529 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011530 * Check whether the given premium capability is available for purchase from the carrier.
11531 *
11532 * @param capability The premium capability to check.
11533 * @param subId The subId to check the premium capability for.
11534 *
11535 * @return Whether the given premium capability is available to purchase.
11536 */
11537 @Override
11538 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11539 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11540 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11541 log("Premium capability "
11542 + TelephonyManager.convertPremiumCapabilityToString(capability)
11543 + " is not available for purchase due to missing permissions.");
11544 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11545 + "permission READ_BASIC_PHONE_STATE.");
11546 }
11547
11548 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011549 if (phone == null) {
11550 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11551 return false;
11552 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011553 final long identity = Binder.clearCallingIdentity();
11554 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011555 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011556 .isPremiumCapabilityAvailableForPurchase(capability);
11557 } finally {
11558 Binder.restoreCallingIdentity(identity);
11559 }
11560 }
11561
11562 /**
11563 * Purchase the given premium capability from the carrier.
11564 *
11565 * @param capability The premium capability to purchase.
11566 * @param callback The result of the purchase request.
11567 * @param subId The subId to purchase the premium capability for.
11568 */
11569 @Override
11570 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11571 log("purchasePremiumCapability: capability="
11572 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11573 + getCurrentPackageName());
11574
11575 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11576 mApp, "purchasePremiumCapability")) {
11577 log("purchasePremiumCapability "
11578 + TelephonyManager.convertPremiumCapabilityToString(capability)
11579 + " failed due to missing permissions.");
11580 throw new SecurityException("purchasePremiumCapability requires permission "
11581 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011582 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11583 mApp, "purchasePremiumCapability")) {
11584 log("purchasePremiumCapability "
11585 + TelephonyManager.convertPremiumCapabilityToString(capability)
11586 + " failed due to missing permissions.");
11587 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011588 }
11589
11590 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011591 if (phone == null) {
11592 try {
11593 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11594 callback.accept(result);
11595 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11596 } catch (RemoteException e) {
11597 String logStr = "Purchase premium capability "
11598 + TelephonyManager.convertPremiumCapabilityToString(capability)
11599 + " failed due to RemoteException handling null phone: " + e;
11600 if (DBG) log(logStr);
11601 AnomalyReporter.reportAnomaly(
11602 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11603 }
11604 return;
11605 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011606
11607 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011608 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011609 callingProcess = mApp.getPackageManager().getApplicationInfo(
11610 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011611 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011612 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011613 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011614
11615 boolean isVisible = false;
11616 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11617 if (am != null) {
11618 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11619 if (processes != null) {
11620 for (ActivityManager.RunningAppProcessInfo process : processes) {
11621 log("purchasePremiumCapability: process " + process.processName
11622 + "has importance " + process.importance);
11623 if (process.processName.equals(callingProcess) && process.importance
11624 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11625 isVisible = true;
11626 break;
11627 }
11628 }
11629 }
11630 }
11631
11632 if (!isVisible) {
11633 try {
11634 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11635 callback.accept(result);
11636 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11637 } catch (RemoteException e) {
11638 String logStr = "Purchase premium capability "
11639 + TelephonyManager.convertPremiumCapabilityToString(capability)
11640 + " failed due to RemoteException handling background application: " + e;
11641 if (DBG) log(logStr);
11642 AnomalyReporter.reportAnomaly(
11643 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11644 }
11645 return;
11646 }
11647
Sarah Chin71b3a852022-09-28 15:54:19 -070011648 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011649 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011650 }
11651
11652 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011653 * Register an IMS connection state callback
11654 */
11655 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011656 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11657 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011658 if (feature == ImsFeature.FEATURE_MMTEL) {
11659 // ImsMmTelManager
11660 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11661 TelephonyPermissions
11662 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11663 mApp, subId, "registerImsStateCallback");
11664 } else if (feature == ImsFeature.FEATURE_RCS) {
11665 // ImsRcsManager or SipDelegateManager
11666 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11667 Binder.getCallingUid(), "registerImsStateCallback",
11668 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11669 Manifest.permission.READ_PRECISE_PHONE_STATE,
11670 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11671 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11672 }
11673
11674 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11675 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11676 "IMS not available on device.");
11677 }
11678
11679 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11680 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11681 }
11682
11683 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11684 if (controller == null) {
11685 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11686 "IMS not available on device.");
11687 }
11688
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011689 if (callingPackage == null) {
11690 callingPackage = getCurrentPackageName();
11691 }
11692
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011693 final long token = Binder.clearCallingIdentity();
11694 try {
11695 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011696 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011697 } catch (ImsException e) {
11698 throw new ServiceSpecificException(e.getCode());
11699 } finally {
11700 Binder.restoreCallingIdentity(token);
11701 }
11702 }
11703
11704 /**
11705 * Unregister an IMS connection state callback
11706 */
11707 @Override
11708 public void unregisterImsStateCallback(IImsStateCallback cb) {
11709 final long token = Binder.clearCallingIdentity();
11710 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11711 if (controller == null) {
11712 return;
11713 }
11714 try {
11715 controller.unregisterImsStateCallback(cb);
11716 } finally {
11717 Binder.restoreCallingIdentity(token);
11718 }
11719 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011720
11721 /**
11722 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11723 *
11724 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11725 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11726 * SecurityException.
11727 * If there is current registered network this value will be same as the registered cell
11728 * identity. If the device goes out of service the previous cell identity is cached and
11729 * will be returned. If the cache age of the Cell identity is more than 24 hours
11730 * it will be cleared and null will be returned.
11731 *
11732 */
11733 @Override
11734 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11735 String callingFeatureId) {
11736 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11737 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11738 LocationAccessPolicy.checkLocationPermission(mApp,
11739 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11740 .setCallingPackage(callingPackage)
11741 .setCallingFeatureId(callingFeatureId)
11742 .setCallingPid(Binder.getCallingPid())
11743 .setCallingUid(Binder.getCallingUid())
11744 .setMethod("getLastKnownCellIdentity")
11745 .setLogAsInfo(true)
11746 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11747 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11748 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11749 .build());
11750
11751 boolean hasFinePermission =
11752 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11753 if (!hasFinePermission
11754 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11755 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011756 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011757 }
11758
11759 final long identity = Binder.clearCallingIdentity();
11760 try {
11761 Phone phone = getPhone(subId);
11762 if (phone == null) return null;
11763 ServiceStateTracker sst = phone.getServiceStateTracker();
11764 if (sst == null) return null;
11765 return sst.getLastKnownCellIdentity();
11766 } finally {
11767 Binder.restoreCallingIdentity(identity);
11768 }
11769 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011770
jimsun3b9ccac2021-10-26 15:01:23 +080011771 /**
11772 * Sets the modem service class Name that Telephony will bind to.
11773 *
11774 * @param serviceName The class name of the modem service.
11775 * @return true if the operation is succeed, otherwise false.
11776 */
11777 public boolean setModemService(String serviceName) {
11778 Log.d(LOG_TAG, "setModemService - " + serviceName);
11779 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11781 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11782 "setModemService");
11783 return mPhoneConfigurationManager.setModemService(serviceName);
11784 }
11785
11786 /**
11787 * Return the class name of the currently bounded modem service.
11788 *
11789 * @return the class name of the modem service.
11790 */
11791 public String getModemService() {
11792 String result;
11793 Log.d(LOG_TAG, "getModemService");
11794 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11795 TelephonyPermissions
11796 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11797 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11798 "getModemService");
11799 result = mPhoneConfigurationManager.getModemService();
11800 Log.d(LOG_TAG, "result = " + result);
11801 return result;
11802 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011803
11804 @Override
11805 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11806 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11807 mApp.enforceCallingOrSelfPermission(
11808 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11809 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11810
11811 final long identity = Binder.clearCallingIdentity();
11812 try {
11813 Phone phone = getPhone(subId);
11814 if (phone == null) return;
11815 phone.setVoiceServiceStateOverride(hasService);
11816 } finally {
11817 Binder.restoreCallingIdentity(identity);
11818 }
11819 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011820
11821 /**
11822 * set removable eSIM as default eUICC.
11823 *
11824 * @hide
11825 */
11826 @Override
11827 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11828 enforceModifyPermission();
11829 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11830
11831 final long identity = Binder.clearCallingIdentity();
11832 try {
11833 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11834 } finally {
11835 Binder.restoreCallingIdentity(identity);
11836 }
11837 }
11838
11839 /**
11840 * Returns whether the removable eSIM is default eUICC or not.
11841 *
11842 * @hide
11843 */
11844 @Override
11845 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11846 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11847 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11848
11849 final long identity = Binder.clearCallingIdentity();
11850 try {
11851 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11852 } finally {
11853 Binder.restoreCallingIdentity(identity);
11854 }
11855 }
11856
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011857 /**
11858 * Get the component name of the default app to direct respond-via-message intent for the
11859 * user associated with this subscription, update the cache if there is no respond-via-message
11860 * application currently configured for this user.
11861 * @return component name of the app and class to direct Respond Via Message intent to, or
11862 * {@code null} if the functionality is not supported.
11863 * @hide
11864 */
11865 @Override
11866 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11867 boolean updateIfNeeded) {
11868 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011869
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000011870 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
11871
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011872 UserHandle userHandle = null;
11873 final long identity = Binder.clearCallingIdentity();
11874 try {
11875 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11876 } finally {
11877 Binder.restoreCallingIdentity(identity);
11878 }
11879 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11880 updateIfNeeded, userHandle);
11881 }
Jack Yuf5badd92022-12-08 00:50:53 -080011882
11883 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011884 * Set whether the device is able to connect with null ciphering or integrity
11885 * algorithms. This is a global setting and will apply to all active subscriptions
11886 * and all new subscriptions after this.
11887 *
11888 * @param enabled when true, null cipher and integrity algorithms are allowed.
11889 * @hide
11890 */
11891 @Override
11892 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11893 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11894 enforceModifyPermission();
11895 checkForNullCipherAndIntegritySupport();
11896
11897 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11898 // for listening to these preference changes and applying them immediately.
11899 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11900 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11901 editor.apply();
11902
11903 for (Phone phone: PhoneFactory.getPhones()) {
11904 phone.handleNullCipherEnabledChange();
11905 }
11906 }
11907
11908
11909 /**
11910 * Get whether the device is able to connect with null ciphering or integrity
11911 * algorithms. Note that this retrieves the phone-global preference and not
11912 * the state of the radio.
11913 *
11914 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11915 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11916 * version for this feature.
11917 * @hide
11918 */
11919 @Override
11920 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11921 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11922 enforceReadPermission();
11923 checkForNullCipherAndIntegritySupport();
11924 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11925 }
11926
11927 private void checkForNullCipherAndIntegritySupport() {
11928 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11929 throw new UnsupportedOperationException(
11930 "Null cipher and integrity operations require HAL 2.1 or above");
11931 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000011932 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
11933 throw new UnsupportedOperationException(
11934 "Null cipher and integrity operations unsupported by modem");
11935 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011936 }
11937
11938 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011939 * Get the SIM state for the slot index.
11940 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
11941 *
11942 * @return SIM state as the ordinal of {@link IccCardConstants.State}
11943 */
11944 @Override
11945 @SimState
11946 public int getSimStateForSlotIndex(int slotIndex) {
11947 IccCardConstants.State simState;
11948 if (slotIndex < 0) {
11949 simState = IccCardConstants.State.UNKNOWN;
11950 } else {
11951 Phone phone = null;
11952 try {
11953 phone = PhoneFactory.getPhone(slotIndex);
11954 } catch (IllegalStateException e) {
11955 // ignore
11956 }
11957 if (phone == null) {
11958 simState = IccCardConstants.State.UNKNOWN;
11959 } else {
11960 IccCard icc = phone.getIccCard();
11961 if (icc == null) {
11962 simState = IccCardConstants.State.UNKNOWN;
11963 } else {
11964 simState = icc.getState();
11965 }
11966 }
11967 }
11968 return simState.ordinal();
11969 }
Hui Wang9b5793a2022-12-05 14:38:06 -060011970
11971 /**
11972 * Get current cell broadcast ranges.
11973 */
11974 @Override
11975 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
11976 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
11977 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
11978 "getCellBroadcastIdRanges");
11979 final long identity = Binder.clearCallingIdentity();
11980 try {
11981 return getPhone(subId).getCellBroadcastIdRanges();
11982 } finally {
11983 Binder.restoreCallingIdentity(identity);
11984 }
11985 }
11986
11987 /**
11988 * Set reception of cell broadcast messages with the list of the given ranges
11989 *
11990 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
11991 */
11992 @Override
11993 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
11994 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
11995 @Nullable IIntegerConsumer callback) {
11996 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
11997 "setCellBroadcastIdRanges");
11998 final long identity = Binder.clearCallingIdentity();
11999 try {
12000 Phone phone = getPhoneFromSubId(subId);
12001 if (DBG) {
12002 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12003 }
12004 phone.setCellBroadcastIdRanges(ranges, result -> {
12005 if (callback != null) {
12006 try {
12007 callback.accept(result);
12008 } catch (RemoteException e) {
12009 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12010 }
12011 }
12012 });
12013 } finally {
12014 Binder.restoreCallingIdentity(identity);
12015 }
12016 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012017
12018 /**
12019 * Returns whether the device supports the domain selection service.
12020 *
12021 * @return {@code true} if the device supports the domain selection service.
12022 */
12023 @Override
12024 public boolean isDomainSelectionSupported() {
12025 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12026 "isDomainSelectionSupported");
12027
12028 final long identity = Binder.clearCallingIdentity();
12029 try {
12030 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12031 } finally {
12032 Binder.restoreCallingIdentity(identity);
12033 }
12034 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012035
12036 /**
12037 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12038 *
12039 * <p>This method behaves in one of the following ways:
12040 * <ul>
12041 * <li>return true : if the calling package has the appop permission {@link
12042 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12043 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12044 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12045 * Owner device identifier access check, or the calling package has carrier privileges</>
12046 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12047 * </ul>
12048 */
12049 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12050 String callingPackage, @Nullable String callingFeatureId, String message) {
12051 for (Phone phone : PhoneFactory.getPhones()) {
12052 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12053 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12054 return true;
12055 }
12056 }
12057 return false;
12058 }
arunvoddud7401012022-12-15 16:08:12 +000012059
12060 /**
12061 * Class binds the consumer[callback] and carrierId.
12062 */
12063 private static class CallerCallbackInfo {
12064 private final Consumer<Integer> mConsumer;
12065 private final int mCarrierId;
12066
12067 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12068 mConsumer = consumer;
12069 mCarrierId = carrierId;
12070 }
12071
12072 public Consumer<Integer> getConsumer() {
12073 return mConsumer;
12074 }
12075
12076 public int getCarrierId() {
12077 return mCarrierId;
12078 }
12079 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012080}