blob: cec3a94bb7cd5e6800d9159f043e02d426f00d57 [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;
Sarah Chineccfbd12023-01-20 19:00:35 -0800146import android.telephony.satellite.ISatellitePositionUpdateCallback;
147import android.telephony.satellite.PointingInfo;
148import android.telephony.satellite.SatelliteManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800150import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700151import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700152import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800153import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800154
Andrew Lee312e8172014-10-23 17:01:36 -0700155import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800156import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800157import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800158import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800159import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700160import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700161import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700162import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800163import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800164import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700165import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700166import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800167import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700168import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800169import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800170import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800171import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700172import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000173import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700174import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800175import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700176import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800177import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800178import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800179import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700180import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700181import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700182import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700183import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700184import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800185import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700186import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700187import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700188import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700189import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800190import com.android.internal.telephony.RILConstants;
Sarah Chineccfbd12023-01-20 19:00:35 -0800191import com.android.internal.telephony.RILUtils;
Daniel Bright94f43662021-03-01 14:43:40 -0800192import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700193import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000194import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700195import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700196import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800197import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800198import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800199import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700200import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000201import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800202import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700203import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800204import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700205import com.android.internal.telephony.imsphone.ImsPhone;
206import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000207import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800208import com.android.internal.telephony.metrics.TelephonyMetrics;
Jack Yu285100e2022-12-02 22:48:35 -0800209import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
210import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700211import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700212import com.android.internal.telephony.uicc.IccIoResult;
213import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800214import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700215import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800216import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700217import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000218import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800219import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000220import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800221import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000222import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700223import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700224import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800225import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800226import com.android.phone.callcomposer.CallComposerPictureManager;
227import com.android.phone.callcomposer.CallComposerPictureTransfer;
228import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700229import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700230import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000231import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700232import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800233import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700234import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700235import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800236import com.android.services.telephony.TelecomAccountRegistry;
237import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800238import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800239
Hall Liu82694d52020-12-11 18:22:04 -0800240import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700241import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800242import java.io.IOException;
243import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700244import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700245import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800246import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000247import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800248import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800249import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800250import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800251import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100252import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800253import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700254import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800255import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800256import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700257import java.util.UUID;
Sarah Chineccfbd12023-01-20 19:00:35 -0800258import java.util.concurrent.ConcurrentHashMap;
Hall Liu82694d52020-12-11 18:22:04 -0800259import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800260import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800261import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700262
263/**
264 * Implementation of the ITelephony interface.
265 */
Santos Cordon117fee72014-05-16 17:56:12 -0700266public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700267 private static final String LOG_TAG = "PhoneInterfaceManager";
268 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
269 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800270 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271
272 // Message codes used with mMainThreadHandler
273 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700274 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
275 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700276 private static final int CMD_OPEN_CHANNEL = 9;
277 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
278 private static final int CMD_CLOSE_CHANNEL = 11;
279 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800280 private static final int CMD_NV_READ_ITEM = 13;
281 private static final int EVENT_NV_READ_ITEM_DONE = 14;
282 private static final int CMD_NV_WRITE_ITEM = 15;
283 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
284 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
285 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700286 private static final int CMD_RESET_MODEM_CONFIG = 19;
287 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800288 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
289 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800290 private static final int CMD_SEND_ENVELOPE = 25;
291 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000292 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
293 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700294 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
295 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
296 private static final int CMD_EXCHANGE_SIM_IO = 31;
297 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800298 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
299 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700300 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
301 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700302 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
303 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700304 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
305 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
306 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
307 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700308 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
309 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
310 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
311 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700312 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800313 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
314 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000315 private static final int CMD_SWITCH_SLOTS = 50;
316 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700317 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
318 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
319 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
320 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
321 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
322 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
323 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
324 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700325 private static final int CMD_GET_ALL_CELL_INFO = 60;
326 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
327 private static final int CMD_GET_CELL_LOCATION = 62;
328 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700329 private static final int CMD_MODEM_REBOOT = 64;
330 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700331 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
332 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800333 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
334 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700335 private static final int CMD_GET_MODEM_STATUS = 70;
336 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700337 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
338 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700339 private static final int CMD_ERASE_MODEM_CONFIG = 74;
340 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800341 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
342 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
343 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
344 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800345 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
346 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800347 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800348 private static final int CMD_GET_CALL_FORWARDING = 83;
349 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
350 private static final int CMD_SET_CALL_FORWARDING = 85;
351 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
352 private static final int CMD_GET_CALL_WAITING = 87;
353 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
354 private static final int CMD_SET_CALL_WAITING = 89;
355 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700356 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
357 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
358 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
359 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700360 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
361 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800362 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
363 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800364 private static final int CMD_SET_DATA_THROTTLING = 99;
365 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800366 private static final int CMD_SET_SIM_POWER = 101;
367 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800368 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
369 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
370 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
371 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800372 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
373 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000374 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800375 private static final int CMD_GET_SLICING_CONFIG = 110;
376 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800377 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700378 private static final int CMD_ENABLE_VONR = 113;
379 private static final int EVENT_ENABLE_VONR_DONE = 114;
380 private static final int CMD_IS_VONR_ENABLED = 115;
381 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700382 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
383 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Sarah Chineccfbd12023-01-20 19:00:35 -0800384 private static final int CMD_START_SATELLITE_POSITION_UPDATES = 119;
385 private static final int EVENT_START_SATELLITE_POSITION_UPDATES_DONE = 120;
386 private static final int CMD_STOP_SATELLITE_POSITION_UPDATES = 121;
387 private static final int EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE = 122;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +0000388 private static final int CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG = 123;
389 private static final int EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE = 124;
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800390 // Parameters of select command.
391 private static final int SELECT_COMMAND = 0xA4;
392 private static final int SELECT_P1 = 0x04;
393 private static final int SELECT_P2 = 0;
394 private static final int SELECT_P3 = 0x10;
395
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000396 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
397 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
398
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 /** The singleton instance. */
400 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800401 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700402
Wink Saville3ab207e2014-11-20 13:07:20 -0800403 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800404 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800405 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700406 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800407 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700408 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800409 private MainThreadHandler mMainThreadHandler;
Jack Yue37dd262022-12-16 11:53:37 -0800410 private final SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800411 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700412 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800413 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414
Peter Wangdafb9ac2020-01-15 14:13:38 -0800415 /** User Activity */
416 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800417 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
418
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700419 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chineccfbd12023-01-20 19:00:35 -0800420 private Map<Integer, SatellitePositionUpdateHandler> mSatellitePositionUpdateHandlers =
421 new ConcurrentHashMap<>();
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700422
Derek Tan97ebb422014-09-05 16:55:38 -0700423 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
424 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800425 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800426 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700427
Michelecea4cf22018-12-21 15:00:11 -0800428 // String to store multi SIM allowed
429 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
430
Derek Tan740e1672017-06-27 14:56:27 -0700431 // The AID of ISD-R.
432 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
433
yinxub1bed742017-04-17 11:45:04 -0700434 private NetworkScanRequestTracker mNetworkScanRequestTracker;
435
David Kelly5e06a7f2018-03-12 14:10:59 +0000436 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
437 private static final int MANUFACTURER_CODE_LENGTH = 8;
438
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800439 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800440 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800441
Sarah Chin2ec39f62022-08-31 17:03:26 -0700442 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
443 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
444
Derek Tan89e89d42014-07-08 17:00:10 -0700445 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700446 * Experiment flag to enable erase modem config on reset network, default value is false
447 */
448 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
449 "reset_network_erase_modem_config_enabled";
450
Rambo Wang0f050d82021-02-12 11:43:36 -0800451 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800452
Gary Jian76280a42022-12-07 16:18:33 +0800453 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
454
sandeepjsb6c87872021-09-27 15:34:44 +0000455 /**
456 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
457 * one ICCID active at the same time.
458 * Apps should use below API signatures if targeting SDK is T and beyond.
459 *
460 * @hide
461 */
462 @ChangeId
463 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
464 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800465
Naina Nallurid63128d2019-09-17 14:10:30 -0700466 /**
Chen Xu540470b2021-12-14 17:15:47 -0800467 * Apps targeting on Android T and beyond will get exception whenever icc close channel
468 * operation fails.
469 */
470 @ChangeId
471 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
472 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
473
474 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700475 * A request object to use for transmitting data to an ICC.
476 */
477 private static final class IccAPDUArgument {
478 public int channel, cla, command, p1, p2, p3;
479 public String data;
480
481 public IccAPDUArgument(int channel, int cla, int command,
482 int p1, int p2, int p3, String data) {
483 this.channel = channel;
484 this.cla = cla;
485 this.command = command;
486 this.p1 = p1;
487 this.p2 = p2;
488 this.p3 = p3;
489 this.data = data;
490 }
491 }
492
493 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700494 * A request object to use for transmitting data to an ICC.
495 */
496 private static final class ManualNetworkSelectionArgument {
497 public OperatorInfo operatorInfo;
498 public boolean persistSelection;
499
500 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
501 this.operatorInfo = operatorInfo;
502 this.persistSelection = persistSelection;
503 }
504 }
505
Sarah Chin71b3a852022-09-28 15:54:19 -0700506 private static final class PurchasePremiumCapabilityArgument {
507 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700508 public @NonNull IIntegerConsumer callback;
509
510 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800511 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700512 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700513 this.callback = callback;
514 }
515 }
516
Sarah Chineccfbd12023-01-20 19:00:35 -0800517 private static final class SatellitePositionUpdateHandler extends Handler {
518 public static final int EVENT_POSITION_UPDATE = 1;
519 public static final int EVENT_MESSAGE_TRANSFER_STATE_UPDATE = 2;
520
521 private final ISatellitePositionUpdateCallback mCallback;
522
523 SatellitePositionUpdateHandler(ISatellitePositionUpdateCallback callback, Looper looper) {
524 super(looper);
525 mCallback = callback;
526 }
527
528 @Override
529 public void handleMessage(@NonNull Message msg) {
530 switch (msg.what) {
531 case EVENT_POSITION_UPDATE: {
532 AsyncResult ar = (AsyncResult) msg.obj;
533 PointingInfo pointingInfo = (PointingInfo) ar.result;
534 try {
535 mCallback.onSatellitePositionUpdate(pointingInfo);
536 } catch (RemoteException e) {
537 loge("EVENT_POSITION_UPDATE RemoteException: " + e);
538 }
539 break;
540 }
541 case EVENT_MESSAGE_TRANSFER_STATE_UPDATE: {
542 AsyncResult ar = (AsyncResult) msg.obj;
543 int state = (int) ar.result;
544 try {
545 mCallback.onMessageTransferStateUpdate(state);
546 } catch (RemoteException e) {
547 loge("EVENT_MESSAGE_TRANSFER_STATE_UPDATE RemoteException: " + e);
548 }
549 break;
550 }
551 default:
552 loge("SatellitePositionUpdateHandler unknown event: " + msg.what);
553 }
554 }
555 }
556
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700557 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700558 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
559 * request after sending. The main thread will notify the request when it is complete.
560 */
561 private static final class MainThreadRequest {
562 /** The argument to use for the request */
563 public Object argument;
564 /** The result of the request that is run on the main thread */
565 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800566 // The subscriber id that this request applies to. Defaults to
567 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
568 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700569
Nathan Harold92bed182018-10-12 18:16:49 -0700570 // In cases where subId is unavailable, the caller needs to specify the phone.
571 public Phone phone;
572
vagdeviaf9a5b92018-08-15 16:01:53 -0700573 public WorkSource workSource;
574
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700575 public MainThreadRequest(Object argument) {
576 this.argument = argument;
577 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800578
Nathan Harold92bed182018-10-12 18:16:49 -0700579 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
580 this.argument = argument;
581 if (phone != null) {
582 this.phone = phone;
583 }
584 this.workSource = workSource;
585 }
586
vagdeviaf9a5b92018-08-15 16:01:53 -0700587 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800588 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800589 if (subId != null) {
590 this.subId = subId;
591 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700592 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800593 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700594 }
595
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800596 private static final class IncomingThirdPartyCallArgs {
597 public final ComponentName component;
598 public final String callId;
599 public final String callerDisplayName;
600
601 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
602 String callerDisplayName) {
603 this.component = component;
604 this.callId = callId;
605 this.callerDisplayName = callerDisplayName;
606 }
607 }
608
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700609 /**
610 * A handler that processes messages on the main thread in the phone process. Since many
611 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
612 * inbound binder threads to the main thread in the phone process. The Binder thread
613 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
614 * on, which will be notified when the operation completes and will contain the result of the
615 * request.
616 *
617 * <p>If a MainThreadRequest object is provided in the msg.obj field,
618 * note that request.result must be set to something non-null for the calling thread to
619 * unblock.
620 */
621 private final class MainThreadHandler extends Handler {
622 @Override
623 public void handleMessage(Message msg) {
624 MainThreadRequest request;
625 Message onCompleted;
626 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000627 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700628 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800629 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700630
631 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700632 case CMD_HANDLE_USSD_REQUEST: {
633 request = (MainThreadRequest) msg.obj;
634 final Phone phone = getPhoneFromRequest(request);
635 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800636 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700637 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700638
Pengquan Menga1bb6272018-09-06 09:59:22 -0700639 if (!isUssdApiAllowed(request.subId)) {
640 // Carrier does not support use of this API, return failure.
641 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
642 UssdResponse response = new UssdResponse(ussdRequest, null);
643 Bundle returnData = new Bundle();
644 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
645 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700646
Pengquan Menga1bb6272018-09-06 09:59:22 -0700647 request.result = true;
648 notifyRequester(request);
649 return;
650 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700651
Pengquan Menga1bb6272018-09-06 09:59:22 -0700652 try {
653 request.result = phone != null
654 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
655 } catch (CallStateException cse) {
656 request.result = false;
657 }
658 // Wake up the requesting thread
659 notifyRequester(request);
660 break;
pkanwar32d516d2016-10-14 19:37:38 -0700661 }
662
Yorke Lee716f67e2015-06-17 15:39:16 -0700663 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700664 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700665 final Phone phone = getPhoneFromRequest(request);
666 request.result = phone != null ?
667 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
668 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700669 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700670 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700671 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700672 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700673
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700674 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700676 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000677 uiccPort = getUiccPortFromRequest(request);
678 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700679 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800680 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700681 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700682 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700683 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800684 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000685 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800686 iccArgument.channel, iccArgument.cla, iccArgument.command,
687 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
688 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700689 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 break;
691
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700692 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 ar = (AsyncResult) msg.obj;
694 request = (MainThreadRequest) ar.userObj;
695 if (ar.exception == null && ar.result != null) {
696 request.result = ar.result;
697 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800698 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700699 if (ar.result == null) {
700 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800701 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800703 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700704 } else {
705 loge("iccTransmitApduLogicalChannel: Unknown exception");
706 }
707 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700708 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700709 break;
710
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700711 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
712 request = (MainThreadRequest) msg.obj;
713 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000714 uiccPort = getUiccPortFromRequest(request);
715 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700716 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800717 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700718 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700719 } else {
720 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800721 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000722 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800723 iccArgument.cla, iccArgument.command, iccArgument.p1,
724 iccArgument.p2,
725 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700726 }
727 break;
728
729 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
730 ar = (AsyncResult) msg.obj;
731 request = (MainThreadRequest) ar.userObj;
732 if (ar.exception == null && ar.result != null) {
733 request.result = ar.result;
734 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800735 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700736 if (ar.result == null) {
737 loge("iccTransmitApduBasicChannel: Empty response");
738 } else if (ar.exception instanceof CommandException) {
739 loge("iccTransmitApduBasicChannel: CommandException: " +
740 ar.exception);
741 } else {
742 loge("iccTransmitApduBasicChannel: Unknown exception");
743 }
744 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700745 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700746 break;
747
748 case CMD_EXCHANGE_SIM_IO:
749 request = (MainThreadRequest) msg.obj;
750 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000751 uiccPort = getUiccPortFromRequest(request);
752 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700753 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800754 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700755 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700756 } else {
757 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
758 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000759 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700760 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
761 iccArgument.data, onCompleted);
762 }
763 break;
764
765 case EVENT_EXCHANGE_SIM_IO_DONE:
766 ar = (AsyncResult) msg.obj;
767 request = (MainThreadRequest) ar.userObj;
768 if (ar.exception == null && ar.result != null) {
769 request.result = ar.result;
770 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800771 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700772 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700773 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700774 break;
775
Derek Tan4d5e5c12014-02-04 11:54:58 -0800776 case CMD_SEND_ENVELOPE:
777 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000778 uiccPort = getUiccPortFromRequest(request);
779 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700780 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800781 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700782 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700783 } else {
784 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800785 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700786 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800787 break;
788
789 case EVENT_SEND_ENVELOPE_DONE:
790 ar = (AsyncResult) msg.obj;
791 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700792 if (ar.exception == null && ar.result != null) {
793 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800794 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800795 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700796 if (ar.result == null) {
797 loge("sendEnvelopeWithStatus: Empty response");
798 } else if (ar.exception instanceof CommandException) {
799 loge("sendEnvelopeWithStatus: CommandException: " +
800 ar.exception);
801 } else {
802 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
803 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800804 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700805 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800806 break;
807
Shishir Agrawal566b7612013-10-28 14:41:00 -0700808 case CMD_OPEN_CHANNEL:
809 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000810 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800811 IccLogicalChannelRequest openChannelRequest =
812 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000813 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700814 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800815 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800816 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700817 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700818 } else {
819 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800820 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
821 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700822 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700823 break;
824
825 case EVENT_OPEN_CHANNEL_DONE:
826 ar = (AsyncResult) msg.obj;
827 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700828 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700829 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700830 int[] result = (int[]) ar.result;
831 int channelId = result[0];
832 byte[] selectResponse = null;
833 if (result.length > 1) {
834 selectResponse = new byte[result.length - 1];
835 for (int i = 1; i < result.length; ++i) {
836 selectResponse[i - 1] = (byte) result[i];
837 }
838 }
839 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800840 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800841
842 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700843 if (uiccPort == null) {
844 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
845 } else {
846 IccLogicalChannelRequest channelRequest =
847 (IccLogicalChannelRequest) request.argument;
848 channelRequest.channel = channelId;
849 uiccPort.onLogicalChannelOpened(channelRequest);
850 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700851 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700852 if (ar.result == null) {
853 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700854 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700855 if (ar.exception != null) {
856 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
857 }
858
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700859 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700860 if (ar.exception instanceof CommandException) {
861 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800862 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700863 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700864 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700865 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700866 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700867 }
868 }
869 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800870 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700871 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700872 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700873 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700874 break;
875
876 case CMD_CLOSE_CHANNEL:
877 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000878 uiccPort = getUiccPortFromRequest(request);
879 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700880 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800881 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800882 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800883 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700884 } else {
885 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000886 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700887 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700888 break;
889
890 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800891 ar = (AsyncResult) msg.obj;
892 request = (MainThreadRequest) ar.userObj;
893 if (ar.exception == null) {
894 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800895 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700896 if (uiccPort == null) {
897 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
898 } else {
899 final int channelId = (Integer) request.argument;
900 uiccPort.onLogicalChannelClosed(channelId);
901 }
Chen Xu540470b2021-12-14 17:15:47 -0800902 } else {
903 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800904 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800905 if (ar.exception instanceof CommandException) {
906 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
907 CommandException.Error error =
908 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800909 if (error == CommandException.Error.INVALID_ARGUMENTS) {
910 // should only throw exceptions from the binder threads.
911 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800912 "iccCloseLogicalChannel: invalid argument ");
913 }
914 } else {
915 loge("iccCloseLogicalChannel: Unknown exception");
916 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800917 request.result = (exception != null) ? exception :
918 new IllegalStateException(
919 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800920 }
921 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800922 break;
923
924 case CMD_NV_READ_ITEM:
925 request = (MainThreadRequest) msg.obj;
926 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800927 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
928 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800929 break;
930
931 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700932 ar = (AsyncResult) msg.obj;
933 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800934 if (ar.exception == null && ar.result != null) {
935 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700936 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800937 request.result = "";
938 if (ar.result == null) {
939 loge("nvReadItem: Empty response");
940 } else if (ar.exception instanceof CommandException) {
941 loge("nvReadItem: CommandException: " +
942 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700943 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800944 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700945 }
946 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700947 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700948 break;
949
Jake Hambye994d462014-02-03 13:10:13 -0800950 case CMD_NV_WRITE_ITEM:
951 request = (MainThreadRequest) msg.obj;
952 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
953 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800954 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700955 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800956 break;
957
958 case EVENT_NV_WRITE_ITEM_DONE:
959 handleNullReturnEvent(msg, "nvWriteItem");
960 break;
961
962 case CMD_NV_WRITE_CDMA_PRL:
963 request = (MainThreadRequest) msg.obj;
964 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800965 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800966 break;
967
968 case EVENT_NV_WRITE_CDMA_PRL_DONE:
969 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
970 break;
971
chen xu6dac5ab2018-10-26 17:39:23 -0700972 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800973 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700974 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800975 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800976 break;
977
chen xu6dac5ab2018-10-26 17:39:23 -0700978 case EVENT_RESET_MODEM_CONFIG_DONE:
979 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800980 break;
981
Sooraj Sasindran37444802020-08-11 10:40:43 -0700982 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
983 request = (MainThreadRequest) msg.obj;
984 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
985 request);
986 Phone phone = getPhoneFromRequest(request);
987 if (phone != null) {
988 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
989 } else {
990 loge("isNRDualConnectivityEnabled: No phone object");
991 request.result = false;
992 notifyRequester(request);
993 }
994 break;
995 }
996
997 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
998 ar = (AsyncResult) msg.obj;
999 request = (MainThreadRequest) ar.userObj;
1000 if (ar.exception == null && ar.result != null) {
1001 request.result = ar.result;
1002 } else {
1003 // request.result must be set to something non-null
1004 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001005 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -07001006 request.result = ar.result;
1007 } else {
1008 request.result = false;
1009 }
1010 if (ar.result == null) {
1011 loge("isNRDualConnectivityEnabled: Empty response");
1012 } else if (ar.exception instanceof CommandException) {
1013 loge("isNRDualConnectivityEnabled: CommandException: "
1014 + ar.exception);
1015 } else {
1016 loge("isNRDualConnectivityEnabled: Unknown exception");
1017 }
1018 }
1019 notifyRequester(request);
1020 break;
1021
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001022 case CMD_IS_VONR_ENABLED: {
1023 request = (MainThreadRequest) msg.obj;
1024 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1025 request);
1026 Phone phone = getPhoneFromRequest(request);
1027 if (phone != null) {
1028 phone.isVoNrEnabled(onCompleted, request.workSource);
1029 } else {
1030 loge("isVoNrEnabled: No phone object");
1031 request.result = false;
1032 notifyRequester(request);
1033 }
1034 break;
1035 }
1036
1037 case EVENT_IS_VONR_ENABLED_DONE:
1038 ar = (AsyncResult) msg.obj;
1039 request = (MainThreadRequest) ar.userObj;
1040 if (ar.exception == null && ar.result != null) {
1041 request.result = ar.result;
1042 } else {
1043 // request.result must be set to something non-null
1044 // for the calling thread to unblock
1045 if (ar.result != null) {
1046 request.result = ar.result;
1047 } else {
1048 request.result = false;
1049 }
1050 if (ar.result == null) {
1051 loge("isVoNrEnabled: Empty response");
1052 } else if (ar.exception instanceof CommandException) {
1053 loge("isVoNrEnabled: CommandException: "
1054 + ar.exception);
1055 } else {
1056 loge("isVoNrEnabled: Unknown exception");
1057 }
1058 }
1059 notifyRequester(request);
1060 break;
1061
Sooraj Sasindran37444802020-08-11 10:40:43 -07001062 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1063 request = (MainThreadRequest) msg.obj;
1064 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1065 Phone phone = getPhoneFromRequest(request);
1066 if (phone != null) {
1067 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1068 request.workSource);
1069 } else {
1070 loge("enableNrDualConnectivity: No phone object");
1071 request.result =
1072 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1073 notifyRequester(request);
1074 }
1075 break;
1076 }
1077
1078 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1079 ar = (AsyncResult) msg.obj;
1080 request = (MainThreadRequest) ar.userObj;
1081 if (ar.exception == null) {
1082 request.result =
1083 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1084 } else {
1085 request.result =
1086 TelephonyManager
1087 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1088 if (ar.exception instanceof CommandException) {
1089 CommandException.Error error =
1090 ((CommandException) (ar.exception)).getCommandError();
1091 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1092 request.result =
1093 TelephonyManager
1094 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001095 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1096 request.result =
1097 TelephonyManager
1098 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001099 }
1100 loge("enableNrDualConnectivity" + ": CommandException: "
1101 + ar.exception);
1102 } else {
1103 loge("enableNrDualConnectivity" + ": Unknown exception");
1104 }
1105 }
1106 notifyRequester(request);
1107 break;
1108 }
1109
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001110 case CMD_ENABLE_VONR: {
1111 request = (MainThreadRequest) msg.obj;
1112 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1113 Phone phone = getPhoneFromRequest(request);
1114 if (phone != null) {
1115 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1116 request.workSource);
1117 } else {
1118 loge("setVoNrEnabled: No phone object");
1119 request.result =
1120 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1121 notifyRequester(request);
1122 }
1123 break;
1124 }
1125
1126 case EVENT_ENABLE_VONR_DONE: {
1127 ar = (AsyncResult) msg.obj;
1128 request = (MainThreadRequest) ar.userObj;
1129 if (ar.exception == null) {
1130 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1131 } else {
1132 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1133 if (ar.exception instanceof CommandException) {
1134 CommandException.Error error =
1135 ((CommandException) (ar.exception)).getCommandError();
1136 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1137 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1138 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1139 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1140 } else {
1141 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1142 }
1143 loge("setVoNrEnabled" + ": CommandException: "
1144 + ar.exception);
1145 } else {
1146 loge("setVoNrEnabled" + ": Unknown exception");
1147 }
1148 }
1149 notifyRequester(request);
1150 break;
1151 }
1152
SongFerngWang3ef3e072020-12-21 16:41:52 +08001153 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001154 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001155 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1156 request);
1157 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001158 break;
1159
SongFerngWang3ef3e072020-12-21 16:41:52 +08001160 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001161 ar = (AsyncResult) msg.obj;
1162 request = (MainThreadRequest) ar.userObj;
1163 if (ar.exception == null && ar.result != null) {
1164 request.result = ar.result; // Integer
1165 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301166 // request.result must be set to something non-null
1167 // for the calling thread to unblock
1168 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001169 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001170 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001171 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001172 loge("getAllowedNetworkTypesBitmask: CommandException: "
1173 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001174 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001175 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001176 }
1177 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001178 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001179 break;
1180
SongFerngWang3ef3e072020-12-21 16:41:52 +08001181 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001182 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001183 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1184 request);
1185 Pair<Integer, Long> reasonWithNetworkTypes =
1186 (Pair<Integer, Long>) request.argument;
1187 getPhoneFromRequest(request).setAllowedNetworkTypes(
1188 reasonWithNetworkTypes.first,
1189 reasonWithNetworkTypes.second,
1190 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001191 break;
1192
SongFerngWang3ef3e072020-12-21 16:41:52 +08001193 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1194 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001195 break;
1196
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001197 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1198 request = (MainThreadRequest)msg.obj;
1199 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001200 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001201 break;
1202
1203 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1204 ar = (AsyncResult)msg.obj;
1205 request = (MainThreadRequest)ar.userObj;
1206 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001207 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001208 break;
1209
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001210 case CMD_SET_VOICEMAIL_NUMBER:
1211 request = (MainThreadRequest) msg.obj;
1212 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1213 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001214 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1215 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001216 break;
1217
1218 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1219 handleNullReturnEvent(msg, "setVoicemailNumber");
1220 break;
1221
Stuart Scott54788802015-03-30 13:18:01 -07001222 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1223 request = (MainThreadRequest) msg.obj;
1224 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1225 request);
1226 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1227 break;
1228
1229 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1230 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1231 break;
1232
Shishir Agrawal302c8692015-06-19 13:49:39 -07001233 case CMD_PERFORM_NETWORK_SCAN:
1234 request = (MainThreadRequest) msg.obj;
1235 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1236 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1237 break;
1238
Hall Liu27d24262020-09-18 19:04:59 -07001239 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001240 request = (MainThreadRequest) msg.obj;
1241 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001242 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1243 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1244 request.argument;
1245 int callForwardingReason = args.first;
1246 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001247 break;
Hall Liu27d24262020-09-18 19:04:59 -07001248 }
1249 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001250 ar = (AsyncResult) msg.obj;
1251 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001252 TelephonyManager.CallForwardingInfoCallback callback =
1253 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1254 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001255 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001256 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001257 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1258 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1259 // Service Class is a bit mask per 3gpp 27.007. Search for
1260 // any service for voice call.
1261 if ((callForwardInfo.serviceClass
1262 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001263 callForwardingInfo = new CallForwardingInfo(
1264 callForwardInfo.status
1265 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001266 callForwardInfo.reason,
1267 callForwardInfo.number,
1268 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001269 break;
1270 }
1271 }
1272 // Didn't find a call forward info for voice call.
1273 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001274 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1275 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001276 }
Hall Liu27d24262020-09-18 19:04:59 -07001277 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001278 } else {
1279 if (ar.result == null) {
1280 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1281 }
1282 if (ar.exception != null) {
1283 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1284 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001285 int errorCode = TelephonyManager
1286 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001287 if (ar.exception instanceof CommandException) {
1288 CommandException.Error error =
1289 ((CommandException) (ar.exception)).getCommandError();
1290 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001291 errorCode = TelephonyManager
1292 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001293 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001294 errorCode = TelephonyManager
1295 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001296 }
1297 }
Hall Liu27d24262020-09-18 19:04:59 -07001298 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001299 }
Shuo Qian4a594052020-01-23 11:59:30 -08001300 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 CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001304 request = (MainThreadRequest) msg.obj;
1305 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001306 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001307 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001308 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1309 request.argument).first;
1310 request.phone.setCallForwardingOption(
1311 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001312 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001313 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001314 callForwardingInfoToSet.getReason(),
1315 callForwardingInfoToSet.getNumber(),
1316 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1317 break;
Hall Liu27d24262020-09-18 19:04:59 -07001318 }
Shuo Qian4a594052020-01-23 11:59:30 -08001319
Hall Liu27d24262020-09-18 19:04:59 -07001320 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001321 ar = (AsyncResult) msg.obj;
1322 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001323 Consumer<Integer> callback =
1324 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1325 request.argument).second;
1326 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001327 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001328 int errorCode = TelephonyManager.CallForwardingInfoCallback
1329 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001330 if (ar.exception instanceof CommandException) {
1331 CommandException.Error error =
1332 ((CommandException) (ar.exception)).getCommandError();
1333 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001334 errorCode = TelephonyManager.CallForwardingInfoCallback
1335 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001336 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001337 errorCode = TelephonyManager.CallForwardingInfoCallback
1338 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001339 }
1340 }
1341 callback.accept(errorCode);
1342 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001343 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001344 }
Shuo Qian4a594052020-01-23 11:59:30 -08001345 break;
Hall Liu27d24262020-09-18 19:04:59 -07001346 }
Shuo Qian4a594052020-01-23 11:59:30 -08001347
Hall Liu27d24262020-09-18 19:04:59 -07001348 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001349 request = (MainThreadRequest) msg.obj;
1350 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1351 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1352 break;
Hall Liu27d24262020-09-18 19:04:59 -07001353 }
Shuo Qian4a594052020-01-23 11:59:30 -08001354
Hall Liu27d24262020-09-18 19:04:59 -07001355 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001356 ar = (AsyncResult) msg.obj;
1357 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001358 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001359 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001360 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001361 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001362 // Service Class is a bit mask per 3gpp 27.007.
1363 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001364 if (callForwardResults.length > 1
1365 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001366 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001367 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001368 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1369 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001370 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001371 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001372 }
1373 } else {
1374 if (ar.result == null) {
1375 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1376 }
1377 if (ar.exception != null) {
1378 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1379 }
1380 if (ar.exception instanceof CommandException) {
1381 CommandException.Error error =
1382 ((CommandException) (ar.exception)).getCommandError();
1383 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001384 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001385 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001386 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1387 callWaitingStatus =
1388 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001389 }
1390 }
1391 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001392 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001393 break;
Hall Liu27d24262020-09-18 19:04:59 -07001394 }
Shuo Qian4a594052020-01-23 11:59:30 -08001395
Hall Liu27d24262020-09-18 19:04:59 -07001396 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001397 request = (MainThreadRequest) msg.obj;
1398 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001399 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1400 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001401 break;
Hall Liu27d24262020-09-18 19:04:59 -07001402 }
Shuo Qian4a594052020-01-23 11:59:30 -08001403
Hall Liu27d24262020-09-18 19:04:59 -07001404 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001405 ar = (AsyncResult) msg.obj;
1406 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001407 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1408 Consumer<Integer> callback =
1409 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1410 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001411 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001412 if (ar.exception instanceof CommandException) {
1413 CommandException.Error error =
1414 ((CommandException) (ar.exception)).getCommandError();
1415 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1416 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001417 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1418 callback.accept(
1419 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001420 } else {
1421 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1422 }
1423 } else {
1424 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1425 }
1426 } else {
1427 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1428 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001429 }
Shuo Qian4a594052020-01-23 11:59:30 -08001430 break;
Hall Liu27d24262020-09-18 19:04:59 -07001431 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001432 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1433 ar = (AsyncResult) msg.obj;
1434 request = (MainThreadRequest) ar.userObj;
1435 CellNetworkScanResult cellScanResult;
1436 if (ar.exception == null && ar.result != null) {
1437 cellScanResult = new CellNetworkScanResult(
1438 CellNetworkScanResult.STATUS_SUCCESS,
1439 (List<OperatorInfo>) ar.result);
1440 } else {
1441 if (ar.result == null) {
1442 loge("getCellNetworkScanResults: Empty response");
1443 }
1444 if (ar.exception != null) {
1445 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1446 }
1447 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1448 if (ar.exception instanceof CommandException) {
1449 CommandException.Error error =
1450 ((CommandException) (ar.exception)).getCommandError();
1451 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1452 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1453 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1454 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1455 }
1456 }
1457 cellScanResult = new CellNetworkScanResult(errorCode, null);
1458 }
1459 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001460 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001461 break;
1462
1463 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1464 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001465 ManualNetworkSelectionArgument selArg =
1466 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001467 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1468 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001469 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1470 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001471 break;
1472
1473 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001474 ar = (AsyncResult) msg.obj;
1475 request = (MainThreadRequest) ar.userObj;
1476 if (ar.exception == null) {
1477 request.result = true;
1478 } else {
1479 request.result = false;
1480 loge("setNetworkSelectionModeManual " + ar.exception);
1481 }
1482 notifyRequester(request);
1483 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001484 break;
1485
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001486 case CMD_GET_MODEM_ACTIVITY_INFO:
1487 request = (MainThreadRequest) msg.obj;
1488 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001489 if (defaultPhone != null) {
1490 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001491 } else {
1492 ResultReceiver result = (ResultReceiver) request.argument;
1493 Bundle bundle = new Bundle();
1494 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001495 new ModemActivityInfo(0, 0, 0,
1496 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001497 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001498 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001499 break;
1500
Hall Liud0f208c2020-10-14 16:54:44 -07001501 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001502 ar = (AsyncResult) msg.obj;
1503 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001504 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001505 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001506 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001507 if (mLastModemActivityInfo == null) {
1508 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1509 mLastModemActivitySpecificInfo[0] =
1510 new ActivityStatsTechSpecificInfo(
1511 0,
1512 0,
1513 new int[ModemActivityInfo.getNumTxPowerLevels()],
1514 0);
1515 mLastModemActivityInfo =
1516 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1517 }
1518
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001519 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001520 // Update the last modem activity info and the result of the request.
1521 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1522 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001523 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001524 } else {
1525 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001526 }
Kai Shi917fdc62022-11-28 14:01:02 -08001527 // This is needed to decouple ret from mLastModemActivityInfo
1528 // We don't want to return mLastModemActivityInfo which is updated
1529 // inside mergeModemActivityInfo()
1530 ret = new ModemActivityInfo(
1531 mLastModemActivityInfo.getTimestampMillis(),
1532 mLastModemActivityInfo.getSleepTimeMillis(),
1533 mLastModemActivityInfo.getIdleTimeMillis(),
1534 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001535
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001536 } else {
1537 if (ar.result == null) {
1538 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001539 error = TelephonyManager.ModemActivityInfoException
1540 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001541 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001542 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001543 error = TelephonyManager.ModemActivityInfoException
1544 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001545 } else {
1546 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001547 error = TelephonyManager.ModemActivityInfoException
1548 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001549 }
1550 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001551 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001552 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001553 bundle.putParcelable(
1554 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001555 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001556 } else {
1557 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1558 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001559 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001560 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001561 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001562 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001563
Meng Wang1a7c35a2016-05-05 20:56:15 -07001564 case CMD_SET_ALLOWED_CARRIERS:
1565 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001566 CarrierRestrictionRules argument =
1567 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001568 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001569 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001570 break;
1571
1572 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1573 ar = (AsyncResult) msg.obj;
1574 request = (MainThreadRequest) ar.userObj;
1575 if (ar.exception == null && ar.result != null) {
1576 request.result = ar.result;
1577 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001578 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1579 if (ar.exception instanceof CommandException) {
1580 loge("setAllowedCarriers: CommandException: " + ar.exception);
1581 CommandException.Error error =
1582 ((CommandException) (ar.exception)).getCommandError();
1583 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1584 request.result =
1585 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1586 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001587 } else {
1588 loge("setAllowedCarriers: Unknown exception");
1589 }
1590 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001591 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001592 break;
1593
1594 case CMD_GET_ALLOWED_CARRIERS:
1595 request = (MainThreadRequest) msg.obj;
1596 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001597 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001598 break;
1599
1600 case EVENT_GET_ALLOWED_CARRIERS_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 {
Michele Berionne482f8202018-11-27 18:57:59 -08001606 request.result = new IllegalStateException(
1607 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001608 if (ar.result == null) {
1609 loge("getAllowedCarriers: Empty response");
1610 } else if (ar.exception instanceof CommandException) {
1611 loge("getAllowedCarriers: CommandException: " +
1612 ar.exception);
1613 } else {
1614 loge("getAllowedCarriers: Unknown exception");
1615 }
1616 }
arunvoddud7401012022-12-15 16:08:12 +00001617 if (request.argument != null) {
1618 // This is for the implementation of carrierRestrictionStatus.
1619 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1620 Consumer<Integer> callback = callbackInfo.getConsumer();
1621 int callerCarrierId = callbackInfo.getCarrierId();
1622 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1623 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1624 CarrierRestrictionRules carrierRestrictionRules =
1625 (CarrierRestrictionRules) ar.result;
1626 int carrierId = -1;
1627 try {
1628 CarrierIdentifier carrierIdentifier =
1629 carrierRestrictionRules.getAllowedCarriers().get(0);
1630 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1631 carrierIdentifier);
1632 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1633 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1634 }
1635 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1636 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1637 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
1638 lockStatus =
1639 TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
1640 }
1641 } else {
1642 Rlog.e(LOG_TAG,
1643 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1644 }
1645 callback.accept(lockStatus);
1646 } else {
1647 // This is for the implementation of getAllowedCarriers.
1648 notifyRequester(request);
1649 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001650 break;
1651
Nathan Haroldb3014052017-01-25 15:57:32 -08001652 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1653 ar = (AsyncResult) msg.obj;
1654 request = (MainThreadRequest) ar.userObj;
1655 if (ar.exception == null && ar.result != null) {
1656 request.result = ar.result;
1657 } else {
1658 request.result = new IllegalArgumentException(
1659 "Failed to retrieve Forbidden Plmns");
1660 if (ar.result == null) {
1661 loge("getForbiddenPlmns: Empty response");
1662 } else {
1663 loge("getForbiddenPlmns: Unknown exception");
1664 }
1665 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001666 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001667 break;
1668
1669 case CMD_GET_FORBIDDEN_PLMNS:
1670 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001671 uiccPort = getUiccPortFromRequest(request);
1672 if (uiccPort == null) {
1673 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001674 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001675 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001676 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001677 break;
1678 }
1679 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001680 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001681 if (uiccApp == null) {
1682 loge("getForbiddenPlmns() no app with specified type -- "
1683 + appType);
1684 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001685 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001686 break;
1687 } else {
1688 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1689 + " specified type -- " + appType);
1690 }
1691 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1692 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1693 onCompleted);
1694 break;
1695
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001696 case CMD_SWITCH_SLOTS:
1697 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001698 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001699 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001700 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001701 break;
1702
1703 case EVENT_SWITCH_SLOTS_DONE:
1704 ar = (AsyncResult) msg.obj;
1705 request = (MainThreadRequest) ar.userObj;
1706 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001707 notifyRequester(request);
1708 break;
1709 case CMD_GET_NETWORK_SELECTION_MODE:
1710 request = (MainThreadRequest) msg.obj;
1711 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1712 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1713 break;
1714
1715 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1716 ar = (AsyncResult) msg.obj;
1717 request = (MainThreadRequest) ar.userObj;
1718 if (ar.exception != null) {
1719 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1720 } else {
1721 int mode = ((int[]) ar.result)[0];
1722 if (mode == 0) {
1723 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1724 } else {
1725 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1726 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001727 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001728 notifyRequester(request);
1729 break;
1730 case CMD_GET_CDMA_ROAMING_MODE:
1731 request = (MainThreadRequest) msg.obj;
1732 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1733 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1734 break;
1735 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1736 ar = (AsyncResult) msg.obj;
1737 request = (MainThreadRequest) ar.userObj;
1738 if (ar.exception != null) {
1739 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1740 } else {
1741 request.result = ((int[]) ar.result)[0];
1742 }
1743 notifyRequester(request);
1744 break;
1745 case CMD_SET_CDMA_ROAMING_MODE:
1746 request = (MainThreadRequest) msg.obj;
1747 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1748 int mode = (int) request.argument;
1749 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1750 break;
1751 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1752 ar = (AsyncResult) msg.obj;
1753 request = (MainThreadRequest) ar.userObj;
1754 request.result = ar.exception == null;
1755 notifyRequester(request);
1756 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001757 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1758 request = (MainThreadRequest) msg.obj;
1759 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1760 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1761 break;
1762 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1763 ar = (AsyncResult) msg.obj;
1764 request = (MainThreadRequest) ar.userObj;
1765 if (ar.exception != null) {
1766 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1767 } else {
1768 request.result = ((int[]) ar.result)[0];
1769 }
1770 notifyRequester(request);
1771 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001772 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1773 request = (MainThreadRequest) msg.obj;
1774 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1775 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001776 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1777 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001778 break;
1779 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1780 ar = (AsyncResult) msg.obj;
1781 request = (MainThreadRequest) ar.userObj;
1782 request.result = ar.exception == null;
1783 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001784 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001785 case CMD_GET_ALL_CELL_INFO:
1786 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001787 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001788 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001789 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001790 case EVENT_GET_ALL_CELL_INFO_DONE:
1791 ar = (AsyncResult) msg.obj;
1792 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001793 // If a timeout occurs, the response will be null
1794 request.result = (ar.exception == null && ar.result != null)
1795 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001796 synchronized (request) {
1797 request.notifyAll();
1798 }
1799 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001800 case CMD_REQUEST_CELL_INFO_UPDATE:
1801 request = (MainThreadRequest) msg.obj;
1802 request.phone.requestCellInfoUpdate(request.workSource,
1803 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1804 break;
1805 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1806 ar = (AsyncResult) msg.obj;
1807 request = (MainThreadRequest) ar.userObj;
1808 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1809 try {
1810 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001811 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001812 cb.onError(
1813 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1814 ar.exception.getClass().getName(),
1815 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001816 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001817 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001818 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001819 } else {
1820 // use the result as returned
1821 cb.onCellInfo((List<CellInfo>) ar.result);
1822 }
1823 } catch (RemoteException re) {
1824 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1825 }
1826 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001827 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001828 request = (MainThreadRequest) msg.obj;
1829 WorkSource ws = (WorkSource) request.argument;
1830 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001831 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001832 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001833 }
1834 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001835 ar = (AsyncResult) msg.obj;
1836 request = (MainThreadRequest) ar.userObj;
1837 if (ar.exception == null) {
1838 request.result = ar.result;
1839 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001840 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001841 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001842 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001843 }
1844
1845 synchronized (request) {
1846 request.notifyAll();
1847 }
1848 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001849 }
chen xu6dac5ab2018-10-26 17:39:23 -07001850 case CMD_MODEM_REBOOT:
1851 request = (MainThreadRequest) msg.obj;
1852 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001853 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001854 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001855 case EVENT_CMD_MODEM_REBOOT_DONE:
1856 handleNullReturnEvent(msg, "rebootModem");
1857 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001858 case CMD_REQUEST_ENABLE_MODEM:
1859 request = (MainThreadRequest) msg.obj;
1860 boolean enable = (boolean) request.argument;
1861 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001862 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001863 PhoneConfigurationManager.getInstance()
1864 .enablePhone(request.phone, enable, onCompleted);
1865 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001866 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001867 ar = (AsyncResult) msg.obj;
1868 request = (MainThreadRequest) ar.userObj;
1869 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001870 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001871 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001872 if ((boolean) request.result) {
1873 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1874 updateModemStateMetrics();
1875 } else {
1876 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1877 + ar.exception);
1878 }
1879 notifyRequester(request);
1880 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001881 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001882 case CMD_GET_MODEM_STATUS:
1883 request = (MainThreadRequest) msg.obj;
1884 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1885 PhoneConfigurationManager.getInstance()
1886 .getPhoneStatusFromModem(request.phone, onCompleted);
1887 break;
1888 case EVENT_GET_MODEM_STATUS_DONE:
1889 ar = (AsyncResult) msg.obj;
1890 request = (MainThreadRequest) ar.userObj;
1891 int id = request.phone.getPhoneId();
1892 if (ar.exception == null && ar.result != null) {
1893 request.result = ar.result;
1894 //update the cache as modem status has changed
1895 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1896 (boolean) request.result);
1897 } else {
1898 // Return true if modem status cannot be retrieved. For most cases,
1899 // modem status is on. And for older version modems, GET_MODEM_STATUS
1900 // and disable modem are not supported. Modem is always on.
1901 // TODO: this should be fixed in R to support a third
1902 // status UNKNOWN b/131631629
1903 request.result = true;
1904 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1905 + ar.exception);
1906 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001907 notifyRequester(request);
1908 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001909 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1910 request = (MainThreadRequest) msg.obj;
1911 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1912 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1913 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1914 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1915 break;
1916 }
1917 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1918 ar = (AsyncResult) msg.obj;
1919 request = (MainThreadRequest) ar.userObj;
1920 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1921 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1922 args.second.accept(ar.exception == null);
1923 notifyRequester(request);
1924 break;
1925 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001926 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1927 request = (MainThreadRequest) msg.obj;
1928 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1929 Phone phone = getPhoneFromRequest(request);
1930 if (phone != null) {
1931 phone.getSystemSelectionChannels(onCompleted);
1932 } else {
1933 loge("getSystemSelectionChannels: No phone object");
1934 request.result = new ArrayList<RadioAccessSpecifier>();
1935 notifyRequester(request);
1936 }
1937 break;
1938 }
1939 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1940 ar = (AsyncResult) msg.obj;
1941 request = (MainThreadRequest) ar.userObj;
1942 if (ar.exception == null && ar.result != null) {
1943 request.result = ar.result;
1944 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001945 request.result = new IllegalStateException(
1946 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001947 if (ar.result == null) {
1948 loge("getSystemSelectionChannels: Empty response");
1949 } else {
1950 loge("getSystemSelectionChannels: Unknown exception");
1951 }
1952 }
1953 notifyRequester(request);
1954 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001955 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1956 ar = (AsyncResult) msg.obj;
1957 request = (MainThreadRequest) ar.userObj;
1958 if (ar.exception == null && ar.result != null) {
1959 request.result = ar.result;
1960 } else {
1961 request.result = -1;
1962 loge("Failed to set Forbidden Plmns");
1963 if (ar.result == null) {
1964 loge("setForbidenPlmns: Empty response");
1965 } else if (ar.exception != null) {
1966 loge("setForbiddenPlmns: Exception: " + ar.exception);
1967 request.result = -1;
1968 } else {
1969 loge("setForbiddenPlmns: Unknown exception");
1970 }
1971 }
1972 notifyRequester(request);
1973 break;
1974 case CMD_SET_FORBIDDEN_PLMNS:
1975 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001976 uiccPort = getUiccPortFromRequest(request);
1977 if (uiccPort == null) {
1978 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001979 request.result = -1;
1980 notifyRequester(request);
1981 break;
1982 }
1983 Pair<Integer, List<String>> setFplmnsArgs =
1984 (Pair<Integer, List<String>>) request.argument;
1985 appType = setFplmnsArgs.first;
1986 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001987 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001988 if (uiccApp == null) {
1989 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1990 request.result = -1;
1991 loge("Failed to get UICC App");
1992 notifyRequester(request);
1993 } else {
1994 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1995 ((SIMRecords) uiccApp.getIccRecords())
1996 .setForbiddenPlmns(onCompleted, fplmns);
1997 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001998 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001999 case CMD_ERASE_MODEM_CONFIG:
2000 request = (MainThreadRequest) msg.obj;
2001 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
2002 defaultPhone.eraseModemConfig(onCompleted);
2003 break;
2004 case EVENT_ERASE_MODEM_CONFIG_DONE:
2005 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07002006 break;
zoey chene02881a2019-12-30 16:11:23 +08002007
Kai Shif70f46f2021-03-03 13:59:46 -08002008 case CMD_ERASE_DATA_SHARED_PREFERENCES:
2009 request = (MainThreadRequest) msg.obj;
2010 request.result = defaultPhone.eraseDataInSharedPreferences();
2011 notifyRequester(request);
2012 break;
2013
zoey chene02881a2019-12-30 16:11:23 +08002014 case CMD_CHANGE_ICC_LOCK_PASSWORD:
2015 request = (MainThreadRequest) msg.obj;
2016 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
2017 Pair<String, String> changed = (Pair<String, String>) request.argument;
2018 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
2019 changed.first, changed.second, onCompleted);
2020 break;
2021 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2022 ar = (AsyncResult) msg.obj;
2023 request = (MainThreadRequest) ar.userObj;
2024 if (ar.exception == null) {
2025 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002026 // If the operation is successful, update the PIN storage
2027 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2028 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002029 UiccController.getInstance().getPinStorage()
2030 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002031 } else {
2032 request.result = msg.arg1;
2033 }
2034 notifyRequester(request);
2035 break;
2036
Michele Berionne5e411512020-11-13 02:36:59 +00002037 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002038 request = (MainThreadRequest) msg.obj;
2039 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2040 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2041 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2042 enabled.first, enabled.second, onCompleted);
2043 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002044 }
zoey chene02881a2019-12-30 16:11:23 +08002045 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2046 ar = (AsyncResult) msg.obj;
2047 request = (MainThreadRequest) ar.userObj;
2048 if (ar.exception == null) {
2049 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002050 // If the operation is successful, update the PIN storage
2051 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2052 int phoneId = getPhoneFromRequest(request).getPhoneId();
2053 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002054 UiccController.getInstance().getPinStorage()
2055 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002056 } else {
2057 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2058 }
zoey chene02881a2019-12-30 16:11:23 +08002059 } else {
2060 request.result = msg.arg1;
2061 }
Michele Berionne5e411512020-11-13 02:36:59 +00002062
2063
zoey chene02881a2019-12-30 16:11:23 +08002064 notifyRequester(request);
2065 break;
2066
Peter Wangdafb9ac2020-01-15 14:13:38 -08002067 case MSG_NOTIFY_USER_ACTIVITY:
2068 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002069 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002070 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2071 getDefaultPhone().getContext().sendBroadcastAsUser(
2072 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2073 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002074
2075 case CMD_SET_DATA_THROTTLING: {
2076 request = (MainThreadRequest) msg.obj;
2077 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2078 DataThrottlingRequest dataThrottlingRequest =
2079 (DataThrottlingRequest) request.argument;
2080 Phone phone = getPhoneFromRequest(request);
2081 if (phone != null) {
2082 phone.setDataThrottling(onCompleted,
2083 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2084 dataThrottlingRequest.getCompletionDurationMillis());
2085 } else {
2086 loge("setDataThrottling: No phone object");
2087 request.result =
2088 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2089 notifyRequester(request);
2090 }
2091
2092 break;
2093 }
2094 case EVENT_SET_DATA_THROTTLING_DONE:
2095 ar = (AsyncResult) msg.obj;
2096 request = (MainThreadRequest) ar.userObj;
2097
2098 if (ar.exception == null) {
2099 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2100 } else if (ar.exception instanceof CommandException) {
2101 loge("setDataThrottling: CommandException: " + ar.exception);
2102 CommandException.Error error =
2103 ((CommandException) (ar.exception)).getCommandError();
2104
2105 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2106 request.result = TelephonyManager
2107 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2108 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2109 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002110 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2111 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002112 } else {
2113 request.result =
2114 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2115 }
2116 } else {
2117 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2118 }
2119 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2120 notifyRequester(request);
2121 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002122
2123 case CMD_SET_SIM_POWER: {
2124 request = (MainThreadRequest) msg.obj;
2125 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2126 request = (MainThreadRequest) msg.obj;
2127 int stateToSet =
2128 ((Pair<Integer, IIntegerConsumer>)
2129 request.argument).first;
2130 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2131 break;
2132 }
2133 case EVENT_SET_SIM_POWER_DONE: {
2134 ar = (AsyncResult) msg.obj;
2135 request = (MainThreadRequest) ar.userObj;
2136 IIntegerConsumer callback =
2137 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2138 if (ar.exception != null) {
2139 loge("setSimPower exception: " + ar.exception);
2140 int errorCode = TelephonyManager.CallForwardingInfoCallback
2141 .RESULT_ERROR_UNKNOWN;
2142 if (ar.exception instanceof CommandException) {
2143 CommandException.Error error =
2144 ((CommandException) (ar.exception)).getCommandError();
2145 if (error == CommandException.Error.SIM_ERR) {
2146 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2147 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2148 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2149 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2150 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2151 } else {
2152 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2153 }
2154 }
2155 try {
2156 callback.accept(errorCode);
2157 } catch (RemoteException e) {
2158 // Ignore if the remote process is no longer available to call back.
2159 Log.w(LOG_TAG, "setSimPower: callback not available.");
2160 }
2161 } else {
2162 try {
2163 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2164 } catch (RemoteException e) {
2165 // Ignore if the remote process is no longer available to call back.
2166 Log.w(LOG_TAG, "setSimPower: callback not available.");
2167 }
2168 }
2169 break;
2170 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002171 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2172 request = (MainThreadRequest) msg.obj;
2173
2174 final Phone phone = getPhoneFromRequest(request);
2175 if (phone == null || phone.getServiceStateTracker() == null) {
2176 request.result = new IllegalStateException("Phone or SST is null");
2177 notifyRequester(request);
2178 break;
2179 }
2180
2181 Pair<Integer, SignalStrengthUpdateRequest> pair =
2182 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2183 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2184 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002185 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002186 request.subId, pair.first /*callingUid*/,
2187 pair.second /*request*/, onCompleted);
2188 break;
2189 }
2190 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2191 ar = (AsyncResult) msg.obj;
2192 request = (MainThreadRequest) ar.userObj;
2193 // request.result will be the exception of ar if present, true otherwise.
2194 // Be cautious not to leave result null which will wait() forever
2195 request.result = ar.exception != null ? ar.exception : true;
2196 notifyRequester(request);
2197 break;
2198 }
2199 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2200 request = (MainThreadRequest) msg.obj;
2201
2202 Phone phone = getPhoneFromRequest(request);
2203 if (phone == null || phone.getServiceStateTracker() == null) {
2204 request.result = new IllegalStateException("Phone or SST is null");
2205 notifyRequester(request);
2206 break;
2207 }
2208
2209 Pair<Integer, SignalStrengthUpdateRequest> pair =
2210 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2211 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2212 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002213 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002214 request.subId, pair.first /*callingUid*/,
2215 pair.second /*request*/, onCompleted);
2216 break;
2217 }
2218 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2219 ar = (AsyncResult) msg.obj;
2220 request = (MainThreadRequest) ar.userObj;
2221 request.result = ar.exception != null ? ar.exception : true;
2222 notifyRequester(request);
2223 break;
2224 }
Jordan Liu109698e2020-11-24 14:50:34 -08002225
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002226 case CMD_GET_SLICING_CONFIG: {
2227 request = (MainThreadRequest) msg.obj;
2228 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2229 request.phone.getSlicingConfig(onCompleted);
2230 break;
2231 }
2232 case EVENT_GET_SLICING_CONFIG_DONE: {
2233 ar = (AsyncResult) msg.obj;
2234 request = (MainThreadRequest) ar.userObj;
2235 ResultReceiver result = (ResultReceiver) request.argument;
2236
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002237 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002238 Bundle bundle = new Bundle();
2239 int resultCode = 0;
2240 if (ar.exception != null) {
2241 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2242 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002243 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002244 } else if (ar.result == null) {
2245 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002246 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002247 } else {
2248 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002249 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2250 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002251 }
2252
2253 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002254 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002255 }
2256 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2257 result.send(resultCode, bundle);
2258 notifyRequester(request);
2259 break;
2260 }
2261
Sarah Chin71b3a852022-09-28 15:54:19 -07002262 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002263 request = (MainThreadRequest) msg.obj;
2264 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002265 PurchasePremiumCapabilityArgument arg =
2266 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002267 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chinb8218c22023-01-04 13:35:29 -08002268 arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002269 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002270 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002271
Sarah Chin71b3a852022-09-28 15:54:19 -07002272 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002273 ar = (AsyncResult) msg.obj;
2274 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002275 PurchasePremiumCapabilityArgument arg =
2276 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002277 try {
2278 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002279 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002280 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002281 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002282 + ", result= "
2283 + TelephonyManager.convertPurchaseResultToString(result));
2284 } catch (RemoteException e) {
2285 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002286 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002287 + " failed: " + e;
2288 if (DBG) log(logStr);
2289 AnomalyReporter.reportAnomaly(
2290 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2291 }
2292 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002293 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002294
Michele Berionne5e411512020-11-13 02:36:59 +00002295 case CMD_PREPARE_UNATTENDED_REBOOT:
2296 request = (MainThreadRequest) msg.obj;
2297 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002298 UiccController.getInstance().getPinStorage()
2299 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002300 notifyRequester(request);
2301 break;
2302
Sarah Chineccfbd12023-01-20 19:00:35 -08002303 case CMD_START_SATELLITE_POSITION_UPDATES: {
2304 request = (MainThreadRequest) msg.obj;
2305 onCompleted =
2306 obtainMessage(EVENT_START_SATELLITE_POSITION_UPDATES_DONE, request);
2307 Phone phone = getPhoneFromRequest(request);
2308 if (phone != null) {
2309 phone.startSatellitePositionUpdates(onCompleted);
2310 } else {
2311 loge("startSatellitePositionUpdates: No phone object");
Sarah Chinf75afa72023-02-01 01:32:19 -08002312 request.result =
2313 SatelliteManager.SATELLITE_SERVICE_TELEPHONY_INTERNAL_ERROR;
Sarah Chineccfbd12023-01-20 19:00:35 -08002314 notifyRequester(request);
2315 }
2316 break;
2317 }
2318
2319 case EVENT_START_SATELLITE_POSITION_UPDATES_DONE: {
2320 ar = (AsyncResult) msg.obj;
2321 request = (MainThreadRequest) ar.userObj;
2322 if (ar.exception == null) {
2323 request.result = SatelliteManager.SATELLITE_SERVICE_SUCCESS;
2324 } else {
2325 request.result = SatelliteManager.SATELLITE_SERVICE_ERROR;
2326 if (ar.exception instanceof CommandException) {
2327 CommandException.Error error =
2328 ((CommandException) (ar.exception)).getCommandError();
2329 request.result = RILUtils.convertToSatelliteError(error);
2330 loge("startSatellitePositionUpdates CommandException: " + ar.exception);
2331 } else {
2332 loge("startSatellitePositionUpdates unknown exception:" + ar.exception);
2333 }
2334 }
2335 notifyRequester(request);
2336 break;
2337 }
2338
2339 case CMD_STOP_SATELLITE_POSITION_UPDATES: {
2340 request = (MainThreadRequest) msg.obj;
2341 onCompleted =
2342 obtainMessage(EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE, request);
2343 Phone phone = getPhoneFromRequest(request);
2344 if (phone != null) {
2345 phone.stopSatellitePositionUpdates(onCompleted);
2346 } else {
2347 loge("stopSatellitePositionUpdates: No phone object");
Sarah Chinf75afa72023-02-01 01:32:19 -08002348 request.result =
2349 SatelliteManager.SATELLITE_SERVICE_TELEPHONY_INTERNAL_ERROR;
Sarah Chineccfbd12023-01-20 19:00:35 -08002350 notifyRequester(request);
2351 }
2352 break;
2353 }
2354
2355 case EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE: {
2356 ar = (AsyncResult) msg.obj;
2357 request = (MainThreadRequest) ar.userObj;
2358 if (ar.exception == null) {
2359 request.result = SatelliteManager.SATELLITE_SERVICE_SUCCESS;
2360 } else {
2361 request.result = SatelliteManager.SATELLITE_SERVICE_ERROR;
2362 if (ar.exception instanceof CommandException) {
2363 CommandException.Error error =
2364 ((CommandException) (ar.exception)).getCommandError();
2365 request.result = RILUtils.convertToSatelliteError(error);
2366 loge("stopSatellitePositionUpdates CommandException: " + ar.exception);
2367 } else {
2368 loge("stopSatellitePositionUpdates unknown exception:" + ar.exception);
2369 }
2370 }
2371 notifyRequester(request);
2372 break;
2373 }
2374
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002375 case CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG: {
2376 request = (MainThreadRequest) msg.obj;
2377 onCompleted = obtainMessage(EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE,
2378 request);
2379 Phone phone = getPhoneFromRequest(request);
2380 if (phone != null) {
2381 phone.getMaxCharactersPerSatelliteTextMessage(onCompleted);
2382 } else {
2383 loge("getMaxCharactersPerSatelliteTextMessage: No phone object");
2384 request.result = SatelliteManager
2385 .SATELLITE_SERVICE_TELEPHONY_INTERNAL_ERROR;
2386 notifyRequester(request);
2387 }
2388 break;
2389 }
2390
2391 case EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE: {
2392 ar = (AsyncResult) msg.obj;
2393 request = (MainThreadRequest) ar.userObj;
2394 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
2395 if (ar.exception != null) {
2396 request.result = SatelliteManager.SATELLITE_SERVICE_ERROR;
2397 if (ar.exception instanceof CommandException) {
2398 CommandException.Error error =
2399 ((CommandException) (ar.exception)).getCommandError();
2400 request.result = RILUtils.convertToSatelliteError(error);
2401 loge("getMaxCharactersPerSatelliteTextMessage: "
2402 + "CommandException: " + ar.exception);
2403 } else {
2404 loge("getMaxCharactersPerSatelliteTextMessage: "
2405 + "unknown exception:" + ar.exception);
2406 }
2407 } else if (ar.result == null) {
2408 request.result = SatelliteManager
2409 .SATELLITE_SERVICE_TELEPHONY_INTERNAL_ERROR;
2410 loge("getMaxCharactersPerSatelliteTextMessage: result is null");
2411 } else {
2412 request.result = SatelliteManager.SATELLITE_SERVICE_SUCCESS;
2413 int maxCharLimit = ((int[]) ar.result)[0];
2414 if(DBG) log("getMaxCharactersPerSatelliteTextMessage "
2415 + "maxCharLimit:" + maxCharLimit);
2416 callback.accept(maxCharLimit);
2417 }
2418 notifyRequester(request);
2419 break;
2420 }
2421
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422 default:
2423 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2424 break;
2425 }
2426 }
Jake Hambye994d462014-02-03 13:10:13 -08002427
Pengquan Menga1bb6272018-09-06 09:59:22 -07002428 private void notifyRequester(MainThreadRequest request) {
2429 synchronized (request) {
2430 request.notifyAll();
2431 }
2432 }
2433
Jake Hambye994d462014-02-03 13:10:13 -08002434 private void handleNullReturnEvent(Message msg, String command) {
2435 AsyncResult ar = (AsyncResult) msg.obj;
2436 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2437 if (ar.exception == null) {
2438 request.result = true;
2439 } else {
2440 request.result = false;
2441 if (ar.exception instanceof CommandException) {
2442 loge(command + ": CommandException: " + ar.exception);
2443 } else {
2444 loge(command + ": Unknown exception");
2445 }
2446 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002447 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002448 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 }
2450
2451 /**
2452 * Posts the specified command to be executed on the main thread,
2453 * waits for the request to complete, and returns the result.
2454 * @see #sendRequestAsync
2455 */
2456 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002457 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2458 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002459 }
2460
2461 /**
2462 * Posts the specified command to be executed on the main thread,
2463 * waits for the request to complete, and returns the result.
2464 * @see #sendRequestAsync
2465 */
2466 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2467 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002468 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002469 }
2470
2471 /**
2472 * Posts the specified command to be executed on the main thread,
2473 * waits for the request to complete, and returns the result.
2474 * @see #sendRequestAsync
2475 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002476 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002477 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2478 }
2479
2480 /**
2481 * Posts the specified command to be executed on the main thread,
2482 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2483 * if not timeout or null otherwise.
2484 * @see #sendRequestAsync
2485 */
2486 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2487 long timeoutInMs) {
2488 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002489 }
2490
2491 /**
2492 * Posts the specified command to be executed on the main thread,
2493 * waits for the request to complete, and returns the result.
2494 * @see #sendRequestAsync
2495 */
Nathan Harold92bed182018-10-12 18:16:49 -07002496 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002497 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002498 }
2499
2500 /**
2501 * Posts the specified command to be executed on the main thread,
2502 * waits for the request to complete, and returns the result.
2503 * @see #sendRequestAsync
2504 */
2505 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002506 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2507 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002508 }
2509
2510 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002511 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2512 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2513 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002514 * @see #sendRequestAsync
2515 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002516 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2517 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002518 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2519 throw new RuntimeException("This method will deadlock if called from the main thread.");
2520 }
2521
Nathan Harold92bed182018-10-12 18:16:49 -07002522 MainThreadRequest request = null;
2523 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2524 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2525 } else if (phone != null) {
2526 request = new MainThreadRequest(argument, phone, workSource);
2527 } else {
2528 request = new MainThreadRequest(argument, subId, workSource);
2529 }
2530
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002531 Message msg = mMainThreadHandler.obtainMessage(command, request);
2532 msg.sendToTarget();
2533
Rambo Wang0f050d82021-02-12 11:43:36 -08002534
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002535 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002536 if (timeoutInMs >= 0) {
2537 // Wait for at least timeoutInMs before returning null request result
2538 long now = SystemClock.elapsedRealtime();
2539 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002540 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002541 try {
2542 request.wait(deadline - now);
2543 } catch (InterruptedException e) {
2544 // Do nothing, go back and check if request is completed or timeout
2545 } finally {
2546 now = SystemClock.elapsedRealtime();
2547 }
2548 }
2549 } else {
2550 // Wait for the request to complete
2551 while (request.result == null) {
2552 try {
2553 request.wait();
2554 } catch (InterruptedException e) {
2555 // Do nothing, go back and wait until the request is complete
2556 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002557 }
2558 }
2559 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002560 if (request.result == null) {
2561 Log.wtf(LOG_TAG,
2562 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 return request.result;
2565 }
2566
2567 /**
2568 * Asynchronous ("fire and forget") version of sendRequest():
2569 * Posts the specified command to be executed on the main thread, and
2570 * returns immediately.
2571 * @see #sendRequest
2572 */
2573 private void sendRequestAsync(int command) {
2574 mMainThreadHandler.sendEmptyMessage(command);
2575 }
2576
2577 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002578 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002579 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002580 */
2581 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002582 sendRequestAsync(command, argument, null, null);
2583 }
2584
2585 /**
2586 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2587 * @see {@link #sendRequest(int,Object)}
2588 */
2589 private void sendRequestAsync(
2590 int command, Object argument, Phone phone, WorkSource workSource) {
2591 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002592 Message msg = mMainThreadHandler.obtainMessage(command, request);
2593 msg.sendToTarget();
2594 }
2595
2596 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002597 * Initialize the singleton PhoneInterfaceManager instance.
2598 * This is only done once, at startup, from PhoneApp.onCreate().
2599 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002600 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002601 synchronized (PhoneInterfaceManager.class) {
2602 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002603 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002604 } else {
2605 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2606 }
2607 return sInstance;
2608 }
2609 }
2610
2611 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002612 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002613 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002614 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002615 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002616 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002617 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002618 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002619 mMainThreadHandler = new MainThreadHandler();
Jack Yue37dd262022-12-16 11:53:37 -08002620 if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) {
2621 mSubscriptionController = SubscriptionController.getInstance();
2622 } else {
2623 mSubscriptionController = null;
2624 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002625 mTelephonySharedPreferences =
2626 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002627 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002628 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002629 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002630 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002631 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002632 publish();
arunvoddud7401012022-12-15 16:08:12 +00002633 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 }
2635
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002636 @VisibleForTesting
2637 public SharedPreferences getSharedPreferences() {
2638 return mTelephonySharedPreferences;
2639 }
2640
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002641 /**
2642 * Get the default phone for this device.
2643 */
2644 @VisibleForTesting
2645 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002646 Phone thePhone = getPhone(getDefaultSubscription());
2647 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2648 }
2649
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002650 private void publish() {
2651 if (DBG) log("publish: " + this);
2652
Peter Wangc035ce42020-01-08 21:00:22 -08002653 TelephonyFrameworkInitializer
2654 .getTelephonyServiceManager()
2655 .getTelephonyServiceRegisterer()
2656 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002657 }
2658
Stuart Scott584921c2015-01-15 17:10:34 -08002659 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002660 if (request.phone != null) {
2661 return request.phone;
2662 } else {
2663 return getPhoneFromSubId(request.subId);
2664 }
2665 }
2666
2667 private Phone getPhoneFromSubId(int subId) {
2668 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2669 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002670 }
2671
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002672 /**
2673 * Get phone object associated with a subscription.
2674 * Return default phone if phone object associated with subscription is null
2675 * @param subId - subscriptionId
2676 * @return phone object associated with a subscription or default phone if null.
2677 */
2678 private Phone getPhoneFromSubIdOrDefault(int subId) {
2679 Phone phone = getPhoneFromSubId(subId);
2680 if (phone == null) {
2681 phone = getDefaultPhone();
2682 }
2683 return phone;
2684 }
2685
Rambo Wange53e07d2022-05-10 13:01:13 -07002686 @Nullable
2687 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002688 Phone phone = getPhoneFromRequest(request);
2689 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002690 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002691 }
2692
Wink Saville36469e72014-06-11 15:17:00 -07002693 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002694 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002695 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002697
Kai Shif70f46f2021-03-03 13:59:46 -08002698 private void sendEraseModemConfig(@NonNull Phone phone) {
2699 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2700 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2701 }
2702
2703 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2704 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2705 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002706 }
2707
Peter Wang44b186e2020-01-13 23:33:09 -08002708 private boolean isImsAvailableOnDevice() {
2709 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2710 if (pm == null) {
2711 // For some reason package manger is not available.. This will fail internally anyway,
2712 // so do not throw error and allow.
2713 return true;
2714 }
2715 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2716 }
2717
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002718 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002719 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002720 }
2721
Wink Savilleb564aae2014-10-23 10:18:09 -07002722 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002723 if (DBG) log("dial: " + number);
2724 // No permission check needed here: This is just a wrapper around the
2725 // ACTION_DIAL intent, which is available to any app since it puts up
2726 // the UI before it does anything.
2727
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002728 final long identity = Binder.clearCallingIdentity();
2729 try {
2730 String url = createTelUrl(number);
2731 if (url == null) {
2732 return;
2733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002734
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735 // PENDING: should we just silently fail if phone is offhook or ringing?
2736 PhoneConstants.State state = mCM.getState(subId);
2737 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2738 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2739 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2740 mApp.startActivity(intent);
2741 }
2742 } finally {
2743 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002744 }
2745 }
2746
2747 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002748 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002749 }
2750
Wink Savilleb564aae2014-10-23 10:18:09 -07002751 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002752 if (DBG) log("call: " + number);
2753
2754 // This is just a wrapper around the ACTION_CALL intent, but we still
2755 // need to do a permission check since we're calling startActivity()
2756 // from the context of the phone app.
2757 enforceCallPermission();
2758
Jordan Liu1617b712019-07-10 15:06:26 -07002759 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002760 != AppOpsManager.MODE_ALLOWED) {
2761 return;
2762 }
2763
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764 final long identity = Binder.clearCallingIdentity();
2765 try {
2766 String url = createTelUrl(number);
2767 if (url == null) {
2768 return;
2769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002770
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002771 boolean isValid = false;
2772 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2773 if (slist != null) {
2774 for (SubscriptionInfo subInfoRecord : slist) {
2775 if (subInfoRecord.getSubscriptionId() == subId) {
2776 isValid = true;
2777 break;
2778 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002779 }
Wink Saville08874612014-08-31 19:19:58 -07002780 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002781 if (!isValid) {
2782 return;
2783 }
Wink Saville08874612014-08-31 19:19:58 -07002784
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002785 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2786 intent.putExtra(SUBSCRIPTION_KEY, subId);
2787 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2788 mApp.startActivity(intent);
2789 } finally {
2790 Binder.restoreCallingIdentity(identity);
2791 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 }
2793
Wink Savilleb564aae2014-10-23 10:18:09 -07002794 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002795 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002796 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2797 }
2798
Wink Savilleb564aae2014-10-23 10:18:09 -07002799 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002800 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002801 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2802 }
2803
Wink Savilleb564aae2014-10-23 10:18:09 -07002804 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002805 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002806
2807 final long identity = Binder.clearCallingIdentity();
2808 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002809 Phone phone = getPhone(subId);
2810 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002811 checkSimPin.start();
2812 return checkSimPin.unlockSim(null, pin);
2813 } finally {
2814 Binder.restoreCallingIdentity(identity);
2815 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002816 }
2817
Wink Savilleb564aae2014-10-23 10:18:09 -07002818 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002819 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002820
2821 final long identity = Binder.clearCallingIdentity();
2822 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002823 Phone phone = getPhone(subId);
2824 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002825 checkSimPuk.start();
2826 return checkSimPuk.unlockSim(puk, pin);
2827 } finally {
2828 Binder.restoreCallingIdentity(identity);
2829 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002830 }
2831
2832 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002833 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002834 * a synchronous one.
2835 */
2836 private static class UnlockSim extends Thread {
2837
2838 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002839 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002840
2841 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002842 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2843 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002844
2845 // For replies from SimCard interface
2846 private Handler mHandler;
2847
2848 // For async handler to identify request type
2849 private static final int SUPPLY_PIN_COMPLETE = 100;
2850
Michele Berionne5e411512020-11-13 02:36:59 +00002851 UnlockSim(int phoneId, IccCard simCard) {
2852 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002853 mSimCard = simCard;
2854 }
2855
2856 @Override
2857 public void run() {
2858 Looper.prepare();
2859 synchronized (UnlockSim.this) {
2860 mHandler = new Handler() {
2861 @Override
2862 public void handleMessage(Message msg) {
2863 AsyncResult ar = (AsyncResult) msg.obj;
2864 switch (msg.what) {
2865 case SUPPLY_PIN_COMPLETE:
2866 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2867 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002868 mRetryCount = msg.arg1;
2869 if (ar.exception != null) {
2870 if (ar.exception instanceof CommandException &&
2871 ((CommandException)(ar.exception)).getCommandError()
2872 == CommandException.Error.PASSWORD_INCORRECT) {
2873 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002874 } //When UiccCardApp dispose,handle message and return exception
2875 else if (ar.exception instanceof CommandException &&
2876 ((CommandException) (ar.exception)).getCommandError()
2877 == CommandException.Error.ABORTED) {
2878 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002879 } else {
2880 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2881 }
2882 } else {
2883 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2884 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002885 mDone = true;
2886 UnlockSim.this.notifyAll();
2887 }
2888 break;
2889 }
2890 }
2891 };
2892 UnlockSim.this.notifyAll();
2893 }
2894 Looper.loop();
2895 }
2896
2897 /*
2898 * Use PIN or PUK to unlock SIM card
2899 *
2900 * If PUK is null, unlock SIM card with PIN
2901 *
2902 * If PUK is not null, unlock SIM card with PUK and set PIN code
2903 */
Wink Saville9de0f752013-10-22 19:04:03 -07002904 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002905
2906 while (mHandler == null) {
2907 try {
2908 wait();
2909 } catch (InterruptedException e) {
2910 Thread.currentThread().interrupt();
2911 }
2912 }
2913 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2914
2915 if (puk == null) {
2916 mSimCard.supplyPin(pin, callback);
2917 } else {
2918 mSimCard.supplyPuk(puk, pin, callback);
2919 }
2920
2921 while (!mDone) {
2922 try {
2923 Log.d(LOG_TAG, "wait for done");
2924 wait();
2925 } catch (InterruptedException e) {
2926 // Restore the interrupted status
2927 Thread.currentThread().interrupt();
2928 }
2929 }
2930 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002931 int[] resultArray = new int[2];
2932 resultArray[0] = mResult;
2933 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002934
2935 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002936 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002937 }
2938
Wink Saville9de0f752013-10-22 19:04:03 -07002939 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002940 }
2941 }
2942
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002943 /**
2944 * This method has been removed due to privacy and stability concerns.
2945 */
2946 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002947 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002948 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2949 return;
Wink Saville36469e72014-06-11 15:17:00 -07002950 }
2951
Nathan Harold1f889d82020-06-04 17:05:26 -07002952 @Override
2953 public void updateServiceLocationWithPackageName(String callingPackage) {
2954 mApp.getSystemService(AppOpsManager.class)
2955 .checkPackage(Binder.getCallingUid(), callingPackage);
2956
Nathan Haroldf096d982020-11-18 17:18:06 -08002957 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002958 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2959 // Callers targeting S have no business invoking this method.
2960 return;
2961 }
2962
2963 LocationAccessPolicy.LocationPermissionResult locationResult =
2964 LocationAccessPolicy.checkLocationPermission(mApp,
2965 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2966 .setCallingPackage(callingPackage)
2967 .setCallingFeatureId(null)
2968 .setCallingPid(Binder.getCallingPid())
2969 .setCallingUid(Binder.getCallingUid())
2970 .setMethod("updateServiceLocation")
2971 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2972 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2973 .build());
2974 // Apps that lack location permission have no business calling this method;
2975 // however, because no permission was declared in the public API, denials must
2976 // all be "soft".
2977 switch (locationResult) {
2978 case DENIED_HARD: /* fall through */
2979 case DENIED_SOFT:
2980 return;
2981 }
2982
2983 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002984 final long identity = Binder.clearCallingIdentity();
2985 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002986 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002987 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002988 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002989 }
2990 } finally {
2991 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002992 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002993 }
2994
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002995 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002996 @Override
2997 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002998 return isRadioOnWithFeature(callingPackage, null);
2999 }
3000
3001
3002 @Override
3003 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
3004 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
3005 callingFeatureId);
3006 }
3007
3008 @Deprecated
3009 @Override
3010 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
3011 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07003012 }
3013
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003014 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003015 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
3016 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003017 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003018 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003019 return false;
3020 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021
3022 final long identity = Binder.clearCallingIdentity();
3023 try {
3024 return isRadioOnForSubscriber(subId);
3025 } finally {
3026 Binder.restoreCallingIdentity(identity);
3027 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003028 }
3029
3030 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003031 final long identity = Binder.clearCallingIdentity();
3032 try {
3033 final Phone phone = getPhone(subId);
3034 if (phone != null) {
3035 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
3036 } else {
3037 return false;
3038 }
3039 } finally {
3040 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003041 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003042 }
3043
3044 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003045 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003046 }
Wink Saville36469e72014-06-11 15:17:00 -07003047
Wink Savilleb564aae2014-10-23 10:18:09 -07003048 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003049 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003050
3051 final long identity = Binder.clearCallingIdentity();
3052 try {
3053 final Phone phone = getPhone(subId);
3054 if (phone != null) {
3055 phone.setRadioPower(!isRadioOnForSubscriber(subId));
3056 }
3057 } finally {
3058 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003059 }
Wink Saville36469e72014-06-11 15:17:00 -07003060 }
3061
3062 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003063 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07003064 }
3065
Wink Savilleb564aae2014-10-23 10:18:09 -07003066 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07003067 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003068
3069 final long identity = Binder.clearCallingIdentity();
3070 try {
3071 final Phone phone = getPhone(subId);
3072 if (phone == null) {
3073 return false;
3074 }
3075 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
3076 toggleRadioOnOffForSubscriber(subId);
3077 }
3078 return true;
3079 } finally {
3080 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003081 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003082 }
Wink Saville36469e72014-06-11 15:17:00 -07003083
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003084 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08003085 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003086 /*
3087 * If any of the Radios are available, it will need to be
3088 * shutdown. So return true if any Radio is available.
3089 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003090 final long identity = Binder.clearCallingIdentity();
3091 try {
3092 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3093 Phone phone = PhoneFactory.getPhone(i);
3094 if (phone != null && phone.isRadioAvailable()) return true;
3095 }
3096 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3097 return false;
3098 } finally {
3099 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003100 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003101 }
3102
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003103 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003104 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003105 enforceModifyPermission();
3106
3107 final long identity = Binder.clearCallingIdentity();
3108 try {
3109 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3110 logv("Shutting down Phone " + i);
3111 shutdownRadioUsingPhoneId(i);
3112 }
3113 } finally {
3114 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003115 }
3116 }
3117
3118 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003119 Phone phone = PhoneFactory.getPhone(phoneId);
3120 if (phone != null && phone.isRadioAvailable()) {
3121 phone.shutdownRadio();
3122 }
3123 }
3124
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003125 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003126 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003127
Ling Ma83dc5ea2023-01-12 15:06:04 -08003128 if (!turnOn) {
3129 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3130 }
3131
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003132 final long identity = Binder.clearCallingIdentity();
3133 try {
3134 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3135 if (defaultPhone != null) {
3136 defaultPhone.setRadioPower(turnOn);
3137 return true;
3138 } else {
3139 loge("There's no default phone.");
3140 return false;
3141 }
3142 } finally {
3143 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003144 }
Wink Saville36469e72014-06-11 15:17:00 -07003145 }
3146
Wink Savilleb564aae2014-10-23 10:18:09 -07003147 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003148 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003149
Ling Ma83dc5ea2023-01-12 15:06:04 -08003150 if (!turnOn) {
3151 log("setRadioPowerForSubscriber off: subId=" + subId
3152 + ",callingPackage=" + getCurrentPackageName());
3153 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003154 final long identity = Binder.clearCallingIdentity();
3155 try {
3156 final Phone phone = getPhone(subId);
3157 if (phone != null) {
3158 phone.setRadioPower(turnOn);
3159 return true;
3160 } else {
3161 return false;
3162 }
3163 } finally {
3164 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003165 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003166 }
3167
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003168 /**
3169 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3170 * no reason to power it off. When any of the voters want to power it off, it will be turned
3171 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3172 * powering it off, and these radio off votes will be cleared.
3173 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3174 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3175 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3176 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3177 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3178 * check its vote.
3179 *
3180 * @param subId The subscription ID.
3181 * @param reason The reason for powering off radio.
3182 * @return true on success and false on failure.
3183 */
3184 public boolean requestRadioPowerOffForReason(int subId,
3185 @TelephonyManager.RadioPowerReason int reason) {
3186 enforceModifyPermission();
3187
Ling Ma83dc5ea2023-01-12 15:06:04 -08003188 log("requestRadioPowerOffForReason: subId=" + subId
3189 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003190 final long identity = Binder.clearCallingIdentity();
3191 try {
3192 final Phone phone = getPhone(subId);
3193 if (phone != null) {
3194 phone.setRadioPowerForReason(false, reason);
3195 return true;
3196 } else {
3197 return false;
3198 }
3199 } finally {
3200 Binder.restoreCallingIdentity(identity);
3201 }
3202 }
3203
3204 /**
3205 * Remove the vote on powering off the radio for a reason, as requested by
3206 * {@link requestRadioPowerOffForReason}.
3207 *
3208 * @param subId The subscription ID.
3209 * @param reason The reason for powering off radio.
3210 * @return true on success and false on failure.
3211 */
3212 public boolean clearRadioPowerOffForReason(int subId,
3213 @TelephonyManager.RadioPowerReason int reason) {
3214 enforceModifyPermission();
3215
3216 final long identity = Binder.clearCallingIdentity();
3217 try {
3218 final Phone phone = getPhone(subId);
3219 if (phone != null) {
3220 phone.setRadioPowerForReason(true, reason);
3221 return true;
3222 } else {
3223 return false;
3224 }
3225 } finally {
3226 Binder.restoreCallingIdentity(identity);
3227 }
3228 }
3229
3230 /**
3231 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3232 *
3233 * @param subId The subscription ID.
3234 * @param callingPackage The package making the call.
3235 * @param callingFeatureId The feature in the package.
3236 * @return List of reasons for powering off radio.
3237 */
3238 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3239 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3240
3241 final long identity = Binder.clearCallingIdentity();
3242 List result = new ArrayList();
3243 try {
3244 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3245 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3246 return result;
3247 }
3248
3249 final Phone phone = getPhone(subId);
3250 if (phone != null) {
3251 result.addAll(phone.getRadioPowerOffReasons());
3252 }
3253 } finally {
3254 Binder.restoreCallingIdentity(identity);
3255 }
3256 return result;
3257 }
3258
Wink Saville36469e72014-06-11 15:17:00 -07003259 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003260 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003261 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003262 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003263
3264 final long identity = Binder.clearCallingIdentity();
3265 try {
Jack Yu285100e2022-12-02 22:48:35 -08003266 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003267 final Phone phone = getPhone(subId);
3268 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003269 phone.getDataSettingsManager().setDataEnabled(
3270 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003271 return true;
3272 } else {
3273 return false;
3274 }
3275 } finally {
3276 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003277 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003278 }
3279
Wink Saville36469e72014-06-11 15:17:00 -07003280 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003281 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003282 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003283 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003284
3285 final long identity = Binder.clearCallingIdentity();
3286 try {
Jack Yu285100e2022-12-02 22:48:35 -08003287 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003288 final Phone phone = getPhone(subId);
3289 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003290 phone.getDataSettingsManager().setDataEnabled(
3291 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003292 return true;
3293 } else {
3294 return false;
3295 }
3296 } finally {
3297 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003298 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003299 }
3300
Sanket Padawe356d7632015-06-22 14:03:32 -07003301 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003302 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003303 final long identity = Binder.clearCallingIdentity();
3304 try {
3305 final Phone phone = getPhone(subId);
3306 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003307 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003308 } else {
3309 return false;
3310 }
3311 } finally {
3312 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003313 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003314 }
3315
3316 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003317 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003318 }
3319
pkanwarae03a6b2016-11-06 20:37:09 -08003320 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003321 enforceCallPermission();
3322
3323 final long identity = Binder.clearCallingIdentity();
3324 try {
3325 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3326 return;
3327 }
3328 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3329 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3330 } finally {
3331 Binder.restoreCallingIdentity(identity);
3332 }
pkanwar32d516d2016-10-14 19:37:38 -07003333 };
3334
Wink Savilleb564aae2014-10-23 10:18:09 -07003335 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003336 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003337
3338 final long identity = Binder.clearCallingIdentity();
3339 try {
3340 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3341 return false;
3342 }
3343 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3344 } finally {
3345 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003346 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003347 }
3348
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003349 /**
3350 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3351 * tag on getCallState Binder call.
3352 */
3353 @Deprecated
3354 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003355 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003356 if (CompatChanges.isChangeEnabled(
3357 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3358 Binder.getCallingUid())) {
3359 // Do not allow this API to be called on API version 31+, it should only be
3360 // called on old apps using this Binder call directly.
3361 throw new SecurityException("This method can only be used for applications "
3362 + "targeting API version 30 or less.");
3363 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003364 final long identity = Binder.clearCallingIdentity();
3365 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003366 Phone phone = getPhone(getDefaultSubscription());
3367 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3368 PhoneConstantConversions.convertCallState(phone.getState());
3369 } finally {
3370 Binder.restoreCallingIdentity(identity);
3371 }
3372 }
3373
3374 @Override
3375 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3376 if (CompatChanges.isChangeEnabled(
3377 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3378 Binder.getCallingUid())) {
3379 // Check READ_PHONE_STATE for API version 31+
3380 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3381 featureId, "getCallStateForSubscription")) {
3382 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3383 + "targeting API level 31+.");
3384 }
3385 }
3386 final long identity = Binder.clearCallingIdentity();
3387 try {
3388 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003389 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3390 PhoneConstantConversions.convertCallState(phone.getState());
3391 } finally {
3392 Binder.restoreCallingIdentity(identity);
3393 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003394 }
3395
Sanket Padawe356d7632015-06-22 14:03:32 -07003396 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003397 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003398 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003399 }
3400
3401 @Override
3402 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003403 final long identity = Binder.clearCallingIdentity();
3404 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003405 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003406 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003407 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003408 } else {
3409 return PhoneConstantConversions.convertDataState(
3410 PhoneConstants.DataState.DISCONNECTED);
3411 }
3412 } finally {
3413 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003414 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003415 }
3416
Sanket Padawe356d7632015-06-22 14:03:32 -07003417 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003418 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003419 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003420 }
3421
3422 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003423 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003424 final long identity = Binder.clearCallingIdentity();
3425 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003426 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003427 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003428 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003429 } else {
3430 return TelephonyManager.DATA_ACTIVITY_NONE;
3431 }
3432 } finally {
3433 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003434 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003435 }
3436
3437 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003438 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003439 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003440 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003441
3442 LocationAccessPolicy.LocationPermissionResult locationResult =
3443 LocationAccessPolicy.checkLocationPermission(mApp,
3444 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3445 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003446 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003447 .setCallingPid(Binder.getCallingPid())
3448 .setCallingUid(Binder.getCallingUid())
3449 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003450 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003451 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3452 .build());
3453 switch (locationResult) {
3454 case DENIED_HARD:
3455 throw new SecurityException("Not allowed to access cell location");
3456 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003457 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3458 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003459 }
3460
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003461 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003462 final long identity = Binder.clearCallingIdentity();
3463 try {
3464 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003465 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003466 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003467 } finally {
3468 Binder.restoreCallingIdentity(identity);
3469 }
Svetoslav64fad262015-04-14 14:35:21 -07003470 }
3471
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003472 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003473 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003474 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3475 // registered cell info, so return a NULL country instead.
3476 final long identity = Binder.clearCallingIdentity();
3477 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003478 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3479 // Get default phone in this case.
3480 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3481 }
Jack Yu285100e2022-12-02 22:48:35 -08003482 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003483 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003484 if (phone == null) return "";
3485 ServiceStateTracker sst = phone.getServiceStateTracker();
3486 if (sst == null) return "";
3487 LocaleTracker lt = sst.getLocaleTracker();
3488 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003489 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003490 } finally {
3491 Binder.restoreCallingIdentity(identity);
3492 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003493 }
3494
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003495 /**
3496 * This method was removed due to potential issues caused by performing partial
3497 * updates of service state, and lack of a credible use case.
3498 *
3499 * This has the ability to break the telephony implementation by disabling notification of
3500 * changes in device connectivity. DO NOT USE THIS!
3501 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003502 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003503 public void enableLocationUpdates() {
3504 mApp.enforceCallingOrSelfPermission(
3505 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003506 }
3507
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003508 /**
3509 * This method was removed due to potential issues caused by performing partial
3510 * updates of service state, and lack of a credible use case.
3511 *
3512 * This has the ability to break the telephony implementation by disabling notification of
3513 * changes in device connectivity. DO NOT USE THIS!
3514 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003515 @Override
3516 public void disableLocationUpdates() {
3517 mApp.enforceCallingOrSelfPermission(
3518 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003519 }
3520
3521 @Override
3522 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003523 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3524 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003525 try {
3526 mApp.getSystemService(AppOpsManager.class)
3527 .checkPackage(Binder.getCallingUid(), callingPackage);
3528 } catch (SecurityException e) {
3529 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3530 throw e;
3531 }
3532
Nathan Haroldf096d982020-11-18 17:18:06 -08003533 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003534 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3535 throw new SecurityException(
3536 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3537 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003538
Jordan Liu1617b712019-07-10 15:06:26 -07003539 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003540 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3541 return null;
3542 }
Svetoslav64fad262015-04-14 14:35:21 -07003543
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003544 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003545
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003546 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003547 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003548
Nathan Haroldf180aac2018-06-01 18:43:55 -07003549 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3550 for (CellInfo ci : info) {
3551 if (ci instanceof CellInfoGsm) {
3552 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3553 } else if (ci instanceof CellInfoWcdma) {
3554 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003556 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003557 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003558 }
3559
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003560 private List<CellInfo> getCachedCellInfo() {
3561 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3562 for (Phone phone : PhoneFactory.getPhones()) {
3563 List<CellInfo> info = phone.getAllCellInfo();
3564 if (info != null) cellInfos.addAll(info);
3565 }
3566 return cellInfos;
3567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003568
3569 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003570 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003571 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003572 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003573
3574 LocationAccessPolicy.LocationPermissionResult locationResult =
3575 LocationAccessPolicy.checkLocationPermission(mApp,
3576 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3577 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003578 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003579 .setCallingPid(Binder.getCallingPid())
3580 .setCallingUid(Binder.getCallingUid())
3581 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003582 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003583 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3584 .build());
3585 switch (locationResult) {
3586 case DENIED_HARD:
3587 throw new SecurityException("Not allowed to access cell info");
3588 case DENIED_SOFT:
3589 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003590 }
3591
Nathan Haroldf096d982020-11-18 17:18:06 -08003592 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003593 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3594 return getCachedCellInfo();
3595 }
3596
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003597 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003598 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003599 final long identity = Binder.clearCallingIdentity();
3600 try {
3601 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3602 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003603 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003604 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003605 if (info != null) cellInfos.addAll(info);
3606 }
3607 return cellInfos;
3608 } finally {
3609 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003610 }
3611 }
3612
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003613 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003614 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3615 String callingFeatureId) {
3616 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3617 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003618 }
3619
3620 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003621 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3622 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003623 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003624 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003625 }
3626
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003627 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3628 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003629 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003630 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003631
3632 LocationAccessPolicy.LocationPermissionResult locationResult =
3633 LocationAccessPolicy.checkLocationPermission(mApp,
3634 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3635 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003636 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003637 .setCallingPid(Binder.getCallingPid())
3638 .setCallingUid(Binder.getCallingUid())
3639 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003640 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3641 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003642 .build());
3643 switch (locationResult) {
3644 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003645 if (TelephonyPermissions
3646 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003647 // Safetynet logging for b/154934934
3648 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3649 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003650 throw new SecurityException("Not allowed to access cell info");
3651 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003652 if (TelephonyPermissions
3653 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003654 // Safetynet logging for b/154934934
3655 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3656 }
Nathan Harold5320c422019-05-09 10:26:08 -07003657 try {
3658 cb.onCellInfo(new ArrayList<CellInfo>());
3659 } catch (RemoteException re) {
3660 // Drop without consequences
3661 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003662 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003663 }
3664
Nathan Harolda939a962019-05-09 10:13:47 -07003665
3666 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003667 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3668
3669 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3670 }
3671
3672 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003673 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003674 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003675 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003676
3677 final long identity = Binder.clearCallingIdentity();
3678 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003679 Phone phone = getPhone(subId);
3680 if (phone == null) {
3681 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3682 } else {
3683 phone.setCellInfoListRate(rateInMillis, workSource);
3684 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003685 } finally {
3686 Binder.restoreCallingIdentity(identity);
3687 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003688 }
3689
Shishir Agrawala9f32182016-04-12 12:00:16 -07003690 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003691 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003692 Phone phone = PhoneFactory.getPhone(slotIndex);
3693 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003694 return null;
3695 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003696 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003697 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003698 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003699 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003700 return null;
3701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003702
3703 final long identity = Binder.clearCallingIdentity();
3704 try {
3705 return phone.getImei();
3706 } finally {
3707 Binder.restoreCallingIdentity(identity);
3708 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003709 }
3710
3711 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003712 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3713 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3714 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3715 callingFeatureId, "getPrimaryImei")) {
3716 throw new SecurityException("Caller does not have permission");
3717 }
3718 final long identity = Binder.clearCallingIdentity();
3719 try {
3720 for (Phone phone : PhoneFactory.getPhones()) {
3721 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3722 return phone.getImei();
3723 }
3724 }
3725 throw new UnsupportedOperationException("Operation not supported");
3726 } finally {
3727 Binder.restoreCallingIdentity(identity);
3728 }
3729 }
3730
3731 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003732 public String getTypeAllocationCodeForSlot(int slotIndex) {
3733 Phone phone = PhoneFactory.getPhone(slotIndex);
3734 String tac = null;
3735 if (phone != null) {
3736 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003737 try {
3738 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3739 } catch (IndexOutOfBoundsException e) {
3740 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3741 return null;
3742 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003743 }
3744 return tac;
3745 }
3746
3747 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003748 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003749 try {
3750 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3751 } catch (SecurityException se) {
3752 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3753 throw new SecurityException("Package " + callingPackage + " does not belong to "
3754 + Binder.getCallingUid());
3755 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003756 Phone phone = PhoneFactory.getPhone(slotIndex);
3757 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003758 return null;
3759 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003760
Jeff Davidson913390f2018-02-23 17:11:49 -08003761 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003762 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003763 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003764 return null;
3765 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003766
3767 final long identity = Binder.clearCallingIdentity();
3768 try {
3769 return phone.getMeid();
3770 } finally {
3771 Binder.restoreCallingIdentity(identity);
3772 }
Jack Yu2af8d712017-03-15 17:14:14 -07003773 }
3774
3775 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003776 public String getManufacturerCodeForSlot(int slotIndex) {
3777 Phone phone = PhoneFactory.getPhone(slotIndex);
3778 String manufacturerCode = null;
3779 if (phone != null) {
3780 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003781 try {
3782 manufacturerCode =
3783 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3784 } catch (IndexOutOfBoundsException e) {
3785 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3786 return null;
3787 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003788 }
3789 return manufacturerCode;
3790 }
3791
3792 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003793 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3794 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003795 Phone phone = PhoneFactory.getPhone(slotIndex);
3796 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003797 return null;
3798 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003799 int subId = phone.getSubId();
3800 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003801 mApp, subId, callingPackage, callingFeatureId,
3802 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003803 return null;
3804 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003805
3806 final long identity = Binder.clearCallingIdentity();
3807 try {
3808 return phone.getDeviceSvn();
3809 } finally {
3810 Binder.restoreCallingIdentity(identity);
3811 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003812 }
3813
fionaxu43304da2017-11-27 22:51:16 -08003814 @Override
3815 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003816 final long identity = Binder.clearCallingIdentity();
3817 try {
3818 final Phone phone = getPhone(subId);
3819 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3820 } finally {
3821 Binder.restoreCallingIdentity(identity);
3822 }
fionaxu43304da2017-11-27 22:51:16 -08003823 }
3824
3825 @Override
3826 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003827 final long identity = Binder.clearCallingIdentity();
3828 try {
3829 final Phone phone = getPhone(subId);
3830 return phone == null ? null : phone.getCarrierName();
3831 } finally {
3832 Binder.restoreCallingIdentity(identity);
3833 }
fionaxu43304da2017-11-27 22:51:16 -08003834 }
3835
calvinpanffe225e2018-11-01 19:43:06 +08003836 @Override
chen xu0026ca62019-03-06 15:28:50 -08003837 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003838 final long identity = Binder.clearCallingIdentity();
3839 try {
3840 final Phone phone = getPhone(subId);
3841 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003842 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003843 } finally {
3844 Binder.restoreCallingIdentity(identity);
3845 }
3846 }
3847
3848 @Override
chen xu0026ca62019-03-06 15:28:50 -08003849 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003850 final long identity = Binder.clearCallingIdentity();
3851 try {
3852 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003853 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003854 } finally {
3855 Binder.restoreCallingIdentity(identity);
3856 }
3857 }
3858
chen xu651eec72018-11-11 19:03:44 -08003859 @Override
chen xu864e11c2018-12-06 22:10:03 -08003860 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3861 if (!isSubscriptionMccMnc) {
3862 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3863 }
chen xu651eec72018-11-11 19:03:44 -08003864 final Phone phone = PhoneFactory.getPhone(slotIndex);
3865 if (phone == null) {
3866 return TelephonyManager.UNKNOWN_CARRIER_ID;
3867 }
3868 final long identity = Binder.clearCallingIdentity();
3869 try {
3870 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3871 } finally {
3872 Binder.restoreCallingIdentity(identity);
3873 }
3874 }
3875
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003876 //
3877 // Internal helper methods.
3878 //
3879
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003880 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003881 * Make sure the caller is the calling package itself
3882 *
3883 * @throws SecurityException if the caller is not the calling package
3884 */
3885 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3886 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003887 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3888 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003889 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003890 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003891 } catch (PackageManager.NameNotFoundException e) {
3892 // packageUid is -1
3893 }
3894 if (packageUid != callingUid) {
3895 throw new SecurityException(message + ": Package " + callingPackage
3896 + " does not belong to " + callingUid);
3897 }
3898 }
3899
3900 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003901 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3902 *
3903 * @throws SecurityException if the caller does not have the required permission
3904 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003905 @VisibleForTesting
3906 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003907 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3908 }
3909
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003910 /**
arunvoddud7401012022-12-15 16:08:12 +00003911 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003912 *
3913 * @throws SecurityException if the caller does not have the required permission
3914 */
3915 @VisibleForTesting
3916 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003917 enforceReadPermission(null);
3918 }
3919
3920 /**
3921 * Make sure the caller has the READ_PHONE_STATE permissions.
3922 *
3923 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3924 */
3925 @VisibleForTesting
3926 public void enforceReadPermission(String msg) {
3927 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003928 }
3929
Shuo Qian3b6ee772019-11-13 17:43:31 -08003930 private void enforceActiveEmergencySessionPermission() {
3931 mApp.enforceCallingOrSelfPermission(
3932 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3933 }
3934
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003935 /**
3936 * Make sure the caller has the CALL_PHONE permission.
3937 *
3938 * @throws SecurityException if the caller does not have the required permission
3939 */
3940 private void enforceCallPermission() {
3941 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3942 }
3943
paulhu5a773602019-08-23 19:17:33 +08003944 private void enforceSettingsPermission() {
3945 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003946 }
3947
Michele Berionne5e411512020-11-13 02:36:59 +00003948 private void enforceRebootPermission() {
3949 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3950 }
3951
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003952 /**
3953 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3954 * @param message - log message to print.
3955 * @throws SecurityException if the caller does not have the required permission
3956 */
3957 private void enforceSatelliteCommunicationPermission(String message) {
3958 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3959 }
3960
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003961 private String createTelUrl(String number) {
3962 if (TextUtils.isEmpty(number)) {
3963 return null;
3964 }
3965
Jake Hambye994d462014-02-03 13:10:13 -08003966 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003967 }
3968
Ihab Awadf9e92732013-12-05 18:02:52 -08003969 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003970 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003971 }
3972
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003973 private static void logv(String msg) {
3974 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3975 }
3976
Ihab Awadf9e92732013-12-05 18:02:52 -08003977 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003978 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3979 }
3980
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003981 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003982 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003983 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003984 }
3985
Sanket Padawe356d7632015-06-22 14:03:32 -07003986 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003987 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003988 final long identity = Binder.clearCallingIdentity();
3989 try {
3990 final Phone phone = PhoneFactory.getPhone(slotIndex);
3991 if (phone == null) {
3992 return PhoneConstants.PHONE_TYPE_NONE;
3993 } else {
3994 return phone.getPhoneType();
3995 }
3996 } finally {
3997 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003998 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003999 }
4000
4001 /**
4002 * Returns the CDMA ERI icon index to display
4003 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004004 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004005 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4006 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4007 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004008 }
4009
Sanket Padawe356d7632015-06-22 14:03:32 -07004010 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004011 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4012 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004013 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004014 mApp, subId, callingPackage, callingFeatureId,
4015 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004016 return -1;
4017 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004018
4019 final long identity = Binder.clearCallingIdentity();
4020 try {
4021 final Phone phone = getPhone(subId);
4022 if (phone != null) {
4023 return phone.getCdmaEriIconIndex();
4024 } else {
4025 return -1;
4026 }
4027 } finally {
4028 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004029 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004030 }
4031
4032 /**
4033 * Returns the CDMA ERI icon mode,
4034 * 0 - ON
4035 * 1 - FLASHING
4036 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004037 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004038 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4039 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4040 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004041 }
4042
Sanket Padawe356d7632015-06-22 14:03:32 -07004043 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004044 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4045 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004046 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004047 mApp, subId, callingPackage, callingFeatureId,
4048 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004049 return -1;
4050 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004051
4052 final long identity = Binder.clearCallingIdentity();
4053 try {
4054 final Phone phone = getPhone(subId);
4055 if (phone != null) {
4056 return phone.getCdmaEriIconMode();
4057 } else {
4058 return -1;
4059 }
4060 } finally {
4061 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004062 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004063 }
4064
4065 /**
4066 * Returns the CDMA ERI text,
4067 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004068 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004069 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4070 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4071 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004072 }
4073
Sanket Padawe356d7632015-06-22 14:03:32 -07004074 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004075 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4076 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004077 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004078 mApp, subId, callingPackage, callingFeatureId,
4079 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004080 return null;
4081 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004082
4083 final long identity = Binder.clearCallingIdentity();
4084 try {
4085 final Phone phone = getPhone(subId);
4086 if (phone != null) {
4087 return phone.getCdmaEriText();
4088 } else {
4089 return null;
4090 }
4091 } finally {
4092 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004093 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004094 }
4095
4096 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004097 * Returns the CDMA MDN.
4098 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004099 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004100 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4102 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004103
4104 final long identity = Binder.clearCallingIdentity();
4105 try {
4106 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004107 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004108 return phone.getLine1Number();
4109 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004110 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004111 return null;
4112 }
4113 } finally {
4114 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004115 }
4116 }
4117
4118 /**
4119 * Returns the CDMA MIN.
4120 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004121 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004122 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004123 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4124 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004125
4126 final long identity = Binder.clearCallingIdentity();
4127 try {
4128 final Phone phone = getPhone(subId);
4129 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4130 return phone.getCdmaMin();
4131 } else {
4132 return null;
4133 }
4134 } finally {
4135 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004136 }
4137 }
4138
Hall Liud892bec2018-11-30 14:51:45 -08004139 @Override
4140 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4141 INumberVerificationCallback callback, String callingPackage) {
4142 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4143 != PERMISSION_GRANTED) {
4144 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4145 }
4146 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4147
4148 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4149 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004150 throw new SecurityException("Calling package must be configured in the device config: "
4151 + "calling package: " + callingPackage
4152 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004153 }
4154
4155 if (range == null) {
4156 throw new NullPointerException("Range must be non-null");
4157 }
4158
4159 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004160 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004161
4162 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4163 }
4164
Junda Liuca05d5d2014-08-14 22:36:34 -07004165 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004166 * Returns true if CDMA provisioning needs to run.
4167 */
4168 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004169 final long identity = Binder.clearCallingIdentity();
4170 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004171 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004172 } finally {
4173 Binder.restoreCallingIdentity(identity);
4174 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004175 }
4176
4177 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004178 * Sets the voice mail number of a given subId.
4179 */
4180 @Override
4181 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004182 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4183 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004184
4185 final long identity = Binder.clearCallingIdentity();
4186 try {
4187 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4188 new Pair<String, String>(alphaTag, number), new Integer(subId));
4189 return success;
4190 } finally {
4191 Binder.restoreCallingIdentity(identity);
4192 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004193 }
4194
Ta-wei Yen87c49842016-05-13 21:19:52 -07004195 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004196 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4197 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004198 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4199 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004200 if (!TextUtils.equals(callingPackage, systemDialer)) {
4201 throw new SecurityException("caller must be system dialer");
4202 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004203
4204 final long identity = Binder.clearCallingIdentity();
4205 try {
4206 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4207 if (phoneAccountHandle == null) {
4208 return null;
4209 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004210 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004211 } finally {
4212 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004213 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004214 }
4215
4216 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004217 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4218 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004219 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004220 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004221 mApp, subId, callingPackage, callingFeatureId,
4222 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004223 return null;
4224 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004225
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004226 final long identity = Binder.clearCallingIdentity();
4227 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004228 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004229 } finally {
4230 Binder.restoreCallingIdentity(identity);
4231 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004232 }
4233
4234 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004235 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4236 VisualVoicemailSmsFilterSettings settings) {
4237 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004238
4239 final long identity = Binder.clearCallingIdentity();
4240 try {
4241 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004242 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004243 } finally {
4244 Binder.restoreCallingIdentity(identity);
4245 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004246 }
4247
4248 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004249 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4250 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004251
4252 final long identity = Binder.clearCallingIdentity();
4253 try {
4254 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004255 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004256 } finally {
4257 Binder.restoreCallingIdentity(identity);
4258 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004259 }
4260
4261 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004262 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4263 String callingPackage, int subId) {
4264 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004265
4266 final long identity = Binder.clearCallingIdentity();
4267 try {
4268 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004269 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004270 } finally {
4271 Binder.restoreCallingIdentity(identity);
4272 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004273 }
4274
4275 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004276 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004277 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004278
4279 final long identity = Binder.clearCallingIdentity();
4280 try {
4281 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004282 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004283 } finally {
4284 Binder.restoreCallingIdentity(identity);
4285 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004286 }
4287
4288 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004289 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4290 String callingAttributionTag, int subId, String number, int port, String text,
4291 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004292 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004293 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004294 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004295 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004296 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4297 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004298 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004299
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004300 /**
fionaxu0152e512016-11-14 13:36:14 -08004301 * Sets the voice activation state of a given subId.
4302 */
4303 @Override
4304 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4306 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004307
4308 final long identity = Binder.clearCallingIdentity();
4309 try {
4310 final Phone phone = getPhone(subId);
4311 if (phone != null) {
4312 phone.setVoiceActivationState(activationState);
4313 } else {
4314 loge("setVoiceActivationState fails with invalid subId: " + subId);
4315 }
4316 } finally {
4317 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004318 }
4319 }
4320
4321 /**
4322 * Sets the data activation state of a given subId.
4323 */
4324 @Override
4325 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4327 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004328
4329 final long identity = Binder.clearCallingIdentity();
4330 try {
4331 final Phone phone = getPhone(subId);
4332 if (phone != null) {
4333 phone.setDataActivationState(activationState);
4334 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004335 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004336 }
4337 } finally {
4338 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004339 }
4340 }
4341
4342 /**
4343 * Returns the voice activation state of a given subId.
4344 */
4345 @Override
4346 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004347 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004348
fionaxu0152e512016-11-14 13:36:14 -08004349 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004350 final long identity = Binder.clearCallingIdentity();
4351 try {
4352 if (phone != null) {
4353 return phone.getVoiceActivationState();
4354 } else {
4355 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4356 }
4357 } finally {
4358 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004359 }
4360 }
4361
4362 /**
4363 * Returns the data activation state of a given subId.
4364 */
4365 @Override
4366 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004367 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004368
fionaxu0152e512016-11-14 13:36:14 -08004369 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004370 final long identity = Binder.clearCallingIdentity();
4371 try {
4372 if (phone != null) {
4373 return phone.getDataActivationState();
4374 } else {
4375 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4376 }
4377 } finally {
4378 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004379 }
4380 }
4381
4382 /**
Wink Saville36469e72014-06-11 15:17:00 -07004383 * Returns the unread count of voicemails for a subId
4384 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004385 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004386 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4387 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004388 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004389 mApp, subId, callingPackage, callingFeatureId,
4390 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004391 return 0;
4392 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004393 final long identity = Binder.clearCallingIdentity();
4394 try {
4395 final Phone phone = getPhone(subId);
4396 if (phone != null) {
4397 return phone.getVoiceMessageCount();
4398 } else {
4399 return 0;
4400 }
4401 } finally {
4402 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004404 }
4405
4406 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004407 * returns true, if the device is in a state where both voice and data
4408 * are supported simultaneously. This can change based on location or network condition.
4409 */
4410 @Override
4411 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004412 final long identity = Binder.clearCallingIdentity();
4413 try {
4414 final Phone phone = getPhone(subId);
4415 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4416 } finally {
4417 Binder.restoreCallingIdentity(identity);
4418 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004419 }
4420
4421 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004422 * Send the dialer code if called from the current default dialer or the caller has
4423 * carrier privilege.
4424 * @param inputCode The dialer code to send
4425 */
4426 @Override
4427 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004428 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004429 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004430 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4431 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004432 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004433 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004434 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004435 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004436
4437 final long identity = Binder.clearCallingIdentity();
4438 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004439 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004440 } finally {
4441 Binder.restoreCallingIdentity(identity);
4442 }
fionaxu235cc5e2017-03-06 22:25:57 -08004443 }
4444
Pengquan Menga1bb6272018-09-06 09:59:22 -07004445 @Override
4446 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004447 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004448 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004449 mApp, subId, "getNetworkSelectionMode");
4450 final long identity = Binder.clearCallingIdentity();
4451 try {
4452 if (!isActiveSubscription(subId)) {
4453 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4454 }
4455 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4456 } finally {
4457 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004458 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004459 }
4460
Brad Ebinger35c841c2018-10-01 10:40:55 -07004461 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004462 public boolean isInEmergencySmsMode() {
4463 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4464 final long identity = Binder.clearCallingIdentity();
4465 try {
4466 for (Phone phone : PhoneFactory.getPhones()) {
4467 if (phone.isInEmergencySmsMode()) {
4468 return true;
4469 }
4470 }
4471 } finally {
4472 Binder.restoreCallingIdentity(identity);
4473 }
4474 return false;
4475 }
4476
shilu366312e2019-12-17 09:28:10 -08004477 /**
4478 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4479 * @param subId The subscription to use to check the configuration.
4480 * @param c The callback that will be used to send the result.
4481 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004482 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004483 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4484 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004485 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004486 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004487
4488 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4489 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4490 "IMS not available on device.");
4491 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004492 final long token = Binder.clearCallingIdentity();
4493 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004494 int slotId = getSlotIndexOrException(subId);
4495 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004496
4497 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4498 if (controller != null) {
4499 ImsManager imsManager = controller.getImsManager(subId);
4500 if (imsManager != null) {
4501 imsManager.addRegistrationCallbackForSubscription(c, subId);
4502 } else {
4503 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4504 }
4505 } else {
4506 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4507 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004508 } catch (ImsException e) {
4509 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004510 } finally {
4511 Binder.restoreCallingIdentity(token);
4512 }
4513 }
4514
shilu366312e2019-12-17 09:28:10 -08004515 /**
4516 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4517 * @param subId The subscription to use to check the configuration.
4518 * @param c The callback that will be used to send the result.
4519 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004520 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004521 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004522 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004523 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004524 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4525 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4526 }
Meng Wangafbc5852019-09-19 17:37:13 -07004527 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004528
Meng Wangafbc5852019-09-19 17:37:13 -07004529 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004530 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4531 if (controller != null) {
4532 ImsManager imsManager = controller.getImsManager(subId);
4533 if (imsManager != null) {
4534 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4535 } else {
4536 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4537 + "is inactive, ignoring unregister.");
4538 // If the ImsManager is not valid, just return, since the callback
4539 // will already have been removed internally.
4540 }
4541 }
Meng Wangafbc5852019-09-19 17:37:13 -07004542 } finally {
4543 Binder.restoreCallingIdentity(token);
4544 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004545 }
4546
Brad Ebingera34a6c22019-10-22 17:36:18 -07004547 /**
4548 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4549 */
4550 @Override
4551 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4552 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4553 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4554 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4555 "IMS not available on device.");
4556 }
4557 final long token = Binder.clearCallingIdentity();
4558 try {
4559 Phone phone = getPhone(subId);
4560 if (phone == null) {
4561 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4562 + subId + "'");
4563 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4564 }
4565 phone.getImsRegistrationState(regState -> {
4566 try {
4567 consumer.accept((regState == null)
4568 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4569 } catch (RemoteException e) {
4570 // Ignore if the remote process is no longer available to call back.
4571 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4572 }
4573 });
4574 } finally {
4575 Binder.restoreCallingIdentity(token);
4576 }
4577 }
4578
4579 /**
4580 * Get the transport type for the IMS service registration state.
4581 */
4582 @Override
4583 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004584 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004585 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004586 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4587 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4588 "IMS not available on device.");
4589 }
4590 final long token = Binder.clearCallingIdentity();
4591 try {
4592 Phone phone = getPhone(subId);
4593 if (phone == null) {
4594 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4595 + subId + "'");
4596 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4597 }
4598 phone.getImsRegistrationTech(regTech -> {
4599 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4600 int regTechConverted = (regTech == null)
4601 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4602 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4603 regTechConverted);
4604 try {
4605 consumer.accept(regTechConverted);
4606 } catch (RemoteException e) {
4607 // Ignore if the remote process is no longer available to call back.
4608 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4609 }
4610 });
4611 } finally {
4612 Binder.restoreCallingIdentity(token);
4613 }
4614 }
4615
shilu366312e2019-12-17 09:28:10 -08004616 /**
4617 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4618 * @param subId The subscription to use to check the configuration.
4619 * @param c The callback that will be used to send the result.
4620 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004621 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004622 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4623 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004624 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004625 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004626 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4627 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4628 "IMS not available on device.");
4629 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004630 final long token = Binder.clearCallingIdentity();
4631 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004632 int slotId = getSlotIndexOrException(subId);
4633 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004634
4635 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4636 if (controller != null) {
4637 ImsManager imsManager = controller.getImsManager(subId);
4638 if (imsManager != null) {
4639 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4640 } else {
4641 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4642 }
4643 } else {
4644 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4645 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004646 } catch (ImsException e) {
4647 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004648 } finally {
4649 Binder.restoreCallingIdentity(token);
4650 }
4651 }
4652
shilu366312e2019-12-17 09:28:10 -08004653 /**
4654 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4655 * @param subId The subscription to use to check the configuration.
4656 * @param c The callback that will be used to send the result.
4657 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004658 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004659 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004660 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004661 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004662 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4663 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4664 }
Meng Wangafbc5852019-09-19 17:37:13 -07004665
4666 final long token = Binder.clearCallingIdentity();
4667 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004668 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4669 if (controller != null) {
4670 ImsManager imsManager = controller.getImsManager(subId);
4671 if (imsManager != null) {
4672 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4673 } else {
4674 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4675 + " is inactive, ignoring unregister.");
4676 // If the ImsManager is not valid, just return, since the callback
4677 // will already have been removed internally.
4678 }
4679 }
Meng Wangafbc5852019-09-19 17:37:13 -07004680 } finally {
4681 Binder.restoreCallingIdentity(token);
4682 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004683 }
4684
4685 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004686 public boolean isCapable(int subId, int capability, int regTech) {
4687 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004688 final long token = Binder.clearCallingIdentity();
4689 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004690 int slotId = getSlotIndexOrException(subId);
4691 verifyImsMmTelConfiguredOrThrow(slotId);
4692 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4693 } catch (com.android.ims.ImsException e) {
4694 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4695 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004696 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004697 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4698 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004699 } finally {
4700 Binder.restoreCallingIdentity(token);
4701 }
4702 }
4703
4704 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004705 public boolean isAvailable(int subId, int capability, int regTech) {
4706 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004707 final long token = Binder.clearCallingIdentity();
4708 try {
4709 Phone phone = getPhone(subId);
4710 if (phone == null) return false;
4711 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004712 } catch (com.android.ims.ImsException e) {
4713 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4714 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004715 } finally {
4716 Binder.restoreCallingIdentity(token);
4717 }
4718 }
4719
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004720 /**
4721 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4722 * subscription.
4723 * @param subId The subscription to use to check the configuration.
4724 * @param callback The callback that will be used to send the result.
4725 * @param capability The MmTelFeature capability that will be used to send the result.
4726 * @param transportType The transport type of the MmTelFeature capability.
4727 */
4728 @Override
4729 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4730 int transportType) {
4731 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004732 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4733 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4734 "IMS not available on device.");
4735 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004736 final long token = Binder.clearCallingIdentity();
4737 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004738 int slotId = getSlotIndex(subId);
4739 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4740 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4741 + subId + "'");
4742 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4743 }
4744 verifyImsMmTelConfiguredOrThrow(slotId);
4745 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4746 transportType, aBoolean -> {
4747 try {
4748 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4749 } catch (RemoteException e) {
4750 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4751 + "running. Ignore");
4752 }
4753 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004754 } catch (ImsException e) {
4755 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004756 } finally {
4757 Binder.restoreCallingIdentity(token);
4758 }
4759 }
4760
shilu366312e2019-12-17 09:28:10 -08004761 /**
4762 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4763 * @param subId The subscription to use to check the configuration.
4764 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004765 @Override
4766 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004767 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004768 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004769
Brad Ebinger35c841c2018-10-01 10:40:55 -07004770 final long token = Binder.clearCallingIdentity();
4771 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004772 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004773 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004774 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004775 } catch (ImsException e) {
4776 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004777 } finally {
4778 Binder.restoreCallingIdentity(token);
4779 }
4780 }
4781
4782 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004783 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004785 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004786 final long identity = Binder.clearCallingIdentity();
4787 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004788 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004789 // This setting doesn't require an active ImsService connection, so do not verify. The
4790 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004791 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004792 } catch (ImsException e) {
4793 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004794 } finally {
4795 Binder.restoreCallingIdentity(identity);
4796 }
4797 }
4798
shilu366312e2019-12-17 09:28:10 -08004799 /**
4800 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4801 * @param subId The subscription to use to check the configuration.
4802 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004803 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004804 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004805 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004806 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004807 final long identity = Binder.clearCallingIdentity();
4808 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004809 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004810 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004811 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004812 } catch (ImsException e) {
4813 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004814 } finally {
4815 Binder.restoreCallingIdentity(identity);
4816 }
4817 }
4818
4819 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004820 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004821 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004822 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004823 final long identity = Binder.clearCallingIdentity();
4824 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004825 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004826 // This setting doesn't require an active ImsService connection, so do not verify. The
4827 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004828 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
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
shilu366312e2019-12-17 09:28:10 -08004836 /**
4837 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4838 * @param subId The subscription to use to check the configuration.
4839 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004840 @Override
4841 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004842 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004843 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004844 final long identity = Binder.clearCallingIdentity();
4845 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004846 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004847 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004848 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004849 } catch (ImsException e) {
4850 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004851 } finally {
4852 Binder.restoreCallingIdentity(identity);
4853 }
4854 }
4855
4856 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004857 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004859 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004860 final long identity = Binder.clearCallingIdentity();
4861 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004862 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004863 // This setting doesn't require an active ImsService connection, so do not verify. The
4864 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004865 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004866 } catch (ImsException e) {
4867 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004868 } finally {
4869 Binder.restoreCallingIdentity(identity);
4870 }
4871 }
4872
shilu366312e2019-12-17 09:28:10 -08004873 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004874 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4875 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4876 * @param subId The subscription to use to check the configuration.
4877 */
4878 @Override
4879 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004880 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004881 mApp, subId, "isCrossSimCallingEnabledByUser");
4882 final long identity = Binder.clearCallingIdentity();
4883 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004884 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004885 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004886 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004887 } catch (ImsException e) {
4888 throw new ServiceSpecificException(e.getCode());
4889 } finally {
4890 Binder.restoreCallingIdentity(identity);
4891 }
4892 }
4893
4894 /**
4895 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4896 * Requires MODIFY_PHONE_STATE permission.
4897 * @param subId The subscription to use to check the configuration.
4898 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4899 * false otherwise
4900 */
4901 @Override
4902 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4904 "setCrossSimCallingEnabled");
4905 final long identity = Binder.clearCallingIdentity();
4906 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004907 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004908 // This setting doesn't require an active ImsService connection, so do not verify. The
4909 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004910 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004911 } catch (ImsException e) {
4912 throw new ServiceSpecificException(e.getCode());
4913 } finally {
4914 Binder.restoreCallingIdentity(identity);
4915 }
4916 }
4917
4918 /**
shilu366312e2019-12-17 09:28:10 -08004919 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4920 * @param subId The subscription to use to check the configuration.
4921 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004922 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004923
Brad Ebinger35c841c2018-10-01 10:40:55 -07004924 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004925 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004926 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004927 final long identity = Binder.clearCallingIdentity();
4928 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004929 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004930 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004931 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004932 } catch (ImsException e) {
4933 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004934 } finally {
4935 Binder.restoreCallingIdentity(identity);
4936 }
4937 }
4938
4939 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004940 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004942 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004943 final long identity = Binder.clearCallingIdentity();
4944 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004945 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004946 // This setting doesn't require an active ImsService connection, so do not verify. The
4947 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004948 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004949 } catch (ImsException e) {
4950 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004951 } finally {
4952 Binder.restoreCallingIdentity(identity);
4953 }
4954 }
4955
4956 @Override
4957 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4958 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4959 "setVoWiFiNonPersistent");
4960 final long identity = Binder.clearCallingIdentity();
4961 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004962 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004963 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004964 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004965 } catch (ImsException e) {
4966 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004967 } finally {
4968 Binder.restoreCallingIdentity(identity);
4969 }
4970 }
4971
shilu366312e2019-12-17 09:28:10 -08004972 /**
4973 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4974 * @param subId The subscription to use to check the configuration.
4975 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004976 @Override
4977 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004978 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004979 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004980 final long identity = Binder.clearCallingIdentity();
4981 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004982 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004983 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004984 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004985 } catch (ImsException e) {
4986 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004987 } finally {
4988 Binder.restoreCallingIdentity(identity);
4989 }
4990 }
4991
4992 @Override
4993 public void setVoWiFiModeSetting(int subId, int mode) {
4994 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4995 "setVoWiFiModeSetting");
4996 final long identity = Binder.clearCallingIdentity();
4997 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004998 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004999 // This setting doesn't require an active ImsService connection, so do not verify. The
5000 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005001 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005002 } catch (ImsException e) {
5003 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005004 } finally {
5005 Binder.restoreCallingIdentity(identity);
5006 }
5007 }
5008
5009 @Override
5010 public int getVoWiFiRoamingModeSetting(int subId) {
5011 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
5012 final long identity = Binder.clearCallingIdentity();
5013 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005014 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005015 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005016 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005017 } catch (ImsException e) {
5018 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005019 } finally {
5020 Binder.restoreCallingIdentity(identity);
5021 }
5022 }
5023
5024 @Override
5025 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5027 "setVoWiFiRoamingModeSetting");
5028 final long identity = Binder.clearCallingIdentity();
5029 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005030 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005031 // This setting doesn't require an active ImsService connection, so do not verify. The
5032 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005033 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005034 } catch (ImsException e) {
5035 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005036 } finally {
5037 Binder.restoreCallingIdentity(identity);
5038 }
5039 }
5040
5041 @Override
5042 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5044 "setRttCapabilityEnabled");
5045 final long identity = Binder.clearCallingIdentity();
5046 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005047 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005048 // This setting doesn't require an active ImsService connection, so do not verify. The
5049 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005050 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005051 } catch (ImsException e) {
5052 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005053 } finally {
5054 Binder.restoreCallingIdentity(identity);
5055 }
5056 }
5057
shilu366312e2019-12-17 09:28:10 -08005058 /**
5059 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5060 * @param subId The subscription to use to check the configuration.
5061 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005062 @Override
5063 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005064 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005065 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005066 final long identity = Binder.clearCallingIdentity();
5067 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005068 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005069 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005070 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005071 } catch (ImsException e) {
5072 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005073 } finally {
5074 Binder.restoreCallingIdentity(identity);
5075 }
5076 }
5077
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005078 @Override
5079 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5080 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005081
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005082 final long identity = Binder.clearCallingIdentity();
5083 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005084 if (!isImsAvailableOnDevice()) {
5085 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5086 "IMS not available on device.");
5087 }
5088 int slotId = getSlotIndexOrException(subId);
5089 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005090
5091 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5092 if (controller != null) {
5093 ImsManager imsManager = controller.getImsManager(subId);
5094 if (imsManager != null) {
5095 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5096 } else {
5097 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5098 }
5099 } else {
5100 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5101 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005102 } catch (ImsException e) {
5103 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005104 } finally {
5105 Binder.restoreCallingIdentity(identity);
5106 }
5107 }
5108
5109 @Override
5110 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5111 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005112
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005113 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005114 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5115 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5116 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005117 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005118 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5119 if (controller != null) {
5120 ImsManager imsManager = controller.getImsManager(subId);
5121 if (imsManager != null) {
5122 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5123 } else {
5124 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5125 + " is inactive, ignoring unregister.");
5126 // If the ImsManager is not valid, just return, since the callback will already
5127 // have been removed internally.
5128 }
5129 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005130 } finally {
5131 Binder.restoreCallingIdentity(identity);
5132 }
5133 }
5134
joonhunshincffb7fc2021-11-28 07:32:01 +00005135 @Override
5136 public void registerFeatureProvisioningChangedCallback(int subId,
5137 IFeatureProvisioningCallback callback) {
5138 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5139 mApp, subId, "registerFeatureProvisioningChangedCallback");
5140
5141 final long identity = Binder.clearCallingIdentity();
5142 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5143 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5144 }
5145
joonhunshin91bc1952022-04-29 08:47:15 +00005146 try {
5147 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5148 if (controller == null) {
5149 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5150 "Device does not support IMS");
5151 }
5152 controller.addFeatureProvisioningChangedCallback(subId, callback);
5153 } finally {
5154 Binder.restoreCallingIdentity(identity);
5155 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005156 }
5157
5158 @Override
5159 public void unregisterFeatureProvisioningChangedCallback(int subId,
5160 IFeatureProvisioningCallback callback) {
5161 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5162 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5163
5164 final long identity = Binder.clearCallingIdentity();
5165 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5166 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5167 }
5168
joonhunshin91bc1952022-04-29 08:47:15 +00005169 try {
5170 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5171 if (controller == null) {
5172 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5173 return;
5174 }
5175 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5176 } finally {
5177 Binder.restoreCallingIdentity(identity);
5178 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005179 }
allenwtsu99c623b2020-01-03 18:24:23 +08005180
5181 private void checkModifyPhoneStatePermission(int subId, String message) {
5182 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5183 message);
5184 }
5185
allenwtsu99c623b2020-01-03 18:24:23 +08005186 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005187 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005188 boolean isProvisioned) {
5189 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5190
5191 final long identity = Binder.clearCallingIdentity();
5192 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005193 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5194 if (controller == null) {
5195 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5196 return;
5197 }
5198 controller.setRcsProvisioningStatusForCapability(
5199 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005200 } finally {
5201 Binder.restoreCallingIdentity(identity);
5202 }
allenwtsu99c623b2020-01-03 18:24:23 +08005203 }
5204
5205
5206 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005207 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5208 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5209 mApp, subId, "getRcsProvisioningStatusForCapability");
5210
allenwtsu99c623b2020-01-03 18:24:23 +08005211 final long identity = Binder.clearCallingIdentity();
5212 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005213 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5214 if (controller == null) {
5215 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5216
5217 // device does not support IMS, this method will return true always.
5218 return true;
5219 }
5220 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005221 } finally {
5222 Binder.restoreCallingIdentity(identity);
5223 }
5224 }
5225
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005226 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005227 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5228 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005229 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005230
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005231 final long identity = Binder.clearCallingIdentity();
5232 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005233 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5234 if (controller == null) {
5235 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5236 return;
5237 }
5238 controller.setImsProvisioningStatusForCapability(
5239 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005240 } finally {
5241 Binder.restoreCallingIdentity(identity);
5242 }
5243 }
5244
5245 @Override
5246 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005247 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5248 mApp, subId, "getProvisioningStatusForCapability");
5249
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005250 final long identity = Binder.clearCallingIdentity();
5251 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005252 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5253 if (controller == null) {
5254 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005255
joonhunshin91bc1952022-04-29 08:47:15 +00005256 // device does not support IMS, this method will return true always.
5257 return true;
5258 }
5259 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005260 } finally {
5261 Binder.restoreCallingIdentity(identity);
5262 }
5263 }
5264
5265 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005266 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5267 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5268 mApp, subId, "isProvisioningRequiredForCapability");
5269
5270 final long identity = Binder.clearCallingIdentity();
5271 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005272 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5273 if (controller == null) {
5274 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5275
5276 // device does not support IMS, this method will return false
5277 return false;
5278 }
5279 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005280 } finally {
5281 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005282 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005283 }
5284
5285 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005286 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5287 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5288 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005289
joonhunshincffb7fc2021-11-28 07:32:01 +00005290 final long identity = Binder.clearCallingIdentity();
5291 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005292 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5293 if (controller == null) {
5294 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5295
5296 // device does not support IMS, this method will return false
5297 return false;
5298 }
5299 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005300 } finally {
5301 Binder.restoreCallingIdentity(identity);
5302 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005303 }
5304
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005305 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005306 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005307 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5308 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5309 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005310 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5311 mApp, subId, "getImsProvisioningInt");
5312
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005313 final long identity = Binder.clearCallingIdentity();
5314 try {
5315 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005316 int slotId = getSlotIndex(subId);
5317 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5318 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5319 + subId + "' for key:" + key);
5320 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5321 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005322
joonhunshin91bc1952022-04-29 08:47:15 +00005323 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5324 if (controller == null) {
5325 loge("getImsProvisioningInt: Device does not support IMS");
5326
5327 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5328 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5329 }
5330 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005331 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5332 return retVal;
5333 }
5334
calvinpanb5a34062021-02-08 19:59:36 +08005335 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005336 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005337 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5338 + subId + "' for key:" + key);
5339 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005340 } finally {
5341 Binder.restoreCallingIdentity(identity);
5342 }
5343 }
5344
5345 @Override
5346 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005347 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5348 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5349 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005350 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5351 mApp, subId, "getImsProvisioningString");
5352
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005353 final long identity = Binder.clearCallingIdentity();
5354 try {
5355 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005356 int slotId = getSlotIndex(subId);
5357 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5358 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5359 + subId + "' for key:" + key);
5360 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5361 }
calvinpanb5a34062021-02-08 19:59:36 +08005362 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005363 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005364 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5365 + subId + "' for key:" + key);
5366 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005367 } finally {
5368 Binder.restoreCallingIdentity(identity);
5369 }
5370 }
5371
5372 @Override
5373 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005374 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5375 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5376 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5378 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005379
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005380 final long identity = Binder.clearCallingIdentity();
5381 try {
5382 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005383 int slotId = getSlotIndex(subId);
5384 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5385 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5386 + subId + "' for key:" + key);
5387 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5388 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005389
joonhunshin91bc1952022-04-29 08:47:15 +00005390 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5391 if (controller == null) {
5392 loge("setImsProvisioningInt: Device does not support IMS");
5393
5394 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5395 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5396 }
5397 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005398 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5399 return retVal;
5400 }
5401
calvinpanb5a34062021-02-08 19:59:36 +08005402 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5403 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005404 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005405 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005406 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005407 } finally {
5408 Binder.restoreCallingIdentity(identity);
5409 }
5410 }
5411
5412 @Override
5413 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005414 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5415 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5416 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5418 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005419 final long identity = Binder.clearCallingIdentity();
5420 try {
5421 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005422 int slotId = getSlotIndex(subId);
5423 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5424 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5425 + subId + "' for key:" + key);
5426 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5427 }
calvinpanb5a34062021-02-08 19:59:36 +08005428 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5429 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005430 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005431 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005432 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005433 } finally {
5434 Binder.restoreCallingIdentity(identity);
5435 }
5436 }
5437
Brad Ebinger919631e2021-06-02 17:46:35 -07005438 /**
5439 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5440 * for the given slot ID or no ImsResolver instance has been created.
5441 * @param slotId The slot ID that the IMS service is created for.
5442 * @throws ImsException If there is no ImsService configured for this slot.
5443 */
5444 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5445 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5446 ImsFeature.FEATURE_MMTEL)) {
5447 throw new ImsException("This subscription does not support MMTEL over IMS",
5448 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5449 }
5450 }
5451
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005452 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005453 int slotId = SubscriptionManager.getSlotIndex(subId);
5454 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005455 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5456 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005457 }
5458 return slotId;
5459 }
5460
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005461 private int getSlotIndex(int subId) {
5462 int slotId = SubscriptionManager.getSlotIndex(subId);
5463 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5464 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5465 }
5466 return slotId;
5467 }
5468
Wink Saville36469e72014-06-11 15:17:00 -07005469 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005470 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005471 */
5472 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005473 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5474 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005475 try {
5476 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5477 } catch (SecurityException se) {
5478 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5479 throw new SecurityException("Package " + callingPackage + " does not belong to "
5480 + Binder.getCallingUid());
5481 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005482 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005483 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005484 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005485 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005486 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005487 mApp, subId, callingPackage, callingFeatureId,
5488 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005489 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5490 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005491
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005492 final long identity = Binder.clearCallingIdentity();
5493 try {
5494 final Phone phone = getPhone(subId);
5495 if (phone != null) {
5496 return phone.getServiceState().getDataNetworkType();
5497 } else {
5498 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5499 }
5500 } finally {
5501 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005502 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005503 }
5504
5505 /**
5506 * Returns the data network type
5507 */
5508 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005509 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005510 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005511 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005512 }
5513
5514 /**
5515 * Returns the data network type for a subId
5516 */
5517 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005518 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5519 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005520 String functionName = "getDataNetworkTypeForSubscriber";
5521 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5522 mApp, functionName)) {
5523 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5524 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5525 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5526 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005527 }
5528
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005529 final long identity = Binder.clearCallingIdentity();
5530 try {
5531 final Phone phone = getPhone(subId);
5532 if (phone != null) {
5533 return phone.getServiceState().getDataNetworkType();
5534 } else {
5535 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5536 }
5537 } finally {
5538 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005539 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005540 }
5541
5542 /**
Wink Saville36469e72014-06-11 15:17:00 -07005543 * Returns the Voice network type for a subId
5544 */
5545 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005546 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5547 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005548 String functionName = "getVoiceNetworkTypeForSubscriber";
5549 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5550 mApp, functionName)) {
5551 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5552 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5553 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5554 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005555 }
5556
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005557 final long identity = Binder.clearCallingIdentity();
5558 try {
5559 final Phone phone = getPhone(subId);
5560 if (phone != null) {
5561 return phone.getServiceState().getVoiceNetworkType();
5562 } else {
5563 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5564 }
5565 } finally {
5566 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005568 }
5569
5570 /**
5571 * @return true if a ICC card is present
5572 */
5573 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005574 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005575 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005576 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005577 }
5578
5579 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005580 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005581 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005582 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005583 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005584 final long identity = Binder.clearCallingIdentity();
5585 try {
5586 final Phone phone = PhoneFactory.getPhone(slotIndex);
5587 if (phone != null) {
5588 return phone.getIccCard().hasIccCard();
5589 } else {
5590 return false;
5591 }
5592 } finally {
5593 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005594 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005595 }
5596
5597 /**
5598 * Return if the current radio is LTE on CDMA. This
5599 * is a tri-state return value as for a period of time
5600 * the mode may be unknown.
5601 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005602 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005603 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005604 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005605 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005606 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005607 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5608 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5609 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005610 }
5611
Sanket Padawe356d7632015-06-22 14:03:32 -07005612 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005613 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5614 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005615 try {
5616 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5617 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005618 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5619 }
5620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005621 final long identity = Binder.clearCallingIdentity();
5622 try {
5623 final Phone phone = getPhone(subId);
5624 if (phone == null) {
5625 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5626 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005627 return TelephonyProperties.lte_on_cdma_device()
5628 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629 }
5630 } finally {
5631 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005632 }
Wink Saville36469e72014-06-11 15:17:00 -07005633 }
5634
Wink Saville36469e72014-06-11 15:17:00 -07005635 /**
5636 * {@hide}
5637 * Returns Default subId, 0 in the case of single standby.
5638 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005639 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005640 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005641 }
5642
Shishir Agrawala9f32182016-04-12 12:00:16 -07005643 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005644 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005645 }
5646
Wink Savilleb564aae2014-10-23 10:18:09 -07005647 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005648 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005649 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005650
Pengquan Menge92a50d2018-09-21 15:54:48 -07005651 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08005652 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
5653 return SubscriptionManagerService.getInstance().isActiveSubId(subId,
5654 mApp.getOpPackageName(), mApp.getFeatureId());
5655 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005656 return mSubscriptionController.isActiveSubId(subId);
5657 }
5658
Ihab Awadf2177b72013-11-25 13:33:23 -08005659 /**
5660 * @see android.telephony.TelephonyManager.WifiCallingChoices
5661 */
5662 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005663 final long identity = Binder.clearCallingIdentity();
5664 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005665 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5667 getWhenToMakeWifiCallsDefaultPreference());
5668 } finally {
5669 Binder.restoreCallingIdentity(identity);
5670 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005671 }
5672
5673 /**
5674 * @see android.telephony.TelephonyManager.WifiCallingChoices
5675 */
5676 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677 final long identity = Binder.clearCallingIdentity();
5678 try {
5679 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005680 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5682 } finally {
5683 Binder.restoreCallingIdentity(identity);
5684 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005685 }
5686
Sailesh Nepald1e68152013-12-12 19:08:02 -08005687 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005688 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005689 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005690 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005691
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005692 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5693 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5694 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005695 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005696 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5697 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005698 }
5699 return PhoneFactory.getPhone(phoneId);
5700 }
5701
Shishir Agrawal566b7612013-10-28 14:41:00 -07005702 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005703 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005704 @NonNull IccLogicalChannelRequest request) {
5705 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5706 /*message=*/ "iccOpenLogicalChannel");
5707
5708 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5709 // Verify that the callingPackage in the request belongs to the calling UID
5710 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5711
5712 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005713 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005714
Rambo Wanga1782702021-11-10 20:15:19 -08005715 private Phone getPhoneFromValidIccLogicalChannelRequest(
5716 @NonNull IccLogicalChannelRequest request, String message) {
5717 Phone phone;
5718 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5719 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5720 mApp, request.subId, message);
5721 phone = getPhoneFromSubId(request.subId);
5722 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5723 enforceModifyPermission();
5724 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5725 } else {
5726 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005727 }
Rambo Wanga1782702021-11-10 20:15:19 -08005728 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005729 }
5730
5731 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005732 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005733 final long identity = Binder.clearCallingIdentity();
5734 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005735 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005737 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5738 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005739 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5740 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741 loge("The calling package is not allowed to access ISD-R.");
5742 throw new SecurityException(
5743 "The calling package is not allowed to access ISD-R.");
5744 }
Derek Tan740e1672017-06-27 14:56:27 -07005745 }
Derek Tan740e1672017-06-27 14:56:27 -07005746
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005748 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5749 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005750 return response;
5751 } finally {
5752 Binder.restoreCallingIdentity(identity);
5753 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005754 }
5755
5756 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005757 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5758 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5759 /*message=*/"iccCloseLogicalChannel");
5760
5761 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5762
5763 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005764 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005765
Rambo Wanga1782702021-11-10 20:15:19 -08005766 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5767 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005768 // before this feature is enabled, this API should only return false if
5769 // the operation fails instead of throwing runtime exception for
5770 // backward-compatibility.
5771 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5772 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005773 final long identity = Binder.clearCallingIdentity();
5774 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005775 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005776 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005777 }
Chen Xue9d737e2022-01-01 23:41:31 -08005778 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005779 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005780 Boolean success = false;
5781 if (result instanceof RuntimeException) {
5782 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005783 if (shouldThrowExceptionOnFailure) {
5784 throw (RuntimeException) result;
5785 } else {
5786 return false;
5787 }
Chen Xue9d737e2022-01-01 23:41:31 -08005788 } else if (result instanceof Boolean) {
5789 success = (Boolean) result;
5790 } else {
5791 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5792 }
Rambo Wanga1782702021-11-10 20:15:19 -08005793 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005794 return success;
5795 } finally {
5796 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005797 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005798 }
5799
5800 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005801 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005802 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5804 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005805 if (DBG) {
5806 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5807 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5808 + p3 + " data=" + data);
5809 }
5810 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5811 command, p1, p2, p3, data);
5812 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005813
Jordan Liu4c733742019-02-28 12:03:40 -08005814 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005815 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5816 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005817 enforceModifyPermission();
5818 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005819 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5820 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5821 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005822 }
5823 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005824 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5825 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005826 }
5827
5828 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5829 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005830 final long identity = Binder.clearCallingIdentity();
5831 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005832 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005833 return "";
5834 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005835
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005836 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005837 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5838 null /* workSource */);
5839 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005840
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005841 // Append the returned status code to the end of the response payload.
5842 String s = Integer.toHexString(
5843 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5844 if (response.payload != null) {
5845 s = IccUtils.bytesToHexString(response.payload) + s;
5846 }
5847 return s;
5848 } finally {
5849 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005850 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005851 }
Jake Hambye994d462014-02-03 13:10:13 -08005852
Evan Charltonc66da362014-05-16 14:06:40 -07005853 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005854 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5855 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005856 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5857 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005858 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005859 if (DBG) {
5860 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5861 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5862 }
5863 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5864 cla, command, p1, p2, p3, data);
5865 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005866
Jordan Liu4c733742019-02-28 12:03:40 -08005867 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005868 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5869 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005870 enforceModifyPermission();
5871 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5872 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005873 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5874 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5875 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005876 }
5877
5878 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005879 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5880 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005881 }
5882
5883 // open APDU basic channel assuming the caller has sufficient permissions
5884 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5885 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005886 final long identity = Binder.clearCallingIdentity();
5887 try {
5888 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5889 && TextUtils.equals(ISDR_AID, data)) {
5890 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005891 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5892 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005893 if (bestComponent == null
5894 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5895 loge("The calling package is not allowed to select ISD-R.");
5896 throw new SecurityException(
5897 "The calling package is not allowed to select ISD-R.");
5898 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005899 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005900
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005901 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005902 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5903 null /* workSource */);
5904 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005905
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005906 // Append the returned status code to the end of the response payload.
5907 String s = Integer.toHexString(
5908 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5909 if (response.payload != null) {
5910 s = IccUtils.bytesToHexString(response.payload) + s;
5911 }
5912 return s;
5913 } finally {
5914 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005915 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005916 }
5917
5918 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005919 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005920 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5922 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005923
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005924 final long identity = Binder.clearCallingIdentity();
5925 try {
5926 if (DBG) {
5927 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5928 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5929 }
5930
5931 IccIoResult response =
5932 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5933 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5934 subId);
5935
5936 if (DBG) {
5937 log("Exchange SIM_IO [R]" + response);
5938 }
5939
5940 byte[] result = null;
5941 int length = 2;
5942 if (response.payload != null) {
5943 length = 2 + response.payload.length;
5944 result = new byte[length];
5945 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5946 } else {
5947 result = new byte[length];
5948 }
5949
5950 result[length - 1] = (byte) response.sw2;
5951 result[length - 2] = (byte) response.sw1;
5952 return result;
5953 } finally {
5954 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005955 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005956 }
5957
Nathan Haroldb3014052017-01-25 15:57:32 -08005958 /**
5959 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5960 * on a particular subscription
5961 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005962 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5963 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005964 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005965 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005966 return null;
5967 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005968
5969 final long identity = Binder.clearCallingIdentity();
5970 try {
5971 if (appType != TelephonyManager.APPTYPE_USIM
5972 && appType != TelephonyManager.APPTYPE_SIM) {
5973 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5974 return null;
5975 }
5976 Object response = sendRequest(
5977 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5978 if (response instanceof String[]) {
5979 return (String[]) response;
5980 }
yincheng zhao2737e882019-09-06 17:06:54 -07005981 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005982 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005983 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984 } finally {
5985 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005986 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005987 }
5988
yincheng zhao2737e882019-09-06 17:06:54 -07005989 /**
5990 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5991 * subscription.
5992 *
5993 * @param subId the id of the subscription.
5994 * @param appType the uicc app type, must be USIM or SIM.
5995 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5996 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005997 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005998 * @return number of fplmns that is successfully written to the SIM.
5999 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006000 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6001 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006002 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6003 mApp, subId, "setForbiddenPlmns");
6004
yincheng zhao2737e882019-09-06 17:06:54 -07006005 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6006 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6007 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6008 }
6009 if (fplmns == null) {
6010 throw new IllegalArgumentException("Fplmn List provided is null");
6011 }
6012 for (String fplmn : fplmns) {
6013 if (!CellIdentity.isValidPlmn(fplmn)) {
6014 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6015 }
6016 }
6017 final long identity = Binder.clearCallingIdentity();
6018 try {
6019 Object response = sendRequest(
6020 CMD_SET_FORBIDDEN_PLMNS,
6021 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6022 subId);
6023 return (int) response;
6024 } finally {
6025 Binder.restoreCallingIdentity(identity);
6026 }
6027 }
6028
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006029 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006030 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6032 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006033
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006034 final long identity = Binder.clearCallingIdentity();
6035 try {
6036 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6037 if (response.payload == null) {
6038 return "";
6039 }
Evan Charltonc66da362014-05-16 14:06:40 -07006040
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006041 // Append the returned status code to the end of the response payload.
6042 String s = Integer.toHexString(
6043 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6044 s = IccUtils.bytesToHexString(response.payload) + s;
6045 return s;
6046 } finally {
6047 Binder.restoreCallingIdentity(identity);
6048 }
Evan Charltonc66da362014-05-16 14:06:40 -07006049 }
6050
Jake Hambye994d462014-02-03 13:10:13 -08006051 /**
6052 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6053 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6054 *
6055 * @param itemID the ID of the item to read
6056 * @return the NV item as a String, or null on error.
6057 */
6058 @Override
6059 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006060 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6062 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006063
6064 final long identity = Binder.clearCallingIdentity();
6065 try {
6066 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006067 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6069 return value;
6070 } finally {
6071 Binder.restoreCallingIdentity(identity);
6072 }
Jake Hambye994d462014-02-03 13:10:13 -08006073 }
6074
6075 /**
6076 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6077 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6078 *
6079 * @param itemID the ID of the item to read
6080 * @param itemValue the value to write, as a String
6081 * @return true on success; false on any failure
6082 */
6083 @Override
6084 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006085 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6087 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006088
6089 final long identity = Binder.clearCallingIdentity();
6090 try {
6091 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6092 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006093 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006094 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6095 return success;
6096 } finally {
6097 Binder.restoreCallingIdentity(identity);
6098 }
Jake Hambye994d462014-02-03 13:10:13 -08006099 }
6100
6101 /**
6102 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6103 * Used for device configuration by some CDMA operators.
6104 *
6105 * @param preferredRoamingList byte array containing the new PRL
6106 * @return true on success; false on any failure
6107 */
6108 @Override
6109 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6111 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112
6113 final long identity = Binder.clearCallingIdentity();
6114 try {
6115 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6116 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6117 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6118 return success;
6119 } finally {
6120 Binder.restoreCallingIdentity(identity);
6121 }
Jake Hambye994d462014-02-03 13:10:13 -08006122 }
6123
6124 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006125 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006126 * Used for device configuration by some CDMA operators.
6127 *
chen xu6dac5ab2018-10-26 17:39:23 -07006128 * @param slotIndex - device slot.
6129 *
Jake Hambye994d462014-02-03 13:10:13 -08006130 * @return true on success; false on any failure
6131 */
6132 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006133 public boolean resetModemConfig(int slotIndex) {
6134 Phone phone = PhoneFactory.getPhone(slotIndex);
6135 if (phone != null) {
6136 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6137 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006138
chen xu6dac5ab2018-10-26 17:39:23 -07006139 final long identity = Binder.clearCallingIdentity();
6140 try {
6141 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6142 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6143 return success;
6144 } finally {
6145 Binder.restoreCallingIdentity(identity);
6146 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006147 }
chen xu6dac5ab2018-10-26 17:39:23 -07006148 return false;
6149 }
6150
6151 /**
6152 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6153 *
6154 * @param slotIndex - device slot.
6155 *
6156 * @return true on success; false on any failure
6157 */
6158 @Override
6159 public boolean rebootModem(int slotIndex) {
6160 Phone phone = PhoneFactory.getPhone(slotIndex);
6161 if (phone != null) {
6162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6163 mApp, phone.getSubId(), "rebootModem");
6164
6165 final long identity = Binder.clearCallingIdentity();
6166 try {
6167 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6168 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6169 return success;
6170 } finally {
6171 Binder.restoreCallingIdentity(identity);
6172 }
6173 }
6174 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006175 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006176
Brad Ebinger51f743a2017-01-23 13:50:20 -08006177 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006178 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6179 * {@link #disableIms(int)}.
6180 * @param slotIndex device slot.
6181 */
6182 public void resetIms(int slotIndex) {
6183 enforceModifyPermission();
6184
6185 final long identity = Binder.clearCallingIdentity();
6186 try {
6187 if (mImsResolver == null) {
6188 // may happen if the does not support IMS.
6189 return;
6190 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006191 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006192 } finally {
6193 Binder.restoreCallingIdentity(identity);
6194 }
6195 }
6196
6197 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006198 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6199 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006200 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006201 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006202 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006203
6204 final long identity = Binder.clearCallingIdentity();
6205 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006206 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006207 // may happen if the device does not support IMS.
6208 return;
6209 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006210 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006211 } finally {
6212 Binder.restoreCallingIdentity(identity);
6213 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006214 }
6215
6216 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006217 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6218 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006219 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006220 public void disableIms(int slotId) {
6221 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006222
6223 final long identity = Binder.clearCallingIdentity();
6224 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006225 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006226 // may happen if the device does not support IMS.
6227 return;
6228 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006229 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006230 } finally {
6231 Binder.restoreCallingIdentity(identity);
6232 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006233 }
6234
6235 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006236 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6237 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006238 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006239 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006240 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006241 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006242
6243 final long identity = Binder.clearCallingIdentity();
6244 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006245 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006246 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6247 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006248 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006249 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006250 } finally {
6251 Binder.restoreCallingIdentity(identity);
6252 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006253 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006254 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006255 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6256 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006257 @Override
6258 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006259 enforceModifyPermission();
6260
6261 final long identity = Binder.clearCallingIdentity();
6262 try {
6263 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006264 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006265 } finally {
6266 Binder.restoreCallingIdentity(identity);
6267 }
6268 }
6269
6270 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006271 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006272 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006273 */
6274 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6275 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006276
6277 final long identity = Binder.clearCallingIdentity();
6278 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006279 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006280 // may happen if the device does not support IMS.
6281 return null;
6282 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006283 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006284 } finally {
6285 Binder.restoreCallingIdentity(identity);
6286 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006287 }
6288
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006289 /**
6290 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006291 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006292 */
6293 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6294 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006295
6296 final long identity = Binder.clearCallingIdentity();
6297 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006298 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006299 // may happen if the device does not support IMS.
6300 return null;
6301 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006302 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006303 } finally {
6304 Binder.restoreCallingIdentity(identity);
6305 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006306 }
6307
Brad Ebinger884c07b2018-02-15 16:17:40 -08006308 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006309 * Sets the ImsService Package Name that Telephony will bind to.
6310 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006311 * @param slotIndex the slot ID that the ImsService should bind for.
6312 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006313 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006314 * @param featureTypes An integer array of feature types associated with a packageName.
6315 * @param packageName The name of the package that the current configuration will be replaced
6316 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006317 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006318 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006319 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6320 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006321 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006323 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006324
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006325 final long identity = Binder.clearCallingIdentity();
6326 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006327 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006328 // may happen if the device does not support IMS.
6329 return false;
6330 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006331 Map<Integer, String> featureConfig = new HashMap<>();
6332 for (int featureType : featureTypes) {
6333 featureConfig.put(featureType, packageName);
6334 }
6335 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6336 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006337 } finally {
6338 Binder.restoreCallingIdentity(identity);
6339 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006340 }
6341
6342 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006343 * Clears any carrier ImsService overrides for the slot index specified that were previously
6344 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6345 *
6346 * This should only be used for testing.
6347 *
6348 * @param slotIndex the slot ID that the ImsService should bind for.
6349 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6350 */
6351 @Override
6352 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006353 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6354 "clearCarrierImsServiceOverride");
6355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006356 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006357
6358 final long identity = Binder.clearCallingIdentity();
6359 try {
6360 if (mImsResolver == null) {
6361 // may happen if the device does not support IMS.
6362 return false;
6363 }
6364 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6365 } finally {
6366 Binder.restoreCallingIdentity(identity);
6367 }
6368 }
6369
6370 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006371 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006372 *
6373 * @param slotId The slot that the ImsService is associated with.
6374 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6375 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006376 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006377 * @return the package name of the ImsService configuration.
6378 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006379 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6380 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006381 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006382 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6383 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006384
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006385 final long identity = Binder.clearCallingIdentity();
6386 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006387 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006388 // may happen if the device does not support IMS.
6389 return "";
6390 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006391 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006392 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6393 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006394 } finally {
6395 Binder.restoreCallingIdentity(identity);
6396 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006397 }
6398
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006399 /**
6400 * Get the MmTelFeature state associated with the requested subscription id.
6401 * @param subId The subscription that the MmTelFeature is associated with.
6402 * @param callback A callback with an integer containing the
6403 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6404 */
6405 @Override
6406 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6407 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006408 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6409 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6410 "IMS not available on device.");
6411 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006412 final long token = Binder.clearCallingIdentity();
6413 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006414 int slotId = getSlotIndex(subId);
6415 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6416 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6417 + subId + "'");
6418 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6419 }
6420 verifyImsMmTelConfiguredOrThrow(slotId);
6421 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6422 try {
6423 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6424 } catch (RemoteException e) {
6425 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6426 + "Ignore");
6427 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006428 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006429 } catch (ImsException e) {
6430 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006431 } finally {
6432 Binder.restoreCallingIdentity(token);
6433 }
6434 }
6435
Daniel Brightbb5840b2021-01-12 15:48:18 -08006436 /**
6437 * Sets the ims registration state on all valid {@link Phone}s.
6438 */
6439 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006440 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006441
6442 final long identity = Binder.clearCallingIdentity();
6443 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006444 // NOTE: Before S, this method only set the default phone.
6445 for (final Phone phone : PhoneFactory.getPhones()) {
6446 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6447 phone.setImsRegistrationState(registered);
6448 }
6449 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006450 } finally {
6451 Binder.restoreCallingIdentity(identity);
6452 }
Wink Saville36469e72014-06-11 15:17:00 -07006453 }
6454
6455 /**
Stuart Scott54788802015-03-30 13:18:01 -07006456 * Set the network selection mode to automatic.
6457 *
6458 */
6459 @Override
6460 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6462 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006463
6464 final long identity = Binder.clearCallingIdentity();
6465 try {
shilufc958392020-01-20 11:36:01 -08006466 if (!isActiveSubscription(subId)) {
6467 return;
6468 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006469 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006470 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6471 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006472 } finally {
6473 Binder.restoreCallingIdentity(identity);
6474 }
Stuart Scott54788802015-03-30 13:18:01 -07006475 }
6476
Jack Yud10cdd42020-09-28 20:28:01 -07006477 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006478 * Ask the radio to connect to the input network and change selection mode to manual.
6479 *
6480 * @param subId the id of the subscription.
6481 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6482 * the operator to attach to.
6483 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6484 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6485 * normal network selection next time.
6486 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006487 */
6488 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006489 public boolean setNetworkSelectionModeManual(
6490 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6492 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006493
Jack Yu285100e2022-12-02 22:48:35 -08006494 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006495 if (!isActiveSubscription(subId)) {
6496 return false;
6497 }
6498
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006499 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006500 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006501 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006502 if (DBG) {
6503 log("setNetworkSelectionModeManual: subId: " + subId
6504 + " operator: " + operatorInfo);
6505 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006506 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6507 } finally {
6508 Binder.restoreCallingIdentity(identity);
6509 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006510 }
shilu84f6e8b2019-12-19 13:58:01 -08006511 /**
6512 * Get the manual network selection
6513 *
6514 * @param subId the id of the subscription.
6515 *
6516 * @return the previously saved user selected PLMN
6517 */
6518 @Override
6519 public String getManualNetworkSelectionPlmn(int subId) {
6520 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006521 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006522 mApp, subId, "getManualNetworkSelectionPlmn");
6523
6524 final long identity = Binder.clearCallingIdentity();
6525 try {
6526 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006527 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006528 }
6529
6530 final Phone phone = getPhone(subId);
6531 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006532 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006533 }
6534 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6535 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6536 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6537 } finally {
6538 Binder.restoreCallingIdentity(identity);
6539 }
6540 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006541
6542 /**
6543 * Scans for available networks.
6544 */
6545 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006546 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6547 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6549 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006550 LocationAccessPolicy.LocationPermissionResult locationResult =
6551 LocationAccessPolicy.checkLocationPermission(mApp,
6552 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6553 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006554 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006555 .setCallingPid(Binder.getCallingPid())
6556 .setCallingUid(Binder.getCallingUid())
6557 .setMethod("getCellNetworkScanResults")
6558 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006559 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6560 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006561 .build());
6562 switch (locationResult) {
6563 case DENIED_HARD:
6564 throw new SecurityException("Not allowed to access scan results -- location");
6565 case DENIED_SOFT:
6566 return null;
6567 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006568
Pengquan Menga1bb6272018-09-06 09:59:22 -07006569 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006570 try {
6571 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006572 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006573 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006574 } finally {
6575 Binder.restoreCallingIdentity(identity);
6576 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006577 }
6578
6579 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006580 * Get the call forwarding info, given the call forwarding reason.
6581 */
6582 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006583 public void getCallForwarding(int subId, int callForwardingReason,
6584 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006585 enforceReadPrivilegedPermission("getCallForwarding");
6586 long identity = Binder.clearCallingIdentity();
6587 try {
6588 if (DBG) {
6589 log("getCallForwarding: subId " + subId
6590 + " callForwardingReason" + callForwardingReason);
6591 }
Hall Liu27d24262020-09-18 19:04:59 -07006592
6593 Phone phone = getPhone(subId);
6594 if (phone == null) {
6595 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006596 callback.onError(
6597 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006598 } catch (RemoteException e) {
6599 // ignore
6600 }
6601 return;
6602 }
6603
6604 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6605 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6606 @Override
6607 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6608 try {
6609 callback.onCallForwardingInfoAvailable(info);
6610 } catch (RemoteException e) {
6611 // ignore
6612 }
6613 }
6614
6615 @Override
6616 public void onError(int error) {
6617 try {
6618 callback.onError(error);
6619 } catch (RemoteException e) {
6620 // ignore
6621 }
6622 }
6623 });
6624 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006625 } finally {
6626 Binder.restoreCallingIdentity(identity);
6627 }
6628 }
6629
6630 /**
6631 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6632 * reason, the number to forward, and the timeout before the forwarding is attempted.
6633 */
6634 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006635 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6636 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006637 enforceModifyPermission();
6638 long identity = Binder.clearCallingIdentity();
6639 try {
6640 if (DBG) {
6641 log("setCallForwarding: subId " + subId
6642 + " callForwardingInfo" + callForwardingInfo);
6643 }
Hall Liu27d24262020-09-18 19:04:59 -07006644
6645 Phone phone = getPhone(subId);
6646 if (phone == null) {
6647 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006648 callback.accept(
6649 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006650 } catch (RemoteException e) {
6651 // ignore
6652 }
6653 return;
6654 }
6655
6656 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6657 FunctionalUtils.ignoreRemoteException(callback::accept));
6658
6659 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006660 } finally {
6661 Binder.restoreCallingIdentity(identity);
6662 }
6663 }
6664
6665 /**
Hall Liu27d24262020-09-18 19:04:59 -07006666 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006667 */
6668 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006669 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006670 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006671 long identity = Binder.clearCallingIdentity();
6672 try {
Hall Liu27d24262020-09-18 19:04:59 -07006673 Phone phone = getPhone(subId);
6674 if (phone == null) {
6675 try {
6676 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6677 } catch (RemoteException e) {
6678 // ignore
6679 }
6680 return;
6681 }
SongFerngWang0e767992021-03-31 22:08:45 +08006682 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6683 PersistableBundle c = configManager.getConfigForSubId(subId);
6684 boolean requireUssd = c.getBoolean(
6685 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006686
Shuo Qian4a594052020-01-23 11:59:30 -08006687 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006688 if (requireUssd) {
6689 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6690 getSubscriptionCarrierId(subId));
6691 String newUssdCommand = "";
6692 try {
6693 newUssdCommand = carrierXmlParser.getFeature(
6694 CarrierXmlParser.FEATURE_CALL_WAITING)
6695 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6696 } catch (NullPointerException e) {
6697 loge("Failed to generate USSD number" + e);
6698 }
6699 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6700 mMainThreadHandler, callback, carrierXmlParser,
6701 CarrierXmlParser.SsEntry.SSAction.QUERY);
6702 final String ussdCommand = newUssdCommand;
6703 Executors.newSingleThreadExecutor().execute(() -> {
6704 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6705 });
6706 } else {
6707 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6708 callback::accept);
6709 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6710 }
Shuo Qian4a594052020-01-23 11:59:30 -08006711 } finally {
6712 Binder.restoreCallingIdentity(identity);
6713 }
6714 }
6715
6716 /**
Hall Liu27d24262020-09-18 19:04:59 -07006717 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006718 */
6719 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006720 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006721 enforceModifyPermission();
6722 long identity = Binder.clearCallingIdentity();
6723 try {
Hall Liu27d24262020-09-18 19:04:59 -07006724 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6725
6726 Phone phone = getPhone(subId);
6727 if (phone == null) {
6728 try {
6729 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6730 } catch (RemoteException e) {
6731 // ignore
6732 }
6733 return;
6734 }
6735
SongFerngWang0e767992021-03-31 22:08:45 +08006736 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6737 PersistableBundle c = configManager.getConfigForSubId(subId);
6738 boolean requireUssd = c.getBoolean(
6739 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006740
SongFerngWang0e767992021-03-31 22:08:45 +08006741 if (DBG) log("getCallWaitingStatus: subId " + subId);
6742 if (requireUssd) {
6743 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6744 getSubscriptionCarrierId(subId));
6745 CarrierXmlParser.SsEntry.SSAction ssAction =
6746 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6747 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6748 String newUssdCommand = "";
6749 try {
6750 newUssdCommand = carrierXmlParser.getFeature(
6751 CarrierXmlParser.FEATURE_CALL_WAITING)
6752 .makeCommand(ssAction, null);
6753 } catch (NullPointerException e) {
6754 loge("Failed to generate USSD number" + e);
6755 }
6756 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6757 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6758 final String ussdCommand = newUssdCommand;
6759 Executors.newSingleThreadExecutor().execute(() -> {
6760 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6761 });
6762 } else {
6763 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6764 FunctionalUtils.ignoreRemoteException(callback::accept));
6765
6766 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6767 }
Shuo Qian4a594052020-01-23 11:59:30 -08006768 } finally {
6769 Binder.restoreCallingIdentity(identity);
6770 }
6771 }
6772
6773 /**
yinxub1bed742017-04-17 11:45:04 -07006774 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006775 *
yinxub1bed742017-04-17 11:45:04 -07006776 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006777 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6778 * location related information which will be sent if the caller already possess
6779 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006780 * @param request contains the radio access networks with bands/channels to scan
6781 * @param messenger callback messenger for scan results or errors
6782 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006783 * @return the id of the requested scan which can be used to stop the scan.
6784 */
6785 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006786 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6787 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006788 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6790 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006791 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006792 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6793 if (!renounceFineLocationAccess) {
6794 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6795 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6796 .setCallingPackage(callingPackage)
6797 .setCallingFeatureId(callingFeatureId)
6798 .setCallingPid(Binder.getCallingPid())
6799 .setCallingUid(Binder.getCallingUid())
6800 .setMethod("requestNetworkScan")
6801 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6802 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6803 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6804 .build());
6805 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006806 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006807 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6808 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006809 if (e != null) {
6810 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6811 throw e;
6812 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006813 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006814 return TelephonyScanManager.INVALID_SCAN_ID;
6815 }
6816 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006817 }
Hall Liu912dfd32019-04-25 14:02:26 -07006818 int callingUid = Binder.getCallingUid();
6819 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006820 final long identity = Binder.clearCallingIdentity();
6821 try {
6822 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006823 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006824 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006825 } finally {
6826 Binder.restoreCallingIdentity(identity);
6827 }
yinxu504e1392017-04-12 16:03:22 -07006828 }
6829
Hall Liub2ac8ef2019-02-28 15:56:23 -08006830 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006831 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006832 boolean hasCarrierPriv;
6833 final long identity = Binder.clearCallingIdentity();
6834 try {
6835 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6836 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6837 } finally {
6838 Binder.restoreCallingIdentity(identity);
6839 }
Hall Liu558027f2019-05-15 19:14:05 -07006840 boolean hasNetworkScanPermission =
6841 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6842 == PERMISSION_GRANTED;
6843
6844 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6845 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6846 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006847 }
6848
6849 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6850 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006851 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6852 return new SecurityException("Specific channels must not be"
6853 + " scanned without location access.");
6854 }
6855 }
6856 }
6857
Hall Liub2ac8ef2019-02-28 15:56:23 -08006858 return null;
6859 }
6860
yinxu504e1392017-04-12 16:03:22 -07006861 /**
6862 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006863 *
6864 * @param subId id of the subscription
6865 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006866 */
6867 @Override
6868 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6870 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006871
Hall Liu912dfd32019-04-25 14:02:26 -07006872 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006873 final long identity = Binder.clearCallingIdentity();
6874 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006875 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006876 } finally {
6877 Binder.restoreCallingIdentity(identity);
6878 }
yinxu504e1392017-04-12 16:03:22 -07006879 }
6880
6881 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006882 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006883 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006884 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006885 */
6886 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006887 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006888 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006889 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006890 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006891
6892 final long identity = Binder.clearCallingIdentity();
6893 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006894 if (DBG) log("getAllowedNetworkTypesBitmask");
6895 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6896 int networkTypesBitmask = (result != null ? result[0] : -1);
6897 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6898 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006899 } finally {
6900 Binder.restoreCallingIdentity(identity);
6901 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006902 }
6903
6904 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006905 * Get the allowed network types for certain reason.
6906 *
6907 * @param subId the id of the subscription.
6908 * @param reason the reason the allowed network type change is taking place
6909 * @return the allowed network types.
6910 */
6911 @Override
6912 public long getAllowedNetworkTypesForReason(int subId,
6913 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006914 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006915 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006916 final long identity = Binder.clearCallingIdentity();
6917 try {
6918 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6919 } finally {
6920 Binder.restoreCallingIdentity(identity);
6921 }
6922 }
6923
6924 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006925 * Enable/Disable E-UTRA-NR Dual Connectivity
6926 * @param subId subscription id of the sim card
6927 * @param nrDualConnectivityState expected NR dual connectivity state
6928 * This can be passed following states
6929 * <ol>
6930 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6931 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6932 * <li>Disable NR dual connectivity and force secondary cell to be released
6933 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6934 * </ol>
6935 * @return operation result.
6936 */
6937 @Override
6938 public int setNrDualConnectivityState(int subId,
6939 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6940 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6941 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006942 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006943 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6944 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6945 }
6946
Sooraj Sasindran37444802020-08-11 10:40:43 -07006947 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6948 final long identity = Binder.clearCallingIdentity();
6949 try {
6950 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6951 nrDualConnectivityState, subId,
6952 workSource);
6953 if (DBG) log("enableNRDualConnectivity result: " + result);
6954 return result;
6955 } finally {
6956 Binder.restoreCallingIdentity(identity);
6957 }
6958 }
6959
6960 /**
6961 * Is E-UTRA-NR Dual Connectivity enabled
6962 * @return true if dual connectivity is enabled else false
6963 */
6964 @Override
6965 public boolean isNrDualConnectivityEnabled(int subId) {
6966 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006967 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006968 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006969 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006970 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6971 return false;
6972 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006973 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6974 final long identity = Binder.clearCallingIdentity();
6975 try {
6976 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6977 null, subId, workSource);
6978 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6979 return isEnabled;
6980 } finally {
6981 Binder.restoreCallingIdentity(identity);
6982 }
6983 }
6984
6985 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006986 * Set the allowed network types of the device and
6987 * provide the reason triggering the allowed network change.
6988 *
6989 * @param subId the id of the subscription.
6990 * @param reason the reason the allowed network type change is taking place
6991 * @param allowedNetworkTypes the allowed network types.
6992 * @return true on success; false on any failure.
6993 */
6994 @Override
6995 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006996 @TelephonyManager.AllowedNetworkTypesReason int reason,
6997 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6999 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007000 // If the caller only has carrier privileges, then they should not be able to override
7001 // any network types which were set for security reasons.
7002 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7003 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007004 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007005 throw new SecurityException(
7006 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007007 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007008 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08007009 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007010 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007011 return false;
7012 }
7013 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7014 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007015 return false;
7016 }
7017
Jack Yu5b494332023-01-23 18:18:04 +00007018 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7019 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007020
Jack Yue37dd262022-12-16 11:53:37 -08007021 Phone phone = getPhone(subId);
7022 if (phone == null) {
7023 return false;
7024 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007025
Jack Yue37dd262022-12-16 11:53:37 -08007026 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007027 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007028 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007029 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007030
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007031 final long identity = Binder.clearCallingIdentity();
7032 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007033 Boolean success = (Boolean) sendRequest(
7034 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7035 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7036
7037 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7038 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007039 } finally {
7040 Binder.restoreCallingIdentity(identity);
7041 }
7042 }
7043
7044 /**
Miaoa84611c2019-03-15 09:21:10 +08007045 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007046 *
Miaoa84611c2019-03-15 09:21:10 +08007047 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007048 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007049 * @hide
7050 */
7051 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007052 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007053 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007054 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007055 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007056 try {
Miaoa84611c2019-03-15 09:21:10 +08007057 if (phone != null) {
7058 return phone.hasMatchedTetherApnSetting();
7059 } else {
7060 return false;
7061 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007062 } finally {
7063 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007064 }
Junda Liu475951f2014-11-07 16:45:03 -08007065 }
7066
7067 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007068 * Get the user enabled state of Mobile Data.
7069 *
7070 * TODO: remove and use isUserDataEnabled.
7071 * This can't be removed now because some vendor codes
7072 * calls through ITelephony directly while they should
7073 * use TelephonyManager.
7074 *
7075 * @return true on enabled
7076 */
7077 @Override
7078 public boolean getDataEnabled(int subId) {
7079 return isUserDataEnabled(subId);
7080 }
7081
7082 /**
7083 * Get whether mobile data is enabled per user setting.
7084 *
7085 * There are other factors deciding whether mobile data is actually enabled, but they are
7086 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007087 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007088 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7089 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007090 *
7091 * @return {@code true} if data is enabled else {@code false}
7092 */
7093 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007094 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007095 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007096 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007097 try {
7098 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7099 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007100 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007101 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7102 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007103 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007104 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007105 mApp, subId, functionName);
7106
Robert Greenwalt646120a2014-05-23 11:54:03 -07007107 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007108
7109 final long identity = Binder.clearCallingIdentity();
7110 try {
Jack Yu285100e2022-12-02 22:48:35 -08007111 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007112 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7113 Phone phone = PhoneFactory.getPhone(phoneId);
7114 if (phone != null) {
7115 boolean retVal = phone.isUserDataEnabled();
7116 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7117 return retVal;
7118 } else {
7119 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7120 return false;
7121 }
7122 } finally {
7123 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007124 }
7125 }
7126
7127 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007128 * Checks if the device is capable of mobile data by considering whether whether the
7129 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7130 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007131 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007132 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007133 */
7134 @Override
7135 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007136 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007137 try {
7138 try {
7139 mApp.enforceCallingOrSelfPermission(
7140 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007141 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007142 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007143 try {
7144 mApp.enforceCallingOrSelfPermission(
7145 android.Manifest.permission.READ_PHONE_STATE,
7146 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007147 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007148 mApp.enforceCallingOrSelfPermission(
7149 permission.READ_BASIC_PHONE_STATE, functionName);
7150 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007151 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007152 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007153 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007154 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007155
7156 final long identity = Binder.clearCallingIdentity();
7157 try {
Jack Yu285100e2022-12-02 22:48:35 -08007158 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007159 Phone phone = PhoneFactory.getPhone(phoneId);
7160 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007161 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007162 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007163 return retVal;
7164 } else {
7165 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7166 return false;
7167 }
7168 } finally {
7169 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007170 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007171 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007172
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007173 /**
7174 * Check if data is enabled for a specific reason
7175 * @param subId Subscription index
7176 * @param reason the reason the data enable change is taking place
7177 * @return {@code true} if the overall data is enabled; {@code false} if not.
7178 */
7179 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007180 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007181 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007182 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007183 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007184 try {
7185 mApp.enforceCallingOrSelfPermission(
7186 android.Manifest.permission.ACCESS_NETWORK_STATE,
7187 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007188 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007189 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7190 functionName);
7191 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007192 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007193 try {
7194 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007195 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007196 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007197 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007198 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007199 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007200 }
7201
7202
7203 final long identity = Binder.clearCallingIdentity();
7204 try {
Jack Yu285100e2022-12-02 22:48:35 -08007205 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007206 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007207 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007208 + " reason=" + reason);
7209 }
7210 Phone phone = PhoneFactory.getPhone(phoneId);
7211 if (phone != null) {
7212 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007213 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007214 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007215 return retVal;
7216 } else {
7217 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007218 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007219 + subId + " retVal=false");
7220 }
7221 return false;
7222 }
7223 } finally {
7224 Binder.restoreCallingIdentity(identity);
7225 }
7226 }
7227
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007228 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007229 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007230 // No permission needed; this only lets the caller inspect their own status.
7231 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007232 }
Junda Liu29340342014-07-10 15:23:27 -07007233
7234 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007235 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007236 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007237 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7238 }
7239
7240 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7241 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007242 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007243 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007244 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7245 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007246 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7247 if (cpt == null) {
7248 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007249 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7250 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007251 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007252 }
7253
7254 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007255 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007256 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007257 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007258 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007259 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007260 Phone phone = getPhone(subId);
7261 if (phone == null) {
7262 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7263 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7264 }
7265 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7266 if (cpt == null) {
7267 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007268 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7269 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007270 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007271 }
7272
7273 @Override
7274 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007275 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007276 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7277 }
7278
7279 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007280 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007281 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007282 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007283 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007284 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7285 Phone phone = PhoneFactory.getPhone(phoneId);
7286 if (phone == null) {
7287 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007288 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007289 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7290 if (cpt == null) {
7291 continue;
7292 }
7293 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007294 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7295 break;
7296 }
7297 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007298 return result;
Junda Liu29340342014-07-10 15:23:27 -07007299 }
Derek Tan89e89d42014-07-08 17:00:10 -07007300
7301 @Override
Junda Liue64de782015-04-16 17:19:16 -07007302 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007303 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007304 Phone phone = PhoneFactory.getPhone(phoneId);
7305 if (phone == null) {
7306 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007307 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007308 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7309 if (cpt == null) {
7310 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007311 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007312 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007313 }
7314
Amith Yamasani6e118872016-02-19 12:53:51 -08007315 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007316 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007317 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007318 Phone phone = PhoneFactory.getPhone(phoneId);
7319 if (phone == null) {
7320 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007321 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007322 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7323 if (cpt == null) {
7324 return Collections.emptyList();
7325 }
7326 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007327 }
7328
chen xuf7e9fe82019-05-09 19:31:02 -07007329 @Override
7330 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007331 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007332 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007333 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007334 try {
7335 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7336 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7337 }
7338 } finally {
7339 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007340 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007341 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007342 }
7343
Rambo Wang6812ffb2022-03-15 16:54:17 -07007344 @Override
7345 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7346 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7347
7348 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7349 if (phone == null) {
7350 return null;
7351 }
7352 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7353 if (cpt == null) {
7354 return null;
7355 }
7356 return cpt.getCarrierServicePackageName();
7357 }
7358
Wink Savilleb564aae2014-10-23 10:18:09 -07007359 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007360 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007361 UiccPort port = phone == null ? null : phone.getUiccPort();
7362 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007363 return null;
7364 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007365 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007366 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007367 return null;
7368 }
7369 return iccId;
7370 }
7371
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007372 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007373 public void setCallComposerStatus(int subId, int status) {
7374 enforceModifyPermission();
7375
7376 final long identity = Binder.clearCallingIdentity();
7377 try {
7378 Phone phone = getPhone(subId);
7379 if (phone != null) {
7380 Phone defaultPhone = phone.getImsPhone();
7381 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7382 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7383 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007384 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7385 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007386 }
7387 }
Shuo Qian284ae752020-12-22 19:10:14 -08007388 } catch (ImsException e) {
7389 throw new ServiceSpecificException(e.getCode());
7390 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007391 Binder.restoreCallingIdentity(identity);
7392 }
7393 }
7394
7395 @Override
7396 public int getCallComposerStatus(int subId) {
7397 enforceReadPrivilegedPermission("getCallComposerStatus");
7398
7399 final long identity = Binder.clearCallingIdentity();
7400 try {
7401 Phone phone = getPhone(subId);
7402 if (phone != null) {
7403 Phone defaultPhone = phone.getImsPhone();
7404 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7405 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7406 return imsPhone.getCallComposerStatus();
7407 }
7408 }
7409 } finally {
7410 Binder.restoreCallingIdentity(identity);
7411 }
7412 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7413 }
7414
7415 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007416 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7417 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007418 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007419 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007420
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007421 final long identity = Binder.clearCallingIdentity();
7422 try {
7423 final String iccId = getIccId(subId);
7424 final Phone phone = getPhone(subId);
7425 if (phone == null) {
7426 return false;
7427 }
7428 final String subscriberId = phone.getSubscriberId();
7429
7430 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007431 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007432 + subscriberId + " to " + number);
7433 }
7434
7435 if (TextUtils.isEmpty(iccId)) {
7436 return false;
7437 }
7438
7439 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7440
7441 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7442 if (alphaTag == null) {
7443 editor.remove(alphaTagPrefKey);
7444 } else {
7445 editor.putString(alphaTagPrefKey, alphaTag);
7446 }
7447
7448 // Record both the line number and IMSI for this ICCID, since we need to
7449 // track all merged IMSIs based on line number
7450 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7451 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7452 if (number == null) {
7453 editor.remove(numberPrefKey);
7454 editor.remove(subscriberPrefKey);
7455 } else {
7456 editor.putString(numberPrefKey, number);
7457 editor.putString(subscriberPrefKey, subscriberId);
7458 }
7459
7460 editor.commit();
7461 return true;
7462 } finally {
7463 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007464 }
Derek Tan7226c842014-07-02 17:42:23 -07007465 }
7466
7467 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007468 public String getLine1NumberForDisplay(int subId, String callingPackage,
7469 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007470 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007471 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007472 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007473 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007474 return null;
7475 }
Derek Tan97ebb422014-09-05 16:55:38 -07007476
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007477 final long identity = Binder.clearCallingIdentity();
7478 try {
7479 String iccId = getIccId(subId);
7480 if (iccId != null) {
7481 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7482 if (DBG_MERGE) {
7483 log("getLine1NumberForDisplay returning "
7484 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7485 }
7486 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007487 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007488 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7489 return null;
7490 } finally {
7491 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007492 }
Derek Tan7226c842014-07-02 17:42:23 -07007493 }
7494
7495 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007496 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7497 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007498 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007499 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007500 return null;
7501 }
Derek Tan97ebb422014-09-05 16:55:38 -07007502
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007503 final long identity = Binder.clearCallingIdentity();
7504 try {
7505 String iccId = getIccId(subId);
7506 if (iccId != null) {
7507 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7508 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7509 }
7510 return null;
7511 } finally {
7512 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007513 }
Derek Tan7226c842014-07-02 17:42:23 -07007514 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007515
7516 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007517 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7518 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007519 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7520 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007521 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007522 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007523 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007524 return null;
7525 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007526
Jordan Liub49b04b2019-05-06 14:45:15 -07007527 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7528 // the process, where TelephonyManager was instantiated.
7529 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007530 final long identity = Binder.clearCallingIdentity();
7531 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007532 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007533 final TelephonyManager tele = TelephonyManager.from(context);
7534 final SubscriptionManager sub = SubscriptionManager.from(context);
7535
7536 // Figure out what subscribers are currently active
7537 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538
Jordan Liub49b04b2019-05-06 14:45:15 -07007539 // Only consider subs which match the current subId
7540 // This logic can be simplified. See b/131189269 for progress.
7541 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007542 activeSubscriberIds.add(tele.getSubscriberId(subId));
7543 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544
7545 // First pass, find a number override for an active subscriber
7546 String mergeNumber = null;
7547 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7548 for (String key : prefs.keySet()) {
7549 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7550 final String subscriberId = (String) prefs.get(key);
7551 if (activeSubscriberIds.contains(subscriberId)) {
7552 final String iccId = key.substring(
7553 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7554 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7555 mergeNumber = (String) prefs.get(numberKey);
7556 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007557 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007558 + " for active subscriber " + subscriberId);
7559 }
7560 if (!TextUtils.isEmpty(mergeNumber)) {
7561 break;
7562 }
7563 }
7564 }
7565 }
7566
7567 // Shortcut when no active merged subscribers
7568 if (TextUtils.isEmpty(mergeNumber)) {
7569 return null;
7570 }
7571
7572 // Second pass, find all subscribers under that line override
7573 final ArraySet<String> result = new ArraySet<>();
7574 for (String key : prefs.keySet()) {
7575 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7576 final String number = (String) prefs.get(key);
7577 if (mergeNumber.equals(number)) {
7578 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7579 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7580 final String subscriberId = (String) prefs.get(subscriberKey);
7581 if (!TextUtils.isEmpty(subscriberId)) {
7582 result.add(subscriberId);
7583 }
7584 }
7585 }
7586 }
7587
7588 final String[] resultArray = result.toArray(new String[result.size()]);
7589 Arrays.sort(resultArray);
7590 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007591 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007592 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7593 }
7594 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007595 } finally {
7596 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007597 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007598 }
7599
7600 @Override
zoey chen38003472019-12-13 17:16:31 +08007601 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7602 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007603
7604 final long identity = Binder.clearCallingIdentity();
7605 try {
7606 final TelephonyManager telephonyManager = mApp.getSystemService(
7607 TelephonyManager.class);
7608 String subscriberId = telephonyManager.getSubscriberId(subId);
7609 if (subscriberId == null) {
7610 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007611 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007612 + subId);
7613 }
7614 return null;
7615 }
7616
Jack Yu285100e2022-12-02 22:48:35 -08007617 ParcelUuid groupUuid;
7618 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7619 final SubscriptionInfo info = SubscriptionManagerService.getInstance()
7620 .getSubscriptionInfo(subId);
7621 groupUuid = info.getGroupUuid();
7622 } else {
7623 final SubscriptionInfo info = mSubscriptionController
7624 .getSubscriptionInfo(subId);
7625 groupUuid = info.getGroupUuid();
7626 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007627 // If it doesn't belong to any group, return just subscriberId of itself.
7628 if (groupUuid == null) {
7629 return new String[]{subscriberId};
7630 }
7631
7632 // Get all subscriberIds from the group.
7633 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007634 List<SubscriptionInfo> groupInfos;
7635 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7636 groupInfos = SubscriptionManagerService.getInstance()
7637 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7638 mApp.getAttributionTag());
7639 } else {
7640 groupInfos = mSubscriptionController
7641 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7642 mApp.getAttributionTag());
7643 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007644 for (SubscriptionInfo subInfo : groupInfos) {
7645 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7646 if (subscriberId != null) {
7647 mergedSubscriberIds.add(subscriberId);
7648 }
7649 }
7650
7651 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7652 } finally {
7653 Binder.restoreCallingIdentity(identity);
7654
7655 }
7656 }
7657
7658 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007659 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007660 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007661 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007662
7663 final long identity = Binder.clearCallingIdentity();
7664 try {
7665 final Phone phone = getPhone(subId);
7666 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7667 } finally {
7668 Binder.restoreCallingIdentity(identity);
7669 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007670 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007671
7672 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007673 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007674 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7675 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007676 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7677 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007678
7679 final long identity = Binder.clearCallingIdentity();
7680 try {
7681 final Phone phone = getPhone(subId);
7682 if (phone == null) {
7683 return false;
7684 }
7685 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7686 cdmaNonRoamingList);
7687 } finally {
7688 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007689 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007690 }
7691
7692 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007693 @Deprecated
7694 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7695 enforceModifyPermission();
7696
7697 int returnValue = 0;
7698 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007699 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007700 if(result.exception == null) {
7701 if (result.result != null) {
7702 byte[] responseData = (byte[])(result.result);
7703 if(responseData.length > oemResp.length) {
7704 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7705 responseData.length + "bytes. Buffer Size is " +
7706 oemResp.length + "bytes.");
7707 }
7708 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7709 returnValue = responseData.length;
7710 }
7711 } else {
7712 CommandException ex = (CommandException) result.exception;
7713 returnValue = ex.getCommandError().ordinal();
7714 if(returnValue > 0) returnValue *= -1;
7715 }
7716 } catch (RuntimeException e) {
7717 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7718 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7719 if(returnValue > 0) returnValue *= -1;
7720 }
7721
7722 return returnValue;
7723 }
7724
7725 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007726 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007727 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007728 try {
7729 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007730 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007731 mApp, phone.getSubId(), "getRadioAccessFamily");
7732 } catch (SecurityException e) {
7733 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7734 throw e;
7735 }
chen xub97461a2018-10-26 14:17:57 -07007736 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007737 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007738 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007739 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007740 final long identity = Binder.clearCallingIdentity();
7741 try {
chen xub97461a2018-10-26 14:17:57 -07007742 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007743 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007744 mApp, phone.getSubId(), "getRadioAccessFamily");
7745 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007746 } finally {
7747 Binder.restoreCallingIdentity(identity);
7748 }
chen xub97461a2018-10-26 14:17:57 -07007749 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007750 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007751
7752 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007753 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007754 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007755 try {
7756 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7757 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007758 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007759 }
7760 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007761 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007762 }
7763 RoleManager rm = mApp.getSystemService(RoleManager.class);
7764 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7765 if (!dialerRoleHolders.contains(callingPackage)) {
7766 throw new SecurityException("App must be the dialer role holder to"
7767 + " upload a call composer pic");
7768 }
7769
7770 Executors.newSingleThreadExecutor().execute(() -> {
7771 ByteArrayOutputStream output = new ByteArrayOutputStream(
7772 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7773 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7774 boolean readUntilEnd = false;
7775 int totalBytesRead = 0;
7776 byte[] buffer = new byte[16 * 1024];
7777 while (true) {
7778 int numRead;
7779 try {
7780 numRead = input.read(buffer);
7781 } catch (IOException e) {
7782 try {
7783 fd.checkError();
7784 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7785 null);
7786 } catch (IOException e1) {
7787 // This means that the other side closed explicitly with an error. If this
7788 // happens, log and ignore.
7789 loge("Remote end of call composer picture pipe closed: " + e1);
7790 }
7791 break;
7792 }
7793 if (numRead == -1) {
7794 readUntilEnd = true;
7795 break;
7796 }
7797 totalBytesRead += numRead;
7798 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7799 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7800 try {
7801 input.close();
7802 } catch (IOException e) {
7803 // ignore
7804 }
7805 break;
7806 }
7807 output.write(buffer, 0, numRead);
7808 }
7809 // Generally, the remote end will close the file descriptors. The only case where we
7810 // close is above, where the picture size is too big.
7811
7812 try {
7813 fd.checkError();
7814 } catch (IOException e) {
7815 loge("Remote end for call composer closed with an error: " + e);
7816 return;
7817 }
7818
Hall Liuaa4211e2021-01-20 15:43:39 -08007819 if (!readUntilEnd) {
7820 loge("Did not finish reading entire image; aborting");
7821 return;
7822 }
Hall Liu82694d52020-12-11 18:22:04 -08007823
Hall Liuaa4211e2021-01-20 15:43:39 -08007824 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7825 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7826 new CallComposerPictureTransfer.Factory() {},
7827 imageData,
7828 (result) -> {
7829 if (result.first != null) {
7830 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7831 Bundle outputResult = new Bundle();
7832 outputResult.putParcelable(
7833 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7834 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7835 outputResult);
7836 } else {
7837 callback.send(result.second, null);
7838 }
7839 }
7840 );
Hall Liu82694d52020-12-11 18:22:04 -08007841 });
7842 }
7843
7844 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007845 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007846 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007847 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007848
7849 final long identity = Binder.clearCallingIdentity();
7850 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007851 ImsManager.getInstance(defaultPhone.getContext(),
7852 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007853 } finally {
7854 Binder.restoreCallingIdentity(identity);
7855 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007856 }
7857
7858 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007859 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007860 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007861 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7862 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007863 return false;
7864 }
Svet Ganovb320e182015-04-16 12:30:10 -07007865
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007866 final long identity = Binder.clearCallingIdentity();
7867 try {
7868 // Check the user preference and the system-level IMS setting. Even if the user has
7869 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7870 // In the long run, we may instead need to check if there exists a connection service
7871 // which can support video calling.
7872 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007873 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007874 return imsManager.isVtEnabledByPlatform()
7875 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7876 && imsManager.isVtEnabledByUser();
7877 } finally {
7878 Binder.restoreCallingIdentity(identity);
7879 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007880 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007881
Andrew Leea1239f22015-03-02 17:44:07 -08007882 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007883 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7884 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007885 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007886 mApp, subId, callingPackage, callingFeatureId,
7887 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007888 return false;
7889 }
7890
7891 final long identity = Binder.clearCallingIdentity();
7892 try {
7893 CarrierConfigManager configManager =
7894 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007895 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007896 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7897 } finally {
7898 Binder.restoreCallingIdentity(identity);
7899 }
Andrew Leea1239f22015-03-02 17:44:07 -08007900 }
7901
7902 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007903 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007904 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007905 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007906 return false;
7907 }
7908
7909 final long identity = Binder.clearCallingIdentity();
7910 try {
7911 CarrierConfigManager configManager =
7912 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007913 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007914 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7915 } finally {
7916 Binder.restoreCallingIdentity(identity);
7917 }
Andrew Leea1239f22015-03-02 17:44:07 -08007918 }
7919
Andrew Lee9431b832015-03-09 18:46:45 -07007920 @Override
7921 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007922 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007923 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007924 }
7925
7926 @Override
7927 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007928 final long identity = Binder.clearCallingIdentity();
7929 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007930 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007931 } finally {
7932 Binder.restoreCallingIdentity(identity);
7933 }
Andrew Lee9431b832015-03-09 18:46:45 -07007934 }
7935
Hall Liuf6668912018-10-31 17:05:23 -07007936 /**
7937 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7938 * support for the feature and device firmware support.
7939 *
7940 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7941 */
7942 @Override
7943 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007944 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007945 final Phone phone = getPhone(subscriptionId);
7946 if (phone == null) {
7947 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7948 return false;
7949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007950 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007951 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007952 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7953 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007954 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007955 return isCarrierSupported && isDeviceSupported;
7956 } finally {
7957 Binder.restoreCallingIdentity(identity);
7958 }
Hall Liu98187582018-01-22 19:15:32 -08007959 }
7960
Hall Liuf6668912018-10-31 17:05:23 -07007961 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007962 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7963 * RTT setting, will return true if the device and carrier both support RTT.
7964 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007965 */
7966 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007967 final long identity = Binder.clearCallingIdentity();
7968 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007969 boolean isRttSupported = isRttSupported(subscriptionId);
7970 boolean isUserRttSettingOn = Settings.Secure.getInt(
7971 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7972 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7973 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7974 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007975 } finally {
7976 Binder.restoreCallingIdentity(identity);
7977 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007978 }
7979
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007980 @Deprecated
7981 @Override
7982 public String getDeviceId(String callingPackage) {
7983 return getDeviceIdWithFeature(callingPackage, null);
7984 }
7985
Sanket Padawe7310cc72015-01-14 09:53:20 -08007986 /**
7987 * Returns the unique device ID of phone, for example, the IMEI for
7988 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7989 *
7990 * <p>Requires Permission:
7991 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7992 */
7993 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007994 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007995 try {
7996 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7997 } catch (SecurityException se) {
7998 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7999 throw new SecurityException("Package " + callingPackage + " does not belong to "
8000 + Binder.getCallingUid());
8001 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008002 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008003 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008004 return null;
8005 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008006 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008007 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008008 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008009 return null;
8010 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008011
8012 final long identity = Binder.clearCallingIdentity();
8013 try {
8014 return phone.getDeviceId();
8015 } finally {
8016 Binder.restoreCallingIdentity(identity);
8017 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008018 }
8019
Ping Sunc67b7c22016-03-02 19:16:45 +08008020 /**
8021 * {@hide}
8022 * Returns the IMS Registration Status on a particular subid
8023 *
8024 * @param subId
8025 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008026 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008027 Phone phone = getPhone(subId);
8028 if (phone != null) {
8029 return phone.isImsRegistered();
8030 } else {
8031 return false;
8032 }
8033 }
8034
Santos Cordon7a1885b2015-02-03 11:15:19 -08008035 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008036 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008037 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008038 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008039 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008040 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8041 }
8042 final long identity = Binder.clearCallingIdentity();
8043 try {
8044 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8045 } finally {
8046 Binder.restoreCallingIdentity(identity);
8047 }
8048 }
8049
8050 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008051 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008052 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008053 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008054 mApp,
8055 subscriptionId,
8056 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07008057 final long identity = Binder.clearCallingIdentity();
8058 try {
8059 Phone phone = getPhone(subscriptionId);
8060 if (phone == null) {
8061 return null;
8062 }
8063 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8064 } finally {
8065 Binder.restoreCallingIdentity(identity);
8066 }
8067 }
8068
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008069 /**
8070 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008071 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008072 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008073 final long identity = Binder.clearCallingIdentity();
8074 try {
8075 Phone phone = getPhone(subId);
8076 if (phone != null) {
8077 return phone.isWifiCallingEnabled();
8078 } else {
8079 return false;
8080 }
8081 } finally {
8082 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008083 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008084 }
8085
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008086 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008087 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008088 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008089 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008090 final long identity = Binder.clearCallingIdentity();
8091 try {
8092 Phone phone = getPhone(subId);
8093 if (phone != null) {
8094 return phone.isVideoEnabled();
8095 } else {
8096 return false;
8097 }
8098 } finally {
8099 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008100 }
8101 }
8102
8103 /**
8104 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8105 * defined in {@link ImsRegistrationImplBase}.
8106 */
8107 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008108 final long identity = Binder.clearCallingIdentity();
8109 try {
8110 Phone phone = getPhone(subId);
8111 if (phone != null) {
8112 return phone.getImsRegistrationTech();
8113 } else {
8114 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8115 }
8116 } finally {
8117 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008118 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008119 }
8120
Stuart Scott8eef64f2015-04-08 15:13:54 -07008121 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008122 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008123 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07008124 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8125 return;
8126 }
Kai Shif70f46f2021-03-03 13:59:46 -08008127 Phone defaultPhone = getDefaultPhone();
8128 if (defaultPhone != null) {
8129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8130 mApp, getDefaultPhone().getSubId(), "factoryReset");
8131 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008132 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008133
Svet Ganovcc087f82015-05-12 20:35:54 -07008134 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008135 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8136 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008137 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008138 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008139 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008140 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008141 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008142 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08008143 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008144 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008145 // There has been issues when Sms raw table somehow stores orphan
8146 // fragments. They lead to garbled message when new fragments come
8147 // in and combined with those stale ones. In case this happens again,
8148 // user can reset all network settings which will clean up this table.
8149 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008150 // Clean up IMS settings as well here.
8151 int slotId = getSlotIndex(subId);
8152 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8153 ImsManager.getInstance(mApp, slotId).factoryReset();
8154 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008155
Kai Shif70f46f2021-03-03 13:59:46 -08008156 if (defaultPhone == null) {
8157 return;
8158 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008159 // Erase modem config if erase modem on network setting is enabled.
8160 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8161 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8162 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008163 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008164 }
Kai Shif70f46f2021-03-03 13:59:46 -08008165
8166 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008167 } finally {
8168 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008169 }
8170 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008171
SongFerngWangfd89b102021-05-27 22:44:54 +08008172 @VisibleForTesting
8173 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8174 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8175 return;
8176 }
8177 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8178 RILConstants.PREFERRED_NETWORK_MODE);
8179 SubscriptionManager.setSubscriptionProperty(subId,
8180 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8181 "user=" + defaultNetworkType);
8182 phone.loadAllowedNetworksFromSubscriptionDatabase();
8183 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8184 defaultNetworkType, null);
8185 }
8186
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008187 private void cleanUpSmsRawTable(Context context) {
8188 ContentResolver resolver = context.getContentResolver();
8189 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8190 resolver.delete(uri, null, null);
8191 }
8192
Narayan Kamath1c496c22015-04-16 14:40:19 +01008193 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008194 public String getSimLocaleForSubscriber(int subId) {
8195 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8196 final Phone phone = getPhone(subId);
8197 if (phone == null) {
8198 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008199 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008200 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008201 final long identity = Binder.clearCallingIdentity();
8202 try {
Jack Yu285100e2022-12-02 22:48:35 -08008203 SubscriptionInfo info;
8204 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8205 info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId,
8206 phone.getContext().getOpPackageName(),
8207 phone.getContext().getAttributionTag());
8208 if (info == null) {
8209 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8210 return null;
8211 }
8212 } else {
8213 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
8214 phone.getContext().getOpPackageName(),
8215 phone.getContext().getAttributionTag());
8216 if (info == null) {
8217 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8218 return null;
8219 }
chen xu6291c472019-02-04 12:55:53 -08008220 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008221 // Try and fetch the locale from the carrier properties or from the SIM language
8222 // preferences (EF-PL and EF-LI)...
8223 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008224 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008225 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8226 if (localeFromDefaultSim != null) {
8227 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8228 if (DBG) log("Using locale from subId: " + subId + " locale: "
8229 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008230 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008231 } else {
8232 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008233 }
8234 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008235
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008236 // The SIM language preferences only store a language (e.g. fr = French), not an
8237 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8238 // the SIM and carrier preferences does not include a country we add the country
8239 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008240 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008241 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008242 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008243 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008244 }
8245
8246 if (DBG) log("No locale found - returning null");
8247 return null;
8248 } finally {
8249 Binder.restoreCallingIdentity(identity);
8250 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008251 }
8252
tom hsu0b59d292022-09-29 23:49:21 +08008253 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008254 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008255 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008256 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008257 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008258 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8259 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008260 Locale.forLanguageTag(localeTag).getCountry())) {
8261 return localeTag;
8262 }
8263 }
8264 return inputLocale.toLanguageTag();
8265 }
8266
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008267 /**
8268 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8269 */
8270 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08008271 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8272 return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList(
8273 mApp.getOpPackageName(), mApp.getAttributionTag());
8274 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008275 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08008276 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008277 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008278
Gary Jian3aa9a762022-01-24 16:41:19 +08008279 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8280 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008281
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008282 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008283 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8284 * representing the state of the modem.
8285 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008286 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8287 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008288 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008289 */
8290 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008291 public void requestModemActivityInfo(ResultReceiver result) {
8292 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008293 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008294
8295 final long identity = Binder.clearCallingIdentity();
8296 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008297 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008298 } finally {
8299 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008300 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008301 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008302
Gary Jian76280a42022-12-07 16:18:33 +08008303 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008304 // less than total activity duration.
8305 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8306 if (info == null) {
8307 return false;
8308 }
8309 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008310 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008311 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8312
Hall Liu49656c02020-10-09 19:00:11 -07008313 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8314
Siddharth Rayb8114062018-06-17 15:02:38 -07008315 return (info.isValid()
8316 && (info.getSleepTimeMillis() <= activityDurationMs)
Gary Jian76280a42022-12-07 16:18:33 +08008317 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008318 }
8319
Gary Jian3aa9a762022-01-24 16:41:19 +08008320 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8321 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8322 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8323 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8324
8325 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8326 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8327 }
8328
8329 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8330 mLastModemActivityInfo.setReceiveTimeMillis(
8331 rat,
8332 freq,
8333 info.getReceiveTimeMillis(rat, freq)
8334 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8335 }
8336
8337 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8338 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8339 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8340 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8341
8342 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8343 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8344 }
8345 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8346 mLastModemActivityInfo.setReceiveTimeMillis(
8347 rat,
8348 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8349 }
8350
8351 /**
8352 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8353 * @param info recent ModemActivityInfo
8354 */
8355 private void mergeModemActivityInfo(ModemActivityInfo info) {
8356 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008357 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008358 boolean matched;
8359 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8360 matched = false;
8361 int rat = info.getSpecificInfoRat(i);
8362 int freq = info.getSpecificInfoFrequencyRange(i);
8363 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8364 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8365 //if it already exists
8366 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8367 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8368 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8369 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8370 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8371 updateLastModemActivityInfo(info, rat, freq);
8372 matched = true;
8373 }
8374 } else {
8375 updateLastModemActivityInfo(info, rat);
8376 matched = true;
8377 }
8378 }
8379 }
8380
8381 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008382 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008383 new ActivityStatsTechSpecificInfo(
8384 rat,
8385 freq,
8386 info.getTransmitTimeMillis(rat, freq),
8387 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008388 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008389 }
8390 }
8391 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8392 mLastModemActivitySpecificInfo =
8393 new ActivityStatsTechSpecificInfo[merged.size()];
8394 merged.toArray(mLastModemActivitySpecificInfo);
8395
8396 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8397 mLastModemActivityInfo.setSleepTimeMillis(
8398 info.getSleepTimeMillis()
8399 + mLastModemActivityInfo.getSleepTimeMillis());
8400 mLastModemActivityInfo.setIdleTimeMillis(
8401 info.getIdleTimeMillis()
8402 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008403
8404 mLastModemActivityInfo =
8405 new ModemActivityInfo(
8406 mLastModemActivityInfo.getTimestampMillis(),
8407 mLastModemActivityInfo.getSleepTimeMillis(),
8408 mLastModemActivityInfo.getIdleTimeMillis(),
8409 mLastModemActivitySpecificInfo);
8410 }
8411
8412 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8413 ActivityStatsTechSpecificInfo[] info) {
8414 int infoSize = info.length;
8415 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8416 for (int i = 0; i < infoSize; i++) {
8417 ret[i] = new ActivityStatsTechSpecificInfo(
8418 info[i].getRat(), info[i].getFrequencyRange(),
8419 info[i].getTransmitTimeMillis(),
8420 (int) info[i].getReceiveTimeMillis());
8421 }
8422 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008423 }
8424
Jack Yu85bd38a2015-11-09 11:34:32 -08008425 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008426 * Returns the service state information on specified subscription.
8427 */
8428 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008429 public ServiceState getServiceStateForSubscriber(int subId,
8430 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8431 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008432 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008433 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008434 return null;
8435 }
8436
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008437 boolean hasFinePermission = false;
8438 boolean hasCoarsePermission = false;
8439 if (!renounceFineLocationAccess) {
8440 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8441 LocationAccessPolicy.checkLocationPermission(mApp,
8442 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8443 .setCallingPackage(callingPackage)
8444 .setCallingFeatureId(callingFeatureId)
8445 .setCallingPid(Binder.getCallingPid())
8446 .setCallingUid(Binder.getCallingUid())
8447 .setMethod("getServiceStateForSubscriber")
8448 .setLogAsInfo(true)
8449 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8450 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8451 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8452 .build());
8453 hasFinePermission =
8454 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8455 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008456
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008457 if (!renounceCoarseLocationAccess) {
8458 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8459 LocationAccessPolicy.checkLocationPermission(mApp,
8460 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8461 .setCallingPackage(callingPackage)
8462 .setCallingFeatureId(callingFeatureId)
8463 .setCallingPid(Binder.getCallingPid())
8464 .setCallingUid(Binder.getCallingUid())
8465 .setMethod("getServiceStateForSubscriber")
8466 .setLogAsInfo(true)
8467 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8468 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8469 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8470 .build());
8471 hasCoarsePermission =
8472 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8473 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008474
Jack Yu479f40e2020-10-27 21:29:25 -07008475 final Phone phone = getPhone(subId);
8476 if (phone == null) {
8477 return null;
8478 }
8479
Jordan Liu0f2bc442020-11-18 16:47:37 -08008480 final long identity = Binder.clearCallingIdentity();
8481
Jack Yu479f40e2020-10-27 21:29:25 -07008482 boolean isCallingPackageDataService = phone.getDataServicePackages()
8483 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008484 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008485 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008486 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
8487 SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance()
8488 .getSubscriptionInfoInternal(subId);
8489 if (subInfo == null || !subInfo.isActive()) {
8490 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8491 + "subId=" + subId);
8492 return null;
8493 }
8494 } else {
8495 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8496 callingFeatureId)) {
8497 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8498 + "subId=" + subId);
8499 return null;
8500 }
Jordan Liuc437b192020-08-17 10:59:12 -07008501 }
8502
Hall Liuf19c44f2018-11-27 14:38:17 -08008503 ServiceState ss = phone.getServiceState();
8504
8505 // Scrub out the location info in ServiceState depending on what level of access
8506 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008507 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008508 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8509 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008510 } finally {
8511 Binder.restoreCallingIdentity(identity);
8512 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008513 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008514
8515 /**
8516 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8517 *
8518 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8519 * voicemail ringtone.
8520 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8521 * PhoneAccount.
8522 */
8523 @Override
8524 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008525 final long identity = Binder.clearCallingIdentity();
8526 try {
8527 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8528 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008529 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008530 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008531
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008532 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8533 } finally {
8534 Binder.restoreCallingIdentity(identity);
8535 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008536 }
8537
8538 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008539 * Sets the per-account voicemail ringtone.
8540 *
8541 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8542 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8543 *
8544 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8545 * voicemail ringtone.
8546 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8547 * PhoneAccount.
8548 */
8549 @Override
8550 public void setVoicemailRingtoneUri(String callingPackage,
8551 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008552 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008553 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008554 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8555 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8557 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8558 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008559 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008560
8561 final long identity = Binder.clearCallingIdentity();
8562 try {
8563 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8564 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008565 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008566 }
8567 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8568 } finally {
8569 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008570 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008571 }
8572
8573 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008574 * Returns whether vibration is set for voicemail notification in Phone settings.
8575 *
8576 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8577 * voicemail vibration setting.
8578 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8579 */
8580 @Override
8581 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008582 final long identity = Binder.clearCallingIdentity();
8583 try {
8584 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8585 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008586 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008587 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008588
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008589 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8590 } finally {
8591 Binder.restoreCallingIdentity(identity);
8592 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008593 }
8594
Youhan Wange64578a2016-05-02 15:32:42 -07008595 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008596 * Sets the per-account voicemail vibration.
8597 *
8598 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8599 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8600 *
8601 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8602 * voicemail vibration setting.
8603 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8604 * specific PhoneAccount.
8605 */
8606 @Override
8607 public void setVoicemailVibrationEnabled(String callingPackage,
8608 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008609 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008610 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008611 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8612 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8614 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8615 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008616 }
8617
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008618 final long identity = Binder.clearCallingIdentity();
8619 try {
8620 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8621 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008622 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008623 }
8624 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8625 } finally {
8626 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008627 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008628 }
8629
8630 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008631 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8632 *
8633 * @throws SecurityException if the caller does not have the required permission
8634 */
arunvoddud7401012022-12-15 16:08:12 +00008635 @VisibleForTesting
8636 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008637 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008638 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008639 }
8640
8641 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008642 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8643 * permission.
8644 *
8645 * @throws SecurityException if the caller does not have the required permission
8646 */
8647 private void enforceSendSmsPermission() {
8648 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8649 }
8650
8651 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008652 * Make sure either called from same process as self (phone) or IPC caller has interact across
8653 * users permission.
8654 *
8655 * @throws SecurityException if the caller does not have the required permission
8656 */
8657 private void enforceInteractAcrossUsersPermission(String message) {
8658 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8659 }
8660
8661 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008662 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008663 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008664 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008665 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008666 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008667 final long identity = Binder.clearCallingIdentity();
8668 try {
8669 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008670 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008671 if (componentName == null) {
8672 throw new SecurityException(
8673 "Caller not current active visual voicemail package[null]");
8674 }
8675 String vvmPackage = componentName.getPackageName();
8676 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008677 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008678 }
8679 } finally {
8680 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008681 }
8682 }
8683
8684 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008685 * Return the application ID for the app type.
8686 *
8687 * @param subId the subscription ID that this request applies to.
8688 * @param appType the uicc app type.
8689 * @return Application ID for specificied app type, or null if no uicc.
8690 */
8691 @Override
8692 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008693 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008694 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008695
8696 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008697 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008698 if (phone == null) {
8699 return null;
8700 }
8701 String aid = null;
8702 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008703 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008704 .getApplicationByType(appType).getAid();
8705 } catch (Exception e) {
8706 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8707 }
8708 return aid;
8709 } finally {
8710 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008711 }
Youhan Wange64578a2016-05-02 15:32:42 -07008712 }
8713
Youhan Wang4001d252016-05-11 10:29:41 -07008714 /**
8715 * Return the Electronic Serial Number.
8716 *
8717 * @param subId the subscription ID that this request applies to.
8718 * @return ESN or null if error.
8719 */
8720 @Override
8721 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008722 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008723 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008724
8725 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008726 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008727 if (phone == null) {
8728 return null;
8729 }
8730 String esn = null;
8731 try {
8732 esn = phone.getEsn();
8733 } catch (Exception e) {
8734 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8735 }
8736 return esn;
8737 } finally {
8738 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008739 }
Youhan Wang4001d252016-05-11 10:29:41 -07008740 }
8741
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008742 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008743 * Return the Preferred Roaming List Version.
8744 *
8745 * @param subId the subscription ID that this request applies to.
8746 * @return PRLVersion or null if error.
8747 */
8748 @Override
8749 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008750 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008751 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008752
8753 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008754 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008755 if (phone == null) {
8756 return null;
8757 }
8758 String cdmaPrlVersion = null;
8759 try {
8760 cdmaPrlVersion = phone.getCdmaPrlVersion();
8761 } catch (Exception e) {
8762 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8763 }
8764 return cdmaPrlVersion;
8765 } finally {
8766 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008767 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008768 }
8769
8770 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008771 * Get snapshot of Telephony histograms
8772 * @return List of Telephony histograms
8773 * @hide
8774 */
8775 @Override
8776 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008777 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8778 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008779
8780 final long identity = Binder.clearCallingIdentity();
8781 try {
8782 return RIL.getTelephonyRILTimingHistograms();
8783 } finally {
8784 Binder.restoreCallingIdentity(identity);
8785 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008786 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008787
8788 /**
8789 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008790 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8791 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008792 * Require system privileges. In the future we may add this to carrier APIs.
8793 *
Michele Berionne482f8202018-11-27 18:57:59 -08008794 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008795 */
8796 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008797 @TelephonyManager.SetCarrierRestrictionResult
8798 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008799 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008800 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008801
Michele Berionne482f8202018-11-27 18:57:59 -08008802 if (carrierRestrictionRules == null) {
8803 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008804 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008805
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008806 final long identity = Binder.clearCallingIdentity();
8807 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008808 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008809 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008810 } finally {
8811 Binder.restoreCallingIdentity(identity);
8812 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008813 }
8814
8815 /**
8816 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008817 * Get the allowed carrier list and the excluded carrier list, including the priority between
8818 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008819 * Require system privileges. In the future we may add this to carrier APIs.
8820 *
Michele Berionne482f8202018-11-27 18:57:59 -08008821 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008822 */
8823 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008824 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008825 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008826 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008827
8828 final long identity = Binder.clearCallingIdentity();
8829 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008830 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8831 if (response instanceof CarrierRestrictionRules) {
8832 return (CarrierRestrictionRules) response;
8833 }
8834 // Response is an Exception of some kind,
8835 // which is signalled to the user as a NULL retval
8836 return null;
8837 } catch (Exception e) {
8838 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8839 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008840 } finally {
8841 Binder.restoreCallingIdentity(identity);
8842 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008843 }
8844
fionaxu59545b42016-05-25 15:53:37 -07008845 /**
arunvoddud7401012022-12-15 16:08:12 +00008846 * Fetches the carrier restriction status of the device and sends the status to the caller
8847 * through the callback.
8848 *
8849 * @param callback The callback that will be used to send the result.
8850 * @throws SecurityException if the caller does not have the required permission/privileges or
8851 * the caller is not allowlisted.
8852 */
8853 @Override
8854 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8855 enforceReadPermission("getCarrierRestrictionStatus");
8856 int carrierId = validateCallerAndGetCarrierId(packageName);
8857 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8858 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8859 throw new SecurityException("Not an authorized caller");
8860 }
8861 final long identity = Binder.clearCallingIdentity();
8862 try {
8863 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8864 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8865 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8866 } finally {
8867 Binder.restoreCallingIdentity(identity);
8868 }
8869 }
8870
8871 @VisibleForTesting
8872 public int validateCallerAndGetCarrierId(String packageName) {
8873 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8874 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8875 }
8876
8877 /**
fionaxu59545b42016-05-25 15:53:37 -07008878 * Action set from carrier signalling broadcast receivers to enable/disable radio
8879 * @param subId the subscription ID that this action applies to.
8880 * @param enabled control enable or disable radio.
8881 * {@hide}
8882 */
8883 @Override
8884 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8885 enforceModifyPermission();
8886 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008887
8888 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008889 if (phone == null) {
8890 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8891 return;
8892 }
8893 try {
8894 phone.carrierActionSetRadioEnabled(enabled);
8895 } catch (Exception e) {
8896 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008897 } finally {
8898 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008899 }
8900 }
8901
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008902 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008903 * Enable or disable Voice over NR (VoNR)
8904 * @param subId the subscription ID that this action applies to.
8905 * @param enabled enable or disable VoNR.
8906 * @return operation result.
8907 */
8908 @Override
8909 public int setVoNrEnabled(int subId, boolean enabled) {
8910 enforceModifyPermission();
8911 final Phone phone = getPhone(subId);
8912
8913 final long identity = Binder.clearCallingIdentity();
8914 if (phone == null) {
8915 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8916 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8917 }
8918
8919 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8920 try {
8921 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8922 workSource);
8923 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008924
8925 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8926 if (DBG) {
8927 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8928 }
8929 SubscriptionManager.setSubscriptionProperty(
8930 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8931 (enabled ? "1" : "0"));
8932 }
8933
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008934 return result;
8935 } finally {
8936 Binder.restoreCallingIdentity(identity);
8937 }
8938 }
8939
8940 /**
8941 * Is voice over NR enabled
8942 * @return true if VoNR is enabled else false
8943 */
8944 @Override
8945 public boolean isVoNrEnabled(int subId) {
8946 enforceReadPrivilegedPermission("isVoNrEnabled");
8947 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8948 final long identity = Binder.clearCallingIdentity();
8949 try {
8950 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8951 null, subId, workSource);
8952 if (DBG) log("isVoNrEnabled: " + isEnabled);
8953 return isEnabled;
8954 } finally {
8955 Binder.restoreCallingIdentity(identity);
8956 }
8957 }
8958
8959 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008960 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8961 * network status based on which carrier apps could apply actions accordingly,
8962 * enable/disable default url handler for example.
8963 *
8964 * @param subId the subscription ID that this action applies to.
8965 * @param report control start/stop reporting the default network status.
8966 * {@hide}
8967 */
8968 @Override
8969 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8970 enforceModifyPermission();
8971 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008972
8973 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008974 if (phone == null) {
8975 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8976 return;
8977 }
8978 try {
8979 phone.carrierActionReportDefaultNetworkStatus(report);
8980 } catch (Exception e) {
8981 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008982 } finally {
8983 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008984 }
8985 }
8986
8987 /**
fionaxud9622282017-07-17 17:51:30 -07008988 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8989 * @param subId the subscription ID that this action applies to.
8990 * {@hide}
8991 */
8992 @Override
8993 public void carrierActionResetAll(int subId) {
8994 enforceModifyPermission();
8995 final Phone phone = getPhone(subId);
8996 if (phone == null) {
8997 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8998 return;
8999 }
9000 try {
9001 phone.carrierActionResetAll();
9002 } catch (Exception e) {
9003 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9004 }
9005 }
9006
9007 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009008 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9009 * bug report is being generated.
9010 */
9011 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009012 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009013 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9014 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009015 writer.println("Permission Denial: can't dump Phone from pid="
9016 + Binder.getCallingPid()
9017 + ", uid=" + Binder.getCallingUid()
9018 + "without permission "
9019 + android.Manifest.permission.DUMP);
9020 return;
9021 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009022 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009023 }
Jack Yueb89b242016-06-22 13:27:47 -07009024
Brad Ebingerdac2f002018-04-03 15:17:52 -07009025 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009026 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9027 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9028 @NonNull String[] args) {
9029 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9030 this, in.getFileDescriptor(), out.getFileDescriptor(),
9031 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009032 }
9033
Jack Yueb89b242016-06-22 13:27:47 -07009034 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009035 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009036 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009037 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009038 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009039 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009040 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009041 */
9042 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009043 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009044 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009045 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9046 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9047 try {
9048 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009049 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009050 } catch (SecurityException se) {
9051 enforceModifyPermission();
9052 }
9053 } else {
9054 enforceModifyPermission();
9055 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009056
9057 final long identity = Binder.clearCallingIdentity();
9058 try {
9059 Phone phone = getPhone(subId);
9060 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009061 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9062 phone.carrierActionSetMeteredApnsEnabled(enabled);
9063 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009064 phone.getDataSettingsManager().setDataEnabled(
9065 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009067 }
9068 } finally {
9069 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009070 }
9071 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009072
9073 /**
9074 * Get Client request stats
9075 * @return List of Client Request Stats
9076 * @hide
9077 */
9078 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009079 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9080 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009081 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009082 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009083 return null;
9084 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009085 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009086
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009087 final long identity = Binder.clearCallingIdentity();
9088 try {
9089 if (phone != null) {
9090 return phone.getClientRequestStats();
9091 }
9092
9093 return null;
9094 } finally {
9095 Binder.restoreCallingIdentity(identity);
9096 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009097 }
9098
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009099 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009100 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009101 if (uid == Process.ROOT_UID && packageName == null) {
9102 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9103 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9104 // exception. ROOT_UID seems not to have a valid package name returned by
9105 // PackageManager, so just fake it here to avoid issues when running telephony shell
9106 // commands that plumb through the RIL as root, like so:
9107 // $ adb root
9108 // $ adb shell cmd phone ...
9109 packageName = "root";
9110 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009111 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009112 }
Jack Yueb4124c2017-02-16 15:32:43 -08009113
9114 /**
Grace Chen70990072017-03-24 17:21:30 -07009115 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009116 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009117 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009118 * @param state State of SIM (power down, power up, pass through)
9119 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9120 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9121 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009122 *
9123 **/
9124 @Override
Grace Chen70990072017-03-24 17:21:30 -07009125 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009126 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009127 Phone phone = PhoneFactory.getPhone(slotIndex);
9128
vagdeviaf9a5b92018-08-15 16:01:53 -07009129 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9130
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009131 final long identity = Binder.clearCallingIdentity();
9132 try {
9133 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009134 phone.setSimPowerState(state, null, workSource);
9135 }
9136 } finally {
9137 Binder.restoreCallingIdentity(identity);
9138 }
9139 }
9140
9141 /**
9142 * Set SIM card power state.
9143 *
9144 * @param slotIndex SIM slot id.
9145 * @param state State of SIM (power down, power up, pass through)
9146 * @param callback callback to trigger after success or failure
9147 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9148 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9149 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9150 *
9151 **/
9152 @Override
9153 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9154 IIntegerConsumer callback) {
9155 enforceModifyPermission();
9156 Phone phone = PhoneFactory.getPhone(slotIndex);
9157
9158 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9159
9160 final long identity = Binder.clearCallingIdentity();
9161 try {
9162 if (phone != null) {
9163 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9164 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009165 }
9166 } finally {
9167 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009168 }
9169 }
Shuo Qiandd210312017-04-12 22:11:33 +00009170
Tyler Gunn65d45c22017-06-05 11:22:26 -07009171 private boolean isUssdApiAllowed(int subId) {
9172 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009173 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009174 if (configManager == null) {
9175 return false;
9176 }
9177 PersistableBundle pb = configManager.getConfigForSubId(subId);
9178 if (pb == null) {
9179 return false;
9180 }
9181 return pb.getBoolean(
9182 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9183 }
9184
Shuo Qiandd210312017-04-12 22:11:33 +00009185 /**
9186 * Check if phone is in emergency callback mode
9187 * @return true if phone is in emergency callback mode
9188 * @param subId sub id
9189 */
goneil9c5f4872017-12-05 14:07:56 -08009190 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009191 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009192 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00009193 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009194
9195 final long identity = Binder.clearCallingIdentity();
9196 try {
9197 if (phone != null) {
9198 return phone.isInEcm();
9199 } else {
9200 return false;
9201 }
9202 } finally {
9203 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009204 }
9205 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009206
9207 /**
9208 * Get the current signal strength information for the given subscription.
9209 * Because this information is not updated when the device is in a low power state
9210 * it should not be relied-upon to be current.
9211 * @param subId Subscription index
9212 * @return the most recent cached signal strength info from the modem
9213 */
9214 @Override
9215 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009216 final long identity = Binder.clearCallingIdentity();
9217 try {
9218 Phone p = getPhone(subId);
9219 if (p == null) {
9220 return null;
9221 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009223 return p.getSignalStrength();
9224 } finally {
9225 Binder.restoreCallingIdentity(identity);
9226 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009227 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009228
Pengquan Meng77b7f132018-08-22 14:49:57 -07009229 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009230 * Get the current modem radio state for the given slot.
9231 * @param slotIndex slot index.
9232 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009233 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009234 * @return the current radio power state from the modem
9235 */
9236 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009237 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009238 Phone phone = PhoneFactory.getPhone(slotIndex);
9239 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009240 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9241 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009242 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9243 }
9244
9245 final long identity = Binder.clearCallingIdentity();
9246 try {
9247 return phone.getRadioPowerState();
9248 } finally {
9249 Binder.restoreCallingIdentity(identity);
9250 }
9251 }
9252 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9253 }
9254
9255 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009256 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9257 *
9258 * <p>Requires one of the following permissions:
9259 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009260 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009261 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9262 * privileges.
9263 *
9264 * @param subId subscription id
9265 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9266 * {@code false}.
9267 */
9268 @Override
9269 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009270 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009271 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009272 try {
9273 mApp.enforceCallingOrSelfPermission(
9274 android.Manifest.permission.ACCESS_NETWORK_STATE,
9275 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009276 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009277 mApp.enforceCallingOrSelfPermission(
9278 permission.READ_BASIC_PHONE_STATE, functionName);
9279 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009280 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009281 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009282 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009283 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009284
Pengquan Menga1bb6272018-09-06 09:59:22 -07009285 boolean isEnabled = false;
9286 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009287 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009288 Phone phone = getPhone(subId);
9289 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009290 } finally {
9291 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009292 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009293 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009294 }
9295
9296
9297 /**
9298 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9299 *
9300 * <p> Requires permission:
9301 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9302 * privileges.
9303 *
9304 * @param subId subscription id
9305 * @param isEnabled {@code true} means enable, {@code false} means disable.
9306 */
9307 @Override
9308 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9310 mApp, subId, "setDataRoamingEnabled");
9311
Pengquan Menga1bb6272018-09-06 09:59:22 -07009312 final long identity = Binder.clearCallingIdentity();
9313 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009314 Phone phone = getPhone(subId);
9315 if (phone != null) {
9316 phone.setDataRoamingEnabled(isEnabled);
9317 }
9318 } finally {
9319 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009320 }
9321 }
9322
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009323 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009324 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009325 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009326 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07009327 mApp, subId, "isManualNetworkSelectionAllowed");
9328
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009329 boolean isAllowed = true;
9330 final long identity = Binder.clearCallingIdentity();
9331 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009332 Phone phone = getPhone(subId);
9333 if (phone != null) {
9334 isAllowed = phone.isCspPlmnEnabled();
9335 }
9336 } finally {
9337 Binder.restoreCallingIdentity(identity);
9338 }
9339 return isAllowed;
9340 }
9341
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009342 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9343 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009344 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009345 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009346 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009347 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9348 if (phone == null) {
9349 return false;
9350 }
9351 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9352 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9353 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009354 }
9355
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009356 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009357 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009358 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009359 mApp.getSystemService(AppOpsManager.class)
9360 .checkPackage(Binder.getCallingUid(), callingPackage);
9361
Jordan Liu1e142fc2019-04-22 15:10:43 -07009362 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009363 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009364 try {
9365 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009366 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009367 } catch (SecurityException e) {
9368 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9369 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009370 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08009371 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009372 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009373 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009374 }
sandeepjsb6c87872021-09-27 15:34:44 +00009375 // checking compatibility, if calling app's target SDK is T and beyond.
9376 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9377 Binder.getCallingUid())) {
9378 isIccIdAccessRestricted = true;
9379 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009380 final long identity = Binder.clearCallingIdentity();
9381 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009382 UiccController uiccController = UiccController.getInstance();
9383 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009384 if (hasReadPermission) {
9385 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009386 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009387
9388 // Remove private info if the caller doesn't have access
9389 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9390 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009391 //setting the value after compatibility check
9392 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009393 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9394 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009395 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009396 if (card == null) {
9397 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009398 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009399 continue;
9400 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009401 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9402 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009403 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009404 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009405 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009406 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9407 for (UiccPortInfo portInfo : portInfos) {
9408 UiccPort port = uiccController.getUiccPortForSlot(
9409 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9410 if (port == null) {
9411 // assume no access if port is null
9412 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9413 continue;
9414 }
9415 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9416 uiccPortInfos.add(portInfo);
9417 } else {
9418 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9419 }
9420 }
9421 filteredInfos.add(new UiccCardInfo(
9422 cardInfo.isEuicc(),
9423 cardInfo.getCardId(),
9424 null,
9425 cardInfo.getPhysicalSlotIndex(),
9426 cardInfo.isRemovable(),
9427 cardInfo.isMultipleEnabledProfilesSupported(),
9428 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009429 }
9430 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009431 } finally {
9432 Binder.restoreCallingIdentity(identity);
9433 }
9434 }
9435
sandeepjsb6c87872021-09-27 15:34:44 +00009436 /**
9437 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9438 * generally private and require carrier privileges to view.
9439 *
9440 * @hide
9441 */
9442 @NonNull
9443 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9444 List<UiccPortInfo> portinfo = new ArrayList<>();
9445 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9446 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9447 }
9448 return new UiccCardInfo(
9449 cardInfo.isEuicc(),
9450 cardInfo.getCardId(),
9451 null,
9452 cardInfo.getPhysicalSlotIndex(),
9453 cardInfo.isRemovable(),
9454 cardInfo.isMultipleEnabledProfilesSupported(),
9455 portinfo
9456 );
9457 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009458
sandeepjsb6c87872021-09-27 15:34:44 +00009459 /**
9460 * @hide
9461 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9462 * These values are generally private and require carrier privileges to view.
9463 */
9464 @NonNull
9465 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9466 return new UiccPortInfo(
9467 UiccPortInfo.ICCID_REDACTED,
9468 portInfo.getPortIndex(),
9469 portInfo.getLogicalSlotIndex(),
9470 portInfo.isActive()
9471 );
9472 }
9473 @Override
9474 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009475 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009476 mApp.getSystemService(AppOpsManager.class)
9477 .checkPackage(Binder.getCallingUid(), callingPackage);
9478
sandeepjsb6c87872021-09-27 15:34:44 +00009479 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009480
Aman Guptaf3c90b32022-03-17 04:54:16 +00009481 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9482 // we are reading iccId which is PII data.
9483 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009484
9485 // checking compatibility, if calling app's target SDK is T and beyond.
9486 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9487 Binder.getCallingUid())) {
9488 isLogicalSlotAccessRestricted = true;
9489 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009490 final long identity = Binder.clearCallingIdentity();
9491 try {
9492 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009493 if (slots == null || slots.length == 0) {
9494 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009495 return null;
9496 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009497 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9498 for (int i = 0; i < slots.length; i++) {
9499 UiccSlot slot = slots[i];
9500 if (slot == null) {
9501 continue;
9502 }
9503
Jordan Liu7be7e652019-05-06 18:55:02 +00009504 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009505 UiccCard card = slot.getUiccCard();
9506 if (card != null) {
9507 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009508 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009509 cardId = slot.getEid();
9510 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009511 // If cardId is null, use iccId of default port as cardId.
9512 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009513 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009514 }
9515
Jordan Liu857451f2019-05-09 16:35:35 -07009516 if (cardId != null) {
9517 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9518 // if cardId is an EID, it's all digits so this is fine
9519 cardId = IccUtils.stripTrailingFs(cardId);
9520 }
9521
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009522 int cardState = 0;
9523 switch (slot.getCardState()) {
9524 case CARDSTATE_ABSENT:
9525 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9526 break;
9527 case CARDSTATE_PRESENT:
9528 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9529 break;
9530 case CARDSTATE_ERROR:
9531 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9532 break;
9533 case CARDSTATE_RESTRICTED:
9534 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9535 break;
9536 default:
9537 break;
9538
9539 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009540 List<UiccPortInfo> portInfos = new ArrayList<>();
9541 int[] portIndexes = slot.getPortList();
9542 for (int portIdx : portIndexes) {
9543 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009544 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009545 portInfos.add(new UiccPortInfo(iccId, portIdx,
9546 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009547 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009548 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009549 slot.isEuicc(),
9550 cardId,
9551 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009552 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009553 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009554 //setting the value after compatibility check
9555 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009556 }
9557 return infos;
9558 } finally {
9559 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009560 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009561 }
9562
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009563 /* Returns null if doesn't have read permission or carrier privilege access. */
9564 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9565 boolean hasReadPermission) {
9566 String iccId = slot.getIccId(portIndex);
9567 if (hasReadPermission) { // if has read permission
9568 return iccId;
9569 } else {
9570 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9571 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9572 // if no read permission, checking carrier privilege access
9573 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9574 return iccId;
9575 }
9576 }
9577 }
9578 // No read permission or carrier privilege access.
9579 return UiccPortInfo.ICCID_REDACTED;
9580 }
9581
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009582 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009583 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009584 public boolean switchSlots(int[] physicalSlots) {
9585 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009586
9587 final long identity = Binder.clearCallingIdentity();
9588 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009589 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9590 for (int i = 0; i < physicalSlots.length; i++) {
9591 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9592 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9593 physicalSlots[i], i));
9594 }
9595 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009596 } finally {
9597 Binder.restoreCallingIdentity(identity);
9598 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009599 }
Jack Yu4c988042018-02-27 15:30:01 -08009600
9601 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009602 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9603 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9604 enforceModifyPermission();
9605
9606 final long identity = Binder.clearCallingIdentity();
9607 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009608 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009609 } finally {
9610 Binder.restoreCallingIdentity(identity);
9611 }
9612 }
9613
9614 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009615 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009616 final long identity = Binder.clearCallingIdentity();
9617 try {
9618 return UiccController.getInstance().getCardIdForDefaultEuicc();
9619 } finally {
9620 Binder.restoreCallingIdentity(identity);
9621 }
9622 }
9623
Pengquan Meng85728fb2018-03-12 16:31:21 -07009624 /**
goneil47ffb6e2018-04-06 15:40:58 -07009625 * A test API to reload the UICC profile.
9626 *
9627 * <p>Requires that the calling app has permission
9628 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9629 * @hide
9630 */
9631 @Override
9632 public void refreshUiccProfile(int subId) {
9633 enforceModifyPermission();
9634
9635 final long identity = Binder.clearCallingIdentity();
9636 try {
9637 Phone phone = getPhone(subId);
9638 if (phone == null) {
9639 return;
9640 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009641 UiccPort uiccPort = phone.getUiccPort();
9642 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009643 return;
9644 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009645 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009646 if (uiccProfile == null) {
9647 return;
9648 }
9649 uiccProfile.refresh();
9650 } finally {
9651 Binder.restoreCallingIdentity(identity);
9652 }
9653 }
9654
9655 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009656 * Returns false if the mobile data is disabled by default, otherwise return true.
9657 */
9658 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009659 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009660 }
9661
9662 /**
9663 * Returns true if the data roaming is enabled by default, i.e the system property
9664 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9665 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9666 */
9667 private boolean getDefaultDataRoamingEnabled(int subId) {
9668 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009669 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009670 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009671 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9672 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9673 return isDataRoamingEnabled;
9674 }
9675
9676 /**
9677 * Returns the default network type for the given {@code subId}, if the default network type is
9678 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9679 */
9680 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009681 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009682 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009683 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9684 return list.get(phoneId);
9685 }
9686 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009687 }
fionaxua13278b2018-03-21 00:08:13 -07009688
9689 @Override
9690 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009691 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009692 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009693
9694 final long identity = Binder.clearCallingIdentity();
9695 try {
9696 final Phone phone = getPhone(subId);
9697 if (phone == null) {
9698 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9699 return;
9700 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009701 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9702 if (cpt != null) {
9703 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9704 }
9705 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009706 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9707 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009708 if (carrierPrivilegeRules == null) {
9709 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9710 } else {
9711 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9712 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009713 } finally {
9714 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009715 }
fionaxua13278b2018-03-21 00:08:13 -07009716 }
9717
9718 @Override
9719 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009720 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009721
9722 final long identity = Binder.clearCallingIdentity();
9723 try {
9724 final Phone phone = getPhone(subId);
9725 if (phone == null) {
9726 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9727 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9728 }
9729 return phone.getCarrierIdListVersion();
9730 } finally {
9731 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009732 }
fionaxua13278b2018-03-21 00:08:13 -07009733 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009734
9735 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009736 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9737 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009738 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009739 mApp, subId, callingPackage, callingFeatureId,
9740 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009741 return -1;
9742 }
9743
9744 final long identity = Binder.clearCallingIdentity();
9745 try {
9746 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9747 } finally {
9748 Binder.restoreCallingIdentity(identity);
9749 }
9750 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009751
9752 @Override
9753 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009754 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009755 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009756 mApp, subId, "getCdmaRoamingMode");
9757
9758 final long identity = Binder.clearCallingIdentity();
9759 try {
9760 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9761 } finally {
9762 Binder.restoreCallingIdentity(identity);
9763 }
9764 }
9765
9766 @Override
9767 public boolean setCdmaRoamingMode(int subId, int mode) {
9768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9769 mApp, subId, "setCdmaRoamingMode");
9770
9771 final long identity = Binder.clearCallingIdentity();
9772 try {
9773 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9774 } finally {
9775 Binder.restoreCallingIdentity(identity);
9776 }
9777 }
9778
9779 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009780 public int getCdmaSubscriptionMode(int subId) {
9781 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009782 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009783 mApp, subId, "getCdmaSubscriptionMode");
9784
9785 final long identity = Binder.clearCallingIdentity();
9786 try {
9787 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9788 } finally {
9789 Binder.restoreCallingIdentity(identity);
9790 }
9791 }
9792
9793 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009794 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9796 mApp, subId, "setCdmaSubscriptionMode");
9797
9798 final long identity = Binder.clearCallingIdentity();
9799 try {
9800 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9801 } finally {
9802 Binder.restoreCallingIdentity(identity);
9803 }
9804 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009805
sqianc5eccab2018-10-19 18:46:41 -07009806 @Override
sqian8c685422019-02-22 15:55:18 -08009807 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009808 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009809 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009810 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9811 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009812 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9813 }
9814 final long identity = Binder.clearCallingIdentity();
9815 try {
sqian854d44b2018-12-12 16:48:18 -08009816 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9817 for (Phone phone: PhoneFactory.getPhones()) {
9818 if (phone.getEmergencyNumberTracker() != null
9819 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9820 emergencyNumberListInternal.put(
9821 phone.getSubId(),
9822 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9823 }
sqian11b7a0e2018-12-05 18:48:28 -08009824 }
sqian854d44b2018-12-12 16:48:18 -08009825 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009826 } finally {
9827 Binder.restoreCallingIdentity(identity);
9828 }
sqianc5eccab2018-10-19 18:46:41 -07009829 }
9830
9831 @Override
sqian8c685422019-02-22 15:55:18 -08009832 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009833 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009834 if (!exactMatch) {
9835 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009836 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009837 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009838 }
9839 final long identity = Binder.clearCallingIdentity();
9840 try {
sqian854d44b2018-12-12 16:48:18 -08009841 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009842 //Note: we ignore passed in param exactMatch. We can remove it once
9843 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009844 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009845 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009846 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009847 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009848 }
sqian11b7a0e2018-12-05 18:48:28 -08009849 }
9850 return false;
9851 } finally {
9852 Binder.restoreCallingIdentity(identity);
9853 }
9854 }
9855
sqianf4ca7ed2019-01-15 18:32:07 -08009856 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009857 * Start emergency callback mode for GsmCdmaPhone for testing.
9858 */
9859 @Override
9860 public void startEmergencyCallbackMode() {
9861 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9862 "startEmergencyCallbackMode");
9863 enforceModifyPermission();
9864 final long identity = Binder.clearCallingIdentity();
9865 try {
9866 for (Phone phone : PhoneFactory.getPhones()) {
9867 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9868 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9869 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9870 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9871 gsmCdmaPhone.obtainMessage(
9872 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9873 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9874 }
9875 }
9876 } finally {
9877 Binder.restoreCallingIdentity(identity);
9878 }
9879 }
9880
9881 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009882 * Update emergency number list for test mode.
9883 */
9884 @Override
9885 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9886 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9887 "updateEmergencyNumberListTestMode");
9888
9889 final long identity = Binder.clearCallingIdentity();
9890 try {
9891 for (Phone phone: PhoneFactory.getPhones()) {
9892 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9893 if (tracker != null) {
9894 tracker.executeEmergencyNumberTestModeCommand(action, num);
9895 }
9896 }
9897 } finally {
9898 Binder.restoreCallingIdentity(identity);
9899 }
9900 }
9901
9902 /**
9903 * Get the full emergency number list for test mode.
9904 */
9905 @Override
9906 public List<String> getEmergencyNumberListTestMode() {
9907 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9908 "getEmergencyNumberListTestMode");
9909
9910 final long identity = Binder.clearCallingIdentity();
9911 try {
9912 Set<String> emergencyNumbers = new HashSet<>();
9913 for (Phone phone: PhoneFactory.getPhones()) {
9914 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9915 if (tracker != null) {
9916 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9917 emergencyNumbers.add(num.getNumber());
9918 }
9919 }
9920 }
9921 return new ArrayList<>(emergencyNumbers);
9922 } finally {
9923 Binder.restoreCallingIdentity(identity);
9924 }
9925 }
9926
chen xud6b45bd2018-10-30 22:27:10 -07009927 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009928 public int getEmergencyNumberDbVersion(int subId) {
9929 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9930
9931 final long identity = Binder.clearCallingIdentity();
9932 try {
9933 final Phone phone = getPhone(subId);
9934 if (phone == null) {
9935 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9936 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9937 }
9938 return phone.getEmergencyNumberDbVersion();
9939 } finally {
9940 Binder.restoreCallingIdentity(identity);
9941 }
9942 }
9943
9944 @Override
9945 public void notifyOtaEmergencyNumberDbInstalled() {
9946 enforceModifyPermission();
9947
9948 final long identity = Binder.clearCallingIdentity();
9949 try {
9950 for (Phone phone: PhoneFactory.getPhones()) {
9951 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9952 if (tracker != null) {
9953 tracker.updateOtaEmergencyNumberDatabase();
9954 }
9955 }
9956 } finally {
9957 Binder.restoreCallingIdentity(identity);
9958 }
9959 }
9960
9961 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009962 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009963 enforceActiveEmergencySessionPermission();
9964
9965 final long identity = Binder.clearCallingIdentity();
9966 try {
9967 for (Phone phone: PhoneFactory.getPhones()) {
9968 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9969 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009970 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9971 }
9972 }
9973 } finally {
9974 Binder.restoreCallingIdentity(identity);
9975 }
9976 }
9977
9978 @Override
9979 public void resetOtaEmergencyNumberDbFilePath() {
9980 enforceActiveEmergencySessionPermission();
9981
9982 final long identity = Binder.clearCallingIdentity();
9983 try {
9984 for (Phone phone: PhoneFactory.getPhones()) {
9985 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9986 if (tracker != null) {
9987 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009988 }
9989 }
9990 } finally {
9991 Binder.restoreCallingIdentity(identity);
9992 }
9993 }
9994
9995 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009996 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9997 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9998 Phone phone = getPhone(subId);
9999 if (phone == null) {
10000 return null;
10001 }
10002 final long identity = Binder.clearCallingIdentity();
10003 try {
10004 UiccProfile profile = UiccController.getInstance()
10005 .getUiccProfileForPhone(phone.getPhoneId());
10006 if (profile != null) {
10007 return profile.getCertsFromCarrierPrivilegeAccessRules();
10008 }
10009 } finally {
10010 Binder.restoreCallingIdentity(identity);
10011 }
10012 return null;
10013 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010014
10015 /**
10016 * Enable or disable a modem stack.
10017 */
10018 @Override
10019 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10020 enforceModifyPermission();
10021
10022 final long identity = Binder.clearCallingIdentity();
10023 try {
10024 Phone phone = PhoneFactory.getPhone(slotIndex);
10025 if (phone == null) {
10026 return false;
10027 } else {
10028 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10029 }
10030 } finally {
10031 Binder.restoreCallingIdentity(identity);
10032 }
10033 }
Michelecea4cf22018-12-21 15:00:11 -080010034
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010035 /**
10036 * Whether a modem stack is enabled or not.
10037 */
10038 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010039 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10040 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010041 Phone phone = PhoneFactory.getPhone(slotIndex);
10042 if (phone == null) return false;
10043
10044 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010045 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10046 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010047 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10048 }
10049
10050 final long identity = Binder.clearCallingIdentity();
10051 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010052 try {
10053 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10054 } catch (NoSuchElementException ex) {
10055 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10056 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010057 } finally {
10058 Binder.restoreCallingIdentity(identity);
10059 }
10060 }
10061
Michelecea4cf22018-12-21 15:00:11 -080010062 @Override
Michele0ea7d782019-03-19 14:58:42 -070010063 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010064 enforceModifyPermission();
10065
10066 final long identity = Binder.clearCallingIdentity();
10067 try {
10068 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010069 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010070 .commit();
10071 } finally {
10072 Binder.restoreCallingIdentity(identity);
10073 }
10074 }
10075
10076 @Override
Michele0ea7d782019-03-19 14:58:42 -070010077 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010078 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010079 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010080 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10081 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010082 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010083 }
Michelecea4cf22018-12-21 15:00:11 -080010084
10085 final long identity = Binder.clearCallingIdentity();
10086 try {
Michele0ea7d782019-03-19 14:58:42 -070010087 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010088 } finally {
10089 Binder.restoreCallingIdentity(identity);
10090 }
10091 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010092
Michele0ea7d782019-03-19 14:58:42 -070010093 @TelephonyManager.IsMultiSimSupportedResult
10094 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010095 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10096 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10097 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010098 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10099 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010100 }
10101 // Check if the hardware supports multisim functionality. If usage of multisim is not
10102 // supported by the modem, indicate that it is restricted.
10103 PhoneCapability staticCapability =
10104 mPhoneConfigurationManager.getStaticPhoneCapability();
10105 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010106 loge("isMultiSimSupportedInternal: no static configuration available");
10107 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010108 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010109 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010110 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10111 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010112 }
10113 // Check if support of multiple SIMs is restricted by carrier
10114 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010115 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010116 }
10117
Michele0ea7d782019-03-19 14:58:42 -070010118 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010119 }
10120
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010121 /**
10122 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010123 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10124 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10125 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010126 * @param numOfSims number of active sims we want to switch to
10127 */
10128 @Override
10129 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010130 if (numOfSims == 1) {
10131 enforceModifyPermission();
10132 } else {
10133 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10134 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10135 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010136 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010137
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010138 try {
Michele30b57b22019-03-01 12:01:14 -080010139 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010140 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010141 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10142 return;
10143 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010144 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10145 } finally {
10146 Binder.restoreCallingIdentity(identity);
10147 }
10148 }
10149
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010150 @Override
10151 public boolean isApplicationOnUicc(int subId, int appType) {
10152 enforceReadPrivilegedPermission("isApplicationOnUicc");
10153 Phone phone = getPhone(subId);
10154 if (phone == null) {
10155 return false;
10156 }
10157 final long identity = Binder.clearCallingIdentity();
10158 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010159 UiccPort uiccPort = phone.getUiccPort();
10160 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010161 return false;
10162 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010163 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010164 if (uiccProfile == null) {
10165 return false;
10166 }
10167 if (TelephonyManager.APPTYPE_SIM <= appType
10168 && appType <= TelephonyManager.APPTYPE_ISIM) {
10169 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10170 }
10171 return false;
10172 } finally {
10173 Binder.restoreCallingIdentity(identity);
10174 }
10175 }
10176
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010177 /**
chen xub4baa772019-04-03 10:23:41 -070010178 * Get whether making changes to modem configurations will trigger reboot.
10179 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010180 */
10181 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010182 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10183 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010184 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010185 mApp, subId, callingPackage, callingFeatureId,
10186 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010187 return false;
10188 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010189 final long identity = Binder.clearCallingIdentity();
10190 try {
10191 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10192 } finally {
10193 Binder.restoreCallingIdentity(identity);
10194 }
10195 }
10196
Nathan Harold29f5f052019-02-15 13:41:57 -080010197 private void updateModemStateMetrics() {
10198 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10199 // TODO: check the state for each modem if the api is ready.
10200 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10201 }
10202
Pengquan Meng3889a572019-01-23 11:16:29 -080010203 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010204 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010205 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010206 // Verify that the callingPackage belongs to the calling UID
10207 mApp.getSystemService(AppOpsManager.class)
10208 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010209 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010210 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010211 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010212 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10213 if (slotInfos != null) {
10214 for (int i = 0; i < slotInfos.length; i++) {
10215 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10216 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10217 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10218 portInfo.getLogicalSlotIndex()));
10219 }
10220 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010221 }
10222 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010223 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010224 } finally {
10225 Binder.restoreCallingIdentity(identity);
10226 }
10227 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010228
10229 /**
10230 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010231 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010232 */
jimsunf9ec1622022-09-13 21:18:43 +080010233 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010234 @Override
10235 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010236 return getHalVersion(HAL_SERVICE_RADIO);
10237 }
10238
10239 /**
10240 * Get the HAL Version of a specific service
10241 */
10242 @Override
10243 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010244 Phone phone = getDefaultPhone();
10245 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010246 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010247 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10248 return hv.major * 100 + hv.minor;
10249 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010250
10251 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010252 * Get the current calling package name.
10253 * @return the current calling package name
10254 */
10255 @Override
10256 public String getCurrentPackageName() {
10257 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10258 }
10259
10260 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010261 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10262 * corresponding network requests on a subId.
10263 *
10264 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010265 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010266 * 2) APN is un-metered for this subscription, or
10267 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010268 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010269 *
10270 * @return whether data is allowed for a apn type.
10271 *
10272 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010273 */
10274 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010275 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010276 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10277 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010278
10279 // Now that all security checks passes, perform the operation as ourselves.
10280 final long identity = Binder.clearCallingIdentity();
10281 try {
10282 Phone phone = getPhone(subId);
10283 if (phone == null) return false;
10284
Jack Yu27422a52022-03-21 10:38:05 -070010285 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010286 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010287 isMetered = phone.getDataNetworkController().getDataConfigManager()
10288 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10289 phone.getServiceState().getDataRoaming());
10290 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010291 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010292 } finally {
10293 Binder.restoreCallingIdentity(identity);
10294 }
10295 }
10296
10297 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010298 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010299 enforceReadPrivilegedPermission("isApnMetered");
10300
10301 // Now that all security checks passes, perform the operation as ourselves.
10302 final long identity = Binder.clearCallingIdentity();
10303 try {
10304 Phone phone = getPhone(subId);
10305 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010306 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10307 DataUtils.apnTypeToNetworkCapability(apnType),
10308 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010309 } finally {
10310 Binder.restoreCallingIdentity(identity);
10311 }
10312 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010313
10314 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010315 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10316 int subscriptionId, IBooleanConsumer resultCallback) {
10317 enforceModifyPermission();
10318 long token = Binder.clearCallingIdentity();
10319 try {
10320 Phone phone = getPhone(subscriptionId);
10321 if (phone == null) {
10322 try {
10323 if (resultCallback != null) {
10324 resultCallback.accept(false);
10325 }
10326 } catch (RemoteException e) {
10327 // ignore
10328 }
10329 return;
10330 }
10331 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10332 Pair.create(specifiers, (x) -> {
10333 try {
10334 if (resultCallback != null) {
10335 resultCallback.accept(x);
10336 }
10337 } catch (RemoteException e) {
10338 // ignore
10339 }
10340 });
10341 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10342 } finally {
10343 Binder.restoreCallingIdentity(token);
10344 }
10345 }
10346
10347 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010348 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10349 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010350 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010351 mApp, subId, "getSystemSelectionChannels");
10352 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10353 final long identity = Binder.clearCallingIdentity();
10354 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010355 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10356 if (result instanceof IllegalStateException) {
10357 throw (IllegalStateException) result;
10358 }
10359 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010360 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10361 return specifiers;
10362 } finally {
10363 Binder.restoreCallingIdentity(identity);
10364 }
10365 }
10366
10367 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010368 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010369 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010370 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010371 }
10372
10373 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010374 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10375 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010376 if (callingPackage == null) {
10377 callingPackage = getCurrentPackageName();
10378 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010379 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10380 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010381 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10382 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010383 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10384 }
10385 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10386 Intent intent = new Intent();
10387 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10388 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10389 // Bring up choose default SMS subscription dialog right now
10390 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10391 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10392 mApp.startActivity(intent);
10393 }
chen xud5ca2d52019-05-28 15:20:57 -070010394
10395 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010396 public void showSwitchToManagedProfileDialog() {
10397 enforceModifyPermission();
10398
10399 Intent intent = new Intent();
10400 intent.setClass(mApp, ErrorDialogActivity.class);
10401 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10402 mApp.startActivity(intent);
10403 }
10404
10405 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010406 public String getMmsUAProfUrl(int subId) {
10407 //TODO investigate if this API should require proper permission check in R b/133791609
10408 final long identity = Binder.clearCallingIdentity();
10409 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010410 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10411 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10412 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10413 return carrierUAProfUrl;
10414 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010415 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10416 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010417 } finally {
10418 Binder.restoreCallingIdentity(identity);
10419 }
10420 }
10421
10422 @Override
10423 public String getMmsUserAgent(int subId) {
10424 //TODO investigate if this API should require proper permission check in R b/133791609
10425 final long identity = Binder.clearCallingIdentity();
10426 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010427 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10428 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10429 if (!TextUtils.isEmpty(carrierUserAgent)) {
10430 return carrierUserAgent;
10431 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010432 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10433 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010434 } finally {
10435 Binder.restoreCallingIdentity(identity);
10436 }
10437 }
Jack Yub07d4972019-05-28 16:12:25 -070010438
10439 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010440 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10441 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010442
Jack Yub07d4972019-05-28 16:12:25 -070010443 final long identity = Binder.clearCallingIdentity();
10444 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010445 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010446 if (phone == null) return false;
10447
Ling Maf188d502022-09-16 15:22:36 -070010448 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010449 } finally {
10450 Binder.restoreCallingIdentity(identity);
10451 }
10452 }
10453
10454 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010455 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010456 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010457 enforceModifyPermission();
10458
changbettyd5c246e2019-12-24 15:40:37 +080010459 final long identity = Binder.clearCallingIdentity();
10460 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010461 Phone phone = getPhone(subscriptionId);
10462 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010463
Ling Maf188d502022-09-16 15:22:36 -070010464 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010465 } finally {
10466 Binder.restoreCallingIdentity(identity);
10467 }
10468 }
10469
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010470 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010471 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010472 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10473 * otherwise.
10474 */
10475 @Override
10476 public void setCepEnabled(boolean isCepEnabled) {
10477 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10478
10479 final long identity = Binder.clearCallingIdentity();
10480 try {
10481 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10482 for (Phone phone : PhoneFactory.getPhones()) {
10483 Phone defaultPhone = phone.getImsPhone();
10484 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10485 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10486 ImsPhoneCallTracker imsPhoneCallTracker =
10487 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10488 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10489 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10490 + imsPhone.getMsisdn());
10491 }
10492 }
10493 } finally {
10494 Binder.restoreCallingIdentity(identity);
10495 }
10496 }
allenwtsu46dcc572020-01-08 18:24:03 +080010497
10498 /**
10499 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10500 *
10501 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10502 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10503 * before being read.
10504 */
10505 @Override
10506 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10507 isCompressed) {
10508 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10509 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010510 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10511 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10512 }
10513 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010514 // ProvisioningManager can not handle ServiceSpecificException.
10515 // Throw the IllegalStateException and annotate ProvisioningManager.
10516 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010517 }
10518
10519 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010520 try {
Hui Wang761a6682020-10-31 05:12:53 +000010521 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10522 } finally {
10523 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010524 }
10525 }
zoey chene02881a2019-12-30 16:11:23 +080010526
10527 @Override
10528 public boolean isIccLockEnabled(int subId) {
10529 enforceReadPrivilegedPermission("isIccLockEnabled");
10530
10531 // Now that all security checks passes, perform the operation as ourselves.
10532 final long identity = Binder.clearCallingIdentity();
10533 try {
10534 Phone phone = getPhone(subId);
10535 if (phone != null && phone.getIccCard() != null) {
10536 return phone.getIccCard().getIccLockEnabled();
10537 } else {
10538 return false;
10539 }
10540 } finally {
10541 Binder.restoreCallingIdentity(identity);
10542 }
10543 }
10544
10545 /**
10546 * Set the ICC pin lock enabled or disabled.
10547 *
10548 * @return an integer representing the status of IccLock enabled or disabled in the following
10549 * three cases:
10550 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10551 * successfully.
10552 * - Positive number and zero for remaining password attempts.
10553 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10554 *
10555 */
10556 @Override
10557 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10558 enforceModifyPermission();
10559
10560 Phone phone = getPhone(subId);
10561 if (phone == null) {
10562 return 0;
10563 }
10564 // Now that all security checks passes, perform the operation as ourselves.
10565 final long identity = Binder.clearCallingIdentity();
10566 try {
10567 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10568 new Pair<Boolean, String>(enabled, password), phone, null);
10569 return attemptsRemaining;
10570
10571 } catch (Exception e) {
10572 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10573 } finally {
10574 Binder.restoreCallingIdentity(identity);
10575 }
10576 return 0;
10577 }
10578
10579 /**
10580 * Change the ICC password used in ICC pin lock.
10581 *
10582 * @return an integer representing the status of IccLock changed in the following three cases:
10583 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10584 * - Positive number and zero for remaining password attempts.
10585 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10586 *
10587 */
10588 @Override
10589 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10590 enforceModifyPermission();
10591
10592 Phone phone = getPhone(subId);
10593 if (phone == null) {
10594 return 0;
10595 }
10596 // Now that all security checks passes, perform the operation as ourselves.
10597 final long identity = Binder.clearCallingIdentity();
10598 try {
10599 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10600 new Pair<String, String>(oldPassword, newPassword), phone, null);
10601 return attemptsRemaining;
10602
10603 } catch (Exception e) {
10604 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10605 } finally {
10606 Binder.restoreCallingIdentity(identity);
10607 }
10608 return 0;
10609 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010610
10611 /**
10612 * Request for receiving user activity notification
10613 */
10614 @Override
10615 public void requestUserActivityNotification() {
10616 if (!mNotifyUserActivity.get()
10617 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10618 mNotifyUserActivity.set(true);
10619 }
10620 }
10621
10622 /**
10623 * Called when userActivity is signalled in the power manager.
10624 * This is safe to call from any thread, with any window manager locks held or not.
10625 */
10626 @Override
10627 public void userActivity() {
10628 // ***************************************
10629 // * Inherited from PhoneWindowManager *
10630 // ***************************************
10631 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10632 // WITH ITS LOCKS HELD.
10633 //
10634 // This code must be VERY careful about the locks
10635 // it acquires.
10636 // In fact, the current code acquires way too many,
10637 // and probably has lurking deadlocks.
10638
10639 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10640 throw new SecurityException("Only the OS may call notifyUserActivity()");
10641 }
10642
10643 if (mNotifyUserActivity.getAndSet(false)) {
10644 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10645 USER_ACTIVITY_NOTIFICATION_DELAY);
10646 }
10647 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010648
10649 @Override
10650 public boolean canConnectTo5GInDsdsMode() {
10651 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10652 }
Jack Yud10cdd42020-09-28 20:28:01 -070010653
10654 @Override
10655 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10656 String callingFeatureId) {
10657 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10658 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10659 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10660 }
10661
10662 Phone phone = getPhone(subId);
10663 if (phone == null) {
10664 throw new RuntimeException("phone is not available");
10665 }
10666 // Now that all security checks passes, perform the operation as ourselves.
10667 final long identity = Binder.clearCallingIdentity();
10668 try {
10669 return phone.getEquivalentHomePlmns();
10670 } finally {
10671 Binder.restoreCallingIdentity(identity);
10672 }
10673 }
Daniel Bright59e67312020-11-13 11:49:37 -080010674
10675 @Override
10676 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010677 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10678 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010679 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010680 if (radioInterfaceCapabilities == null) {
10681 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010682 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010683 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010684 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010685
Hui Wang641e81c2020-10-12 12:14:23 -070010686 @Override
10687 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10688 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010689 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10690 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10691 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10692 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10693 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010694 if (DBG) {
10695 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10696 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10697 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10698 }
10699
10700 if (!SubscriptionManager.isValidSubscriptionId(subId)
10701 || appType < TelephonyManager.APPTYPE_UNKNOWN
10702 || appType > TelephonyManager.APPTYPE_ISIM
10703 || nafUrl == null || securityProtocol == null || callback == null) {
10704 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10705 if (callback != null) {
10706 try {
10707 callback.onAuthenticationFailure(
10708 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10709 } catch (RemoteException exception) {
10710 log("Fail to notify onAuthenticationFailure due to " + exception);
10711 }
10712 return;
10713 }
10714 }
10715
10716 final long token = Binder.clearCallingIdentity();
10717 try {
10718 getGbaManager(subId).bootstrapAuthenticationRequest(
10719 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10720 forceBootStrapping, callback));
10721 } finally {
10722 Binder.restoreCallingIdentity(token);
10723 }
10724 }
10725
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010726 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010727 * Attempts to set the radio power state for all phones for thermal reason.
10728 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010729 * requested radio power state will actually be set. See {@link
10730 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10731 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010732 * @param enable {@code true} if trying to turn radio on.
10733 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10734 * false}.
10735 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010736 private boolean setRadioPowerForThermal(boolean enable) {
10737 boolean isPhoneAvailable = false;
10738 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10739 Phone phone = PhoneFactory.getPhone(i);
10740 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010741 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010742 isPhoneAvailable = true;
10743 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010744 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010745
10746 // return true if successfully informed the phone object about the thermal radio power
10747 // request.
10748 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010749 }
10750
10751 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010752 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010753 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10754 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10755 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10756 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10757 throw new IllegalArgumentException("modem does not support data throttling");
10758 }
10759
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010760 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10761 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010762 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010763 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10764 }
10765
Sarah Chinecc78c42022-03-31 21:16:48 -070010766 setDataEnabledForReason(
10767 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010768
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010769 if (isDataThrottlingSupported) {
10770 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010771 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010772 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10773 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10774 } else if (thermalMitigationResult
10775 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010776 log("Modem likely does not support data throttling on secondary carrier. Data " +
10777 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10778 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010779 }
10780 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010781 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010782
10783 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010784 }
10785
Jack Nudelman644b91a2021-03-12 14:09:48 -080010786 private static List<String> getThermalMitigationAllowlist(Context context) {
10787 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10788 for (String pckg : context.getResources()
10789 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10790 sThermalMitigationAllowlistedPackages.add(pckg);
10791 }
10792 }
10793
10794 return sThermalMitigationAllowlistedPackages;
10795 }
10796
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010797 private boolean isAnyPhoneInEmergencyState() {
10798 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10799 if (tm.isInEmergencyCall()) {
10800 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10801 return true;
10802 }
10803 for (Phone phone : PhoneFactory.getPhones()) {
10804 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10805 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10806 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10807 + phone.isInEcm());
10808 return true;
10809 }
10810 }
10811
10812 return false;
10813 }
10814
Jack Nudelman644b91a2021-03-12 14:09:48 -080010815 /**
10816 * Used by shell commands to add an authorized package name for thermal mitigation.
10817 * @param packageName name of package to be allowlisted
10818 * @param context
10819 */
10820 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10821 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10822 sThermalMitigationAllowlistedPackages.add(packageName);
10823 }
10824
10825 /**
10826 * Used by shell commands to remove an authorized package name for thermal mitigation.
10827 * @param packageName name of package to remove from allowlist
10828 * @param context
10829 */
10830 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10831 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10832 sThermalMitigationAllowlistedPackages.remove(packageName);
10833 }
10834
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010835 /**
10836 * Thermal mitigation request to control functionalities at modem.
10837 *
10838 * @param subId the id of the subscription.
10839 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010840 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010841 *
10842 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10843 */
10844 @Override
10845 @ThermalMitigationResult
10846 public int sendThermalMitigationRequest(
10847 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010848 ThermalMitigationRequest thermalMitigationRequest,
10849 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010850 enforceModifyPermission();
10851
Jack Nudelman644b91a2021-03-12 14:09:48 -080010852 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10853 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10854 .contains(callingPackage)) {
10855 throw new SecurityException("Calling package must be configured in the device config. "
10856 + "calling package: " + callingPackage);
10857 }
10858
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010859 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10860 final long identity = Binder.clearCallingIdentity();
10861
10862 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10863 try {
10864 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10865 switch (thermalMitigationAction) {
10866 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10867 thermalMitigationResult =
10868 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010869 thermalMitigationRequest.getDataThrottlingRequest(),
10870 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010871 break;
10872 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10873 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10874 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10875 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10876 }
10877
10878 // Ensure that radio is on. If not able to power on due to phone being
10879 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010880 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010881 thermalMitigationResult =
10882 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10883 break;
10884 }
10885
10886 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010887 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010888 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10889 break;
10890 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10891 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10892 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10893 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10894 }
10895
10896 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10897 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010898 Phone phone = getPhone(subId);
10899 if (phone == null) {
10900 thermalMitigationResult =
10901 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10902 break;
10903 }
10904
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010905 TelephonyConnectionService service =
10906 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010907 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010908 Log.e(LOG_TAG, "An emergency call is pending");
10909 thermalMitigationResult =
10910 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10911 break;
10912 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010913 thermalMitigationResult =
10914 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10915 break;
10916 }
10917 } else {
10918 thermalMitigationResult =
10919 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10920 break;
10921 }
10922
10923 // Turn radio off. If not able to power off due to phone being unavailable,
10924 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010925 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010926 thermalMitigationResult =
10927 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10928 break;
10929 }
10930 thermalMitigationResult =
10931 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10932 break;
10933 default:
10934 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10935 + "not exist. Requested action: " + thermalMitigationAction);
10936 }
10937 } catch (IllegalArgumentException e) {
10938 throw e;
10939 } catch (Exception e) {
10940 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10941 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10942 } finally {
10943 Binder.restoreCallingIdentity(identity);
10944 }
10945
10946 if (DBG) {
10947 log("thermalMitigationRequest returning with thermalMitigationResult: "
10948 + thermalMitigationResult);
10949 }
10950
10951 return thermalMitigationResult;
10952 }
Hui Wang641e81c2020-10-12 12:14:23 -070010953
10954 /**
10955 * Set the GbaService Package Name that Telephony will bind to.
10956 *
10957 * @param subId The sim that the GbaService is associated with.
10958 * @param packageName The name of the package to be replaced with.
10959 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10960 */
10961 @Override
10962 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10963 enforceModifyPermission();
10964
10965 final long identity = Binder.clearCallingIdentity();
10966 try {
10967 return getGbaManager(subId).overrideServicePackage(packageName);
10968 } finally {
10969 Binder.restoreCallingIdentity(identity);
10970 }
10971 }
10972
10973 /**
10974 * Return the package name of the currently bound GbaService.
10975 *
10976 * @param subId The sim that the GbaService is associated with.
10977 * @return the package name of the GbaService configuration, null if GBA is not supported.
10978 */
10979 @Override
10980 public String getBoundGbaService(int subId) {
10981 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10982
10983 final long identity = Binder.clearCallingIdentity();
10984 try {
10985 return getGbaManager(subId).getServicePackage();
10986 } finally {
10987 Binder.restoreCallingIdentity(identity);
10988 }
10989 }
10990
10991 /**
10992 * Set the release time for telephony to unbind GbaService.
10993 *
10994 * @param subId The sim that the GbaService is associated with.
10995 * @param interval The release time to unbind GbaService by millisecond.
10996 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10997 */
10998 @Override
10999 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11000 enforceModifyPermission();
11001
11002 final long identity = Binder.clearCallingIdentity();
11003 try {
11004 return getGbaManager(subId).overrideReleaseTime(interval);
11005 } finally {
11006 Binder.restoreCallingIdentity(identity);
11007 }
11008 }
11009
11010 /**
11011 * Return the release time for telephony to unbind GbaService.
11012 *
11013 * @param subId The sim that the GbaService is associated with.
11014 * @return The release time to unbind GbaService by millisecond.
11015 */
11016 @Override
11017 public int getGbaReleaseTime(int subId) {
11018 enforceReadPrivilegedPermission("getGbaReleaseTime");
11019
11020 final long identity = Binder.clearCallingIdentity();
11021 try {
11022 return getGbaManager(subId).getReleaseTime();
11023 } finally {
11024 Binder.restoreCallingIdentity(identity);
11025 }
11026 }
11027
11028 private GbaManager getGbaManager(int subId) {
11029 GbaManager instance = GbaManager.getInstance(subId);
11030 if (instance == null) {
11031 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11032 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11033 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11034 }
11035 return instance;
11036 }
Hui Wang761a6682020-10-31 05:12:53 +000011037
11038 /**
11039 * indicate whether the device and the carrier can support
11040 * RCS VoLTE single registration.
11041 */
11042 @Override
11043 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011044 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11045 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11046 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11047 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011048
11049 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11050 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11051 }
11052
11053 final long identity = Binder.clearCallingIdentity();
11054 try {
11055 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11056 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011057 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11058 if (isCapable != null) {
11059 return isCapable;
11060 }
Hui Wang761a6682020-10-31 05:12:53 +000011061 }
Hui Wang67af90e2021-06-04 16:57:15 -070011062 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11063 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011064 } finally {
11065 Binder.restoreCallingIdentity(identity);
11066 }
11067 }
11068
11069 /**
11070 * Register RCS provisioning callback.
11071 */
11072 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011073 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011074 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011075 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011076 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011077 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11078 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011079
11080 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11081 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11082 }
11083 if (!isImsAvailableOnDevice()) {
11084 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11085 "IMS not available on device.");
11086 }
11087
11088 final long identity = Binder.clearCallingIdentity();
11089 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011090 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011091 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011092 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11093 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011094 }
Hui Wang761a6682020-10-31 05:12:53 +000011095 } finally {
11096 Binder.restoreCallingIdentity(identity);
11097 }
11098 }
11099
11100 /**
11101 * Unregister RCS provisioning callback.
11102 */
11103 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011104 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011105 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011106 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011107 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011108 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11109 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011110
11111 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11112 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11113 }
11114 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011115 // operation failed silently
11116 Rlog.w(LOG_TAG, "IMS not available on device.");
11117 return;
Hui Wang761a6682020-10-31 05:12:53 +000011118 }
11119
11120 final long identity = Binder.clearCallingIdentity();
11121 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011122 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011123 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011124 } finally {
11125 Binder.restoreCallingIdentity(identity);
11126 }
11127 }
11128
11129 /**
11130 * trigger RCS reconfiguration.
11131 */
11132 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011133 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11134 "triggerRcsReconfiguration",
11135 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011136
11137 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11138 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11139 }
11140 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011141 // ProvisioningManager can not handle ServiceSpecificException.
11142 // Throw the IllegalStateException and annotate ProvisioningManager.
11143 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000011144 }
11145
11146 final long identity = Binder.clearCallingIdentity();
11147 try {
11148 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11149 } finally {
11150 Binder.restoreCallingIdentity(identity);
11151 }
11152 }
11153
11154 /**
11155 * Provide the client configuration parameters of the RCS application.
11156 */
11157 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011158 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11159 "setRcsClientConfiguration",
11160 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011161
11162 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11163 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11164 }
11165 if (!isImsAvailableOnDevice()) {
11166 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11167 "IMS not available on device.");
11168 }
11169
11170 final long identity = Binder.clearCallingIdentity();
11171
11172 try {
11173 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11174 if (configBinder == null) {
11175 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011176 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11177 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011178 } else {
11179 configBinder.setRcsClientConfiguration(rcc);
11180 }
joonhunshin3e154242021-09-17 06:33:39 +000011181
11182 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11183 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011184 } catch (RemoteException e) {
11185 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011186 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11187 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011188 } finally {
11189 Binder.restoreCallingIdentity(identity);
11190 }
11191 }
11192
11193 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011194 * Enables or disables the test mode for RCS VoLTE single registration.
11195 */
11196 @Override
11197 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11198 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11199 "setRcsSingleRegistrationTestModeEnabled");
11200
11201 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11202 }
11203
11204 /**
11205 * Gets the test mode for RCS VoLTE single registration.
11206 */
11207 @Override
11208 public boolean getRcsSingleRegistrationTestModeEnabled() {
11209 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11210 "getRcsSingleRegistrationTestModeEnabled");
11211
11212 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11213 }
11214
11215 /**
Hui Wang761a6682020-10-31 05:12:53 +000011216 * Overrides the config of RCS VoLTE single registration enabled for the device.
11217 */
11218 @Override
11219 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11220 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11221 "setDeviceSingleRegistrationEnabledOverride");
11222 enforceModifyPermission();
11223
11224 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11225 : Boolean.parseBoolean(enabledStr);
11226 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011227 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011228 }
11229
11230 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011231 * Sends a device to device communication message. Only usable via shell.
11232 * @param message message to send.
11233 * @param value message value.
11234 */
11235 @Override
11236 public void sendDeviceToDeviceMessage(int message, int value) {
11237 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011238 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011239 enforceModifyPermission();
11240
11241 final long identity = Binder.clearCallingIdentity();
11242 try {
11243 TelephonyConnectionService service =
11244 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11245 if (service == null) {
11246 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11247 return;
11248 }
11249 service.sendTestDeviceToDeviceMessage(message, value);
11250 } finally {
11251 Binder.restoreCallingIdentity(identity);
11252 }
11253 }
11254
Tyler Gunnbabbda02021-02-10 11:05:02 -080011255 /**
11256 * Sets the specified device to device transport active.
11257 * @param transport The transport to set active.
11258 */
11259 @Override
11260 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11261 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11262 "setActiveDeviceToDeviceTransport");
11263 enforceModifyPermission();
11264
11265 final long identity = Binder.clearCallingIdentity();
11266 try {
11267 TelephonyConnectionService service =
11268 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11269 if (service == null) {
11270 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11271 return;
11272 }
11273 service.setActiveDeviceToDeviceTransport(transport);
11274 } finally {
11275 Binder.restoreCallingIdentity(identity);
11276 }
11277 }
Tyler Gunn92479152021-01-20 16:30:10 -080011278
Tyler Gunnd4339262021-05-03 14:46:49 -070011279 @Override
11280 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11281 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11282 "setDeviceToDeviceForceEnabled");
11283
11284 final long identity = Binder.clearCallingIdentity();
11285 try {
11286 Arrays.stream(PhoneFactory.getPhones()).forEach(
11287 p -> {
11288 Phone thePhone = p.getImsPhone();
11289 if (thePhone != null && thePhone instanceof ImsPhone) {
11290 ImsPhone imsPhone = (ImsPhone) thePhone;
11291 CallTracker tracker = imsPhone.getCallTracker();
11292 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11293 ImsPhoneCallTracker imsPhoneCallTracker =
11294 (ImsPhoneCallTracker) tracker;
11295 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11296 }
11297 }
11298 }
11299 );
11300 } finally {
11301 Binder.restoreCallingIdentity(identity);
11302 }
11303 }
11304
Tyler Gunn92479152021-01-20 16:30:10 -080011305 /**
Hui Wang761a6682020-10-31 05:12:53 +000011306 * Gets the config of RCS VoLTE single registration enabled for the device.
11307 */
11308 @Override
11309 public boolean getDeviceSingleRegistrationEnabled() {
11310 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11311 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11312 }
11313
11314 /**
11315 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11316 */
11317 @Override
11318 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11319 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11320 "setCarrierSingleRegistrationEnabledOverride");
11321 enforceModifyPermission();
11322
11323 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11324 : Boolean.parseBoolean(enabledStr);
11325 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11326 subId, enabled);
11327 }
11328
11329 /**
11330 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11331 */
11332 @Override
11333 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11334 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11335 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11336 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011337
11338 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011339 * Overrides the ims feature validation result
11340 */
11341 @Override
11342 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11343 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11344 "setImsFeatureValidationOverride");
11345
11346 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11347 : Boolean.parseBoolean(enabledStr);
11348 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11349 subId, enabled);
11350 }
11351
11352 /**
11353 * Gets the ims feature validation override value
11354 */
11355 @Override
11356 public boolean getImsFeatureValidationOverride(int subId) {
11357 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11358 "getImsFeatureValidationOverride");
11359 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11360 }
11361
11362 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011363 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11364 * their mobile plan.
11365 */
11366 @Override
11367 public String getMobileProvisioningUrl() {
11368 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11369 final long identity = Binder.clearCallingIdentity();
11370 try {
11371 return getDefaultPhone().getMobileProvisioningUrl();
11372 } finally {
11373 Binder.restoreCallingIdentity(identity);
11374 }
11375 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011376
James.cf Linbcdf8b32021-01-14 16:44:13 +080011377 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011378 * Get the EAB contact from the EAB database.
11379 */
11380 @Override
11381 public String getContactFromEab(String contact) {
11382 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11383 enforceModifyPermission();
11384 final long identity = Binder.clearCallingIdentity();
11385 try {
11386 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11387 } finally {
11388 Binder.restoreCallingIdentity(identity);
11389 }
11390 }
11391
11392 /**
Calvin Pana1434322021-07-01 19:27:01 +080011393 * Get the EAB capability from the EAB database.
11394 */
11395 @Override
11396 public String getCapabilityFromEab(String contact) {
11397 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11398 enforceModifyPermission();
11399 final long identity = Binder.clearCallingIdentity();
11400 try {
11401 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11402 } finally {
11403 Binder.restoreCallingIdentity(identity);
11404 }
11405 }
11406
11407 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011408 * Remove the EAB contacts from the EAB database.
11409 */
11410 @Override
11411 public int removeContactFromEab(int subId, String contacts) {
11412 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11413 enforceModifyPermission();
11414 final long identity = Binder.clearCallingIdentity();
11415 try {
11416 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11417 } finally {
11418 Binder.restoreCallingIdentity(identity);
11419 }
11420 }
11421
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011422 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011423 public boolean getDeviceUceEnabled() {
11424 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11425 final long identity = Binder.clearCallingIdentity();
11426 try {
11427 return mApp.getDeviceUceEnabled();
11428 } finally {
11429 Binder.restoreCallingIdentity(identity);
11430 }
11431 }
11432
11433 @Override
11434 public void setDeviceUceEnabled(boolean isEnabled) {
11435 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11436 final long identity = Binder.clearCallingIdentity();
11437 try {
11438 mApp.setDeviceUceEnabled(isEnabled);
11439 } finally {
11440 Binder.restoreCallingIdentity(identity);
11441 }
11442 }
11443
Brad Ebinger14d467f2021-02-12 06:18:28 +000011444 /**
11445 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11446 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11447 */
11448 // Used for SHELL command only right now.
11449 @Override
11450 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11451 List<String> featureTags) {
11452 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11453 "addUceRegistrationOverrideShell");
11454 final long identity = Binder.clearCallingIdentity();
11455 try {
11456 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11457 new ArraySet<>(featureTags));
11458 } catch (ImsException e) {
11459 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11460 } finally {
11461 Binder.restoreCallingIdentity(identity);
11462 }
11463 }
11464
11465 /**
11466 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11467 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11468 */
11469 // Used for SHELL command only right now.
11470 @Override
11471 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11472 List<String> featureTags) {
11473 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11474 "removeUceRegistrationOverrideShell");
11475 final long identity = Binder.clearCallingIdentity();
11476 try {
11477 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11478 new ArraySet<>(featureTags));
11479 } catch (ImsException e) {
11480 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11481 } finally {
11482 Binder.restoreCallingIdentity(identity);
11483 }
11484 }
11485
11486 /**
11487 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11488 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11489 */
11490 // Used for SHELL command only right now.
11491 @Override
11492 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11493 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11494 "clearUceRegistrationOverrideShell");
11495 final long identity = Binder.clearCallingIdentity();
11496 try {
11497 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11498 } catch (ImsException e) {
11499 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11500 } finally {
11501 Binder.restoreCallingIdentity(identity);
11502 }
11503 }
11504
11505 /**
11506 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11507 */
11508 // Used for SHELL command only right now.
11509 @Override
11510 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11511 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11512 "getLatestRcsContactUceCapabilityShell");
11513 final long identity = Binder.clearCallingIdentity();
11514 try {
11515 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11516 } catch (ImsException e) {
11517 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11518 } finally {
11519 Binder.restoreCallingIdentity(identity);
11520 }
11521 }
11522
11523 /**
11524 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11525 * device does not have an active PUBLISH.
11526 */
11527 // Used for SHELL command only right now.
11528 @Override
11529 public String getLastUcePidfXmlShell(int subId) {
11530 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11531 final long identity = Binder.clearCallingIdentity();
11532 try {
11533 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11534 } catch (ImsException e) {
11535 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11536 } finally {
11537 Binder.restoreCallingIdentity(identity);
11538 }
11539 }
11540
James.cf Line8713a42021-04-29 16:04:26 +080011541 /**
11542 * Remove UCE requests cannot be sent to the network status.
11543 */
11544 // Used for SHELL command only right now.
11545 @Override
11546 public boolean removeUceRequestDisallowedStatus(int subId) {
11547 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11548 final long identity = Binder.clearCallingIdentity();
11549 try {
11550 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11551 } catch (ImsException e) {
11552 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11553 } finally {
11554 Binder.restoreCallingIdentity(identity);
11555 }
11556 }
11557
James.cf Lin18bb9002021-05-25 01:37:38 +080011558 /**
11559 * Remove UCE requests cannot be sent to the network status.
11560 */
11561 // Used for SHELL command only.
11562 @Override
11563 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11564 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11565 final long identity = Binder.clearCallingIdentity();
11566 try {
11567 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11568 } catch (ImsException e) {
11569 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11570 } finally {
11571 Binder.restoreCallingIdentity(identity);
11572 }
11573 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011574
James.cf Lin4b784aa2021-01-31 03:25:15 +080011575 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011576 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11577 String callingPackage) {
11578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11579 mApp, subId, "setSignalStrengthUpdateRequest");
11580
11581 final int callingUid = Binder.getCallingUid();
11582 // Verify that tha callingPackage belongs to the calling UID
11583 mApp.getSystemService(AppOpsManager.class)
11584 .checkPackage(callingUid, callingPackage);
11585
Rambo Wang3607f502021-02-01 21:51:40 -080011586 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011587
11588 final long identity = Binder.clearCallingIdentity();
11589 try {
11590 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11591 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11592
11593 if (result instanceof IllegalStateException) {
11594 throw (IllegalStateException) result;
11595 }
11596 } finally {
11597 Binder.restoreCallingIdentity(identity);
11598 }
11599 }
11600
11601 @Override
11602 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11603 String callingPackage) {
11604 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11605 mApp, subId, "clearSignalStrengthUpdateRequest");
11606
11607 final int callingUid = Binder.getCallingUid();
11608 // Verify that tha callingPackage belongs to the calling UID
11609 mApp.getSystemService(AppOpsManager.class)
11610 .checkPackage(callingUid, callingPackage);
11611
11612 final long identity = Binder.clearCallingIdentity();
11613 try {
11614 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11615 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11616
11617 if (result instanceof IllegalStateException) {
11618 throw (IllegalStateException) result;
11619 }
11620 } finally {
11621 Binder.restoreCallingIdentity(identity);
11622 }
11623 }
11624
Rambo Wang3607f502021-02-01 21:51:40 -080011625 private static void validateSignalStrengthUpdateRequest(Context context,
11626 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011627 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11628 // phone/system process do not have further restriction on request
11629 return;
11630 }
11631
11632 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011633 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011634 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011635 context.enforceCallingOrSelfPermission(
11636 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11637 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011638 }
11639
11640 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011641 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011642 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011643 || info.isEnabled()) {
11644 throw new IllegalArgumentException(
11645 "Only system can set hide fields in SignalThresholdInfo");
11646 }
11647
11648 // Thresholds length for each RAN need in range. This has been validated in
11649 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11650 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11651 final int[] thresholds = info.getThresholds();
11652 Objects.requireNonNull(thresholds);
11653 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11654 || thresholds.length
11655 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11656 throw new IllegalArgumentException(
11657 "thresholds length is out of range: " + thresholds.length);
11658 }
11659 }
11660 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011661
11662 /**
11663 * Gets the current phone capability.
11664 *
11665 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11666 * @return the PhoneCapability which describes the data connection capability of modem.
11667 * It's used to evaluate possible phone config change, for example from single
11668 * SIM device to multi-SIM device.
11669 */
11670 @Override
11671 public PhoneCapability getPhoneCapability() {
11672 enforceReadPrivilegedPermission("getPhoneCapability");
11673 final long identity = Binder.clearCallingIdentity();
11674 try {
11675 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11676 } finally {
11677 Binder.restoreCallingIdentity(identity);
11678 }
11679 }
Michele Berionne5e411512020-11-13 02:36:59 +000011680
11681 /**
11682 * Prepare TelephonyManager for an unattended reboot. The reboot is
11683 * required to be done shortly after the API is invoked.
11684 */
11685 @Override
11686 @TelephonyManager.PrepareUnattendedRebootResult
11687 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011688 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011689 enforceRebootPermission();
11690
11691 final long identity = Binder.clearCallingIdentity();
11692 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011693 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011694 } finally {
11695 Binder.restoreCallingIdentity(identity);
11696 }
11697 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011698
11699 /**
11700 * Request to get the current slicing configuration including URSP rules and
11701 * NSSAIs (configured, allowed and rejected).
11702 *
11703 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11704 */
11705 @Override
11706 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011707 TelephonyPermissions
11708 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11709 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011710
11711 final long identity = Binder.clearCallingIdentity();
11712 try {
11713 Phone phone = getDefaultPhone();
11714 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11715 } finally {
11716 Binder.restoreCallingIdentity(identity);
11717 }
11718 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011719
11720 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011721 * Check whether the given premium capability is available for purchase from the carrier.
11722 *
11723 * @param capability The premium capability to check.
11724 * @param subId The subId to check the premium capability for.
11725 *
11726 * @return Whether the given premium capability is available to purchase.
11727 */
11728 @Override
11729 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11730 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11731 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11732 log("Premium capability "
11733 + TelephonyManager.convertPremiumCapabilityToString(capability)
11734 + " is not available for purchase due to missing permissions.");
11735 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11736 + "permission READ_BASIC_PHONE_STATE.");
11737 }
11738
11739 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011740 if (phone == null) {
11741 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11742 return false;
11743 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011744 final long identity = Binder.clearCallingIdentity();
11745 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011746 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011747 .isPremiumCapabilityAvailableForPurchase(capability);
11748 } finally {
11749 Binder.restoreCallingIdentity(identity);
11750 }
11751 }
11752
11753 /**
11754 * Purchase the given premium capability from the carrier.
11755 *
11756 * @param capability The premium capability to purchase.
11757 * @param callback The result of the purchase request.
11758 * @param subId The subId to purchase the premium capability for.
11759 */
11760 @Override
11761 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11762 log("purchasePremiumCapability: capability="
11763 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11764 + getCurrentPackageName());
11765
11766 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11767 mApp, "purchasePremiumCapability")) {
11768 log("purchasePremiumCapability "
11769 + TelephonyManager.convertPremiumCapabilityToString(capability)
11770 + " failed due to missing permissions.");
11771 throw new SecurityException("purchasePremiumCapability requires permission "
11772 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011773 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11774 mApp, "purchasePremiumCapability")) {
11775 log("purchasePremiumCapability "
11776 + TelephonyManager.convertPremiumCapabilityToString(capability)
11777 + " failed due to missing permissions.");
11778 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011779 }
11780
11781 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011782 if (phone == null) {
11783 try {
11784 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11785 callback.accept(result);
11786 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11787 } catch (RemoteException e) {
11788 String logStr = "Purchase premium capability "
11789 + TelephonyManager.convertPremiumCapabilityToString(capability)
11790 + " failed due to RemoteException handling null phone: " + e;
11791 if (DBG) log(logStr);
11792 AnomalyReporter.reportAnomaly(
11793 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11794 }
11795 return;
11796 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011797
11798 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011799 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011800 callingProcess = mApp.getPackageManager().getApplicationInfo(
11801 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011802 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011803 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011804 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011805
11806 boolean isVisible = false;
11807 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11808 if (am != null) {
11809 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11810 if (processes != null) {
11811 for (ActivityManager.RunningAppProcessInfo process : processes) {
11812 log("purchasePremiumCapability: process " + process.processName
11813 + "has importance " + process.importance);
11814 if (process.processName.equals(callingProcess) && process.importance
11815 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11816 isVisible = true;
11817 break;
11818 }
11819 }
11820 }
11821 }
11822
11823 if (!isVisible) {
11824 try {
11825 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11826 callback.accept(result);
11827 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11828 } catch (RemoteException e) {
11829 String logStr = "Purchase premium capability "
11830 + TelephonyManager.convertPremiumCapabilityToString(capability)
11831 + " failed due to RemoteException handling background application: " + e;
11832 if (DBG) log(logStr);
11833 AnomalyReporter.reportAnomaly(
11834 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11835 }
11836 return;
11837 }
11838
Sarah Chin71b3a852022-09-28 15:54:19 -070011839 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011840 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011841 }
11842
11843 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011844 * Register an IMS connection state callback
11845 */
11846 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011847 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11848 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011849 if (feature == ImsFeature.FEATURE_MMTEL) {
11850 // ImsMmTelManager
11851 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11852 TelephonyPermissions
11853 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11854 mApp, subId, "registerImsStateCallback");
11855 } else if (feature == ImsFeature.FEATURE_RCS) {
11856 // ImsRcsManager or SipDelegateManager
11857 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11858 Binder.getCallingUid(), "registerImsStateCallback",
11859 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11860 Manifest.permission.READ_PRECISE_PHONE_STATE,
11861 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11862 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11863 }
11864
11865 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11866 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11867 "IMS not available on device.");
11868 }
11869
11870 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11871 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11872 }
11873
11874 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11875 if (controller == null) {
11876 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11877 "IMS not available on device.");
11878 }
11879
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011880 if (callingPackage == null) {
11881 callingPackage = getCurrentPackageName();
11882 }
11883
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011884 final long token = Binder.clearCallingIdentity();
11885 try {
11886 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011887 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011888 } catch (ImsException e) {
11889 throw new ServiceSpecificException(e.getCode());
11890 } finally {
11891 Binder.restoreCallingIdentity(token);
11892 }
11893 }
11894
11895 /**
11896 * Unregister an IMS connection state callback
11897 */
11898 @Override
11899 public void unregisterImsStateCallback(IImsStateCallback cb) {
11900 final long token = Binder.clearCallingIdentity();
11901 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11902 if (controller == null) {
11903 return;
11904 }
11905 try {
11906 controller.unregisterImsStateCallback(cb);
11907 } finally {
11908 Binder.restoreCallingIdentity(token);
11909 }
11910 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011911
11912 /**
11913 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11914 *
11915 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11916 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11917 * SecurityException.
11918 * If there is current registered network this value will be same as the registered cell
11919 * identity. If the device goes out of service the previous cell identity is cached and
11920 * will be returned. If the cache age of the Cell identity is more than 24 hours
11921 * it will be cleared and null will be returned.
11922 *
11923 */
11924 @Override
11925 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11926 String callingFeatureId) {
11927 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11928 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11929 LocationAccessPolicy.checkLocationPermission(mApp,
11930 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11931 .setCallingPackage(callingPackage)
11932 .setCallingFeatureId(callingFeatureId)
11933 .setCallingPid(Binder.getCallingPid())
11934 .setCallingUid(Binder.getCallingUid())
11935 .setMethod("getLastKnownCellIdentity")
11936 .setLogAsInfo(true)
11937 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11938 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11939 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11940 .build());
11941
11942 boolean hasFinePermission =
11943 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11944 if (!hasFinePermission
11945 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11946 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011947 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011948 }
11949
11950 final long identity = Binder.clearCallingIdentity();
11951 try {
11952 Phone phone = getPhone(subId);
11953 if (phone == null) return null;
11954 ServiceStateTracker sst = phone.getServiceStateTracker();
11955 if (sst == null) return null;
11956 return sst.getLastKnownCellIdentity();
11957 } finally {
11958 Binder.restoreCallingIdentity(identity);
11959 }
11960 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011961
jimsun3b9ccac2021-10-26 15:01:23 +080011962 /**
11963 * Sets the modem service class Name that Telephony will bind to.
11964 *
11965 * @param serviceName The class name of the modem service.
11966 * @return true if the operation is succeed, otherwise false.
11967 */
11968 public boolean setModemService(String serviceName) {
11969 Log.d(LOG_TAG, "setModemService - " + serviceName);
11970 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11972 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11973 "setModemService");
11974 return mPhoneConfigurationManager.setModemService(serviceName);
11975 }
11976
11977 /**
11978 * Return the class name of the currently bounded modem service.
11979 *
11980 * @return the class name of the modem service.
11981 */
11982 public String getModemService() {
11983 String result;
11984 Log.d(LOG_TAG, "getModemService");
11985 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11986 TelephonyPermissions
11987 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11988 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11989 "getModemService");
11990 result = mPhoneConfigurationManager.getModemService();
11991 Log.d(LOG_TAG, "result = " + result);
11992 return result;
11993 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011994
11995 @Override
11996 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11997 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11998 mApp.enforceCallingOrSelfPermission(
11999 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12000 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12001
12002 final long identity = Binder.clearCallingIdentity();
12003 try {
12004 Phone phone = getPhone(subId);
12005 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012006 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12007 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012008 phone.setVoiceServiceStateOverride(hasService);
12009 } finally {
12010 Binder.restoreCallingIdentity(identity);
12011 }
12012 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012013
12014 /**
12015 * set removable eSIM as default eUICC.
12016 *
12017 * @hide
12018 */
12019 @Override
12020 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12021 enforceModifyPermission();
12022 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12023
12024 final long identity = Binder.clearCallingIdentity();
12025 try {
12026 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12027 } finally {
12028 Binder.restoreCallingIdentity(identity);
12029 }
12030 }
12031
12032 /**
12033 * Returns whether the removable eSIM is default eUICC or not.
12034 *
12035 * @hide
12036 */
12037 @Override
12038 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12039 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12040 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12041
12042 final long identity = Binder.clearCallingIdentity();
12043 try {
12044 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12045 } finally {
12046 Binder.restoreCallingIdentity(identity);
12047 }
12048 }
12049
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012050 /**
12051 * Get the component name of the default app to direct respond-via-message intent for the
12052 * user associated with this subscription, update the cache if there is no respond-via-message
12053 * application currently configured for this user.
12054 * @return component name of the app and class to direct Respond Via Message intent to, or
12055 * {@code null} if the functionality is not supported.
12056 * @hide
12057 */
12058 @Override
12059 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12060 boolean updateIfNeeded) {
12061 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012062
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012063 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12064
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012065 UserHandle userHandle = null;
12066 final long identity = Binder.clearCallingIdentity();
12067 try {
12068 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12069 } finally {
12070 Binder.restoreCallingIdentity(identity);
12071 }
12072 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12073 updateIfNeeded, userHandle);
12074 }
Jack Yuf5badd92022-12-08 00:50:53 -080012075
12076 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012077 * Set whether the device is able to connect with null ciphering or integrity
12078 * algorithms. This is a global setting and will apply to all active subscriptions
12079 * and all new subscriptions after this.
12080 *
12081 * @param enabled when true, null cipher and integrity algorithms are allowed.
12082 * @hide
12083 */
12084 @Override
12085 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12086 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12087 enforceModifyPermission();
12088 checkForNullCipherAndIntegritySupport();
12089
12090 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12091 // for listening to these preference changes and applying them immediately.
12092 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12093 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12094 editor.apply();
12095
12096 for (Phone phone: PhoneFactory.getPhones()) {
12097 phone.handleNullCipherEnabledChange();
12098 }
12099 }
12100
12101
12102 /**
12103 * Get whether the device is able to connect with null ciphering or integrity
12104 * algorithms. Note that this retrieves the phone-global preference and not
12105 * the state of the radio.
12106 *
12107 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12108 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12109 * version for this feature.
12110 * @hide
12111 */
12112 @Override
12113 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12114 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12115 enforceReadPermission();
12116 checkForNullCipherAndIntegritySupport();
12117 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12118 }
12119
12120 private void checkForNullCipherAndIntegritySupport() {
12121 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12122 throw new UnsupportedOperationException(
12123 "Null cipher and integrity operations require HAL 2.1 or above");
12124 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012125 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12126 throw new UnsupportedOperationException(
12127 "Null cipher and integrity operations unsupported by modem");
12128 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012129 }
12130
12131 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012132 * Get the SIM state for the slot index.
12133 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12134 *
12135 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12136 */
12137 @Override
12138 @SimState
12139 public int getSimStateForSlotIndex(int slotIndex) {
12140 IccCardConstants.State simState;
12141 if (slotIndex < 0) {
12142 simState = IccCardConstants.State.UNKNOWN;
12143 } else {
12144 Phone phone = null;
12145 try {
12146 phone = PhoneFactory.getPhone(slotIndex);
12147 } catch (IllegalStateException e) {
12148 // ignore
12149 }
12150 if (phone == null) {
12151 simState = IccCardConstants.State.UNKNOWN;
12152 } else {
12153 IccCard icc = phone.getIccCard();
12154 if (icc == null) {
12155 simState = IccCardConstants.State.UNKNOWN;
12156 } else {
12157 simState = icc.getState();
12158 }
12159 }
12160 }
12161 return simState.ordinal();
12162 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012163
12164 /**
12165 * Get current cell broadcast ranges.
12166 */
12167 @Override
12168 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12169 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12170 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12171 "getCellBroadcastIdRanges");
12172 final long identity = Binder.clearCallingIdentity();
12173 try {
12174 return getPhone(subId).getCellBroadcastIdRanges();
12175 } finally {
12176 Binder.restoreCallingIdentity(identity);
12177 }
12178 }
12179
12180 /**
12181 * Set reception of cell broadcast messages with the list of the given ranges
12182 *
12183 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12184 */
12185 @Override
12186 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12187 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12188 @Nullable IIntegerConsumer callback) {
12189 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12190 "setCellBroadcastIdRanges");
12191 final long identity = Binder.clearCallingIdentity();
12192 try {
12193 Phone phone = getPhoneFromSubId(subId);
12194 if (DBG) {
12195 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12196 }
12197 phone.setCellBroadcastIdRanges(ranges, result -> {
12198 if (callback != null) {
12199 try {
12200 callback.accept(result);
12201 } catch (RemoteException e) {
12202 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12203 }
12204 }
12205 });
12206 } finally {
12207 Binder.restoreCallingIdentity(identity);
12208 }
12209 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012210
12211 /**
12212 * Returns whether the device supports the domain selection service.
12213 *
12214 * @return {@code true} if the device supports the domain selection service.
12215 */
12216 @Override
12217 public boolean isDomainSelectionSupported() {
12218 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12219 "isDomainSelectionSupported");
12220
12221 final long identity = Binder.clearCallingIdentity();
12222 try {
12223 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12224 } finally {
12225 Binder.restoreCallingIdentity(identity);
12226 }
12227 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012228
12229 /**
Sarah Chineccfbd12023-01-20 19:00:35 -080012230 * Start receiving satellite position updates.
12231 * This can be called by the pointing UI when the user starts pointing to the satellite.
12232 * Modem should continue to report the pointing input as the device or satellite moves.
12233 *
12234 * @param subId The subId to start satellite position updates for.
12235 * @param callbackId The callback ID associating the public SatellitePositionUpdateCallback to
12236 * the internal ISatellitePositionUpdateCallback below.
12237 * @param callback The callback to notify of changes in satellite position.
12238 * @return The result of the operation.
12239 */
12240 @Override
12241 @SatelliteManager.SatelliteServiceResult public int startSatellitePositionUpdates(int subId,
12242 int callbackId, @NonNull ISatellitePositionUpdateCallback callback) {
Sarah Chinf75afa72023-02-01 01:32:19 -080012243 enforceSatelliteCommunicationPermission("startSatellitePositionUpdates");
12244
12245 if (!isSatelliteEnabled(subId)) {
12246 return SatelliteManager.SATELLITE_SERVICE_DISABLED;
12247 }
12248
Sarah Chineccfbd12023-01-20 19:00:35 -080012249 Phone phone = getPhone(subId);
12250 if (phone == null) {
12251 loge("startSatellitePositionUpdates called with invalid subId: " + subId
12252 + ". Retrying with default phone.");
12253 phone = getDefaultPhone();
12254 if (phone == null) {
12255 loge("startSatellitePositionUpdates failed with no phone object.");
Sarah Chinf75afa72023-02-01 01:32:19 -080012256 return SatelliteManager.SATELLITE_SERVICE_TELEPHONY_INTERNAL_ERROR;
Sarah Chineccfbd12023-01-20 19:00:35 -080012257 }
12258 }
12259
12260 if (mSatellitePositionUpdateHandlers.containsKey(callbackId)) {
12261 log("startSatellitePositionUpdates: callback already registered: " + callbackId);
12262 return SatelliteManager.SATELLITE_SERVICE_SUCCESS;
12263 }
12264
12265 SatellitePositionUpdateHandler handler =
12266 new SatellitePositionUpdateHandler(callback, Looper.getMainLooper());
12267 phone.registerForSatellitePointingInfoChanged(handler,
12268 SatellitePositionUpdateHandler.EVENT_POSITION_UPDATE, null);
12269 phone.registerForSatelliteMessagesTransferComplete(handler,
12270 SatellitePositionUpdateHandler.EVENT_MESSAGE_TRANSFER_STATE_UPDATE, null);
12271 mSatellitePositionUpdateHandlers.put(callbackId, handler);
12272
12273 int result = (int) sendRequest(CMD_START_SATELLITE_POSITION_UPDATES, null, subId);
12274 if (DBG) log("startSatellitePositionUpdates result: " + result);
12275 return result;
12276 }
12277
12278 /**
12279 * Stop receiving satellite position updates.
12280 * This can be called by the pointing UI when the user stops pointing to the satellite.
12281 *
12282 * @param subId The subId to stop satellite position updates for.
12283 * @param callbackId The ID of the callback that was passed in {@link
12284 * #startSatellitePositionUpdates(int, int, ISatellitePositionUpdateCallback)}
12285 * @return The result of the operation.
12286 */
12287 @Override
12288 @SatelliteManager.SatelliteServiceResult public int stopSatellitePositionUpdates(int subId,
12289 int callbackId) {
Sarah Chinf75afa72023-02-01 01:32:19 -080012290 enforceSatelliteCommunicationPermission("stopSatellitePositionUpdates");
12291
12292 if (!isSatelliteEnabled(subId)) {
12293 return SatelliteManager.SATELLITE_SERVICE_DISABLED;
12294 }
12295
Sarah Chineccfbd12023-01-20 19:00:35 -080012296 Phone phone = getPhone(subId);
12297 if (phone == null) {
12298 loge("stopSatellitePositionUpdates called with invalid subId: " + subId
12299 + ". Retrying with default phone.");
12300 phone = getDefaultPhone();
12301 if (phone == null) {
12302 loge("stopSatellitePositionUpdates failed with no phone object.");
Sarah Chinf75afa72023-02-01 01:32:19 -080012303 return SatelliteManager.SATELLITE_SERVICE_TELEPHONY_INTERNAL_ERROR;
Sarah Chineccfbd12023-01-20 19:00:35 -080012304 }
12305 }
12306
12307 SatellitePositionUpdateHandler handler =
12308 mSatellitePositionUpdateHandlers.remove(callbackId);
12309 if (handler == null) {
12310 loge("stopSatellitePositionUpdates: No SatellitePositionArgument");
Sarah Chinf75afa72023-02-01 01:32:19 -080012311 return SatelliteManager.SATELLITE_SERVICE_TELEPHONY_INTERNAL_ERROR;
Sarah Chineccfbd12023-01-20 19:00:35 -080012312 } else {
12313 phone.unregisterForSatellitePointingInfoChanged(handler);
12314 phone.unregisterForSatelliteMessagesTransferComplete(handler);
12315 }
12316
12317 if (!mSatellitePositionUpdateHandlers.isEmpty()) {
12318 log("stopSatellitePositionUpdates: other listeners still exist.");
12319 return SatelliteManager.SATELLITE_SERVICE_SUCCESS;
12320 }
12321
12322 int result = (int) sendRequest(CMD_STOP_SATELLITE_POSITION_UPDATES, null, subId);
12323 if (DBG) log("stopSatellitePositionUpdates result: " + result);
12324 return result;
12325 }
12326
12327 /**
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012328 * Get maximum number of characters per text message on satellite.
12329 * @param subId - The subId of the subscription.
12330 * @param callback - The callback that will be used to send maximum characters limit
12331 * if operation is successful.
12332 * @return The result of the operation.
12333 *
12334 * @throws SecurityException if the caller doesn't have the required permission.
12335 */
12336 @Override
12337 public int getMaxCharactersPerSatelliteTextMessage(int subId, IIntegerConsumer callback) {
12338 enforceSatelliteCommunicationPermission("getMaxCharactersPerSatelliteTextMessage");
12339
12340 if (!isSatelliteEnabled(subId)) {
12341 return SatelliteManager.SATELLITE_SERVICE_DISABLED;
12342 }
12343
12344 Phone phone = getPhone(subId);
12345 if (phone == null) {
12346 loge("getMaxCharactersPerSatelliteTextMessage called with invalid subId: " + subId
12347 + ".Retrying with default phone.");
12348 phone = getDefaultPhone();
12349 if (phone == null) {
12350 loge("getMaxCharactersPerSatelliteTextMessage failed with no phone object.");
12351 return SatelliteManager.SATELLITE_SERVICE_TELEPHONY_INTERNAL_ERROR;
12352 }
12353 }
12354
12355 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
12356 int result = (int) sendRequest(CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG, argument, subId);
12357 if (DBG) log("getMaxCharPerTextMessageOnSatellite result: " + result);
12358 return result;
12359 }
12360
12361 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000012362 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12363 *
12364 * <p>This method behaves in one of the following ways:
12365 * <ul>
12366 * <li>return true : if the calling package has the appop permission {@link
12367 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12368 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12369 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12370 * Owner device identifier access check, or the calling package has carrier privileges</>
12371 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12372 * </ul>
12373 */
12374 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12375 String callingPackage, @Nullable String callingFeatureId, String message) {
12376 for (Phone phone : PhoneFactory.getPhones()) {
12377 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12378 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12379 return true;
12380 }
12381 }
12382 return false;
12383 }
arunvoddud7401012022-12-15 16:08:12 +000012384
12385 /**
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012386 * Check if satellite is enabled for a subscription.
12387 */
12388 private boolean isSatelliteEnabled(int subId) {
12389 if (mSubscriptionController != null) {
12390 String strResult = mSubscriptionController.getSubscriptionProperty(
12391 subId, SubscriptionManager.SATELLITE_ENABLED);
12392 if (strResult != null) {
12393 int intResult = Integer.parseInt(strResult);
12394 return (intResult == 1) ? true : false;
12395 }
12396 }
12397 return false;
12398 }
12399
12400 /**
arunvoddud7401012022-12-15 16:08:12 +000012401 * Class binds the consumer[callback] and carrierId.
12402 */
12403 private static class CallerCallbackInfo {
12404 private final Consumer<Integer> mConsumer;
12405 private final int mCarrierId;
12406
12407 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12408 mConsumer = consumer;
12409 mCarrierId = carrierId;
12410 }
12411
12412 public Consumer<Integer> getConsumer() {
12413 return mConsumer;
12414 }
12415
12416 public int getCarrierId() {
12417 return mCarrierId;
12418 }
12419 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012420}