blob: d54fff0a94dfb5a186424cf5b75439f3b4895412 [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;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080054import android.os.CancellationSignal;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070056import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080057import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080058import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import android.os.Looper;
60import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070061import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080062import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070063import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070064import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080065import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080066import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070067import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070068import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080069import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070071import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070072import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070073import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070074import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080075import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070076import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000077import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090078import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080079import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080080import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070081import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080082import android.telephony.AccessNetworkConstants;
83import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070084import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070085import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080086import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070087import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080088import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070089import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080090import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060091import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -070092import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080093import android.telephony.CellIdentityCdma;
94import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070096import android.telephony.CellInfoGsm;
97import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070098import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080099import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700100import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700101import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700102import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800103import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700104import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800105import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700106import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800107import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800108import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700109import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800110import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800112import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800113import android.telephony.SignalStrengthUpdateRequest;
114import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800115import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800117import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700118import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700119import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800120import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800121import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800122import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800123import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000124import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000125import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000126import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700127import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700128import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800129import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800130import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700131import android.telephony.gba.GbaAuthRequest;
132import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700133import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800134import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000135import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000136import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700137import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000138import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700139import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800140import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700141import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800142import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700143import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000144import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700145import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800146import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800147import android.telephony.ims.stub.ImsRegistrationImplBase;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800148import android.telephony.satellite.ISatelliteStateListener;
Sarah Chineccfbd12023-01-20 19:00:35 -0800149import android.telephony.satellite.PointingInfo;
Sarah Chin503828c2023-02-01 23:54:20 -0800150import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000151import android.telephony.satellite.SatelliteDatagram;
Sarah Chineccfbd12023-01-20 19:00:35 -0800152import android.telephony.satellite.SatelliteManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700153import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800154import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700155import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800157import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800158
Andrew Lee312e8172014-10-23 17:01:36 -0700159import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800160import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800161import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800162import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800163import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700165import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700166import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800167import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800168import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700169import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700170import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800171import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700172import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800173import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800174import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800175import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700176import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000177import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700178import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800179import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700180import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800181import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800182import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800183import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700184import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700185import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700186import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700188import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800189import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700190import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700191import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700192import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700193import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800194import com.android.internal.telephony.RILConstants;
Sarah Chineccfbd12023-01-20 19:00:35 -0800195import com.android.internal.telephony.RILUtils;
Daniel Bright94f43662021-03-01 14:43:40 -0800196import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700197import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000198import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700199import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700200import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800201import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800202import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800203import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700204import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000205import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800206import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700207import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800208import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700209import com.android.internal.telephony.imsphone.ImsPhone;
210import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000211import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800212import com.android.internal.telephony.metrics.TelephonyMetrics;
Jack Yu285100e2022-12-02 22:48:35 -0800213import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
214import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700215import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700216import com.android.internal.telephony.uicc.IccIoResult;
217import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800218import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700219import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800220import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700221import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000222import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800223import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000224import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800225import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000226import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700227import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700228import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800229import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800230import com.android.phone.callcomposer.CallComposerPictureManager;
231import com.android.phone.callcomposer.CallComposerPictureTransfer;
232import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700233import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700234import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000235import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700236import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800237import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700238import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700239import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800240import com.android.services.telephony.TelecomAccountRegistry;
241import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800242import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800243
Hall Liu82694d52020-12-11 18:22:04 -0800244import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700245import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800246import java.io.IOException;
247import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700248import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800250import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000251import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800252import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800253import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800254import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800255import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100256import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800257import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700258import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800259import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800260import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700261import java.util.UUID;
Sarah Chineccfbd12023-01-20 19:00:35 -0800262import java.util.concurrent.ConcurrentHashMap;
Hall Liu82694d52020-12-11 18:22:04 -0800263import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800264import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800265import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700266
267/**
268 * Implementation of the ITelephony interface.
269 */
Santos Cordon117fee72014-05-16 17:56:12 -0700270public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271 private static final String LOG_TAG = "PhoneInterfaceManager";
272 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
273 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800274 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275
276 // Message codes used with mMainThreadHandler
277 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700278 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
279 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700280 private static final int CMD_OPEN_CHANNEL = 9;
281 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
282 private static final int CMD_CLOSE_CHANNEL = 11;
283 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800284 private static final int CMD_NV_READ_ITEM = 13;
285 private static final int EVENT_NV_READ_ITEM_DONE = 14;
286 private static final int CMD_NV_WRITE_ITEM = 15;
287 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
288 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
289 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700290 private static final int CMD_RESET_MODEM_CONFIG = 19;
291 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800292 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
293 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800294 private static final int CMD_SEND_ENVELOPE = 25;
295 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000296 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
297 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700298 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
299 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
300 private static final int CMD_EXCHANGE_SIM_IO = 31;
301 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800302 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
303 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700304 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
305 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700306 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
307 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700308 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
309 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
310 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
311 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700312 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
313 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
314 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
315 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700316 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800317 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
318 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000319 private static final int CMD_SWITCH_SLOTS = 50;
320 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700321 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
322 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
323 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
324 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
325 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
326 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
327 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
328 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700329 private static final int CMD_GET_ALL_CELL_INFO = 60;
330 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
331 private static final int CMD_GET_CELL_LOCATION = 62;
332 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700333 private static final int CMD_MODEM_REBOOT = 64;
334 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700335 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
336 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800337 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
338 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700339 private static final int CMD_GET_MODEM_STATUS = 70;
340 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700341 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
342 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700343 private static final int CMD_ERASE_MODEM_CONFIG = 74;
344 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800345 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
346 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
347 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
348 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800349 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
350 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800351 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800352 private static final int CMD_GET_CALL_FORWARDING = 83;
353 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
354 private static final int CMD_SET_CALL_FORWARDING = 85;
355 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
356 private static final int CMD_GET_CALL_WAITING = 87;
357 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
358 private static final int CMD_SET_CALL_WAITING = 89;
359 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700360 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
361 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
362 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
363 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700364 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
365 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800366 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
367 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800368 private static final int CMD_SET_DATA_THROTTLING = 99;
369 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800370 private static final int CMD_SET_SIM_POWER = 101;
371 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800372 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
373 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
374 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
375 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800376 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
377 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000378 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800379 private static final int CMD_GET_SLICING_CONFIG = 110;
380 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800381 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700382 private static final int CMD_ENABLE_VONR = 113;
383 private static final int EVENT_ENABLE_VONR_DONE = 114;
384 private static final int CMD_IS_VONR_ENABLED = 115;
385 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700386 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
387 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Sarah Chineccfbd12023-01-20 19:00:35 -0800388 private static final int CMD_START_SATELLITE_POSITION_UPDATES = 119;
389 private static final int EVENT_START_SATELLITE_POSITION_UPDATES_DONE = 120;
390 private static final int CMD_STOP_SATELLITE_POSITION_UPDATES = 121;
391 private static final int EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE = 122;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +0000392 private static final int CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG = 123;
393 private static final int EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE = 124;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800394 private static final int CMD_PROVISION_SATELLITE_SERVICE = 125;
395 private static final int EVENT_PROVISION_SATELLITE_SERVICE_DONE = 126;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -0800396 private static final int CMD_DEPROVISION_SATELLITE_SERVICE = 127;
397 private static final int EVENT_DEPROVISION_SATELLITE_SERVICE_DONE = 128;
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800398 private static final int CMD_SET_SATELLITE_ENABLED = 129;
399 private static final int EVENT_SET_SATELLITE_ENABLED_DONE = 130;
400 private static final int CMD_IS_SATELLITE_ENABLED = 131;
401 private static final int EVENT_IS_SATELLITE_ENABLED_DONE = 132;
402 private static final int CMD_IS_SATELLITE_SUPPORTED = 133;
403 private static final int EVENT_IS_SATELLITE_SUPPORTED_DONE = 134;
404 private static final int CMD_GET_SATELLITE_CAPABILITIES = 135;
405 private static final int EVENT_GET_SATELLITE_CAPABILITIES_DONE = 136;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000406 private static final int CMD_POLL_PENDING_SATELLITE_DATAGRAMS = 137;
407 private static final int EVENT_POLL_PENDING_SATELLITE_DATAGRAMS_DONE = 138;
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +0000408 private static final int CMD_SEND_SATELLITE_DATAGRAM = 139;
409 private static final int EVENT_SEND_SATELLITE_DATAGRAM_DONE = 140;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000410
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800411 // Parameters of select command.
412 private static final int SELECT_COMMAND = 0xA4;
413 private static final int SELECT_P1 = 0x04;
414 private static final int SELECT_P2 = 0;
415 private static final int SELECT_P3 = 0x10;
416
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000417 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
418 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
419
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700420 /** The singleton instance. */
421 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800422 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423
Wink Saville3ab207e2014-11-20 13:07:20 -0800424 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800425 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800426 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700427 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800428 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700429 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800430 private MainThreadHandler mMainThreadHandler;
Jack Yue37dd262022-12-16 11:53:37 -0800431 private final SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800432 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700433 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800434 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700435
Peter Wangdafb9ac2020-01-15 14:13:38 -0800436 /** User Activity */
437 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800438 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
439
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700440 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800441
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800442 /**
443 * Map key: subId, value: callback to get error code of the provision request.
444 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800445 private final ConcurrentHashMap<Integer, Consumer<Integer>> mSatelliteProvisionCallbacks =
Sarah Chineccfbd12023-01-20 19:00:35 -0800446 new ConcurrentHashMap<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800447 /**
448 * Map key: subId, value: SatellitePositionUpdateHandler to notify registrants.
449 */
450 private final ConcurrentHashMap<IBinder, SatellitePositionUpdateHandler>
451 mSatellitePositionUpdateHandlers = new ConcurrentHashMap<>();
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800452 /**
453 * Map key: subId, value: SatelliteProvisionStateChangedHandler to notify registrants.
454 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800455 private final ConcurrentHashMap<Integer, SatelliteProvisionStateChangedHandler>
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800456 mSatelliteProvisionStateChangedHandlers = new ConcurrentHashMap<>();
457
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800458 private Boolean mIsSatelliteSupported = null;
459 private final Object mIsSatelliteSupportedLock = new Object();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800460 private final ResultReceiver mSatelliteSupportedReceiver;
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800461
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000462 /**
463 * Map key: subId, value: SatelliteStateChangeHandler to notify registrants.
464 */
465 private ConcurrentHashMap<Integer, SatelliteStateListenerHandler>
466 mSatelliteStateListenerHandlers = new ConcurrentHashMap<>();
467
468 /**
469 * Map key: subId, value: SatelliteDatagramListenerHandler to notify registrants.
470 */
471 private ConcurrentHashMap<Integer, SatelliteDatagramListenerHandler>
472 mSatelliteDatagramListenerHandlers = new ConcurrentHashMap<>();
473
Derek Tan97ebb422014-09-05 16:55:38 -0700474 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
475 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800476 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800477 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700478
Michelecea4cf22018-12-21 15:00:11 -0800479 // String to store multi SIM allowed
480 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
481
Derek Tan740e1672017-06-27 14:56:27 -0700482 // The AID of ISD-R.
483 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
484
yinxub1bed742017-04-17 11:45:04 -0700485 private NetworkScanRequestTracker mNetworkScanRequestTracker;
486
David Kelly5e06a7f2018-03-12 14:10:59 +0000487 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
488 private static final int MANUFACTURER_CODE_LENGTH = 8;
489
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800490 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800491 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800492
Sarah Chin2ec39f62022-08-31 17:03:26 -0700493 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
494 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
495
Derek Tan89e89d42014-07-08 17:00:10 -0700496 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700497 * Experiment flag to enable erase modem config on reset network, default value is false
498 */
499 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
500 "reset_network_erase_modem_config_enabled";
501
Rambo Wang0f050d82021-02-12 11:43:36 -0800502 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800503
Gary Jian76280a42022-12-07 16:18:33 +0800504 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
505
sandeepjsb6c87872021-09-27 15:34:44 +0000506 /**
507 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
508 * one ICCID active at the same time.
509 * Apps should use below API signatures if targeting SDK is T and beyond.
510 *
511 * @hide
512 */
513 @ChangeId
514 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
515 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800516
Naina Nallurid63128d2019-09-17 14:10:30 -0700517 /**
Chen Xu540470b2021-12-14 17:15:47 -0800518 * Apps targeting on Android T and beyond will get exception whenever icc close channel
519 * operation fails.
520 */
521 @ChangeId
522 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
523 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
524
525 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700526 * A request object to use for transmitting data to an ICC.
527 */
528 private static final class IccAPDUArgument {
529 public int channel, cla, command, p1, p2, p3;
530 public String data;
531
532 public IccAPDUArgument(int channel, int cla, int command,
533 int p1, int p2, int p3, String data) {
534 this.channel = channel;
535 this.cla = cla;
536 this.command = command;
537 this.p1 = p1;
538 this.p2 = p2;
539 this.p3 = p3;
540 this.data = data;
541 }
542 }
543
544 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700545 * A request object to use for transmitting data to an ICC.
546 */
547 private static final class ManualNetworkSelectionArgument {
548 public OperatorInfo operatorInfo;
549 public boolean persistSelection;
550
551 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
552 this.operatorInfo = operatorInfo;
553 this.persistSelection = persistSelection;
554 }
555 }
556
Sarah Chin71b3a852022-09-28 15:54:19 -0700557 private static final class PurchasePremiumCapabilityArgument {
558 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700559 public @NonNull IIntegerConsumer callback;
560
561 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800562 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700563 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700564 this.callback = callback;
565 }
566 }
567
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800568 private static final class ProvisionSatelliteServiceArgument {
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800569 public @NonNull String token;
570 public @NonNull Consumer<Integer> callback;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800571 public int subId;
572
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800573 ProvisionSatelliteServiceArgument(String token, Consumer<Integer> callback, int subId) {
574 this.token = token;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800575 this.callback = callback;
576 this.subId = subId;
577 }
578 }
579
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +0000580 private static final class SendSatelliteDatagramArgument {
581 public @SatelliteManager.DatagramType int datagramType;
582 public @NonNull SatelliteDatagram datagram;
583 public @NonNull Consumer<Integer> callback;
584
585 SendSatelliteDatagramArgument(@SatelliteManager.DatagramType int datagramType,
586 SatelliteDatagram datagram, Consumer<Integer> callback) {
587 this.datagramType = datagramType;
588 this.datagram = datagram;
589 this.callback = callback;
590 }
591 }
592
Sarah Chineccfbd12023-01-20 19:00:35 -0800593 private static final class SatellitePositionUpdateHandler extends Handler {
594 public static final int EVENT_POSITION_UPDATE = 1;
595 public static final int EVENT_MESSAGE_TRANSFER_STATE_UPDATE = 2;
596
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800597 private final ISatelliteStateListener mCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800598
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800599 SatellitePositionUpdateHandler(ISatelliteStateListener callback, Looper looper) {
Sarah Chineccfbd12023-01-20 19:00:35 -0800600 super(looper);
601 mCallback = callback;
602 }
603
604 @Override
605 public void handleMessage(@NonNull Message msg) {
606 switch (msg.what) {
607 case EVENT_POSITION_UPDATE: {
608 AsyncResult ar = (AsyncResult) msg.obj;
609 PointingInfo pointingInfo = (PointingInfo) ar.result;
610 try {
611 mCallback.onSatellitePositionUpdate(pointingInfo);
612 } catch (RemoteException e) {
613 loge("EVENT_POSITION_UPDATE RemoteException: " + e);
614 }
615 break;
616 }
617 case EVENT_MESSAGE_TRANSFER_STATE_UPDATE: {
618 AsyncResult ar = (AsyncResult) msg.obj;
619 int state = (int) ar.result;
620 try {
621 mCallback.onMessageTransferStateUpdate(state);
622 } catch (RemoteException e) {
623 loge("EVENT_MESSAGE_TRANSFER_STATE_UPDATE RemoteException: " + e);
624 }
625 break;
626 }
627 default:
628 loge("SatellitePositionUpdateHandler unknown event: " + msg.what);
629 }
630 }
631 }
632
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800633 private static final class SatelliteProvisionStateChangedHandler extends Handler {
634 public static final int EVENT_PROVISION_STATE_CHANGED = 1;
635
636 private ConcurrentHashMap<IBinder, ISatelliteStateListener> mListeners;
637 private final int mSubId;
638
639 SatelliteProvisionStateChangedHandler(Looper looper, int subId) {
640 super(looper);
641 mListeners = new ConcurrentHashMap<>();
642 mSubId = subId;
643 }
644
645 public void addListener(ISatelliteStateListener listener) {
646 mListeners.put(listener.asBinder(), listener);
647 }
648
649 public boolean removeListener(ISatelliteStateListener listener) {
650 return (mListeners.remove(listener.asBinder()) != null);
651 }
652
653 @Override
654 public void handleMessage(@NonNull Message msg) {
655 switch (msg.what) {
656 case EVENT_PROVISION_STATE_CHANGED: {
657 AsyncResult ar = (AsyncResult) msg.obj;
658 boolean provisioned = (boolean) ar.userObj;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800659 log("Received EVENT_PROVISION_STATE_CHANGED for subId=" + mSubId
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800660 + ", provisioned=" + provisioned);
661 mListeners.values().forEach(listener -> {
662 try {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -0800663 listener.onSatelliteProvisionStateChanged(provisioned);
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800664 } catch (RemoteException e) {
665 log("EVENT_PROVISION_STATE_CHANGED RemoteException: " + e);
666 }
667 });
668
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800669 setSatelliteProvisioned(provisioned);
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800670 /**
671 * TODO: Take bugreport if provisioned is true and user did not initiate the
672 * provision procedure for the corresponding subscription.
673 */
674 break;
675 }
676 default:
677 loge("SatelliteProvisionStateChangedHandler unknown event: " + msg.what);
678 }
679 }
680
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800681 private void setSatelliteProvisioned(boolean isProvisioned) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800682 if (mSubId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
683 SubscriptionManager.setSubscriptionProperty(
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800684 mSubId, SubscriptionManager.SATELLITE_ENABLED, isProvisioned ? "1" : "0");
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800685 } else {
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800686 //TODO (b/267826133): set via SatelliteController.
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800687 }
688 }
689 }
690
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000691 private static final class SatelliteStateListenerHandler extends Handler {
692 public static final int EVENT_SATELLITE_MODEM_STATE_CHANGE = 1;
693 public static final int EVENT_PENDING_MESSAGE_COUNT = 2;
694
695 private ConcurrentHashMap<IBinder, ISatelliteStateListener> mListeners;
696 private final int mSubId;
697
698 SatelliteStateListenerHandler(Looper looper, int subId) {
699 super(looper);
700 mSubId = subId;
701 mListeners = new ConcurrentHashMap<>();
702 }
703
704 public void addListener(ISatelliteStateListener listener) {
705 mListeners.put(listener.asBinder(), listener);
706 }
707
708 public boolean removeListener(ISatelliteStateListener listener) {
709 return (mListeners.remove(listener.asBinder()) != null);
710 }
711
712 @Override
713 public void handleMessage(@NonNull Message msg) {
714 switch (msg.what) {
715 case EVENT_SATELLITE_MODEM_STATE_CHANGE : {
716 AsyncResult ar = (AsyncResult) msg.obj;
717 int state = (int) ar.result;
718 log("Received EVENT_SATELLITE_MODEM_STATE_CHANGE for subId=" + mSubId
719 + ", state=" + state);
720 mListeners.values().forEach(listener -> {
721 try {
722 listener.onSatelliteModemStateChange(state);
723 } catch (RemoteException e) {
724 log("EVENT_SATELLITE_MODEM_STATE_CHANGE RemoteException: " + e);
725 }
726 });
727 break;
728 }
729 case EVENT_PENDING_MESSAGE_COUNT: {
730 AsyncResult ar = (AsyncResult) msg.obj;
731 int count = (int) ar.result;
732 log("Received EVENT_PENDING_MESSAGE_COUNT for subId=" + mSubId
733 + ", count=" + count);
734 mListeners.values().forEach(listener -> {
735 try {
736 listener.onPendingMessageCount(count);
737 } catch (RemoteException e) {
738 log("EVENT_PENDING_MESSAGE_COUNT RemoteException: " + e);
739 }
740 });
741 break;
742 }
743 default:
744 loge("SatelliteStateListenerHandler unknown event: " + msg.what);
745 }
746 }
747 }
748
749 private static final class SatelliteDatagramListenerHandler extends Handler {
750 public static final int EVENT_SATELLITE_DATAGRAMS_RECEIVED = 1;
751
752 private ConcurrentHashMap<IBinder, ISatelliteStateListener> mListeners;
753 private final int mSubId;
754
755 SatelliteDatagramListenerHandler(Looper looper, int subId) {
756 super(looper);
757 mSubId = subId;
758 mListeners = new ConcurrentHashMap<>();
759 }
760
761 public void addListener(ISatelliteStateListener listener) {
762 mListeners.put(listener.asBinder(), listener);
763 }
764
765 public boolean removeListener(ISatelliteStateListener listener) {
766 return (mListeners.remove(listener.asBinder()) != null);
767 }
768
769 @Override
770 public void handleMessage(@NonNull Message msg) {
771 switch (msg.what) {
772 case EVENT_SATELLITE_DATAGRAMS_RECEIVED : {
773 AsyncResult ar = (AsyncResult) msg.obj;
774 byte[][] datagrams = (byte[][]) ar.result;
775 SatelliteDatagram[] satelliteDatagramArray =
776 convertToSatelliteDatagramArray(datagrams);
777
778 log("Received EVENT_SATELLITE_DATAGRAMS_RECEIVED for subId=" + mSubId);
779 mListeners.values().forEach(listener -> {
780 try {
781 listener.onSatelliteDatagrams(satelliteDatagramArray);
782 } catch (RemoteException e) {
783 log("EVENT_SATELLITE_DATAGRAMS_RECEIVED RemoteException: " + e);
784 }
785 });
786 break;
787 }
788 default:
789 loge("SatelliteDatagramListenerHandler unknown event: " + msg.what);
790 }
791 }
792 }
793
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700794 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700795 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
796 * request after sending. The main thread will notify the request when it is complete.
797 */
798 private static final class MainThreadRequest {
799 /** The argument to use for the request */
800 public Object argument;
801 /** The result of the request that is run on the main thread */
802 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800803 // The subscriber id that this request applies to. Defaults to
804 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
805 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700806
Nathan Harold92bed182018-10-12 18:16:49 -0700807 // In cases where subId is unavailable, the caller needs to specify the phone.
808 public Phone phone;
809
vagdeviaf9a5b92018-08-15 16:01:53 -0700810 public WorkSource workSource;
811
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700812 public MainThreadRequest(Object argument) {
813 this.argument = argument;
814 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800815
Nathan Harold92bed182018-10-12 18:16:49 -0700816 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
817 this.argument = argument;
818 if (phone != null) {
819 this.phone = phone;
820 }
821 this.workSource = workSource;
822 }
823
vagdeviaf9a5b92018-08-15 16:01:53 -0700824 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800825 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800826 if (subId != null) {
827 this.subId = subId;
828 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700829 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800830 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700831 }
832
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800833 private static final class IncomingThirdPartyCallArgs {
834 public final ComponentName component;
835 public final String callId;
836 public final String callerDisplayName;
837
838 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
839 String callerDisplayName) {
840 this.component = component;
841 this.callId = callId;
842 this.callerDisplayName = callerDisplayName;
843 }
844 }
845
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700846 /**
847 * A handler that processes messages on the main thread in the phone process. Since many
848 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
849 * inbound binder threads to the main thread in the phone process. The Binder thread
850 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
851 * on, which will be notified when the operation completes and will contain the result of the
852 * request.
853 *
854 * <p>If a MainThreadRequest object is provided in the msg.obj field,
855 * note that request.result must be set to something non-null for the calling thread to
856 * unblock.
857 */
858 private final class MainThreadHandler extends Handler {
859 @Override
860 public void handleMessage(Message msg) {
861 MainThreadRequest request;
862 Message onCompleted;
863 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000864 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700865 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800866 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700867
868 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700869 case CMD_HANDLE_USSD_REQUEST: {
870 request = (MainThreadRequest) msg.obj;
871 final Phone phone = getPhoneFromRequest(request);
872 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800873 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700874 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700875
Pengquan Menga1bb6272018-09-06 09:59:22 -0700876 if (!isUssdApiAllowed(request.subId)) {
877 // Carrier does not support use of this API, return failure.
878 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
879 UssdResponse response = new UssdResponse(ussdRequest, null);
880 Bundle returnData = new Bundle();
881 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
882 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700883
Pengquan Menga1bb6272018-09-06 09:59:22 -0700884 request.result = true;
885 notifyRequester(request);
886 return;
887 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700888
Pengquan Menga1bb6272018-09-06 09:59:22 -0700889 try {
890 request.result = phone != null
891 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
892 } catch (CallStateException cse) {
893 request.result = false;
894 }
895 // Wake up the requesting thread
896 notifyRequester(request);
897 break;
pkanwar32d516d2016-10-14 19:37:38 -0700898 }
899
Yorke Lee716f67e2015-06-17 15:39:16 -0700900 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700901 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700902 final Phone phone = getPhoneFromRequest(request);
903 request.result = phone != null ?
904 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
905 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700906 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700907 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700908 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700909 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700910
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700911 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700912 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700913 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000914 uiccPort = getUiccPortFromRequest(request);
915 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700916 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800917 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700918 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700919 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700920 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800921 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000922 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800923 iccArgument.channel, iccArgument.cla, iccArgument.command,
924 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
925 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700926 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700927 break;
928
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700929 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700930 ar = (AsyncResult) msg.obj;
931 request = (MainThreadRequest) ar.userObj;
932 if (ar.exception == null && ar.result != null) {
933 request.result = ar.result;
934 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800935 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700936 if (ar.result == null) {
937 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800938 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700939 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800940 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700941 } else {
942 loge("iccTransmitApduLogicalChannel: Unknown exception");
943 }
944 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700945 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700946 break;
947
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700948 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
949 request = (MainThreadRequest) msg.obj;
950 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000951 uiccPort = getUiccPortFromRequest(request);
952 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700953 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800954 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700955 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700956 } else {
957 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800958 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000959 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800960 iccArgument.cla, iccArgument.command, iccArgument.p1,
961 iccArgument.p2,
962 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700963 }
964 break;
965
966 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
967 ar = (AsyncResult) msg.obj;
968 request = (MainThreadRequest) ar.userObj;
969 if (ar.exception == null && ar.result != null) {
970 request.result = ar.result;
971 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800972 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700973 if (ar.result == null) {
974 loge("iccTransmitApduBasicChannel: Empty response");
975 } else if (ar.exception instanceof CommandException) {
976 loge("iccTransmitApduBasicChannel: CommandException: " +
977 ar.exception);
978 } else {
979 loge("iccTransmitApduBasicChannel: Unknown exception");
980 }
981 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700982 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700983 break;
984
985 case CMD_EXCHANGE_SIM_IO:
986 request = (MainThreadRequest) msg.obj;
987 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000988 uiccPort = getUiccPortFromRequest(request);
989 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700990 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800991 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700992 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700993 } else {
994 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
995 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000996 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700997 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
998 iccArgument.data, onCompleted);
999 }
1000 break;
1001
1002 case EVENT_EXCHANGE_SIM_IO_DONE:
1003 ar = (AsyncResult) msg.obj;
1004 request = (MainThreadRequest) ar.userObj;
1005 if (ar.exception == null && ar.result != null) {
1006 request.result = ar.result;
1007 } else {
Chen Xue9d737e2022-01-01 23:41:31 -08001008 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001009 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001010 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001011 break;
1012
Derek Tan4d5e5c12014-02-04 11:54:58 -08001013 case CMD_SEND_ENVELOPE:
1014 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001015 uiccPort = getUiccPortFromRequest(request);
1016 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001017 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -08001018 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001019 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001020 } else {
1021 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -08001022 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001023 }
Derek Tan4d5e5c12014-02-04 11:54:58 -08001024 break;
1025
1026 case EVENT_SEND_ENVELOPE_DONE:
1027 ar = (AsyncResult) msg.obj;
1028 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -07001029 if (ar.exception == null && ar.result != null) {
1030 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -08001031 } else {
Chen Xue9d737e2022-01-01 23:41:31 -08001032 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -07001033 if (ar.result == null) {
1034 loge("sendEnvelopeWithStatus: Empty response");
1035 } else if (ar.exception instanceof CommandException) {
1036 loge("sendEnvelopeWithStatus: CommandException: " +
1037 ar.exception);
1038 } else {
1039 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
1040 }
Derek Tan4d5e5c12014-02-04 11:54:58 -08001041 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001042 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -08001043 break;
1044
Shishir Agrawal566b7612013-10-28 14:41:00 -07001045 case CMD_OPEN_CHANNEL:
1046 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001047 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -08001048 IccLogicalChannelRequest openChannelRequest =
1049 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001050 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001051 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -08001052 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -08001053 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001054 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001055 } else {
1056 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -08001057 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
1058 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001059 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001060 break;
1061
1062 case EVENT_OPEN_CHANNEL_DONE:
1063 ar = (AsyncResult) msg.obj;
1064 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001065 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -07001066 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001067 int[] result = (int[]) ar.result;
1068 int channelId = result[0];
1069 byte[] selectResponse = null;
1070 if (result.length > 1) {
1071 selectResponse = new byte[result.length - 1];
1072 for (int i = 1; i < result.length; ++i) {
1073 selectResponse[i - 1] = (byte) result[i];
1074 }
1075 }
1076 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -08001077 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -08001078
1079 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -07001080 if (uiccPort == null) {
1081 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
1082 } else {
1083 IccLogicalChannelRequest channelRequest =
1084 (IccLogicalChannelRequest) request.argument;
1085 channelRequest.channel = channelId;
1086 uiccPort.onLogicalChannelOpened(channelRequest);
1087 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001088 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -07001089 if (ar.result == null) {
1090 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -07001091 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001092 if (ar.exception != null) {
1093 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
1094 }
1095
Shishir Agrawal527e8bf2014-08-25 08:54:56 -07001096 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -07001097 if (ar.exception instanceof CommandException) {
1098 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -08001099 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -07001100 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -07001101 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -07001102 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -07001103 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07001104 }
1105 }
1106 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -08001107 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001108 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -07001109 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001110 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001111 break;
1112
1113 case CMD_CLOSE_CHANNEL:
1114 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001115 uiccPort = getUiccPortFromRequest(request);
1116 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001117 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -08001118 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001119 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -08001120 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001121 } else {
1122 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001123 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07001124 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07001125 break;
1126
1127 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -08001128 ar = (AsyncResult) msg.obj;
1129 request = (MainThreadRequest) ar.userObj;
1130 if (ar.exception == null) {
1131 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -08001132 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -07001133 if (uiccPort == null) {
1134 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
1135 } else {
1136 final int channelId = (Integer) request.argument;
1137 uiccPort.onLogicalChannelClosed(channelId);
1138 }
Chen Xu540470b2021-12-14 17:15:47 -08001139 } else {
1140 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -08001141 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -08001142 if (ar.exception instanceof CommandException) {
1143 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
1144 CommandException.Error error =
1145 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -08001146 if (error == CommandException.Error.INVALID_ARGUMENTS) {
1147 // should only throw exceptions from the binder threads.
1148 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -08001149 "iccCloseLogicalChannel: invalid argument ");
1150 }
1151 } else {
1152 loge("iccCloseLogicalChannel: Unknown exception");
1153 }
Chen Xua8f0dff2022-02-12 00:34:15 -08001154 request.result = (exception != null) ? exception :
1155 new IllegalStateException(
1156 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -08001157 }
1158 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001159 break;
1160
1161 case CMD_NV_READ_ITEM:
1162 request = (MainThreadRequest) msg.obj;
1163 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001164 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
1165 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -08001166 break;
1167
1168 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -07001169 ar = (AsyncResult) msg.obj;
1170 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -08001171 if (ar.exception == null && ar.result != null) {
1172 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -07001173 } else {
Jake Hambye994d462014-02-03 13:10:13 -08001174 request.result = "";
1175 if (ar.result == null) {
1176 loge("nvReadItem: Empty response");
1177 } else if (ar.exception instanceof CommandException) {
1178 loge("nvReadItem: CommandException: " +
1179 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001180 } else {
Jake Hambye994d462014-02-03 13:10:13 -08001181 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -07001182 }
1183 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001184 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001185 break;
1186
Jake Hambye994d462014-02-03 13:10:13 -08001187 case CMD_NV_WRITE_ITEM:
1188 request = (MainThreadRequest) msg.obj;
1189 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
1190 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001191 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -07001192 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -08001193 break;
1194
1195 case EVENT_NV_WRITE_ITEM_DONE:
1196 handleNullReturnEvent(msg, "nvWriteItem");
1197 break;
1198
1199 case CMD_NV_WRITE_CDMA_PRL:
1200 request = (MainThreadRequest) msg.obj;
1201 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001202 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -08001203 break;
1204
1205 case EVENT_NV_WRITE_CDMA_PRL_DONE:
1206 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
1207 break;
1208
chen xu6dac5ab2018-10-26 17:39:23 -07001209 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -08001210 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -07001211 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001212 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -08001213 break;
1214
chen xu6dac5ab2018-10-26 17:39:23 -07001215 case EVENT_RESET_MODEM_CONFIG_DONE:
1216 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -08001217 break;
1218
Sooraj Sasindran37444802020-08-11 10:40:43 -07001219 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
1220 request = (MainThreadRequest) msg.obj;
1221 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
1222 request);
1223 Phone phone = getPhoneFromRequest(request);
1224 if (phone != null) {
1225 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
1226 } else {
1227 loge("isNRDualConnectivityEnabled: No phone object");
1228 request.result = false;
1229 notifyRequester(request);
1230 }
1231 break;
1232 }
1233
1234 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
1235 ar = (AsyncResult) msg.obj;
1236 request = (MainThreadRequest) ar.userObj;
1237 if (ar.exception == null && ar.result != null) {
1238 request.result = ar.result;
1239 } else {
1240 // request.result must be set to something non-null
1241 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001242 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -07001243 request.result = ar.result;
1244 } else {
1245 request.result = false;
1246 }
1247 if (ar.result == null) {
1248 loge("isNRDualConnectivityEnabled: Empty response");
1249 } else if (ar.exception instanceof CommandException) {
1250 loge("isNRDualConnectivityEnabled: CommandException: "
1251 + ar.exception);
1252 } else {
1253 loge("isNRDualConnectivityEnabled: Unknown exception");
1254 }
1255 }
1256 notifyRequester(request);
1257 break;
1258
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001259 case CMD_IS_VONR_ENABLED: {
1260 request = (MainThreadRequest) msg.obj;
1261 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1262 request);
1263 Phone phone = getPhoneFromRequest(request);
1264 if (phone != null) {
1265 phone.isVoNrEnabled(onCompleted, request.workSource);
1266 } else {
1267 loge("isVoNrEnabled: No phone object");
1268 request.result = false;
1269 notifyRequester(request);
1270 }
1271 break;
1272 }
1273
1274 case EVENT_IS_VONR_ENABLED_DONE:
1275 ar = (AsyncResult) msg.obj;
1276 request = (MainThreadRequest) ar.userObj;
1277 if (ar.exception == null && ar.result != null) {
1278 request.result = ar.result;
1279 } else {
1280 // request.result must be set to something non-null
1281 // for the calling thread to unblock
1282 if (ar.result != null) {
1283 request.result = ar.result;
1284 } else {
1285 request.result = false;
1286 }
1287 if (ar.result == null) {
1288 loge("isVoNrEnabled: Empty response");
1289 } else if (ar.exception instanceof CommandException) {
1290 loge("isVoNrEnabled: CommandException: "
1291 + ar.exception);
1292 } else {
1293 loge("isVoNrEnabled: Unknown exception");
1294 }
1295 }
1296 notifyRequester(request);
1297 break;
1298
Sooraj Sasindran37444802020-08-11 10:40:43 -07001299 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1300 request = (MainThreadRequest) msg.obj;
1301 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1302 Phone phone = getPhoneFromRequest(request);
1303 if (phone != null) {
1304 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1305 request.workSource);
1306 } else {
1307 loge("enableNrDualConnectivity: No phone object");
1308 request.result =
1309 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1310 notifyRequester(request);
1311 }
1312 break;
1313 }
1314
1315 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1316 ar = (AsyncResult) msg.obj;
1317 request = (MainThreadRequest) ar.userObj;
1318 if (ar.exception == null) {
1319 request.result =
1320 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1321 } else {
1322 request.result =
1323 TelephonyManager
1324 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1325 if (ar.exception instanceof CommandException) {
1326 CommandException.Error error =
1327 ((CommandException) (ar.exception)).getCommandError();
1328 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1329 request.result =
1330 TelephonyManager
1331 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001332 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1333 request.result =
1334 TelephonyManager
1335 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001336 }
1337 loge("enableNrDualConnectivity" + ": CommandException: "
1338 + ar.exception);
1339 } else {
1340 loge("enableNrDualConnectivity" + ": Unknown exception");
1341 }
1342 }
1343 notifyRequester(request);
1344 break;
1345 }
1346
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001347 case CMD_ENABLE_VONR: {
1348 request = (MainThreadRequest) msg.obj;
1349 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1350 Phone phone = getPhoneFromRequest(request);
1351 if (phone != null) {
1352 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1353 request.workSource);
1354 } else {
1355 loge("setVoNrEnabled: No phone object");
1356 request.result =
1357 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1358 notifyRequester(request);
1359 }
1360 break;
1361 }
1362
1363 case EVENT_ENABLE_VONR_DONE: {
1364 ar = (AsyncResult) msg.obj;
1365 request = (MainThreadRequest) ar.userObj;
1366 if (ar.exception == null) {
1367 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1368 } else {
1369 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1370 if (ar.exception instanceof CommandException) {
1371 CommandException.Error error =
1372 ((CommandException) (ar.exception)).getCommandError();
1373 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1374 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1375 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1376 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1377 } else {
1378 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1379 }
1380 loge("setVoNrEnabled" + ": CommandException: "
1381 + ar.exception);
1382 } else {
1383 loge("setVoNrEnabled" + ": Unknown exception");
1384 }
1385 }
1386 notifyRequester(request);
1387 break;
1388 }
1389
SongFerngWang3ef3e072020-12-21 16:41:52 +08001390 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001391 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001392 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1393 request);
1394 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001395 break;
1396
SongFerngWang3ef3e072020-12-21 16:41:52 +08001397 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001398 ar = (AsyncResult) msg.obj;
1399 request = (MainThreadRequest) ar.userObj;
1400 if (ar.exception == null && ar.result != null) {
1401 request.result = ar.result; // Integer
1402 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301403 // request.result must be set to something non-null
1404 // for the calling thread to unblock
1405 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001406 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001407 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001408 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001409 loge("getAllowedNetworkTypesBitmask: CommandException: "
1410 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001411 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001412 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001413 }
1414 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001415 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001416 break;
1417
SongFerngWang3ef3e072020-12-21 16:41:52 +08001418 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001419 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001420 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1421 request);
1422 Pair<Integer, Long> reasonWithNetworkTypes =
1423 (Pair<Integer, Long>) request.argument;
1424 getPhoneFromRequest(request).setAllowedNetworkTypes(
1425 reasonWithNetworkTypes.first,
1426 reasonWithNetworkTypes.second,
1427 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001428 break;
1429
SongFerngWang3ef3e072020-12-21 16:41:52 +08001430 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1431 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001432 break;
1433
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001434 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1435 request = (MainThreadRequest)msg.obj;
1436 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001437 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001438 break;
1439
1440 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1441 ar = (AsyncResult)msg.obj;
1442 request = (MainThreadRequest)ar.userObj;
1443 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001444 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001445 break;
1446
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001447 case CMD_SET_VOICEMAIL_NUMBER:
1448 request = (MainThreadRequest) msg.obj;
1449 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1450 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001451 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1452 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001453 break;
1454
1455 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1456 handleNullReturnEvent(msg, "setVoicemailNumber");
1457 break;
1458
Stuart Scott54788802015-03-30 13:18:01 -07001459 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1460 request = (MainThreadRequest) msg.obj;
1461 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1462 request);
1463 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1464 break;
1465
1466 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1467 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1468 break;
1469
Shishir Agrawal302c8692015-06-19 13:49:39 -07001470 case CMD_PERFORM_NETWORK_SCAN:
1471 request = (MainThreadRequest) msg.obj;
1472 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1473 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1474 break;
1475
Hall Liu27d24262020-09-18 19:04:59 -07001476 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001477 request = (MainThreadRequest) msg.obj;
1478 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001479 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1480 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1481 request.argument;
1482 int callForwardingReason = args.first;
1483 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001484 break;
Hall Liu27d24262020-09-18 19:04:59 -07001485 }
1486 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001487 ar = (AsyncResult) msg.obj;
1488 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001489 TelephonyManager.CallForwardingInfoCallback callback =
1490 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1491 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001492 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001493 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001494 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1495 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1496 // Service Class is a bit mask per 3gpp 27.007. Search for
1497 // any service for voice call.
1498 if ((callForwardInfo.serviceClass
1499 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001500 callForwardingInfo = new CallForwardingInfo(
1501 callForwardInfo.status
1502 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001503 callForwardInfo.reason,
1504 callForwardInfo.number,
1505 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001506 break;
1507 }
1508 }
1509 // Didn't find a call forward info for voice call.
1510 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001511 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1512 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001513 }
Hall Liu27d24262020-09-18 19:04:59 -07001514 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001515 } else {
1516 if (ar.result == null) {
1517 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1518 }
1519 if (ar.exception != null) {
1520 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1521 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001522 int errorCode = TelephonyManager
1523 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001524 if (ar.exception instanceof CommandException) {
1525 CommandException.Error error =
1526 ((CommandException) (ar.exception)).getCommandError();
1527 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001528 errorCode = TelephonyManager
1529 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001530 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001531 errorCode = TelephonyManager
1532 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001533 }
1534 }
Hall Liu27d24262020-09-18 19:04:59 -07001535 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001536 }
Shuo Qian4a594052020-01-23 11:59:30 -08001537 break;
Hall Liu27d24262020-09-18 19:04:59 -07001538 }
Shuo Qian4a594052020-01-23 11:59:30 -08001539
Hall Liu27d24262020-09-18 19:04:59 -07001540 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001541 request = (MainThreadRequest) msg.obj;
1542 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001543 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001544 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001545 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1546 request.argument).first;
1547 request.phone.setCallForwardingOption(
1548 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001549 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001550 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001551 callForwardingInfoToSet.getReason(),
1552 callForwardingInfoToSet.getNumber(),
1553 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1554 break;
Hall Liu27d24262020-09-18 19:04:59 -07001555 }
Shuo Qian4a594052020-01-23 11:59:30 -08001556
Hall Liu27d24262020-09-18 19:04:59 -07001557 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001558 ar = (AsyncResult) msg.obj;
1559 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001560 Consumer<Integer> callback =
1561 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1562 request.argument).second;
1563 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001564 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001565 int errorCode = TelephonyManager.CallForwardingInfoCallback
1566 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001567 if (ar.exception instanceof CommandException) {
1568 CommandException.Error error =
1569 ((CommandException) (ar.exception)).getCommandError();
1570 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001571 errorCode = TelephonyManager.CallForwardingInfoCallback
1572 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001573 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001574 errorCode = TelephonyManager.CallForwardingInfoCallback
1575 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001576 }
1577 }
1578 callback.accept(errorCode);
1579 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001580 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001581 }
Shuo Qian4a594052020-01-23 11:59:30 -08001582 break;
Hall Liu27d24262020-09-18 19:04:59 -07001583 }
Shuo Qian4a594052020-01-23 11:59:30 -08001584
Hall Liu27d24262020-09-18 19:04:59 -07001585 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001586 request = (MainThreadRequest) msg.obj;
1587 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1588 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1589 break;
Hall Liu27d24262020-09-18 19:04:59 -07001590 }
Shuo Qian4a594052020-01-23 11:59:30 -08001591
Hall Liu27d24262020-09-18 19:04:59 -07001592 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001593 ar = (AsyncResult) msg.obj;
1594 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001595 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001596 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001597 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001598 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001599 // Service Class is a bit mask per 3gpp 27.007.
1600 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001601 if (callForwardResults.length > 1
1602 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001603 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001604 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001605 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1606 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001607 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001608 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001609 }
1610 } else {
1611 if (ar.result == null) {
1612 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1613 }
1614 if (ar.exception != null) {
1615 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1616 }
1617 if (ar.exception instanceof CommandException) {
1618 CommandException.Error error =
1619 ((CommandException) (ar.exception)).getCommandError();
1620 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001621 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001622 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001623 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1624 callWaitingStatus =
1625 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001626 }
1627 }
1628 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001629 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001630 break;
Hall Liu27d24262020-09-18 19:04:59 -07001631 }
Shuo Qian4a594052020-01-23 11:59:30 -08001632
Hall Liu27d24262020-09-18 19:04:59 -07001633 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001634 request = (MainThreadRequest) msg.obj;
1635 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001636 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1637 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001638 break;
Hall Liu27d24262020-09-18 19:04:59 -07001639 }
Shuo Qian4a594052020-01-23 11:59:30 -08001640
Hall Liu27d24262020-09-18 19:04:59 -07001641 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001642 ar = (AsyncResult) msg.obj;
1643 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001644 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1645 Consumer<Integer> callback =
1646 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1647 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001648 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001649 if (ar.exception instanceof CommandException) {
1650 CommandException.Error error =
1651 ((CommandException) (ar.exception)).getCommandError();
1652 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1653 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001654 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1655 callback.accept(
1656 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001657 } else {
1658 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1659 }
1660 } else {
1661 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1662 }
1663 } else {
1664 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1665 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001666 }
Shuo Qian4a594052020-01-23 11:59:30 -08001667 break;
Hall Liu27d24262020-09-18 19:04:59 -07001668 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001669 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1670 ar = (AsyncResult) msg.obj;
1671 request = (MainThreadRequest) ar.userObj;
1672 CellNetworkScanResult cellScanResult;
1673 if (ar.exception == null && ar.result != null) {
1674 cellScanResult = new CellNetworkScanResult(
1675 CellNetworkScanResult.STATUS_SUCCESS,
1676 (List<OperatorInfo>) ar.result);
1677 } else {
1678 if (ar.result == null) {
1679 loge("getCellNetworkScanResults: Empty response");
1680 }
1681 if (ar.exception != null) {
1682 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1683 }
1684 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1685 if (ar.exception instanceof CommandException) {
1686 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001687 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001688 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1689 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1690 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1691 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1692 }
1693 }
1694 cellScanResult = new CellNetworkScanResult(errorCode, null);
1695 }
1696 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001697 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001698 break;
1699
1700 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1701 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001702 ManualNetworkSelectionArgument selArg =
1703 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001704 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1705 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001706 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1707 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001708 break;
1709
1710 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001711 ar = (AsyncResult) msg.obj;
1712 request = (MainThreadRequest) ar.userObj;
1713 if (ar.exception == null) {
1714 request.result = true;
1715 } else {
1716 request.result = false;
1717 loge("setNetworkSelectionModeManual " + ar.exception);
1718 }
1719 notifyRequester(request);
1720 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001721 break;
1722
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001723 case CMD_GET_MODEM_ACTIVITY_INFO:
1724 request = (MainThreadRequest) msg.obj;
1725 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001726 if (defaultPhone != null) {
1727 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001728 } else {
1729 ResultReceiver result = (ResultReceiver) request.argument;
1730 Bundle bundle = new Bundle();
1731 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001732 new ModemActivityInfo(0, 0, 0,
1733 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001734 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001735 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001736 break;
1737
Hall Liud0f208c2020-10-14 16:54:44 -07001738 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001739 ar = (AsyncResult) msg.obj;
1740 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001741 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001742 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001743 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001744 if (mLastModemActivityInfo == null) {
1745 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1746 mLastModemActivitySpecificInfo[0] =
1747 new ActivityStatsTechSpecificInfo(
1748 0,
1749 0,
1750 new int[ModemActivityInfo.getNumTxPowerLevels()],
1751 0);
1752 mLastModemActivityInfo =
1753 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1754 }
1755
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001756 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001757 // Update the last modem activity info and the result of the request.
1758 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1759 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001760 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001761 } else {
1762 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001763 }
Kai Shi917fdc62022-11-28 14:01:02 -08001764 // This is needed to decouple ret from mLastModemActivityInfo
1765 // We don't want to return mLastModemActivityInfo which is updated
1766 // inside mergeModemActivityInfo()
1767 ret = new ModemActivityInfo(
1768 mLastModemActivityInfo.getTimestampMillis(),
1769 mLastModemActivityInfo.getSleepTimeMillis(),
1770 mLastModemActivityInfo.getIdleTimeMillis(),
1771 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001772
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001773 } else {
1774 if (ar.result == null) {
1775 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001776 error = TelephonyManager.ModemActivityInfoException
1777 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001778 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001779 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001780 error = TelephonyManager.ModemActivityInfoException
1781 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001782 } else {
1783 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001784 error = TelephonyManager.ModemActivityInfoException
1785 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001786 }
1787 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001788 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001789 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001790 bundle.putParcelable(
1791 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001792 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001793 } else {
1794 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1795 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001796 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001797 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001798 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001799 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001800
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001801 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001802 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001803 CarrierRestrictionRules argument =
1804 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001805 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001806 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001807 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001808 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001809
1810 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1811 ar = (AsyncResult) msg.obj;
1812 request = (MainThreadRequest) ar.userObj;
1813 if (ar.exception == null && ar.result != null) {
1814 request.result = ar.result;
1815 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001816 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1817 if (ar.exception instanceof CommandException) {
1818 loge("setAllowedCarriers: CommandException: " + ar.exception);
1819 CommandException.Error error =
1820 ((CommandException) (ar.exception)).getCommandError();
1821 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1822 request.result =
1823 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1824 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001825 } else {
1826 loge("setAllowedCarriers: Unknown exception");
1827 }
1828 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001829 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001830 break;
1831
1832 case CMD_GET_ALLOWED_CARRIERS:
1833 request = (MainThreadRequest) msg.obj;
1834 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001835 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001836 break;
1837
1838 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1839 ar = (AsyncResult) msg.obj;
1840 request = (MainThreadRequest) ar.userObj;
1841 if (ar.exception == null && ar.result != null) {
1842 request.result = ar.result;
1843 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001844 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001845 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001846 if (ar.result == null) {
1847 loge("getAllowedCarriers: Empty response");
1848 } else if (ar.exception instanceof CommandException) {
1849 loge("getAllowedCarriers: CommandException: " +
1850 ar.exception);
1851 } else {
1852 loge("getAllowedCarriers: Unknown exception");
1853 }
1854 }
arunvoddud7401012022-12-15 16:08:12 +00001855 if (request.argument != null) {
1856 // This is for the implementation of carrierRestrictionStatus.
1857 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1858 Consumer<Integer> callback = callbackInfo.getConsumer();
1859 int callerCarrierId = callbackInfo.getCarrierId();
1860 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1861 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1862 CarrierRestrictionRules carrierRestrictionRules =
1863 (CarrierRestrictionRules) ar.result;
1864 int carrierId = -1;
1865 try {
1866 CarrierIdentifier carrierIdentifier =
1867 carrierRestrictionRules.getAllowedCarriers().get(0);
1868 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1869 carrierIdentifier);
1870 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1871 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1872 }
1873 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1874 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1875 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001876 lockStatus = TelephonyManager
1877 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001878 }
1879 } else {
1880 Rlog.e(LOG_TAG,
1881 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1882 }
1883 callback.accept(lockStatus);
1884 } else {
1885 // This is for the implementation of getAllowedCarriers.
1886 notifyRequester(request);
1887 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001888 break;
1889
Nathan Haroldb3014052017-01-25 15:57:32 -08001890 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1891 ar = (AsyncResult) msg.obj;
1892 request = (MainThreadRequest) ar.userObj;
1893 if (ar.exception == null && ar.result != null) {
1894 request.result = ar.result;
1895 } else {
1896 request.result = new IllegalArgumentException(
1897 "Failed to retrieve Forbidden Plmns");
1898 if (ar.result == null) {
1899 loge("getForbiddenPlmns: Empty response");
1900 } else {
1901 loge("getForbiddenPlmns: Unknown exception");
1902 }
1903 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001904 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001905 break;
1906
1907 case CMD_GET_FORBIDDEN_PLMNS:
1908 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001909 uiccPort = getUiccPortFromRequest(request);
1910 if (uiccPort == null) {
1911 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001912 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001913 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001914 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001915 break;
1916 }
1917 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001918 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001919 if (uiccApp == null) {
1920 loge("getForbiddenPlmns() no app with specified type -- "
1921 + appType);
1922 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001923 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001924 break;
1925 } else {
1926 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1927 + " specified type -- " + appType);
1928 }
1929 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1930 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001931 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001932 break;
1933
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001934 case CMD_SWITCH_SLOTS:
1935 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001936 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001937 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001938 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001939 break;
1940
1941 case EVENT_SWITCH_SLOTS_DONE:
1942 ar = (AsyncResult) msg.obj;
1943 request = (MainThreadRequest) ar.userObj;
1944 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001945 notifyRequester(request);
1946 break;
1947 case CMD_GET_NETWORK_SELECTION_MODE:
1948 request = (MainThreadRequest) msg.obj;
1949 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1950 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1951 break;
1952
1953 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1954 ar = (AsyncResult) msg.obj;
1955 request = (MainThreadRequest) ar.userObj;
1956 if (ar.exception != null) {
1957 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1958 } else {
1959 int mode = ((int[]) ar.result)[0];
1960 if (mode == 0) {
1961 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1962 } else {
1963 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1964 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001965 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001966 notifyRequester(request);
1967 break;
1968 case CMD_GET_CDMA_ROAMING_MODE:
1969 request = (MainThreadRequest) msg.obj;
1970 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1971 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1972 break;
1973 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1974 ar = (AsyncResult) msg.obj;
1975 request = (MainThreadRequest) ar.userObj;
1976 if (ar.exception != null) {
1977 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1978 } else {
1979 request.result = ((int[]) ar.result)[0];
1980 }
1981 notifyRequester(request);
1982 break;
1983 case CMD_SET_CDMA_ROAMING_MODE:
1984 request = (MainThreadRequest) msg.obj;
1985 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1986 int mode = (int) request.argument;
1987 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1988 break;
1989 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1990 ar = (AsyncResult) msg.obj;
1991 request = (MainThreadRequest) ar.userObj;
1992 request.result = ar.exception == null;
1993 notifyRequester(request);
1994 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001995 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1996 request = (MainThreadRequest) msg.obj;
1997 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1998 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1999 break;
2000 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
2001 ar = (AsyncResult) msg.obj;
2002 request = (MainThreadRequest) ar.userObj;
2003 if (ar.exception != null) {
2004 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
2005 } else {
2006 request.result = ((int[]) ar.result)[0];
2007 }
2008 notifyRequester(request);
2009 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07002010 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
2011 request = (MainThreadRequest) msg.obj;
2012 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
2013 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07002014 getPhoneFromRequest(request).setCdmaSubscriptionMode(
2015 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07002016 break;
2017 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
2018 ar = (AsyncResult) msg.obj;
2019 request = (MainThreadRequest) ar.userObj;
2020 request.result = ar.exception == null;
2021 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00002022 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07002023 case CMD_GET_ALL_CELL_INFO:
2024 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07002025 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07002026 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07002027 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07002028 case EVENT_GET_ALL_CELL_INFO_DONE:
2029 ar = (AsyncResult) msg.obj;
2030 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07002031 // If a timeout occurs, the response will be null
2032 request.result = (ar.exception == null && ar.result != null)
2033 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07002034 synchronized (request) {
2035 request.notifyAll();
2036 }
2037 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002038 case CMD_REQUEST_CELL_INFO_UPDATE:
2039 request = (MainThreadRequest) msg.obj;
2040 request.phone.requestCellInfoUpdate(request.workSource,
2041 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
2042 break;
2043 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
2044 ar = (AsyncResult) msg.obj;
2045 request = (MainThreadRequest) ar.userObj;
2046 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
2047 try {
2048 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002049 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07002050 cb.onError(
2051 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
2052 ar.exception.getClass().getName(),
2053 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002054 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002055 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07002056 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002057 } else {
2058 // use the result as returned
2059 cb.onCellInfo((List<CellInfo>) ar.result);
2060 }
2061 } catch (RemoteException re) {
2062 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
2063 }
2064 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08002065 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07002066 request = (MainThreadRequest) msg.obj;
2067 WorkSource ws = (WorkSource) request.argument;
2068 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08002069 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07002070 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08002071 }
2072 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07002073 ar = (AsyncResult) msg.obj;
2074 request = (MainThreadRequest) ar.userObj;
2075 if (ar.exception == null) {
2076 request.result = ar.result;
2077 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08002078 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07002079 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08002080 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07002081 }
2082
2083 synchronized (request) {
2084 request.notifyAll();
2085 }
2086 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08002087 }
chen xu6dac5ab2018-10-26 17:39:23 -07002088 case CMD_MODEM_REBOOT:
2089 request = (MainThreadRequest) msg.obj;
2090 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002091 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07002092 break;
chen xu6dac5ab2018-10-26 17:39:23 -07002093 case EVENT_CMD_MODEM_REBOOT_DONE:
2094 handleNullReturnEvent(msg, "rebootModem");
2095 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002096 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002097 request = (MainThreadRequest) msg.obj;
2098 boolean enable = (boolean) request.argument;
2099 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08002100 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002101 PhoneConfigurationManager.getInstance()
2102 .enablePhone(request.phone, enable, onCompleted);
2103 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002104 }
Michele Berionne5e411512020-11-13 02:36:59 +00002105 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002106 ar = (AsyncResult) msg.obj;
2107 request = (MainThreadRequest) ar.userObj;
2108 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07002109 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08002110 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07002111 if ((boolean) request.result) {
2112 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
2113 updateModemStateMetrics();
2114 } else {
2115 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
2116 + ar.exception);
2117 }
2118 notifyRequester(request);
2119 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002120 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07002121 case CMD_GET_MODEM_STATUS:
2122 request = (MainThreadRequest) msg.obj;
2123 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
2124 PhoneConfigurationManager.getInstance()
2125 .getPhoneStatusFromModem(request.phone, onCompleted);
2126 break;
2127 case EVENT_GET_MODEM_STATUS_DONE:
2128 ar = (AsyncResult) msg.obj;
2129 request = (MainThreadRequest) ar.userObj;
2130 int id = request.phone.getPhoneId();
2131 if (ar.exception == null && ar.result != null) {
2132 request.result = ar.result;
2133 //update the cache as modem status has changed
2134 mPhoneConfigurationManager.addToPhoneStatusCache(id,
2135 (boolean) request.result);
2136 } else {
2137 // Return true if modem status cannot be retrieved. For most cases,
2138 // modem status is on. And for older version modems, GET_MODEM_STATUS
2139 // and disable modem are not supported. Modem is always on.
2140 // TODO: this should be fixed in R to support a third
2141 // status UNKNOWN b/131631629
2142 request.result = true;
2143 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
2144 + ar.exception);
2145 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002146 notifyRequester(request);
2147 break;
Hall Liu73f5d362020-01-20 13:42:00 -08002148 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
2149 request = (MainThreadRequest) msg.obj;
2150 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
2151 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
2152 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
2153 request.phone.setSystemSelectionChannels(args.first, onCompleted);
2154 break;
2155 }
2156 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
2157 ar = (AsyncResult) msg.obj;
2158 request = (MainThreadRequest) ar.userObj;
2159 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
2160 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
2161 args.second.accept(ar.exception == null);
2162 notifyRequester(request);
2163 break;
2164 }
Sarah Chin679c08a2020-11-18 13:39:35 -08002165 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
2166 request = (MainThreadRequest) msg.obj;
2167 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
2168 Phone phone = getPhoneFromRequest(request);
2169 if (phone != null) {
2170 phone.getSystemSelectionChannels(onCompleted);
2171 } else {
2172 loge("getSystemSelectionChannels: No phone object");
2173 request.result = new ArrayList<RadioAccessSpecifier>();
2174 notifyRequester(request);
2175 }
2176 break;
2177 }
2178 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
2179 ar = (AsyncResult) msg.obj;
2180 request = (MainThreadRequest) ar.userObj;
2181 if (ar.exception == null && ar.result != null) {
2182 request.result = ar.result;
2183 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08002184 request.result = new IllegalStateException(
2185 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08002186 if (ar.result == null) {
2187 loge("getSystemSelectionChannels: Empty response");
2188 } else {
2189 loge("getSystemSelectionChannels: Unknown exception");
2190 }
2191 }
2192 notifyRequester(request);
2193 break;
yincheng zhao2737e882019-09-06 17:06:54 -07002194 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
2195 ar = (AsyncResult) msg.obj;
2196 request = (MainThreadRequest) ar.userObj;
2197 if (ar.exception == null && ar.result != null) {
2198 request.result = ar.result;
2199 } else {
2200 request.result = -1;
2201 loge("Failed to set Forbidden Plmns");
2202 if (ar.result == null) {
2203 loge("setForbidenPlmns: Empty response");
2204 } else if (ar.exception != null) {
2205 loge("setForbiddenPlmns: Exception: " + ar.exception);
2206 request.result = -1;
2207 } else {
2208 loge("setForbiddenPlmns: Unknown exception");
2209 }
2210 }
2211 notifyRequester(request);
2212 break;
2213 case CMD_SET_FORBIDDEN_PLMNS:
2214 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002215 uiccPort = getUiccPortFromRequest(request);
2216 if (uiccPort == null) {
2217 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07002218 request.result = -1;
2219 notifyRequester(request);
2220 break;
2221 }
2222 Pair<Integer, List<String>> setFplmnsArgs =
2223 (Pair<Integer, List<String>>) request.argument;
2224 appType = setFplmnsArgs.first;
2225 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002226 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07002227 if (uiccApp == null) {
2228 loge("setForbiddenPlmns: no app with specified type -- " + appType);
2229 request.result = -1;
2230 loge("Failed to get UICC App");
2231 notifyRequester(request);
2232 } else {
2233 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
2234 ((SIMRecords) uiccApp.getIccRecords())
2235 .setForbiddenPlmns(onCompleted, fplmns);
2236 }
yinchengzhao4d163c02019-12-12 15:21:47 -08002237 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07002238 case CMD_ERASE_MODEM_CONFIG:
2239 request = (MainThreadRequest) msg.obj;
2240 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
2241 defaultPhone.eraseModemConfig(onCompleted);
2242 break;
2243 case EVENT_ERASE_MODEM_CONFIG_DONE:
2244 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07002245 break;
zoey chene02881a2019-12-30 16:11:23 +08002246
Kai Shif70f46f2021-03-03 13:59:46 -08002247 case CMD_ERASE_DATA_SHARED_PREFERENCES:
2248 request = (MainThreadRequest) msg.obj;
2249 request.result = defaultPhone.eraseDataInSharedPreferences();
2250 notifyRequester(request);
2251 break;
2252
zoey chene02881a2019-12-30 16:11:23 +08002253 case CMD_CHANGE_ICC_LOCK_PASSWORD:
2254 request = (MainThreadRequest) msg.obj;
2255 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
2256 Pair<String, String> changed = (Pair<String, String>) request.argument;
2257 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
2258 changed.first, changed.second, onCompleted);
2259 break;
2260 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2261 ar = (AsyncResult) msg.obj;
2262 request = (MainThreadRequest) ar.userObj;
2263 if (ar.exception == null) {
2264 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002265 // If the operation is successful, update the PIN storage
2266 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2267 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002268 UiccController.getInstance().getPinStorage()
2269 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002270 } else {
2271 request.result = msg.arg1;
2272 }
2273 notifyRequester(request);
2274 break;
2275
Michele Berionne5e411512020-11-13 02:36:59 +00002276 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002277 request = (MainThreadRequest) msg.obj;
2278 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2279 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2280 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2281 enabled.first, enabled.second, onCompleted);
2282 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002283 }
zoey chene02881a2019-12-30 16:11:23 +08002284 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2285 ar = (AsyncResult) msg.obj;
2286 request = (MainThreadRequest) ar.userObj;
2287 if (ar.exception == null) {
2288 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002289 // If the operation is successful, update the PIN storage
2290 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2291 int phoneId = getPhoneFromRequest(request).getPhoneId();
2292 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002293 UiccController.getInstance().getPinStorage()
2294 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002295 } else {
2296 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2297 }
zoey chene02881a2019-12-30 16:11:23 +08002298 } else {
2299 request.result = msg.arg1;
2300 }
Michele Berionne5e411512020-11-13 02:36:59 +00002301
2302
zoey chene02881a2019-12-30 16:11:23 +08002303 notifyRequester(request);
2304 break;
2305
Peter Wangdafb9ac2020-01-15 14:13:38 -08002306 case MSG_NOTIFY_USER_ACTIVITY:
2307 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002308 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002309 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2310 getDefaultPhone().getContext().sendBroadcastAsUser(
2311 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2312 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002313
2314 case CMD_SET_DATA_THROTTLING: {
2315 request = (MainThreadRequest) msg.obj;
2316 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2317 DataThrottlingRequest dataThrottlingRequest =
2318 (DataThrottlingRequest) request.argument;
2319 Phone phone = getPhoneFromRequest(request);
2320 if (phone != null) {
2321 phone.setDataThrottling(onCompleted,
2322 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2323 dataThrottlingRequest.getCompletionDurationMillis());
2324 } else {
2325 loge("setDataThrottling: No phone object");
2326 request.result =
2327 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2328 notifyRequester(request);
2329 }
2330
2331 break;
2332 }
2333 case EVENT_SET_DATA_THROTTLING_DONE:
2334 ar = (AsyncResult) msg.obj;
2335 request = (MainThreadRequest) ar.userObj;
2336
2337 if (ar.exception == null) {
2338 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2339 } else if (ar.exception instanceof CommandException) {
2340 loge("setDataThrottling: CommandException: " + ar.exception);
2341 CommandException.Error error =
2342 ((CommandException) (ar.exception)).getCommandError();
2343
2344 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2345 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002346 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002347 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2348 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002349 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2350 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002351 } else {
2352 request.result =
2353 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2354 }
2355 } else {
2356 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2357 }
2358 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2359 notifyRequester(request);
2360 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002361
2362 case CMD_SET_SIM_POWER: {
2363 request = (MainThreadRequest) msg.obj;
2364 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2365 request = (MainThreadRequest) msg.obj;
2366 int stateToSet =
2367 ((Pair<Integer, IIntegerConsumer>)
2368 request.argument).first;
2369 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2370 break;
2371 }
2372 case EVENT_SET_SIM_POWER_DONE: {
2373 ar = (AsyncResult) msg.obj;
2374 request = (MainThreadRequest) ar.userObj;
2375 IIntegerConsumer callback =
2376 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2377 if (ar.exception != null) {
2378 loge("setSimPower exception: " + ar.exception);
2379 int errorCode = TelephonyManager.CallForwardingInfoCallback
2380 .RESULT_ERROR_UNKNOWN;
2381 if (ar.exception instanceof CommandException) {
2382 CommandException.Error error =
2383 ((CommandException) (ar.exception)).getCommandError();
2384 if (error == CommandException.Error.SIM_ERR) {
2385 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2386 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2387 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2388 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2389 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2390 } else {
2391 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2392 }
2393 }
2394 try {
2395 callback.accept(errorCode);
2396 } catch (RemoteException e) {
2397 // Ignore if the remote process is no longer available to call back.
2398 Log.w(LOG_TAG, "setSimPower: callback not available.");
2399 }
2400 } else {
2401 try {
2402 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2403 } catch (RemoteException e) {
2404 // Ignore if the remote process is no longer available to call back.
2405 Log.w(LOG_TAG, "setSimPower: callback not available.");
2406 }
2407 }
2408 break;
2409 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002410 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2411 request = (MainThreadRequest) msg.obj;
2412
2413 final Phone phone = getPhoneFromRequest(request);
2414 if (phone == null || phone.getServiceStateTracker() == null) {
2415 request.result = new IllegalStateException("Phone or SST is null");
2416 notifyRequester(request);
2417 break;
2418 }
2419
2420 Pair<Integer, SignalStrengthUpdateRequest> pair =
2421 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2422 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2423 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002424 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002425 request.subId, pair.first /*callingUid*/,
2426 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002427 break;
2428 }
2429 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2430 ar = (AsyncResult) msg.obj;
2431 request = (MainThreadRequest) ar.userObj;
2432 // request.result will be the exception of ar if present, true otherwise.
2433 // Be cautious not to leave result null which will wait() forever
2434 request.result = ar.exception != null ? ar.exception : true;
2435 notifyRequester(request);
2436 break;
2437 }
2438 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2439 request = (MainThreadRequest) msg.obj;
2440
2441 Phone phone = getPhoneFromRequest(request);
2442 if (phone == null || phone.getServiceStateTracker() == null) {
2443 request.result = new IllegalStateException("Phone or SST is null");
2444 notifyRequester(request);
2445 break;
2446 }
2447
2448 Pair<Integer, SignalStrengthUpdateRequest> pair =
2449 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2450 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2451 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002452 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002453 request.subId, pair.first /*callingUid*/,
2454 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002455 break;
2456 }
2457 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2458 ar = (AsyncResult) msg.obj;
2459 request = (MainThreadRequest) ar.userObj;
2460 request.result = ar.exception != null ? ar.exception : true;
2461 notifyRequester(request);
2462 break;
2463 }
Jordan Liu109698e2020-11-24 14:50:34 -08002464
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002465 case CMD_GET_SLICING_CONFIG: {
2466 request = (MainThreadRequest) msg.obj;
2467 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2468 request.phone.getSlicingConfig(onCompleted);
2469 break;
2470 }
2471 case EVENT_GET_SLICING_CONFIG_DONE: {
2472 ar = (AsyncResult) msg.obj;
2473 request = (MainThreadRequest) ar.userObj;
2474 ResultReceiver result = (ResultReceiver) request.argument;
2475
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002476 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002477 Bundle bundle = new Bundle();
2478 int resultCode = 0;
2479 if (ar.exception != null) {
2480 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2481 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002482 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002483 } else if (ar.result == null) {
2484 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002485 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002486 } else {
2487 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002488 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2489 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002490 }
2491
2492 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002493 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002494 }
2495 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2496 result.send(resultCode, bundle);
2497 notifyRequester(request);
2498 break;
2499 }
2500
Sarah Chin71b3a852022-09-28 15:54:19 -07002501 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002502 request = (MainThreadRequest) msg.obj;
2503 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002504 PurchasePremiumCapabilityArgument arg =
2505 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002506 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chinb8218c22023-01-04 13:35:29 -08002507 arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002508 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002509 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002510
Sarah Chin71b3a852022-09-28 15:54:19 -07002511 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002512 ar = (AsyncResult) msg.obj;
2513 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002514 PurchasePremiumCapabilityArgument arg =
2515 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002516 try {
2517 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002518 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002519 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002520 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002521 + ", result= "
2522 + TelephonyManager.convertPurchaseResultToString(result));
2523 } catch (RemoteException e) {
2524 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002525 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002526 + " failed: " + e;
2527 if (DBG) log(logStr);
2528 AnomalyReporter.reportAnomaly(
2529 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2530 }
2531 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002532 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002533
Michele Berionne5e411512020-11-13 02:36:59 +00002534 case CMD_PREPARE_UNATTENDED_REBOOT:
2535 request = (MainThreadRequest) msg.obj;
2536 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002537 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002538 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002539 notifyRequester(request);
2540 break;
2541
Sarah Chineccfbd12023-01-20 19:00:35 -08002542 case CMD_START_SATELLITE_POSITION_UPDATES: {
2543 request = (MainThreadRequest) msg.obj;
2544 onCompleted =
2545 obtainMessage(EVENT_START_SATELLITE_POSITION_UPDATES_DONE, request);
2546 Phone phone = getPhoneFromRequest(request);
2547 if (phone != null) {
2548 phone.startSatellitePositionUpdates(onCompleted);
2549 } else {
2550 loge("startSatellitePositionUpdates: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002551 ((Consumer<Integer>) request.argument).accept(
2552 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Sarah Chineccfbd12023-01-20 19:00:35 -08002553 }
2554 break;
2555 }
2556
2557 case EVENT_START_SATELLITE_POSITION_UPDATES_DONE: {
2558 ar = (AsyncResult) msg.obj;
2559 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002560 int error = getSatelliteError(ar, "startSatellitePositionUpdates", false);
2561 ((Consumer<Integer>) request.argument).accept(error);
Sarah Chineccfbd12023-01-20 19:00:35 -08002562 break;
2563 }
2564
2565 case CMD_STOP_SATELLITE_POSITION_UPDATES: {
2566 request = (MainThreadRequest) msg.obj;
2567 onCompleted =
2568 obtainMessage(EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE, request);
2569 Phone phone = getPhoneFromRequest(request);
2570 if (phone != null) {
2571 phone.stopSatellitePositionUpdates(onCompleted);
2572 } else {
2573 loge("stopSatellitePositionUpdates: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002574 ((Consumer<Integer>) request.argument).accept(
2575 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Sarah Chineccfbd12023-01-20 19:00:35 -08002576 }
2577 break;
2578 }
2579
2580 case EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE: {
2581 ar = (AsyncResult) msg.obj;
2582 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002583 int error = getSatelliteError(ar, "stopSatellitePositionUpdates", false);
2584 ((Consumer<Integer>) request.argument).accept(error);
Sarah Chineccfbd12023-01-20 19:00:35 -08002585 break;
2586 }
2587
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002588 case CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG: {
2589 request = (MainThreadRequest) msg.obj;
2590 onCompleted = obtainMessage(EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE,
2591 request);
2592 Phone phone = getPhoneFromRequest(request);
2593 if (phone != null) {
2594 phone.getMaxCharactersPerSatelliteTextMessage(onCompleted);
2595 } else {
2596 loge("getMaxCharactersPerSatelliteTextMessage: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002597 ((ResultReceiver) request.argument).send(
2598 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002599 }
2600 break;
2601 }
2602
2603 case EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE: {
2604 ar = (AsyncResult) msg.obj;
2605 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002606 int error =
2607 getSatelliteError(ar, "getMaxCharactersPerSatelliteTextMessage", true);
2608 Bundle bundle = new Bundle();
2609 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002610 int maxCharLimit = ((int[]) ar.result)[0];
Sarah Chin503828c2023-02-01 23:54:20 -08002611 if (DBG) log("getMaxCharactersPerSatelliteTextMessage: " + maxCharLimit);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002612 bundle.putInt(SatelliteManager.KEY_MAX_CHARACTERS_PER_SATELLITE_TEXT,
2613 maxCharLimit);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002614 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002615 ((ResultReceiver) request.argument).send(error, bundle);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002616 break;
2617 }
2618
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002619 case CMD_PROVISION_SATELLITE_SERVICE: {
2620 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002621 onCompleted = obtainMessage(EVENT_PROVISION_SATELLITE_SERVICE_DONE, request);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002622 Phone phone = getPhoneFromRequest(request);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002623 ProvisionSatelliteServiceArgument argument =
2624 (ProvisionSatelliteServiceArgument) request.argument;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002625 if (phone != null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002626 handleCmdProvisionSatelliteService(argument, phone, onCompleted);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002627 } else {
2628 loge("provisionSatelliteService: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002629 argument.callback.accept(
2630 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002631 notifyRequester(request);
2632 }
2633 break;
2634 }
2635
2636 case EVENT_PROVISION_SATELLITE_SERVICE_DONE: {
2637 ar = (AsyncResult) msg.obj;
2638 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002639 int errorCode = getSatelliteError(ar, "provisionSatelliteService", false);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002640 handleEventProvisionSatelliteServiceDone(
2641 (ProvisionSatelliteServiceArgument) request.argument, errorCode);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002642 notifyRequester(request);
2643 break;
2644 }
2645
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002646 case CMD_DEPROVISION_SATELLITE_SERVICE: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002647 request = (MainThreadRequest) msg.obj;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002648 onCompleted = obtainMessage(EVENT_DEPROVISION_SATELLITE_SERVICE_DONE, request);
2649 Phone phone = getPhoneFromRequest(request);
2650 ProvisionSatelliteServiceArgument argument =
2651 (ProvisionSatelliteServiceArgument) request.argument;
2652 if (phone != null) {
2653 handleCmdDeprovisionSatelliteService(argument, phone, onCompleted);
2654 } else {
2655 loge("deprovisionSatelliteService: No phone object");
2656 if (argument.callback != null) {
2657 argument.callback.accept(
2658 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
2659 }
2660 notifyRequester(request);
2661 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002662 break;
2663 }
2664
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002665 case EVENT_DEPROVISION_SATELLITE_SERVICE_DONE: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002666 ar = (AsyncResult) msg.obj;
2667 request = (MainThreadRequest) ar.userObj;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002668 int errorCode = getSatelliteError(ar, "deprovisionSatelliteService", false);
2669 handleEventDeprovisionSatelliteServiceDone(
2670 (ProvisionSatelliteServiceArgument) request.argument, errorCode);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002671 notifyRequester(request);
2672 break;
2673 }
2674
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002675 case CMD_SET_SATELLITE_ENABLED: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002676 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002677 onCompleted = obtainMessage(EVENT_SET_SATELLITE_ENABLED_DONE, request);
2678 Pair<Boolean, Consumer<Integer>> argument =
2679 (Pair<Boolean, Consumer<Integer>>) request.argument;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002680 Phone phone = getPhoneFromRequest(request);
2681 if (phone != null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002682 boolean enable = argument.first.booleanValue();
2683 phone.setSatellitePower(onCompleted, enable);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002684 } else {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002685 loge("setSatelliteEnabled: No phone object");
2686 argument.second.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002687 notifyRequester(request);
2688 }
2689 break;
2690 }
2691
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002692 case EVENT_SET_SATELLITE_ENABLED_DONE: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002693 ar = (AsyncResult) msg.obj;
2694 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002695 Pair<Boolean, Consumer<Integer>> argument =
2696 (Pair<Boolean, Consumer<Integer>>) request.argument;
2697 int error = getSatelliteError(ar, "setSatelliteEnabled", false);
2698 argument.second.accept(error);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002699 break;
2700 }
2701
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002702 case CMD_IS_SATELLITE_ENABLED: {
Sarah Chin503828c2023-02-01 23:54:20 -08002703 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002704 onCompleted = obtainMessage(EVENT_IS_SATELLITE_ENABLED_DONE, request);
Sarah Chin503828c2023-02-01 23:54:20 -08002705 Phone phone = getPhoneFromRequest(request);
2706 if (phone != null) {
2707 phone.isSatellitePowerOn(onCompleted);
2708 } else {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002709 loge("isSatelliteEnabled: No phone object");
2710 ((ResultReceiver) request.argument).send(
2711 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002712 }
2713 break;
2714 }
2715
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002716 case EVENT_IS_SATELLITE_ENABLED_DONE: {
Sarah Chin503828c2023-02-01 23:54:20 -08002717 ar = (AsyncResult) msg.obj;
2718 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002719 int error = getSatelliteError(ar, "isSatelliteEnabled", true);
2720 Bundle bundle = new Bundle();
2721 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
2722 boolean enabled = ((int[]) ar.result)[0] == 1;
2723 if (DBG) log("isSatelliteEnabled: " + enabled);
2724 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_ENABLED, enabled);
Sarah Chin503828c2023-02-01 23:54:20 -08002725 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002726 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002727 break;
2728 }
2729
2730 case CMD_IS_SATELLITE_SUPPORTED: {
2731 request = (MainThreadRequest) msg.obj;
2732 onCompleted = obtainMessage(EVENT_IS_SATELLITE_SUPPORTED_DONE, request);
2733 Phone phone = getPhoneFromRequest(request);
2734 if (phone != null) {
2735 phone.isSatelliteSupported(onCompleted);
2736 } else {
2737 loge("isSatelliteSupported: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002738 ((ResultReceiver) request.argument).send(
2739 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002740 }
2741 break;
2742 }
2743
2744 case EVENT_IS_SATELLITE_SUPPORTED_DONE: {
2745 ar = (AsyncResult) msg.obj;
2746 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002747 int error = getSatelliteError(ar, "isSatelliteSupported", true);
2748 Bundle bundle = new Bundle();
2749 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
2750 boolean supported = ((int[]) ar.result)[0] == 1;
2751 if (DBG) log("isSatelliteSupported: " + supported);
2752 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, supported);
Thomas Nguyene77de6d2023-02-10 17:42:43 -08002753 synchronized (mIsSatelliteSupportedLock) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002754 mIsSatelliteSupported = supported;
2755 }
2756 } else {
2757 synchronized (mIsSatelliteSupportedLock) {
2758 mIsSatelliteSupported = null;
Thomas Nguyene77de6d2023-02-10 17:42:43 -08002759 }
Sarah Chin503828c2023-02-01 23:54:20 -08002760 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002761 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002762 break;
2763 }
2764
2765 case CMD_GET_SATELLITE_CAPABILITIES: {
2766 request = (MainThreadRequest) msg.obj;
2767 onCompleted = obtainMessage(EVENT_GET_SATELLITE_CAPABILITIES_DONE, request);
2768 Phone phone = getPhoneFromRequest(request);
2769 if (phone != null) {
2770 phone.getSatelliteCapabilities(onCompleted);
2771 } else {
2772 loge("getSatelliteCapabilities: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002773 ((ResultReceiver) request.argument).send(
2774 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002775 }
2776 break;
2777 }
2778
2779 case EVENT_GET_SATELLITE_CAPABILITIES_DONE: {
2780 ar = (AsyncResult) msg.obj;
2781 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002782 int error = getSatelliteError(ar, "getSatelliteCapabilities", true);
2783 Bundle bundle = new Bundle();
2784 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
Sarah Chin503828c2023-02-01 23:54:20 -08002785 SatelliteCapabilities capabilities = (SatelliteCapabilities) ar.result;
2786 if (DBG) log("getSatelliteCapabilities: " + capabilities);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002787 bundle.putParcelable(SatelliteManager.KEY_SATELLITE_CAPABILITIES,
2788 capabilities);
Sarah Chin503828c2023-02-01 23:54:20 -08002789 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002790 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002791 break;
2792 }
2793
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +00002794 case CMD_POLL_PENDING_SATELLITE_DATAGRAMS: {
2795 request = (MainThreadRequest) msg.obj;
2796 onCompleted = obtainMessage(EVENT_POLL_PENDING_SATELLITE_DATAGRAMS_DONE,
2797 request);
2798 Phone phone = getPhoneFromRequest(request);
2799 if (phone != null) {
2800 phone.pollPendingSatelliteDatagrams(onCompleted);
2801 } else {
2802 loge("pollPendingSatelliteDatagrams: No phone object");
2803 request.result = SatelliteManager
2804 .SATELLITE_INVALID_TELEPHONY_STATE;
2805 notifyRequester(request);
2806 }
2807 break;
2808 }
2809
2810 case EVENT_POLL_PENDING_SATELLITE_DATAGRAMS_DONE: {
2811 ar = (AsyncResult) msg.obj;
2812 request = (MainThreadRequest) ar.userObj;
2813 if (ar.exception != null) {
2814 request.result = SatelliteManager.SATELLITE_SERVICE_ERROR;
2815 if (ar.exception instanceof CommandException) {
2816 CommandException.Error error =
2817 ((CommandException) (ar.exception)).getCommandError();
2818 request.result = RILUtils.convertToSatelliteError(error);
2819 loge("pollPendingSatelliteDatagrams: "
2820 + "CommandException: " + ar.exception);
2821 } else {
2822 loge("pollPendingSatelliteDatagrams: "
2823 + "unknown exception:" + ar.exception);
2824 }
2825 } else if (ar.result == null) {
2826 request.result = SatelliteManager
2827 .SATELLITE_INVALID_TELEPHONY_STATE;
2828 loge("pollPendingSatelliteDatagrams: result is null");
2829 } else {
2830 request.result = SatelliteManager.SATELLITE_ERROR_NONE;
2831 }
2832 notifyRequester(request);
2833 break;
2834 }
2835
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +00002836 case CMD_SEND_SATELLITE_DATAGRAM: {
2837 request = (MainThreadRequest) msg.obj;
2838 onCompleted =
2839 obtainMessage(EVENT_SEND_SATELLITE_DATAGRAM_DONE, request);
2840 Phone phone = getPhoneFromRequest(request);
2841 SendSatelliteDatagramArgument argument =
2842 (SendSatelliteDatagramArgument) request.argument;
2843 if (phone != null) {
2844 phone.sendSatelliteDatagram(onCompleted, argument.datagram);
2845 } else {
2846 loge("sendSatelliteDatagram: No phone object");
2847 argument.callback
2848 .accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
2849 }
2850 break;
2851 }
2852
2853 case EVENT_SEND_SATELLITE_DATAGRAM_DONE: {
2854 ar = (AsyncResult) msg.obj;
2855 request = (MainThreadRequest) ar.userObj;
2856 int error = getSatelliteError(ar, "sendSatelliteDatagram",
2857 false);
2858 SendSatelliteDatagramArgument argument =
2859 (SendSatelliteDatagramArgument) request.argument;
2860 argument.callback.accept(error);
2861 break;
2862 }
2863
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002864 default:
2865 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2866 break;
2867 }
2868 }
Jake Hambye994d462014-02-03 13:10:13 -08002869
Pengquan Menga1bb6272018-09-06 09:59:22 -07002870 private void notifyRequester(MainThreadRequest request) {
2871 synchronized (request) {
2872 request.notifyAll();
2873 }
2874 }
2875
Jake Hambye994d462014-02-03 13:10:13 -08002876 private void handleNullReturnEvent(Message msg, String command) {
2877 AsyncResult ar = (AsyncResult) msg.obj;
2878 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2879 if (ar.exception == null) {
2880 request.result = true;
2881 } else {
2882 request.result = false;
2883 if (ar.exception instanceof CommandException) {
2884 loge(command + ": CommandException: " + ar.exception);
2885 } else {
2886 loge(command + ": Unknown exception");
2887 }
2888 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002889 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002890 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002891 }
2892
2893 /**
2894 * Posts the specified command to be executed on the main thread,
2895 * waits for the request to complete, and returns the result.
2896 * @see #sendRequestAsync
2897 */
2898 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002899 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2900 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002901 }
2902
2903 /**
2904 * Posts the specified command to be executed on the main thread,
2905 * waits for the request to complete, and returns the result.
2906 * @see #sendRequestAsync
2907 */
2908 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2909 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002910 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002911 }
2912
2913 /**
2914 * Posts the specified command to be executed on the main thread,
2915 * waits for the request to complete, and returns the result.
2916 * @see #sendRequestAsync
2917 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002918 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002919 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2920 }
2921
2922 /**
2923 * Posts the specified command to be executed on the main thread,
2924 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2925 * if not timeout or null otherwise.
2926 * @see #sendRequestAsync
2927 */
2928 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2929 long timeoutInMs) {
2930 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002931 }
2932
2933 /**
2934 * Posts the specified command to be executed on the main thread,
2935 * waits for the request to complete, and returns the result.
2936 * @see #sendRequestAsync
2937 */
Nathan Harold92bed182018-10-12 18:16:49 -07002938 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002939 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002940 }
2941
2942 /**
2943 * Posts the specified command to be executed on the main thread,
2944 * waits for the request to complete, and returns the result.
2945 * @see #sendRequestAsync
2946 */
2947 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002948 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2949 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002950 }
2951
2952 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002953 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2954 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2955 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002956 * @see #sendRequestAsync
2957 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002958 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2959 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002960 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2961 throw new RuntimeException("This method will deadlock if called from the main thread.");
2962 }
2963
Nathan Harold92bed182018-10-12 18:16:49 -07002964 MainThreadRequest request = null;
2965 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2966 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2967 } else if (phone != null) {
2968 request = new MainThreadRequest(argument, phone, workSource);
2969 } else {
2970 request = new MainThreadRequest(argument, subId, workSource);
2971 }
2972
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002973 Message msg = mMainThreadHandler.obtainMessage(command, request);
2974 msg.sendToTarget();
2975
Rambo Wang0f050d82021-02-12 11:43:36 -08002976
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002977 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002978 if (timeoutInMs >= 0) {
2979 // Wait for at least timeoutInMs before returning null request result
2980 long now = SystemClock.elapsedRealtime();
2981 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002982 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002983 try {
2984 request.wait(deadline - now);
2985 } catch (InterruptedException e) {
2986 // Do nothing, go back and check if request is completed or timeout
2987 } finally {
2988 now = SystemClock.elapsedRealtime();
2989 }
2990 }
2991 } else {
2992 // Wait for the request to complete
2993 while (request.result == null) {
2994 try {
2995 request.wait();
2996 } catch (InterruptedException e) {
2997 // Do nothing, go back and wait until the request is complete
2998 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002999 }
3000 }
3001 }
Rambo Wang0f050d82021-02-12 11:43:36 -08003002 if (request.result == null) {
3003 Log.wtf(LOG_TAG,
3004 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
3005 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003006 return request.result;
3007 }
3008
3009 /**
3010 * Asynchronous ("fire and forget") version of sendRequest():
3011 * Posts the specified command to be executed on the main thread, and
3012 * returns immediately.
3013 * @see #sendRequest
3014 */
3015 private void sendRequestAsync(int command) {
3016 mMainThreadHandler.sendEmptyMessage(command);
3017 }
3018
3019 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003020 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003021 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003022 */
3023 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003024 sendRequestAsync(command, argument, null, null);
3025 }
3026
3027 /**
3028 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
3029 * @see {@link #sendRequest(int,Object)}
3030 */
3031 private void sendRequestAsync(
3032 int command, Object argument, Phone phone, WorkSource workSource) {
3033 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003034 Message msg = mMainThreadHandler.obtainMessage(command, request);
3035 msg.sendToTarget();
3036 }
3037
3038 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003039 * Initialize the singleton PhoneInterfaceManager instance.
3040 * This is only done once, at startup, from PhoneApp.onCreate().
3041 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003042 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003043 synchronized (PhoneInterfaceManager.class) {
3044 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003045 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003046 } else {
3047 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
3048 }
3049 return sInstance;
3050 }
3051 }
3052
3053 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00003054 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003055 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003056 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00003057 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07003058 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003059 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07003060 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003061 mMainThreadHandler = new MainThreadHandler();
Jack Yue37dd262022-12-16 11:53:37 -08003062 if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) {
3063 mSubscriptionController = SubscriptionController.getInstance();
3064 } else {
3065 mSubscriptionController = null;
3066 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003067 mTelephonySharedPreferences =
3068 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07003069 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07003070 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08003071 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08003072 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07003073 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003074 publish();
arunvoddud7401012022-12-15 16:08:12 +00003075 CarrierAllowListInfo.loadInstance(mApp);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08003076 mSatelliteSupportedReceiver = new ResultReceiver(mMainThreadHandler) {
3077 @Override
3078 protected void onReceiveResult(int resultCode, Bundle resultData) {
3079 if (resultCode == SatelliteManager.SATELLITE_ERROR_NONE
3080 && resultData.containsKey(SatelliteManager.KEY_SATELLITE_SUPPORTED)) {
3081 synchronized (mIsSatelliteSupportedLock) {
3082 mIsSatelliteSupported = resultData.getBoolean(
3083 SatelliteManager.KEY_SATELLITE_SUPPORTED);
3084 }
3085 } else {
3086 synchronized (mIsSatelliteSupportedLock) {
3087 mIsSatelliteSupported = null;
3088 }
3089 }
3090 }
3091 };
3092 requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
3093 mSatelliteSupportedReceiver);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003094 }
3095
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003096 @VisibleForTesting
3097 public SharedPreferences getSharedPreferences() {
3098 return mTelephonySharedPreferences;
3099 }
3100
Gil Cukierman92cc7db2023-01-06 19:25:53 +00003101 /**
3102 * Get the default phone for this device.
3103 */
3104 @VisibleForTesting
3105 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003106 Phone thePhone = getPhone(getDefaultSubscription());
3107 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
3108 }
3109
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003110 private void publish() {
3111 if (DBG) log("publish: " + this);
3112
Peter Wangc035ce42020-01-08 21:00:22 -08003113 TelephonyFrameworkInitializer
3114 .getTelephonyServiceManager()
3115 .getTelephonyServiceRegisterer()
3116 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003117 }
3118
Stuart Scott584921c2015-01-15 17:10:34 -08003119 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08003120 if (request.phone != null) {
3121 return request.phone;
3122 } else {
3123 return getPhoneFromSubId(request.subId);
3124 }
3125 }
3126
3127 private Phone getPhoneFromSubId(int subId) {
3128 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
3129 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08003130 }
3131
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00003132 /**
3133 * Get phone object associated with a subscription.
3134 * Return default phone if phone object associated with subscription is null
3135 * @param subId - subscriptionId
3136 * @return phone object associated with a subscription or default phone if null.
3137 */
3138 private Phone getPhoneFromSubIdOrDefault(int subId) {
3139 Phone phone = getPhoneFromSubId(subId);
3140 if (phone == null) {
3141 phone = getDefaultPhone();
3142 }
3143 return phone;
3144 }
3145
Rambo Wange53e07d2022-05-10 13:01:13 -07003146 @Nullable
3147 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003148 Phone phone = getPhoneFromRequest(request);
3149 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00003150 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003151 }
3152
Wink Saville36469e72014-06-11 15:17:00 -07003153 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07003154 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08003155 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07003156 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003157
Kai Shif70f46f2021-03-03 13:59:46 -08003158 private void sendEraseModemConfig(@NonNull Phone phone) {
3159 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
3160 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
3161 }
3162
3163 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
3164 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
3165 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07003166 }
3167
Peter Wang44b186e2020-01-13 23:33:09 -08003168 private boolean isImsAvailableOnDevice() {
3169 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
3170 if (pm == null) {
3171 // For some reason package manger is not available.. This will fail internally anyway,
3172 // so do not throw error and allow.
3173 return true;
3174 }
3175 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
3176 }
3177
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003178 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003179 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07003180 }
3181
Wink Savilleb564aae2014-10-23 10:18:09 -07003182 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003183 if (DBG) log("dial: " + number);
3184 // No permission check needed here: This is just a wrapper around the
3185 // ACTION_DIAL intent, which is available to any app since it puts up
3186 // the UI before it does anything.
3187
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003188 final long identity = Binder.clearCallingIdentity();
3189 try {
3190 String url = createTelUrl(number);
3191 if (url == null) {
3192 return;
3193 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003194
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003195 // PENDING: should we just silently fail if phone is offhook or ringing?
3196 PhoneConstants.State state = mCM.getState(subId);
3197 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
3198 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
3199 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3200 mApp.startActivity(intent);
3201 }
3202 } finally {
3203 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003204 }
3205 }
3206
3207 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003208 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07003209 }
3210
Wink Savilleb564aae2014-10-23 10:18:09 -07003211 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003212 if (DBG) log("call: " + number);
3213
3214 // This is just a wrapper around the ACTION_CALL intent, but we still
3215 // need to do a permission check since we're calling startActivity()
3216 // from the context of the phone app.
3217 enforceCallPermission();
3218
Jordan Liu1617b712019-07-10 15:06:26 -07003219 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003220 != AppOpsManager.MODE_ALLOWED) {
3221 return;
3222 }
3223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003224 final long identity = Binder.clearCallingIdentity();
3225 try {
3226 String url = createTelUrl(number);
3227 if (url == null) {
3228 return;
3229 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003230
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003231 boolean isValid = false;
3232 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
3233 if (slist != null) {
3234 for (SubscriptionInfo subInfoRecord : slist) {
3235 if (subInfoRecord.getSubscriptionId() == subId) {
3236 isValid = true;
3237 break;
3238 }
Wink Saville3ab207e2014-11-20 13:07:20 -08003239 }
Wink Saville08874612014-08-31 19:19:58 -07003240 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003241 if (!isValid) {
3242 return;
3243 }
Wink Saville08874612014-08-31 19:19:58 -07003244
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003245 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
3246 intent.putExtra(SUBSCRIPTION_KEY, subId);
3247 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3248 mApp.startActivity(intent);
3249 } finally {
3250 Binder.restoreCallingIdentity(identity);
3251 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003252 }
3253
Wink Savilleb564aae2014-10-23 10:18:09 -07003254 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003255 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07003256 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
3257 }
3258
Wink Savilleb564aae2014-10-23 10:18:09 -07003259 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003260 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07003261 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
3262 }
3263
Wink Savilleb564aae2014-10-23 10:18:09 -07003264 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003265 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003266
3267 final long identity = Binder.clearCallingIdentity();
3268 try {
Michele Berionne5e411512020-11-13 02:36:59 +00003269 Phone phone = getPhone(subId);
3270 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003271 checkSimPin.start();
3272 return checkSimPin.unlockSim(null, pin);
3273 } finally {
3274 Binder.restoreCallingIdentity(identity);
3275 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003276 }
3277
Wink Savilleb564aae2014-10-23 10:18:09 -07003278 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003279 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003280
3281 final long identity = Binder.clearCallingIdentity();
3282 try {
Michele Berionne5e411512020-11-13 02:36:59 +00003283 Phone phone = getPhone(subId);
3284 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003285 checkSimPuk.start();
3286 return checkSimPuk.unlockSim(puk, pin);
3287 } finally {
3288 Binder.restoreCallingIdentity(identity);
3289 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003290 }
3291
3292 /**
Wink Saville9de0f752013-10-22 19:04:03 -07003293 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003294 * a synchronous one.
3295 */
3296 private static class UnlockSim extends Thread {
3297
3298 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00003299 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003300
3301 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07003302 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
3303 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003304
3305 // For replies from SimCard interface
3306 private Handler mHandler;
3307
3308 // For async handler to identify request type
3309 private static final int SUPPLY_PIN_COMPLETE = 100;
3310
Michele Berionne5e411512020-11-13 02:36:59 +00003311 UnlockSim(int phoneId, IccCard simCard) {
3312 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003313 mSimCard = simCard;
3314 }
3315
3316 @Override
3317 public void run() {
3318 Looper.prepare();
3319 synchronized (UnlockSim.this) {
3320 mHandler = new Handler() {
3321 @Override
3322 public void handleMessage(Message msg) {
3323 AsyncResult ar = (AsyncResult) msg.obj;
3324 switch (msg.what) {
3325 case SUPPLY_PIN_COMPLETE:
3326 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
3327 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07003328 mRetryCount = msg.arg1;
3329 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08003330 CommandException.Error error = null;
3331 if (ar.exception instanceof CommandException) {
3332 error = ((CommandException) (ar.exception))
3333 .getCommandError();
3334 }
3335 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07003336 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08003337 } else if (error == CommandException.Error.ABORTED) {
3338 /* When UiccCardApp dispose, handle message and return
3339 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08003340 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07003341 } else {
3342 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
3343 }
3344 } else {
3345 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
3346 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003347 mDone = true;
3348 UnlockSim.this.notifyAll();
3349 }
3350 break;
3351 }
3352 }
3353 };
3354 UnlockSim.this.notifyAll();
3355 }
3356 Looper.loop();
3357 }
3358
3359 /*
3360 * Use PIN or PUK to unlock SIM card
3361 *
3362 * If PUK is null, unlock SIM card with PIN
3363 *
3364 * If PUK is not null, unlock SIM card with PUK and set PIN code
3365 */
Wink Saville9de0f752013-10-22 19:04:03 -07003366 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003367
3368 while (mHandler == null) {
3369 try {
3370 wait();
3371 } catch (InterruptedException e) {
3372 Thread.currentThread().interrupt();
3373 }
3374 }
3375 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
3376
3377 if (puk == null) {
3378 mSimCard.supplyPin(pin, callback);
3379 } else {
3380 mSimCard.supplyPuk(puk, pin, callback);
3381 }
3382
3383 while (!mDone) {
3384 try {
3385 Log.d(LOG_TAG, "wait for done");
3386 wait();
3387 } catch (InterruptedException e) {
3388 // Restore the interrupted status
3389 Thread.currentThread().interrupt();
3390 }
3391 }
3392 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07003393 int[] resultArray = new int[2];
3394 resultArray[0] = mResult;
3395 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00003396
3397 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00003398 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00003399 }
3400
Wink Saville9de0f752013-10-22 19:04:03 -07003401 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003402 }
3403 }
3404
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003405 /**
3406 * This method has been removed due to privacy and stability concerns.
3407 */
3408 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003409 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003410 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
3411 return;
Wink Saville36469e72014-06-11 15:17:00 -07003412 }
3413
Nathan Harold1f889d82020-06-04 17:05:26 -07003414 @Override
3415 public void updateServiceLocationWithPackageName(String callingPackage) {
3416 mApp.getSystemService(AppOpsManager.class)
3417 .checkPackage(Binder.getCallingUid(), callingPackage);
3418
Nathan Haroldf096d982020-11-18 17:18:06 -08003419 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07003420 if (targetSdk > android.os.Build.VERSION_CODES.R) {
3421 // Callers targeting S have no business invoking this method.
3422 return;
3423 }
3424
3425 LocationAccessPolicy.LocationPermissionResult locationResult =
3426 LocationAccessPolicy.checkLocationPermission(mApp,
3427 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3428 .setCallingPackage(callingPackage)
3429 .setCallingFeatureId(null)
3430 .setCallingPid(Binder.getCallingPid())
3431 .setCallingUid(Binder.getCallingUid())
3432 .setMethod("updateServiceLocation")
3433 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3434 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3435 .build());
3436 // Apps that lack location permission have no business calling this method;
3437 // however, because no permission was declared in the public API, denials must
3438 // all be "soft".
3439 switch (locationResult) {
3440 case DENIED_HARD: /* fall through */
3441 case DENIED_SOFT:
3442 return;
3443 }
3444
3445 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003446 final long identity = Binder.clearCallingIdentity();
3447 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07003448 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003449 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07003450 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003451 }
3452 } finally {
3453 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003454 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003455 }
3456
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003457 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003458 @Override
3459 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003460 return isRadioOnWithFeature(callingPackage, null);
3461 }
3462
3463
3464 @Override
3465 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
3466 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
3467 callingFeatureId);
3468 }
3469
3470 @Deprecated
3471 @Override
3472 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
3473 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07003474 }
3475
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003476 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003477 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
3478 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003479 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003480 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003481 return false;
3482 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003483
3484 final long identity = Binder.clearCallingIdentity();
3485 try {
3486 return isRadioOnForSubscriber(subId);
3487 } finally {
3488 Binder.restoreCallingIdentity(identity);
3489 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003490 }
3491
3492 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003493 final long identity = Binder.clearCallingIdentity();
3494 try {
3495 final Phone phone = getPhone(subId);
3496 if (phone != null) {
3497 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
3498 } else {
3499 return false;
3500 }
3501 } finally {
3502 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003503 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003504 }
3505
3506 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003507 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003508 }
Wink Saville36469e72014-06-11 15:17:00 -07003509
Wink Savilleb564aae2014-10-23 10:18:09 -07003510 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003511 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003512
3513 final long identity = Binder.clearCallingIdentity();
3514 try {
3515 final Phone phone = getPhone(subId);
3516 if (phone != null) {
3517 phone.setRadioPower(!isRadioOnForSubscriber(subId));
3518 }
3519 } finally {
3520 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003521 }
Wink Saville36469e72014-06-11 15:17:00 -07003522 }
3523
3524 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003525 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07003526 }
3527
Wink Savilleb564aae2014-10-23 10:18:09 -07003528 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07003529 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003530
3531 final long identity = Binder.clearCallingIdentity();
3532 try {
3533 final Phone phone = getPhone(subId);
3534 if (phone == null) {
3535 return false;
3536 }
3537 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
3538 toggleRadioOnOffForSubscriber(subId);
3539 }
3540 return true;
3541 } finally {
3542 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003543 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003544 }
Wink Saville36469e72014-06-11 15:17:00 -07003545
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003546 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08003547 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003548 /*
3549 * If any of the Radios are available, it will need to be
3550 * shutdown. So return true if any Radio is available.
3551 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003552 final long identity = Binder.clearCallingIdentity();
3553 try {
3554 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3555 Phone phone = PhoneFactory.getPhone(i);
3556 if (phone != null && phone.isRadioAvailable()) return true;
3557 }
3558 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3559 return false;
3560 } finally {
3561 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003562 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003563 }
3564
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003565 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003566 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003567 enforceModifyPermission();
3568
3569 final long identity = Binder.clearCallingIdentity();
3570 try {
3571 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3572 logv("Shutting down Phone " + i);
3573 shutdownRadioUsingPhoneId(i);
3574 }
3575 } finally {
3576 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003577 }
3578 }
3579
3580 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003581 Phone phone = PhoneFactory.getPhone(phoneId);
3582 if (phone != null && phone.isRadioAvailable()) {
3583 phone.shutdownRadio();
3584 }
3585 }
3586
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003587 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003588 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003589
Ling Ma83dc5ea2023-01-12 15:06:04 -08003590 if (!turnOn) {
3591 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3592 }
3593
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003594 final long identity = Binder.clearCallingIdentity();
3595 try {
3596 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3597 if (defaultPhone != null) {
3598 defaultPhone.setRadioPower(turnOn);
3599 return true;
3600 } else {
3601 loge("There's no default phone.");
3602 return false;
3603 }
3604 } finally {
3605 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003606 }
Wink Saville36469e72014-06-11 15:17:00 -07003607 }
3608
Wink Savilleb564aae2014-10-23 10:18:09 -07003609 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003610 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003611
Ling Ma83dc5ea2023-01-12 15:06:04 -08003612 if (!turnOn) {
3613 log("setRadioPowerForSubscriber off: subId=" + subId
3614 + ",callingPackage=" + getCurrentPackageName());
3615 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003616 final long identity = Binder.clearCallingIdentity();
3617 try {
3618 final Phone phone = getPhone(subId);
3619 if (phone != null) {
3620 phone.setRadioPower(turnOn);
3621 return true;
3622 } else {
3623 return false;
3624 }
3625 } finally {
3626 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003627 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003628 }
3629
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003630 /**
3631 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3632 * no reason to power it off. When any of the voters want to power it off, it will be turned
3633 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3634 * powering it off, and these radio off votes will be cleared.
3635 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3636 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3637 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3638 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3639 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3640 * check its vote.
3641 *
3642 * @param subId The subscription ID.
3643 * @param reason The reason for powering off radio.
3644 * @return true on success and false on failure.
3645 */
3646 public boolean requestRadioPowerOffForReason(int subId,
3647 @TelephonyManager.RadioPowerReason int reason) {
3648 enforceModifyPermission();
3649
Ling Ma83dc5ea2023-01-12 15:06:04 -08003650 log("requestRadioPowerOffForReason: subId=" + subId
3651 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003652 final long identity = Binder.clearCallingIdentity();
3653 try {
3654 final Phone phone = getPhone(subId);
3655 if (phone != null) {
3656 phone.setRadioPowerForReason(false, reason);
3657 return true;
3658 } else {
3659 return false;
3660 }
3661 } finally {
3662 Binder.restoreCallingIdentity(identity);
3663 }
3664 }
3665
3666 /**
3667 * Remove the vote on powering off the radio for a reason, as requested by
3668 * {@link requestRadioPowerOffForReason}.
3669 *
3670 * @param subId The subscription ID.
3671 * @param reason The reason for powering off radio.
3672 * @return true on success and false on failure.
3673 */
3674 public boolean clearRadioPowerOffForReason(int subId,
3675 @TelephonyManager.RadioPowerReason int reason) {
3676 enforceModifyPermission();
3677
3678 final long identity = Binder.clearCallingIdentity();
3679 try {
3680 final Phone phone = getPhone(subId);
3681 if (phone != null) {
3682 phone.setRadioPowerForReason(true, reason);
3683 return true;
3684 } else {
3685 return false;
3686 }
3687 } finally {
3688 Binder.restoreCallingIdentity(identity);
3689 }
3690 }
3691
3692 /**
3693 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3694 *
3695 * @param subId The subscription ID.
3696 * @param callingPackage The package making the call.
3697 * @param callingFeatureId The feature in the package.
3698 * @return List of reasons for powering off radio.
3699 */
3700 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3701 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3702
3703 final long identity = Binder.clearCallingIdentity();
3704 List result = new ArrayList();
3705 try {
3706 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3707 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3708 return result;
3709 }
3710
3711 final Phone phone = getPhone(subId);
3712 if (phone != null) {
3713 result.addAll(phone.getRadioPowerOffReasons());
3714 }
3715 } finally {
3716 Binder.restoreCallingIdentity(identity);
3717 }
3718 return result;
3719 }
3720
Wink Saville36469e72014-06-11 15:17:00 -07003721 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003722 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003723 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003724 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003725
3726 final long identity = Binder.clearCallingIdentity();
3727 try {
Jack Yu285100e2022-12-02 22:48:35 -08003728 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003729 final Phone phone = getPhone(subId);
3730 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003731 phone.getDataSettingsManager().setDataEnabled(
3732 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003733 return true;
3734 } else {
3735 return false;
3736 }
3737 } finally {
3738 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003739 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003740 }
3741
Wink Saville36469e72014-06-11 15:17:00 -07003742 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003743 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003744 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003745 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003746
3747 final long identity = Binder.clearCallingIdentity();
3748 try {
Jack Yu285100e2022-12-02 22:48:35 -08003749 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003750 final Phone phone = getPhone(subId);
3751 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003752 phone.getDataSettingsManager().setDataEnabled(
3753 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003754 return true;
3755 } else {
3756 return false;
3757 }
3758 } finally {
3759 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003760 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003761 }
3762
Sanket Padawe356d7632015-06-22 14:03:32 -07003763 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003764 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003765 final long identity = Binder.clearCallingIdentity();
3766 try {
3767 final Phone phone = getPhone(subId);
3768 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003769 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003770 } else {
3771 return false;
3772 }
3773 } finally {
3774 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003775 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003776 }
3777
3778 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003779 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003780 }
3781
pkanwarae03a6b2016-11-06 20:37:09 -08003782 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003783 enforceCallPermission();
3784
3785 final long identity = Binder.clearCallingIdentity();
3786 try {
3787 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3788 return;
3789 }
3790 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3791 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3792 } finally {
3793 Binder.restoreCallingIdentity(identity);
3794 }
pkanwar32d516d2016-10-14 19:37:38 -07003795 };
3796
Wink Savilleb564aae2014-10-23 10:18:09 -07003797 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003798 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003799
3800 final long identity = Binder.clearCallingIdentity();
3801 try {
3802 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3803 return false;
3804 }
3805 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3806 } finally {
3807 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003809 }
3810
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003811 /**
3812 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3813 * tag on getCallState Binder call.
3814 */
3815 @Deprecated
3816 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003817 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003818 if (CompatChanges.isChangeEnabled(
3819 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3820 Binder.getCallingUid())) {
3821 // Do not allow this API to be called on API version 31+, it should only be
3822 // called on old apps using this Binder call directly.
3823 throw new SecurityException("This method can only be used for applications "
3824 + "targeting API version 30 or less.");
3825 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003826 final long identity = Binder.clearCallingIdentity();
3827 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003828 Phone phone = getPhone(getDefaultSubscription());
3829 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3830 PhoneConstantConversions.convertCallState(phone.getState());
3831 } finally {
3832 Binder.restoreCallingIdentity(identity);
3833 }
3834 }
3835
3836 @Override
3837 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3838 if (CompatChanges.isChangeEnabled(
3839 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3840 Binder.getCallingUid())) {
3841 // Check READ_PHONE_STATE for API version 31+
3842 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3843 featureId, "getCallStateForSubscription")) {
3844 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3845 + "targeting API level 31+.");
3846 }
3847 }
3848 final long identity = Binder.clearCallingIdentity();
3849 try {
3850 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003851 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3852 PhoneConstantConversions.convertCallState(phone.getState());
3853 } finally {
3854 Binder.restoreCallingIdentity(identity);
3855 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003856 }
3857
Sanket Padawe356d7632015-06-22 14:03:32 -07003858 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003859 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003860 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003861 }
3862
3863 @Override
3864 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003865 final long identity = Binder.clearCallingIdentity();
3866 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003867 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003868 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003869 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003870 } else {
3871 return PhoneConstantConversions.convertDataState(
3872 PhoneConstants.DataState.DISCONNECTED);
3873 }
3874 } finally {
3875 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003876 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003877 }
3878
Sanket Padawe356d7632015-06-22 14:03:32 -07003879 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003880 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003881 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003882 }
3883
3884 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003885 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003886 final long identity = Binder.clearCallingIdentity();
3887 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003888 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003889 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003890 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003891 } else {
3892 return TelephonyManager.DATA_ACTIVITY_NONE;
3893 }
3894 } finally {
3895 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003896 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003897 }
3898
3899 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003900 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003901 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003902 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003903
3904 LocationAccessPolicy.LocationPermissionResult locationResult =
3905 LocationAccessPolicy.checkLocationPermission(mApp,
3906 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3907 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003908 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003909 .setCallingPid(Binder.getCallingPid())
3910 .setCallingUid(Binder.getCallingUid())
3911 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003912 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003913 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3914 .build());
3915 switch (locationResult) {
3916 case DENIED_HARD:
3917 throw new SecurityException("Not allowed to access cell location");
3918 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003919 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3920 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003921 }
3922
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003923 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003924 final long identity = Binder.clearCallingIdentity();
3925 try {
3926 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003927 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003928 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003929 } finally {
3930 Binder.restoreCallingIdentity(identity);
3931 }
Svetoslav64fad262015-04-14 14:35:21 -07003932 }
3933
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003934 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003935 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003936 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3937 // registered cell info, so return a NULL country instead.
3938 final long identity = Binder.clearCallingIdentity();
3939 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003940 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3941 // Get default phone in this case.
3942 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3943 }
Jack Yu285100e2022-12-02 22:48:35 -08003944 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003945 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003946 if (phone == null) return "";
3947 ServiceStateTracker sst = phone.getServiceStateTracker();
3948 if (sst == null) return "";
3949 LocaleTracker lt = sst.getLocaleTracker();
3950 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003951 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003952 } finally {
3953 Binder.restoreCallingIdentity(identity);
3954 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003955 }
3956
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003957 /**
3958 * This method was removed due to potential issues caused by performing partial
3959 * updates of service state, and lack of a credible use case.
3960 *
3961 * This has the ability to break the telephony implementation by disabling notification of
3962 * changes in device connectivity. DO NOT USE THIS!
3963 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003964 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003965 public void enableLocationUpdates() {
3966 mApp.enforceCallingOrSelfPermission(
3967 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003968 }
3969
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003970 /**
3971 * This method was removed due to potential issues caused by performing partial
3972 * updates of service state, and lack of a credible use case.
3973 *
3974 * This has the ability to break the telephony implementation by disabling notification of
3975 * changes in device connectivity. DO NOT USE THIS!
3976 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003977 @Override
3978 public void disableLocationUpdates() {
3979 mApp.enforceCallingOrSelfPermission(
3980 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003981 }
3982
3983 @Override
3984 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003985 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3986 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003987 try {
3988 mApp.getSystemService(AppOpsManager.class)
3989 .checkPackage(Binder.getCallingUid(), callingPackage);
3990 } catch (SecurityException e) {
3991 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3992 throw e;
3993 }
3994
Nathan Haroldf096d982020-11-18 17:18:06 -08003995 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003996 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3997 throw new SecurityException(
3998 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3999 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07004000
Jordan Liu1617b712019-07-10 15:06:26 -07004001 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004002 callingPackage) != AppOpsManager.MODE_ALLOWED) {
4003 return null;
4004 }
Svetoslav64fad262015-04-14 14:35:21 -07004005
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07004006 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004007
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004008 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07004009 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004010
Nathan Haroldf180aac2018-06-01 18:43:55 -07004011 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
4012 for (CellInfo ci : info) {
4013 if (ci instanceof CellInfoGsm) {
4014 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
4015 } else if (ci instanceof CellInfoWcdma) {
4016 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
4017 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004018 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07004019 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004020 }
4021
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004022 private List<CellInfo> getCachedCellInfo() {
4023 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
4024 for (Phone phone : PhoneFactory.getPhones()) {
4025 List<CellInfo> info = phone.getAllCellInfo();
4026 if (info != null) cellInfos.addAll(info);
4027 }
4028 return cellInfos;
4029 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004030
4031 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004032 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004033 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08004034 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08004035
4036 LocationAccessPolicy.LocationPermissionResult locationResult =
4037 LocationAccessPolicy.checkLocationPermission(mApp,
4038 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4039 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004040 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004041 .setCallingPid(Binder.getCallingPid())
4042 .setCallingUid(Binder.getCallingUid())
4043 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08004044 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08004045 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4046 .build());
4047 switch (locationResult) {
4048 case DENIED_HARD:
4049 throw new SecurityException("Not allowed to access cell info");
4050 case DENIED_SOFT:
4051 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004052 }
4053
Nathan Haroldf096d982020-11-18 17:18:06 -08004054 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004055 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
4056 return getCachedCellInfo();
4057 }
4058
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07004059 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004060 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004061 final long identity = Binder.clearCallingIdentity();
4062 try {
4063 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
4064 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07004065 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07004066 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004067 if (info != null) cellInfos.addAll(info);
4068 }
4069 return cellInfos;
4070 } finally {
4071 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004072 }
4073 }
4074
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07004075 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004076 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
4077 String callingFeatureId) {
4078 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
4079 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004080 }
4081
4082 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004083 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
4084 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004085 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004086 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004087 }
4088
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004089 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
4090 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004091 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004092 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08004093
4094 LocationAccessPolicy.LocationPermissionResult locationResult =
4095 LocationAccessPolicy.checkLocationPermission(mApp,
4096 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4097 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004098 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004099 .setCallingPid(Binder.getCallingPid())
4100 .setCallingUid(Binder.getCallingUid())
4101 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07004102 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
4103 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08004104 .build());
4105 switch (locationResult) {
4106 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08004107 if (TelephonyPermissions
4108 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07004109 // Safetynet logging for b/154934934
4110 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
4111 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004112 throw new SecurityException("Not allowed to access cell info");
4113 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08004114 if (TelephonyPermissions
4115 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07004116 // Safetynet logging for b/154934934
4117 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
4118 }
Nathan Harold5320c422019-05-09 10:26:08 -07004119 try {
4120 cb.onCellInfo(new ArrayList<CellInfo>());
4121 } catch (RemoteException re) {
4122 // Drop without consequences
4123 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004124 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004125 }
4126
Nathan Harolda939a962019-05-09 10:13:47 -07004127
4128 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07004129 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
4130
4131 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
4132 }
4133
4134 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00004135 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08004136 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004137 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004138
4139 final long identity = Binder.clearCallingIdentity();
4140 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00004141 Phone phone = getPhone(subId);
4142 if (phone == null) {
4143 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
4144 } else {
4145 phone.setCellInfoListRate(rateInMillis, workSource);
4146 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004147 } finally {
4148 Binder.restoreCallingIdentity(identity);
4149 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004150 }
4151
Shishir Agrawala9f32182016-04-12 12:00:16 -07004152 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004153 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004154 Phone phone = PhoneFactory.getPhone(slotIndex);
4155 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004156 return null;
4157 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004158 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07004159 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07004160 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004161 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004162 return null;
4163 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004164
4165 final long identity = Binder.clearCallingIdentity();
4166 try {
4167 return phone.getImei();
4168 } finally {
4169 Binder.restoreCallingIdentity(identity);
4170 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07004171 }
4172
4173 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00004174 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
4175 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
4176 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
4177 callingFeatureId, "getPrimaryImei")) {
4178 throw new SecurityException("Caller does not have permission");
4179 }
4180 final long identity = Binder.clearCallingIdentity();
4181 try {
4182 for (Phone phone : PhoneFactory.getPhones()) {
4183 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
4184 return phone.getImei();
4185 }
4186 }
4187 throw new UnsupportedOperationException("Operation not supported");
4188 } finally {
4189 Binder.restoreCallingIdentity(identity);
4190 }
4191 }
4192
4193 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00004194 public String getTypeAllocationCodeForSlot(int slotIndex) {
4195 Phone phone = PhoneFactory.getPhone(slotIndex);
4196 String tac = null;
4197 if (phone != null) {
4198 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07004199 try {
4200 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
4201 } catch (IndexOutOfBoundsException e) {
4202 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
4203 return null;
4204 }
David Kelly5e06a7f2018-03-12 14:10:59 +00004205 }
4206 return tac;
4207 }
4208
4209 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004210 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004211 try {
4212 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4213 } catch (SecurityException se) {
4214 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
4215 throw new SecurityException("Package " + callingPackage + " does not belong to "
4216 + Binder.getCallingUid());
4217 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004218 Phone phone = PhoneFactory.getPhone(slotIndex);
4219 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07004220 return null;
4221 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004222
Jeff Davidson913390f2018-02-23 17:11:49 -08004223 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004224 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004225 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004226 return null;
4227 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004228
4229 final long identity = Binder.clearCallingIdentity();
4230 try {
4231 return phone.getMeid();
4232 } finally {
4233 Binder.restoreCallingIdentity(identity);
4234 }
Jack Yu2af8d712017-03-15 17:14:14 -07004235 }
4236
4237 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00004238 public String getManufacturerCodeForSlot(int slotIndex) {
4239 Phone phone = PhoneFactory.getPhone(slotIndex);
4240 String manufacturerCode = null;
4241 if (phone != null) {
4242 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07004243 try {
4244 manufacturerCode =
4245 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
4246 } catch (IndexOutOfBoundsException e) {
4247 Log.e(LOG_TAG, "MEID length shorter than upper index.");
4248 return null;
4249 }
David Kelly5e06a7f2018-03-12 14:10:59 +00004250 }
4251 return manufacturerCode;
4252 }
4253
4254 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004255 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
4256 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004257 Phone phone = PhoneFactory.getPhone(slotIndex);
4258 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004259 return null;
4260 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004261 int subId = phone.getSubId();
4262 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004263 mApp, subId, callingPackage, callingFeatureId,
4264 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004265 return null;
4266 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004267
4268 final long identity = Binder.clearCallingIdentity();
4269 try {
4270 return phone.getDeviceSvn();
4271 } finally {
4272 Binder.restoreCallingIdentity(identity);
4273 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07004274 }
4275
fionaxu43304da2017-11-27 22:51:16 -08004276 @Override
4277 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004278 final long identity = Binder.clearCallingIdentity();
4279 try {
4280 final Phone phone = getPhone(subId);
4281 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
4282 } finally {
4283 Binder.restoreCallingIdentity(identity);
4284 }
fionaxu43304da2017-11-27 22:51:16 -08004285 }
4286
4287 @Override
4288 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004289 final long identity = Binder.clearCallingIdentity();
4290 try {
4291 final Phone phone = getPhone(subId);
4292 return phone == null ? null : phone.getCarrierName();
4293 } finally {
4294 Binder.restoreCallingIdentity(identity);
4295 }
fionaxu43304da2017-11-27 22:51:16 -08004296 }
4297
calvinpanffe225e2018-11-01 19:43:06 +08004298 @Override
chen xu0026ca62019-03-06 15:28:50 -08004299 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08004300 final long identity = Binder.clearCallingIdentity();
4301 try {
4302 final Phone phone = getPhone(subId);
4303 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08004304 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08004305 } finally {
4306 Binder.restoreCallingIdentity(identity);
4307 }
4308 }
4309
4310 @Override
chen xu0026ca62019-03-06 15:28:50 -08004311 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08004312 final long identity = Binder.clearCallingIdentity();
4313 try {
4314 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08004315 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08004316 } finally {
4317 Binder.restoreCallingIdentity(identity);
4318 }
4319 }
4320
chen xu651eec72018-11-11 19:03:44 -08004321 @Override
chen xu864e11c2018-12-06 22:10:03 -08004322 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
4323 if (!isSubscriptionMccMnc) {
4324 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
4325 }
chen xu651eec72018-11-11 19:03:44 -08004326 final Phone phone = PhoneFactory.getPhone(slotIndex);
4327 if (phone == null) {
4328 return TelephonyManager.UNKNOWN_CARRIER_ID;
4329 }
4330 final long identity = Binder.clearCallingIdentity();
4331 try {
4332 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
4333 } finally {
4334 Binder.restoreCallingIdentity(identity);
4335 }
4336 }
4337
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004338 //
4339 // Internal helper methods.
4340 //
4341
Sanket Padaweee13a9b2016-03-08 17:30:28 -08004342 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07004343 * Make sure the caller is the calling package itself
4344 *
4345 * @throws SecurityException if the caller is not the calling package
4346 */
4347 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
4348 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07004349 PackageManager pm = mApp.getBaseContext().createContextAsUser(
4350 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07004351 try {
Grace Jiadbefca02021-04-26 15:13:31 -07004352 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07004353 } catch (PackageManager.NameNotFoundException e) {
4354 // packageUid is -1
4355 }
4356 if (packageUid != callingUid) {
4357 throw new SecurityException(message + ": Package " + callingPackage
4358 + " does not belong to " + callingUid);
4359 }
4360 }
4361
4362 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004363 * Make sure the caller has the MODIFY_PHONE_STATE permission.
4364 *
4365 * @throws SecurityException if the caller does not have the required permission
4366 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004367 @VisibleForTesting
4368 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004369 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
4370 }
4371
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004372 /**
arunvoddud7401012022-12-15 16:08:12 +00004373 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004374 *
4375 * @throws SecurityException if the caller does not have the required permission
4376 */
4377 @VisibleForTesting
4378 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00004379 enforceReadPermission(null);
4380 }
4381
4382 /**
4383 * Make sure the caller has the READ_PHONE_STATE permissions.
4384 *
4385 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
4386 */
4387 @VisibleForTesting
4388 public void enforceReadPermission(String msg) {
4389 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004390 }
4391
Shuo Qian3b6ee772019-11-13 17:43:31 -08004392 private void enforceActiveEmergencySessionPermission() {
4393 mApp.enforceCallingOrSelfPermission(
4394 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
4395 }
4396
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004397 /**
4398 * Make sure the caller has the CALL_PHONE permission.
4399 *
4400 * @throws SecurityException if the caller does not have the required permission
4401 */
4402 private void enforceCallPermission() {
4403 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
4404 }
4405
paulhu5a773602019-08-23 19:17:33 +08004406 private void enforceSettingsPermission() {
4407 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004408 }
4409
Michele Berionne5e411512020-11-13 02:36:59 +00004410 private void enforceRebootPermission() {
4411 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
4412 }
4413
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00004414 /**
4415 * Make sure the caller has SATELLITE_COMMUNICATION permission.
4416 * @param message - log message to print.
4417 * @throws SecurityException if the caller does not have the required permission
4418 */
4419 private void enforceSatelliteCommunicationPermission(String message) {
4420 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
4421 }
4422
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004423 private String createTelUrl(String number) {
4424 if (TextUtils.isEmpty(number)) {
4425 return null;
4426 }
4427
Jake Hambye994d462014-02-03 13:10:13 -08004428 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004429 }
4430
Ihab Awadf9e92732013-12-05 18:02:52 -08004431 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08004432 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004433 }
4434
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07004435 private static void logv(String msg) {
4436 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
4437 }
4438
Ihab Awadf9e92732013-12-05 18:02:52 -08004439 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004440 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
4441 }
4442
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004443 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004444 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07004445 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07004446 }
4447
Sanket Padawe356d7632015-06-22 14:03:32 -07004448 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004449 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004450 final long identity = Binder.clearCallingIdentity();
4451 try {
4452 final Phone phone = PhoneFactory.getPhone(slotIndex);
4453 if (phone == null) {
4454 return PhoneConstants.PHONE_TYPE_NONE;
4455 } else {
4456 return phone.getPhoneType();
4457 }
4458 } finally {
4459 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004460 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004461 }
4462
4463 /**
4464 * Returns the CDMA ERI icon index to display
4465 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004466 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004467 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4468 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4469 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004470 }
4471
Sanket Padawe356d7632015-06-22 14:03:32 -07004472 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004473 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4474 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004475 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004476 mApp, subId, callingPackage, callingFeatureId,
4477 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004478 return -1;
4479 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004480
4481 final long identity = Binder.clearCallingIdentity();
4482 try {
4483 final Phone phone = getPhone(subId);
4484 if (phone != null) {
4485 return phone.getCdmaEriIconIndex();
4486 } else {
4487 return -1;
4488 }
4489 } finally {
4490 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004491 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004492 }
4493
4494 /**
4495 * Returns the CDMA ERI icon mode,
4496 * 0 - ON
4497 * 1 - FLASHING
4498 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004499 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004500 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4501 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4502 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004503 }
4504
Sanket Padawe356d7632015-06-22 14:03:32 -07004505 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004506 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4507 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004508 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004509 mApp, subId, callingPackage, callingFeatureId,
4510 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004511 return -1;
4512 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004513
4514 final long identity = Binder.clearCallingIdentity();
4515 try {
4516 final Phone phone = getPhone(subId);
4517 if (phone != null) {
4518 return phone.getCdmaEriIconMode();
4519 } else {
4520 return -1;
4521 }
4522 } finally {
4523 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004524 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004525 }
4526
4527 /**
4528 * Returns the CDMA ERI text,
4529 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004530 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004531 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4532 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4533 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004534 }
4535
Sanket Padawe356d7632015-06-22 14:03:32 -07004536 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004537 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4538 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004540 mApp, subId, callingPackage, callingFeatureId,
4541 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004542 return null;
4543 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004544
4545 final long identity = Binder.clearCallingIdentity();
4546 try {
4547 final Phone phone = getPhone(subId);
4548 if (phone != null) {
4549 return phone.getCdmaEriText();
4550 } else {
4551 return null;
4552 }
4553 } finally {
4554 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004556 }
4557
4558 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004559 * Returns the CDMA MDN.
4560 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004561 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004562 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4564 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004565
4566 final long identity = Binder.clearCallingIdentity();
4567 try {
4568 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004569 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004570 return phone.getLine1Number();
4571 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004572 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004573 return null;
4574 }
4575 } finally {
4576 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004577 }
4578 }
4579
4580 /**
4581 * Returns the CDMA MIN.
4582 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004583 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004584 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4586 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004587
4588 final long identity = Binder.clearCallingIdentity();
4589 try {
4590 final Phone phone = getPhone(subId);
4591 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4592 return phone.getCdmaMin();
4593 } else {
4594 return null;
4595 }
4596 } finally {
4597 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004598 }
4599 }
4600
Hall Liud892bec2018-11-30 14:51:45 -08004601 @Override
4602 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4603 INumberVerificationCallback callback, String callingPackage) {
4604 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4605 != PERMISSION_GRANTED) {
4606 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4607 }
4608 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4609
4610 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4611 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004612 throw new SecurityException("Calling package must be configured in the device config: "
4613 + "calling package: " + callingPackage
4614 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004615 }
4616
4617 if (range == null) {
4618 throw new NullPointerException("Range must be non-null");
4619 }
4620
4621 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004622 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004623
4624 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4625 }
4626
Junda Liuca05d5d2014-08-14 22:36:34 -07004627 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004628 * Returns true if CDMA provisioning needs to run.
4629 */
4630 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004631 final long identity = Binder.clearCallingIdentity();
4632 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004633 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004634 } finally {
4635 Binder.restoreCallingIdentity(identity);
4636 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004637 }
4638
4639 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004640 * Sets the voice mail number of a given subId.
4641 */
4642 @Override
4643 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004644 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4645 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004646
4647 final long identity = Binder.clearCallingIdentity();
4648 try {
4649 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4650 new Pair<String, String>(alphaTag, number), new Integer(subId));
4651 return success;
4652 } finally {
4653 Binder.restoreCallingIdentity(identity);
4654 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004655 }
4656
Ta-wei Yen87c49842016-05-13 21:19:52 -07004657 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004658 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4659 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004660 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4661 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004662 if (!TextUtils.equals(callingPackage, systemDialer)) {
4663 throw new SecurityException("caller must be system dialer");
4664 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004665
4666 final long identity = Binder.clearCallingIdentity();
4667 try {
4668 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4669 if (phoneAccountHandle == null) {
4670 return null;
4671 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004672 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004673 } finally {
4674 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004675 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004676 }
4677
4678 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004679 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4680 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004681 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004682 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004683 mApp, subId, callingPackage, callingFeatureId,
4684 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004685 return null;
4686 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004687
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004688 final long identity = Binder.clearCallingIdentity();
4689 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004690 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004691 } finally {
4692 Binder.restoreCallingIdentity(identity);
4693 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004694 }
4695
4696 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004697 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4698 VisualVoicemailSmsFilterSettings settings) {
4699 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004700
4701 final long identity = Binder.clearCallingIdentity();
4702 try {
4703 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004704 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004705 } finally {
4706 Binder.restoreCallingIdentity(identity);
4707 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004708 }
4709
4710 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004711 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4712 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004713
4714 final long identity = Binder.clearCallingIdentity();
4715 try {
4716 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004717 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004718 } finally {
4719 Binder.restoreCallingIdentity(identity);
4720 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004721 }
4722
4723 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004724 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4725 String callingPackage, int subId) {
4726 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004727
4728 final long identity = Binder.clearCallingIdentity();
4729 try {
4730 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004731 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004732 } finally {
4733 Binder.restoreCallingIdentity(identity);
4734 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004735 }
4736
4737 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004738 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004739 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004740
4741 final long identity = Binder.clearCallingIdentity();
4742 try {
4743 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004744 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004745 } finally {
4746 Binder.restoreCallingIdentity(identity);
4747 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004748 }
4749
4750 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004751 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4752 String callingAttributionTag, int subId, String number, int port, String text,
4753 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004754 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004755 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004756 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004757 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004758 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4759 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004760 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004761
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004762 /**
fionaxu0152e512016-11-14 13:36:14 -08004763 * Sets the voice activation state of a given subId.
4764 */
4765 @Override
4766 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4768 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004769
4770 final long identity = Binder.clearCallingIdentity();
4771 try {
4772 final Phone phone = getPhone(subId);
4773 if (phone != null) {
4774 phone.setVoiceActivationState(activationState);
4775 } else {
4776 loge("setVoiceActivationState fails with invalid subId: " + subId);
4777 }
4778 } finally {
4779 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004780 }
4781 }
4782
4783 /**
4784 * Sets the data activation state of a given subId.
4785 */
4786 @Override
4787 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4789 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004790
4791 final long identity = Binder.clearCallingIdentity();
4792 try {
4793 final Phone phone = getPhone(subId);
4794 if (phone != null) {
4795 phone.setDataActivationState(activationState);
4796 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004797 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004798 }
4799 } finally {
4800 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004801 }
4802 }
4803
4804 /**
4805 * Returns the voice activation state of a given subId.
4806 */
4807 @Override
4808 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004809 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004810
fionaxu0152e512016-11-14 13:36:14 -08004811 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004812 final long identity = Binder.clearCallingIdentity();
4813 try {
4814 if (phone != null) {
4815 return phone.getVoiceActivationState();
4816 } else {
4817 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4818 }
4819 } finally {
4820 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004821 }
4822 }
4823
4824 /**
4825 * Returns the data activation state of a given subId.
4826 */
4827 @Override
4828 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004829 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004830
fionaxu0152e512016-11-14 13:36:14 -08004831 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004832 final long identity = Binder.clearCallingIdentity();
4833 try {
4834 if (phone != null) {
4835 return phone.getDataActivationState();
4836 } else {
4837 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4838 }
4839 } finally {
4840 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004841 }
4842 }
4843
4844 /**
Wink Saville36469e72014-06-11 15:17:00 -07004845 * Returns the unread count of voicemails for a subId
4846 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004847 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004848 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4849 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004850 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004851 mApp, subId, callingPackage, callingFeatureId,
4852 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004853 return 0;
4854 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004855 final long identity = Binder.clearCallingIdentity();
4856 try {
4857 final Phone phone = getPhone(subId);
4858 if (phone != null) {
4859 return phone.getVoiceMessageCount();
4860 } else {
4861 return 0;
4862 }
4863 } finally {
4864 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004865 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004866 }
4867
4868 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004869 * returns true, if the device is in a state where both voice and data
4870 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004871 */
4872 @Override
4873 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004874 final long identity = Binder.clearCallingIdentity();
4875 try {
4876 final Phone phone = getPhone(subId);
4877 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4878 } finally {
4879 Binder.restoreCallingIdentity(identity);
4880 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004881 }
4882
4883 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004884 * Send the dialer code if called from the current default dialer or the caller has
4885 * carrier privilege.
4886 * @param inputCode The dialer code to send
4887 */
4888 @Override
4889 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004890 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004891 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004892 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4893 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004894 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004895 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004896 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004897 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004898
4899 final long identity = Binder.clearCallingIdentity();
4900 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004901 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004902 } finally {
4903 Binder.restoreCallingIdentity(identity);
4904 }
fionaxu235cc5e2017-03-06 22:25:57 -08004905 }
4906
Pengquan Menga1bb6272018-09-06 09:59:22 -07004907 @Override
4908 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004909 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004910 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4911 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004912 final long identity = Binder.clearCallingIdentity();
4913 try {
4914 if (!isActiveSubscription(subId)) {
4915 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4916 }
4917 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4918 } finally {
4919 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004920 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004921 }
4922
Brad Ebinger35c841c2018-10-01 10:40:55 -07004923 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004924 public boolean isInEmergencySmsMode() {
4925 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4926 final long identity = Binder.clearCallingIdentity();
4927 try {
4928 for (Phone phone : PhoneFactory.getPhones()) {
4929 if (phone.isInEmergencySmsMode()) {
4930 return true;
4931 }
4932 }
4933 } finally {
4934 Binder.restoreCallingIdentity(identity);
4935 }
4936 return false;
4937 }
4938
shilu366312e2019-12-17 09:28:10 -08004939 /**
4940 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4941 * @param subId The subscription to use to check the configuration.
4942 * @param c The callback that will be used to send the result.
4943 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004944 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004945 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4946 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004947 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004948 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004949
4950 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4951 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4952 "IMS not available on device.");
4953 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004954 final long token = Binder.clearCallingIdentity();
4955 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004956 int slotId = getSlotIndexOrException(subId);
4957 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004958
4959 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4960 if (controller != null) {
4961 ImsManager imsManager = controller.getImsManager(subId);
4962 if (imsManager != null) {
4963 imsManager.addRegistrationCallbackForSubscription(c, subId);
4964 } else {
4965 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4966 }
4967 } else {
4968 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4969 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004970 } catch (ImsException e) {
4971 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004972 } finally {
4973 Binder.restoreCallingIdentity(token);
4974 }
4975 }
4976
shilu366312e2019-12-17 09:28:10 -08004977 /**
4978 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4979 * @param subId The subscription to use to check the configuration.
4980 * @param c The callback that will be used to send the result.
4981 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004982 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004983 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004984 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004985 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004986 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4987 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4988 }
Meng Wangafbc5852019-09-19 17:37:13 -07004989 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004990
Meng Wangafbc5852019-09-19 17:37:13 -07004991 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004992 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4993 if (controller != null) {
4994 ImsManager imsManager = controller.getImsManager(subId);
4995 if (imsManager != null) {
4996 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4997 } else {
4998 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4999 + "is inactive, ignoring unregister.");
5000 // If the ImsManager is not valid, just return, since the callback
5001 // will already have been removed internally.
5002 }
5003 }
Meng Wangafbc5852019-09-19 17:37:13 -07005004 } finally {
5005 Binder.restoreCallingIdentity(token);
5006 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07005007 }
5008
Brad Ebingera34a6c22019-10-22 17:36:18 -07005009 /**
5010 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
5011 */
5012 @Override
5013 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
5014 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
5015 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5016 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5017 "IMS not available on device.");
5018 }
5019 final long token = Binder.clearCallingIdentity();
5020 try {
5021 Phone phone = getPhone(subId);
5022 if (phone == null) {
5023 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
5024 + subId + "'");
5025 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5026 }
5027 phone.getImsRegistrationState(regState -> {
5028 try {
5029 consumer.accept((regState == null)
5030 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
5031 } catch (RemoteException e) {
5032 // Ignore if the remote process is no longer available to call back.
5033 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
5034 }
5035 });
5036 } finally {
5037 Binder.restoreCallingIdentity(token);
5038 }
5039 }
5040
5041 /**
5042 * Get the transport type for the IMS service registration state.
5043 */
5044 @Override
5045 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07005046 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005047 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07005048 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5049 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5050 "IMS not available on device.");
5051 }
5052 final long token = Binder.clearCallingIdentity();
5053 try {
5054 Phone phone = getPhone(subId);
5055 if (phone == null) {
5056 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
5057 + subId + "'");
5058 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5059 }
5060 phone.getImsRegistrationTech(regTech -> {
5061 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
5062 int regTechConverted = (regTech == null)
5063 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
5064 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
5065 regTechConverted);
5066 try {
5067 consumer.accept(regTechConverted);
5068 } catch (RemoteException e) {
5069 // Ignore if the remote process is no longer available to call back.
5070 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
5071 }
5072 });
5073 } finally {
5074 Binder.restoreCallingIdentity(token);
5075 }
5076 }
5077
shilu366312e2019-12-17 09:28:10 -08005078 /**
5079 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5080 * @param subId The subscription to use to check the configuration.
5081 * @param c The callback that will be used to send the result.
5082 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005083 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005084 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
5085 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07005086 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005087 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00005088 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5089 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5090 "IMS not available on device.");
5091 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07005092 final long token = Binder.clearCallingIdentity();
5093 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005094 int slotId = getSlotIndexOrException(subId);
5095 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005096
5097 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5098 if (controller != null) {
5099 ImsManager imsManager = controller.getImsManager(subId);
5100 if (imsManager != null) {
5101 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
5102 } else {
5103 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5104 }
5105 } else {
5106 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5107 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005108 } catch (ImsException e) {
5109 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005110 } finally {
5111 Binder.restoreCallingIdentity(token);
5112 }
5113 }
5114
shilu366312e2019-12-17 09:28:10 -08005115 /**
5116 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5117 * @param subId The subscription to use to check the configuration.
5118 * @param c The callback that will be used to send the result.
5119 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005120 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005121 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07005122 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005123 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005124 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5125 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5126 }
Meng Wangafbc5852019-09-19 17:37:13 -07005127
5128 final long token = Binder.clearCallingIdentity();
5129 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005130 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5131 if (controller != null) {
5132 ImsManager imsManager = controller.getImsManager(subId);
5133 if (imsManager != null) {
5134 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
5135 } else {
5136 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
5137 + " is inactive, ignoring unregister.");
5138 // If the ImsManager is not valid, just return, since the callback
5139 // will already have been removed internally.
5140 }
5141 }
Meng Wangafbc5852019-09-19 17:37:13 -07005142 } finally {
5143 Binder.restoreCallingIdentity(token);
5144 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07005145 }
5146
5147 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005148 public boolean isCapable(int subId, int capability, int regTech) {
5149 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005150 final long token = Binder.clearCallingIdentity();
5151 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005152 int slotId = getSlotIndexOrException(subId);
5153 verifyImsMmTelConfiguredOrThrow(slotId);
5154 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
5155 } catch (com.android.ims.ImsException e) {
5156 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
5157 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005158 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08005159 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
5160 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07005161 } finally {
5162 Binder.restoreCallingIdentity(token);
5163 }
5164 }
5165
5166 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005167 public boolean isAvailable(int subId, int capability, int regTech) {
5168 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005169 final long token = Binder.clearCallingIdentity();
5170 try {
5171 Phone phone = getPhone(subId);
5172 if (phone == null) return false;
5173 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07005174 } catch (com.android.ims.ImsException e) {
5175 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
5176 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07005177 } finally {
5178 Binder.restoreCallingIdentity(token);
5179 }
5180 }
5181
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005182 /**
5183 * Determines if the MmTel feature capability is supported by the carrier configuration for this
5184 * subscription.
5185 * @param subId The subscription to use to check the configuration.
5186 * @param callback The callback that will be used to send the result.
5187 * @param capability The MmTelFeature capability that will be used to send the result.
5188 * @param transportType The transport type of the MmTelFeature capability.
5189 */
5190 @Override
5191 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
5192 int transportType) {
5193 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00005194 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5195 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5196 "IMS not available on device.");
5197 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005198 final long token = Binder.clearCallingIdentity();
5199 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005200 int slotId = getSlotIndex(subId);
5201 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5202 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
5203 + subId + "'");
5204 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5205 }
5206 verifyImsMmTelConfiguredOrThrow(slotId);
5207 ImsManager.getInstance(mApp, slotId).isSupported(capability,
5208 transportType, aBoolean -> {
5209 try {
5210 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
5211 } catch (RemoteException e) {
5212 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
5213 + "running. Ignore");
5214 }
5215 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005216 } catch (ImsException e) {
5217 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005218 } finally {
5219 Binder.restoreCallingIdentity(token);
5220 }
5221 }
5222
shilu366312e2019-12-17 09:28:10 -08005223 /**
5224 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5225 * @param subId The subscription to use to check the configuration.
5226 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005227 @Override
5228 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005229 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005230 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08005231
Brad Ebinger35c841c2018-10-01 10:40:55 -07005232 final long token = Binder.clearCallingIdentity();
5233 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005234 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005235 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005236 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005237 } catch (ImsException e) {
5238 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005239 } finally {
5240 Binder.restoreCallingIdentity(token);
5241 }
5242 }
5243
5244 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005245 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005247 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005248 final long identity = Binder.clearCallingIdentity();
5249 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005250 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005251 // This setting doesn't require an active ImsService connection, so do not verify. The
5252 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005253 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005254 } catch (ImsException e) {
5255 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005256 } finally {
5257 Binder.restoreCallingIdentity(identity);
5258 }
5259 }
5260
shilu366312e2019-12-17 09:28:10 -08005261 /**
5262 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5263 * @param subId The subscription to use to check the configuration.
5264 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005265 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005266 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005267 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005268 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005269 final long identity = Binder.clearCallingIdentity();
5270 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005271 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005272 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005273 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005274 } catch (ImsException e) {
5275 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005276 } finally {
5277 Binder.restoreCallingIdentity(identity);
5278 }
5279 }
5280
5281 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005282 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005283 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005284 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005285 final long identity = Binder.clearCallingIdentity();
5286 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005287 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005288 // This setting doesn't require an active ImsService connection, so do not verify. The
5289 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005290 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005291 } catch (ImsException e) {
5292 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005293 } finally {
5294 Binder.restoreCallingIdentity(identity);
5295 }
5296 }
5297
shilu366312e2019-12-17 09:28:10 -08005298 /**
5299 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5300 * @param subId The subscription to use to check the configuration.
5301 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005302 @Override
5303 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005304 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005305 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005306 final long identity = Binder.clearCallingIdentity();
5307 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005308 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005309 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005310 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005311 } catch (ImsException e) {
5312 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005313 } finally {
5314 Binder.restoreCallingIdentity(identity);
5315 }
5316 }
5317
5318 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005319 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005321 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005322 final long identity = Binder.clearCallingIdentity();
5323 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005324 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005325 // This setting doesn't require an active ImsService connection, so do not verify. The
5326 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005327 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005328 } catch (ImsException e) {
5329 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005330 } finally {
5331 Binder.restoreCallingIdentity(identity);
5332 }
5333 }
5334
shilu366312e2019-12-17 09:28:10 -08005335 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005336 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5337 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5338 * @param subId The subscription to use to check the configuration.
5339 */
5340 @Override
5341 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005342 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005343 mApp, subId, "isCrossSimCallingEnabledByUser");
5344 final long identity = Binder.clearCallingIdentity();
5345 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005346 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005347 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005348 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005349 } catch (ImsException e) {
5350 throw new ServiceSpecificException(e.getCode());
5351 } finally {
5352 Binder.restoreCallingIdentity(identity);
5353 }
5354 }
5355
5356 /**
5357 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5358 * Requires MODIFY_PHONE_STATE permission.
5359 * @param subId The subscription to use to check the configuration.
5360 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5361 * false otherwise
5362 */
5363 @Override
5364 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5366 "setCrossSimCallingEnabled");
5367 final long identity = Binder.clearCallingIdentity();
5368 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005369 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005370 // This setting doesn't require an active ImsService connection, so do not verify. The
5371 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005372 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005373 } catch (ImsException e) {
5374 throw new ServiceSpecificException(e.getCode());
5375 } finally {
5376 Binder.restoreCallingIdentity(identity);
5377 }
5378 }
5379
5380 /**
shilu366312e2019-12-17 09:28:10 -08005381 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5382 * @param subId The subscription to use to check the configuration.
5383 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005384 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005385
Brad Ebinger35c841c2018-10-01 10:40:55 -07005386 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005387 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005388 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005389 final long identity = Binder.clearCallingIdentity();
5390 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005391 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005392 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005393 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005394 } catch (ImsException e) {
5395 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005396 } finally {
5397 Binder.restoreCallingIdentity(identity);
5398 }
5399 }
5400
5401 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005402 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005404 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005405 final long identity = Binder.clearCallingIdentity();
5406 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005407 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005408 // This setting doesn't require an active ImsService connection, so do not verify. The
5409 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005410 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005411 } catch (ImsException e) {
5412 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005413 } finally {
5414 Binder.restoreCallingIdentity(identity);
5415 }
5416 }
5417
5418 @Override
5419 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5421 "setVoWiFiNonPersistent");
5422 final long identity = Binder.clearCallingIdentity();
5423 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005424 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005425 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005426 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005427 } catch (ImsException e) {
5428 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005429 } finally {
5430 Binder.restoreCallingIdentity(identity);
5431 }
5432 }
5433
shilu366312e2019-12-17 09:28:10 -08005434 /**
5435 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5436 * @param subId The subscription to use to check the configuration.
5437 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005438 @Override
5439 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005440 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005441 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005442 final long identity = Binder.clearCallingIdentity();
5443 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005444 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005445 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005446 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005447 } catch (ImsException e) {
5448 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005449 } finally {
5450 Binder.restoreCallingIdentity(identity);
5451 }
5452 }
5453
5454 @Override
5455 public void setVoWiFiModeSetting(int subId, int mode) {
5456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5457 "setVoWiFiModeSetting");
5458 final long identity = Binder.clearCallingIdentity();
5459 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005460 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005461 // This setting doesn't require an active ImsService connection, so do not verify. The
5462 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005463 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005464 } catch (ImsException e) {
5465 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005466 } finally {
5467 Binder.restoreCallingIdentity(identity);
5468 }
5469 }
5470
5471 @Override
5472 public int getVoWiFiRoamingModeSetting(int subId) {
5473 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
5474 final long identity = Binder.clearCallingIdentity();
5475 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005476 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005477 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005478 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005479 } catch (ImsException e) {
5480 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005481 } finally {
5482 Binder.restoreCallingIdentity(identity);
5483 }
5484 }
5485
5486 @Override
5487 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5489 "setVoWiFiRoamingModeSetting");
5490 final long identity = Binder.clearCallingIdentity();
5491 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005492 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005493 // This setting doesn't require an active ImsService connection, so do not verify. The
5494 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005495 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005496 } catch (ImsException e) {
5497 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005498 } finally {
5499 Binder.restoreCallingIdentity(identity);
5500 }
5501 }
5502
5503 @Override
5504 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5505 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5506 "setRttCapabilityEnabled");
5507 final long identity = Binder.clearCallingIdentity();
5508 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005509 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005510 // This setting doesn't require an active ImsService connection, so do not verify. The
5511 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005512 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005513 } catch (ImsException e) {
5514 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005515 } finally {
5516 Binder.restoreCallingIdentity(identity);
5517 }
5518 }
5519
shilu366312e2019-12-17 09:28:10 -08005520 /**
5521 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5522 * @param subId The subscription to use to check the configuration.
5523 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005524 @Override
5525 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005526 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005527 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005528 final long identity = Binder.clearCallingIdentity();
5529 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005530 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005531 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005532 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005533 } catch (ImsException e) {
5534 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005535 } finally {
5536 Binder.restoreCallingIdentity(identity);
5537 }
5538 }
5539
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005540 @Override
5541 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5542 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005543
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005544 final long identity = Binder.clearCallingIdentity();
5545 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005546 if (!isImsAvailableOnDevice()) {
5547 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5548 "IMS not available on device.");
5549 }
5550 int slotId = getSlotIndexOrException(subId);
5551 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005552
5553 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5554 if (controller != null) {
5555 ImsManager imsManager = controller.getImsManager(subId);
5556 if (imsManager != null) {
5557 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5558 } else {
5559 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5560 }
5561 } else {
5562 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5563 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005564 } catch (ImsException e) {
5565 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005566 } finally {
5567 Binder.restoreCallingIdentity(identity);
5568 }
5569 }
5570
5571 @Override
5572 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5573 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005574
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005575 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005576 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5577 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5578 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005579 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005580 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5581 if (controller != null) {
5582 ImsManager imsManager = controller.getImsManager(subId);
5583 if (imsManager != null) {
5584 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5585 } else {
5586 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5587 + " is inactive, ignoring unregister.");
5588 // If the ImsManager is not valid, just return, since the callback will already
5589 // have been removed internally.
5590 }
5591 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005592 } finally {
5593 Binder.restoreCallingIdentity(identity);
5594 }
5595 }
5596
joonhunshincffb7fc2021-11-28 07:32:01 +00005597 @Override
5598 public void registerFeatureProvisioningChangedCallback(int subId,
5599 IFeatureProvisioningCallback callback) {
5600 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5601 mApp, subId, "registerFeatureProvisioningChangedCallback");
5602
5603 final long identity = Binder.clearCallingIdentity();
5604 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5605 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5606 }
5607
joonhunshin91bc1952022-04-29 08:47:15 +00005608 try {
5609 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5610 if (controller == null) {
5611 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5612 "Device does not support IMS");
5613 }
5614 controller.addFeatureProvisioningChangedCallback(subId, callback);
5615 } finally {
5616 Binder.restoreCallingIdentity(identity);
5617 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005618 }
5619
5620 @Override
5621 public void unregisterFeatureProvisioningChangedCallback(int subId,
5622 IFeatureProvisioningCallback callback) {
5623 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5624 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5625
5626 final long identity = Binder.clearCallingIdentity();
5627 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5628 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5629 }
5630
joonhunshin91bc1952022-04-29 08:47:15 +00005631 try {
5632 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5633 if (controller == null) {
5634 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5635 return;
5636 }
5637 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5638 } finally {
5639 Binder.restoreCallingIdentity(identity);
5640 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005641 }
allenwtsu99c623b2020-01-03 18:24:23 +08005642
5643 private void checkModifyPhoneStatePermission(int subId, String message) {
5644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5645 message);
5646 }
5647
allenwtsu99c623b2020-01-03 18:24:23 +08005648 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005649 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005650 boolean isProvisioned) {
5651 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5652
5653 final long identity = Binder.clearCallingIdentity();
5654 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005655 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5656 if (controller == null) {
5657 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5658 return;
5659 }
5660 controller.setRcsProvisioningStatusForCapability(
5661 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005662 } finally {
5663 Binder.restoreCallingIdentity(identity);
5664 }
allenwtsu99c623b2020-01-03 18:24:23 +08005665 }
5666
5667
5668 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005669 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5670 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5671 mApp, subId, "getRcsProvisioningStatusForCapability");
5672
allenwtsu99c623b2020-01-03 18:24:23 +08005673 final long identity = Binder.clearCallingIdentity();
5674 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005675 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5676 if (controller == null) {
5677 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5678
5679 // device does not support IMS, this method will return true always.
5680 return true;
5681 }
5682 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685 }
5686 }
5687
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005688 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005689 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5690 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005691 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005692
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005693 final long identity = Binder.clearCallingIdentity();
5694 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005695 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5696 if (controller == null) {
5697 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5698 return;
5699 }
5700 controller.setImsProvisioningStatusForCapability(
5701 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005702 } finally {
5703 Binder.restoreCallingIdentity(identity);
5704 }
5705 }
5706
5707 @Override
5708 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005709 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5710 mApp, subId, "getProvisioningStatusForCapability");
5711
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005712 final long identity = Binder.clearCallingIdentity();
5713 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005714 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5715 if (controller == null) {
5716 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005717
joonhunshin91bc1952022-04-29 08:47:15 +00005718 // device does not support IMS, this method will return true always.
5719 return true;
5720 }
5721 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005722 } finally {
5723 Binder.restoreCallingIdentity(identity);
5724 }
5725 }
5726
5727 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005728 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5729 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5730 mApp, subId, "isProvisioningRequiredForCapability");
5731
5732 final long identity = Binder.clearCallingIdentity();
5733 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005734 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5735 if (controller == null) {
5736 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5737
5738 // device does not support IMS, this method will return false
5739 return false;
5740 }
5741 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005742 } finally {
5743 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005744 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005745 }
5746
5747 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005748 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5749 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5750 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005751
joonhunshincffb7fc2021-11-28 07:32:01 +00005752 final long identity = Binder.clearCallingIdentity();
5753 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005754 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5755 if (controller == null) {
5756 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5757
5758 // device does not support IMS, this method will return false
5759 return false;
5760 }
5761 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005762 } finally {
5763 Binder.restoreCallingIdentity(identity);
5764 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005765 }
5766
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005767 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005768 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005769 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5770 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5771 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005772 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5773 mApp, subId, "getImsProvisioningInt");
5774
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005775 final long identity = Binder.clearCallingIdentity();
5776 try {
5777 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005778 int slotId = getSlotIndex(subId);
5779 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5780 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5781 + subId + "' for key:" + key);
5782 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5783 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005784
joonhunshin91bc1952022-04-29 08:47:15 +00005785 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5786 if (controller == null) {
5787 loge("getImsProvisioningInt: Device does not support IMS");
5788
5789 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5790 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5791 }
5792 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005793 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5794 return retVal;
5795 }
5796
calvinpanb5a34062021-02-08 19:59:36 +08005797 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005798 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005799 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5800 + subId + "' for key:" + key);
5801 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005802 } finally {
5803 Binder.restoreCallingIdentity(identity);
5804 }
5805 }
5806
5807 @Override
5808 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005809 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5810 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5811 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005812 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5813 mApp, subId, "getImsProvisioningString");
5814
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005815 final long identity = Binder.clearCallingIdentity();
5816 try {
5817 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005818 int slotId = getSlotIndex(subId);
5819 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5820 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5821 + subId + "' for key:" + key);
5822 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5823 }
calvinpanb5a34062021-02-08 19:59:36 +08005824 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005825 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005826 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5827 + subId + "' for key:" + key);
5828 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005829 } finally {
5830 Binder.restoreCallingIdentity(identity);
5831 }
5832 }
5833
5834 @Override
5835 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005836 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5837 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5838 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5840 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005841
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005842 final long identity = Binder.clearCallingIdentity();
5843 try {
5844 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005845 int slotId = getSlotIndex(subId);
5846 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5847 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5848 + subId + "' for key:" + key);
5849 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5850 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005851
joonhunshin91bc1952022-04-29 08:47:15 +00005852 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5853 if (controller == null) {
5854 loge("setImsProvisioningInt: Device does not support IMS");
5855
5856 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5857 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5858 }
5859 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005860 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5861 return retVal;
5862 }
5863
calvinpanb5a34062021-02-08 19:59:36 +08005864 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5865 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005866 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005867 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005868 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005869 } finally {
5870 Binder.restoreCallingIdentity(identity);
5871 }
5872 }
5873
5874 @Override
5875 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005876 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5877 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5878 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5880 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005881 final long identity = Binder.clearCallingIdentity();
5882 try {
5883 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005884 int slotId = getSlotIndex(subId);
5885 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5886 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5887 + subId + "' for key:" + key);
5888 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5889 }
calvinpanb5a34062021-02-08 19:59:36 +08005890 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5891 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005892 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005893 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005894 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005895 } finally {
5896 Binder.restoreCallingIdentity(identity);
5897 }
5898 }
5899
Brad Ebinger919631e2021-06-02 17:46:35 -07005900 /**
5901 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5902 * for the given slot ID or no ImsResolver instance has been created.
5903 * @param slotId The slot ID that the IMS service is created for.
5904 * @throws ImsException If there is no ImsService configured for this slot.
5905 */
5906 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5907 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5908 ImsFeature.FEATURE_MMTEL)) {
5909 throw new ImsException("This subscription does not support MMTEL over IMS",
5910 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5911 }
5912 }
5913
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005914 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005915 int slotId = SubscriptionManager.getSlotIndex(subId);
5916 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005917 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5918 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005919 }
5920 return slotId;
5921 }
5922
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005923 private int getSlotIndex(int subId) {
5924 int slotId = SubscriptionManager.getSlotIndex(subId);
5925 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5926 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5927 }
5928 return slotId;
5929 }
5930
Wink Saville36469e72014-06-11 15:17:00 -07005931 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005932 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005933 */
5934 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005935 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5936 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005937 try {
5938 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5939 } catch (SecurityException se) {
5940 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5941 throw new SecurityException("Package " + callingPackage + " does not belong to "
5942 + Binder.getCallingUid());
5943 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005944 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005945 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005946 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005947 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005948 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005949 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005950 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005951 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5952 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005953
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005954 final long identity = Binder.clearCallingIdentity();
5955 try {
5956 final Phone phone = getPhone(subId);
5957 if (phone != null) {
5958 return phone.getServiceState().getDataNetworkType();
5959 } else {
5960 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5961 }
5962 } finally {
5963 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005964 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005965 }
5966
5967 /**
5968 * Returns the data network type
5969 */
5970 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005971 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005972 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005973 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005974 }
5975
5976 /**
5977 * Returns the data network type for a subId
5978 */
5979 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005980 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5981 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005982 String functionName = "getDataNetworkTypeForSubscriber";
5983 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5984 mApp, functionName)) {
5985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5986 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5987 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5988 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005989 }
5990
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005991 final long identity = Binder.clearCallingIdentity();
5992 try {
5993 final Phone phone = getPhone(subId);
5994 if (phone != null) {
5995 return phone.getServiceState().getDataNetworkType();
5996 } else {
5997 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5998 }
5999 } finally {
6000 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006001 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006002 }
6003
6004 /**
Wink Saville36469e72014-06-11 15:17:00 -07006005 * Returns the Voice network type for a subId
6006 */
6007 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006008 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
6009 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006010 String functionName = "getVoiceNetworkTypeForSubscriber";
6011 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
6012 mApp, functionName)) {
6013 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6014 mApp, subId, callingPackage, callingFeatureId, functionName)) {
6015 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6016 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07006017 }
6018
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006019 final long identity = Binder.clearCallingIdentity();
6020 try {
6021 final Phone phone = getPhone(subId);
6022 if (phone != null) {
6023 return phone.getServiceState().getVoiceNetworkType();
6024 } else {
6025 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
6026 }
6027 } finally {
6028 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006029 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006030 }
6031
6032 /**
6033 * @return true if a ICC card is present
6034 */
6035 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07006036 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08006037 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006038 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07006039 }
6040
6041 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006042 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07006043 */
Sanket Padawe356d7632015-06-22 14:03:32 -07006044 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006045 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006046 final long identity = Binder.clearCallingIdentity();
6047 try {
6048 final Phone phone = PhoneFactory.getPhone(slotIndex);
6049 if (phone != null) {
6050 return phone.getIccCard().hasIccCard();
6051 } else {
6052 return false;
6053 }
6054 } finally {
6055 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08006056 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006057 }
6058
6059 /**
6060 * Return if the current radio is LTE on CDMA. This
6061 * is a tri-state return value as for a period of time
6062 * the mode may be unknown.
6063 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006064 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006065 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08006066 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006067 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006068 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006069 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
6070 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
6071 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07006072 }
6073
Sanket Padawe356d7632015-06-22 14:03:32 -07006074 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006075 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
6076 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08006077 try {
6078 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
6079 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006080 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
6081 }
6082
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006083 final long identity = Binder.clearCallingIdentity();
6084 try {
6085 final Phone phone = getPhone(subId);
6086 if (phone == null) {
6087 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
6088 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07006089 return TelephonyProperties.lte_on_cdma_device()
6090 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 }
6092 } finally {
6093 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006094 }
Wink Saville36469e72014-06-11 15:17:00 -07006095 }
6096
Wink Saville36469e72014-06-11 15:17:00 -07006097 /**
6098 * {@hide}
6099 * Returns Default subId, 0 in the case of single standby.
6100 */
Wink Savilleb564aae2014-10-23 10:18:09 -07006101 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08006102 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07006103 }
6104
Shishir Agrawala9f32182016-04-12 12:00:16 -07006105 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08006106 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07006107 }
6108
Wink Savilleb564aae2014-10-23 10:18:09 -07006109 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08006110 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006111 }
Ihab Awadf2177b72013-11-25 13:33:23 -08006112
Pengquan Menge92a50d2018-09-21 15:54:48 -07006113 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08006114 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08006115 return getSubscriptionManagerService().isActiveSubId(subId,
Jack Yu285100e2022-12-02 22:48:35 -08006116 mApp.getOpPackageName(), mApp.getFeatureId());
6117 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07006118 return mSubscriptionController.isActiveSubId(subId);
6119 }
6120
Ihab Awadf2177b72013-11-25 13:33:23 -08006121 /**
6122 * @see android.telephony.TelephonyManager.WifiCallingChoices
6123 */
6124 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006125 final long identity = Binder.clearCallingIdentity();
6126 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006127 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
6129 getWhenToMakeWifiCallsDefaultPreference());
6130 } finally {
6131 Binder.restoreCallingIdentity(identity);
6132 }
Ihab Awadf2177b72013-11-25 13:33:23 -08006133 }
6134
6135 /**
6136 * @see android.telephony.TelephonyManager.WifiCallingChoices
6137 */
6138 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006139 final long identity = Binder.clearCallingIdentity();
6140 try {
6141 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006142 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006143 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
6144 } finally {
6145 Binder.restoreCallingIdentity(identity);
6146 }
Ihab Awadf9e92732013-12-05 18:02:52 -08006147 }
6148
Sailesh Nepald1e68152013-12-12 19:08:02 -08006149 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07006150 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08006151 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08006152 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08006153
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006154 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
6155 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
6156 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08006157 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006158 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006159 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08006160 }
6161 return PhoneFactory.getPhone(phoneId);
6162 }
6163
Shishir Agrawal566b7612013-10-28 14:41:00 -07006164 @Override
Derek Tan740e1672017-06-27 14:56:27 -07006165 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08006166 @NonNull IccLogicalChannelRequest request) {
6167 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6168 /*message=*/ "iccOpenLogicalChannel");
6169
6170 if (DBG) log("iccOpenLogicalChannel: request=" + request);
6171 // Verify that the callingPackage in the request belongs to the calling UID
6172 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
6173
6174 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006175 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006176
Rambo Wanga1782702021-11-10 20:15:19 -08006177 private Phone getPhoneFromValidIccLogicalChannelRequest(
6178 @NonNull IccLogicalChannelRequest request, String message) {
6179 Phone phone;
6180 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
6181 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6182 mApp, request.subId, message);
6183 phone = getPhoneFromSubId(request.subId);
6184 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6185 enforceModifyPermission();
6186 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
6187 } else {
6188 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08006189 }
Rambo Wanga1782702021-11-10 20:15:19 -08006190 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08006191 }
6192
6193 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08006194 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006195 final long identity = Binder.clearCallingIdentity();
6196 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006197 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006198 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006199 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6200 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08006201 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
6202 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006203 loge("The calling package is not allowed to access ISD-R.");
6204 throw new SecurityException(
6205 "The calling package is not allowed to access ISD-R.");
6206 }
Derek Tan740e1672017-06-27 14:56:27 -07006207 }
Derek Tan740e1672017-06-27 14:56:27 -07006208
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006209 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006210 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6211 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006212 return response;
6213 } finally {
6214 Binder.restoreCallingIdentity(identity);
6215 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006216 }
6217
6218 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006219 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
6220 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6221 /*message=*/"iccCloseLogicalChannel");
6222
6223 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6224
6225 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006226 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006227
Rambo Wanga1782702021-11-10 20:15:19 -08006228 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6229 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006230 // before this feature is enabled, this API should only return false if
6231 // the operation fails instead of throwing runtime exception for
6232 // backward-compatibility.
6233 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6234 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006235 final long identity = Binder.clearCallingIdentity();
6236 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006237 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006238 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006239 }
Chen Xue9d737e2022-01-01 23:41:31 -08006240 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006241 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006242 Boolean success = false;
6243 if (result instanceof RuntimeException) {
6244 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006245 if (shouldThrowExceptionOnFailure) {
6246 throw (RuntimeException) result;
6247 } else {
6248 return false;
6249 }
Chen Xue9d737e2022-01-01 23:41:31 -08006250 } else if (result instanceof Boolean) {
6251 success = (Boolean) result;
6252 } else {
6253 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6254 }
Rambo Wanga1782702021-11-10 20:15:19 -08006255 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006256 return success;
6257 } finally {
6258 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006259 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006260 }
6261
6262 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006263 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006264 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6266 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08006267 if (DBG) {
6268 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6269 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6270 + p3 + " data=" + data);
6271 }
6272 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6273 command, p1, p2, p3, data);
6274 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006275
Jordan Liu4c733742019-02-28 12:03:40 -08006276 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006277 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006278 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006279 enforceModifyPermission();
6280 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006281 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006282 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6283 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006284 }
6285 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006286 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6287 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006288 }
6289
6290 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6291 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006292 final long identity = Binder.clearCallingIdentity();
6293 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006294 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006295 return "";
6296 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006299 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6300 null /* workSource */);
6301 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006302
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006303 // Append the returned status code to the end of the response payload.
6304 String s = Integer.toHexString(
6305 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6306 if (response.payload != null) {
6307 s = IccUtils.bytesToHexString(response.payload) + s;
6308 }
6309 return s;
6310 } finally {
6311 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006312 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006313 }
Jake Hambye994d462014-02-03 13:10:13 -08006314
Evan Charltonc66da362014-05-16 14:06:40 -07006315 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006316 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6317 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006318 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6319 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006320 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08006321 if (DBG) {
6322 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6323 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6324 }
6325 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6326 cla, command, p1, p2, p3, data);
6327 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006328
Jordan Liu4c733742019-02-28 12:03:40 -08006329 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006330 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006331 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006332 enforceModifyPermission();
6333 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6334 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006335 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006336 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6337 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006338 }
6339
6340 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006341 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6342 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006343 }
6344
6345 // open APDU basic channel assuming the caller has sufficient permissions
6346 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6347 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006348 final long identity = Binder.clearCallingIdentity();
6349 try {
6350 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6351 && TextUtils.equals(ISDR_AID, data)) {
6352 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006353 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6354 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006355 if (bestComponent == null
6356 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6357 loge("The calling package is not allowed to select ISD-R.");
6358 throw new SecurityException(
6359 "The calling package is not allowed to select ISD-R.");
6360 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006361 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006363 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006364 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6365 null /* workSource */);
6366 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006367
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 // Append the returned status code to the end of the response payload.
6369 String s = Integer.toHexString(
6370 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6371 if (response.payload != null) {
6372 s = IccUtils.bytesToHexString(response.payload) + s;
6373 }
6374 return s;
6375 } finally {
6376 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006377 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006378 }
6379
6380 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006381 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006382 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006383 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6384 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006385
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006386 final long identity = Binder.clearCallingIdentity();
6387 try {
6388 if (DBG) {
6389 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6390 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6391 }
6392
6393 IccIoResult response =
6394 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6395 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6396 subId);
6397
6398 if (DBG) {
6399 log("Exchange SIM_IO [R]" + response);
6400 }
6401
6402 byte[] result = null;
6403 int length = 2;
6404 if (response.payload != null) {
6405 length = 2 + response.payload.length;
6406 result = new byte[length];
6407 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6408 } else {
6409 result = new byte[length];
6410 }
6411
6412 result[length - 1] = (byte) response.sw2;
6413 result[length - 2] = (byte) response.sw1;
6414 return result;
6415 } finally {
6416 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006417 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006418 }
6419
Nathan Haroldb3014052017-01-25 15:57:32 -08006420 /**
6421 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6422 * on a particular subscription
6423 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006424 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6425 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006426 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006427 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006428 return null;
6429 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006430
6431 final long identity = Binder.clearCallingIdentity();
6432 try {
6433 if (appType != TelephonyManager.APPTYPE_USIM
6434 && appType != TelephonyManager.APPTYPE_SIM) {
6435 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6436 return null;
6437 }
6438 Object response = sendRequest(
6439 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6440 if (response instanceof String[]) {
6441 return (String[]) response;
6442 }
yincheng zhao2737e882019-09-06 17:06:54 -07006443 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006444 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006445 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006446 } finally {
6447 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006448 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006449 }
6450
yincheng zhao2737e882019-09-06 17:06:54 -07006451 /**
6452 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6453 * subscription.
6454 *
6455 * @param subId the id of the subscription.
6456 * @param appType the uicc app type, must be USIM or SIM.
6457 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6458 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006459 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006460 * @return number of fplmns that is successfully written to the SIM.
6461 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006462 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6463 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6465 mApp, subId, "setForbiddenPlmns");
6466
yincheng zhao2737e882019-09-06 17:06:54 -07006467 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6468 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6469 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6470 }
6471 if (fplmns == null) {
6472 throw new IllegalArgumentException("Fplmn List provided is null");
6473 }
6474 for (String fplmn : fplmns) {
6475 if (!CellIdentity.isValidPlmn(fplmn)) {
6476 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6477 }
6478 }
6479 final long identity = Binder.clearCallingIdentity();
6480 try {
6481 Object response = sendRequest(
6482 CMD_SET_FORBIDDEN_PLMNS,
6483 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6484 subId);
6485 return (int) response;
6486 } finally {
6487 Binder.restoreCallingIdentity(identity);
6488 }
6489 }
6490
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006491 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006492 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6494 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006495
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006496 final long identity = Binder.clearCallingIdentity();
6497 try {
6498 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6499 if (response.payload == null) {
6500 return "";
6501 }
Evan Charltonc66da362014-05-16 14:06:40 -07006502
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006503 // Append the returned status code to the end of the response payload.
6504 String s = Integer.toHexString(
6505 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6506 s = IccUtils.bytesToHexString(response.payload) + s;
6507 return s;
6508 } finally {
6509 Binder.restoreCallingIdentity(identity);
6510 }
Evan Charltonc66da362014-05-16 14:06:40 -07006511 }
6512
Jake Hambye994d462014-02-03 13:10:13 -08006513 /**
6514 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6515 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6516 *
6517 * @param itemID the ID of the item to read
6518 * @return the NV item as a String, or null on error.
6519 */
6520 @Override
6521 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006522 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6524 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006525
6526 final long identity = Binder.clearCallingIdentity();
6527 try {
6528 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006529 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006530 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6531 return value;
6532 } finally {
6533 Binder.restoreCallingIdentity(identity);
6534 }
Jake Hambye994d462014-02-03 13:10:13 -08006535 }
6536
6537 /**
6538 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6539 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6540 *
6541 * @param itemID the ID of the item to read
6542 * @param itemValue the value to write, as a String
6543 * @return true on success; false on any failure
6544 */
6545 @Override
6546 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006547 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6549 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006550
6551 final long identity = Binder.clearCallingIdentity();
6552 try {
6553 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6554 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006555 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006556 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6557 return success;
6558 } finally {
6559 Binder.restoreCallingIdentity(identity);
6560 }
Jake Hambye994d462014-02-03 13:10:13 -08006561 }
6562
6563 /**
6564 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6565 * Used for device configuration by some CDMA operators.
6566 *
6567 * @param preferredRoamingList byte array containing the new PRL
6568 * @return true on success; false on any failure
6569 */
6570 @Override
6571 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6573 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006574
6575 final long identity = Binder.clearCallingIdentity();
6576 try {
6577 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6578 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6579 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6580 return success;
6581 } finally {
6582 Binder.restoreCallingIdentity(identity);
6583 }
Jake Hambye994d462014-02-03 13:10:13 -08006584 }
6585
6586 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006587 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006588 * Used for device configuration by some CDMA operators.
6589 *
chen xu6dac5ab2018-10-26 17:39:23 -07006590 * @param slotIndex - device slot.
6591 *
Jake Hambye994d462014-02-03 13:10:13 -08006592 * @return true on success; false on any failure
6593 */
6594 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006595 public boolean resetModemConfig(int slotIndex) {
6596 Phone phone = PhoneFactory.getPhone(slotIndex);
6597 if (phone != null) {
6598 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6599 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006600
chen xu6dac5ab2018-10-26 17:39:23 -07006601 final long identity = Binder.clearCallingIdentity();
6602 try {
6603 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6604 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6605 return success;
6606 } finally {
6607 Binder.restoreCallingIdentity(identity);
6608 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006609 }
chen xu6dac5ab2018-10-26 17:39:23 -07006610 return false;
6611 }
6612
6613 /**
6614 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6615 *
6616 * @param slotIndex - device slot.
6617 *
6618 * @return true on success; false on any failure
6619 */
6620 @Override
6621 public boolean rebootModem(int slotIndex) {
6622 Phone phone = PhoneFactory.getPhone(slotIndex);
6623 if (phone != null) {
6624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6625 mApp, phone.getSubId(), "rebootModem");
6626
6627 final long identity = Binder.clearCallingIdentity();
6628 try {
6629 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6630 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6631 return success;
6632 } finally {
6633 Binder.restoreCallingIdentity(identity);
6634 }
6635 }
6636 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006637 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006638
Brad Ebinger51f743a2017-01-23 13:50:20 -08006639 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006640 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6641 * {@link #disableIms(int)}.
6642 * @param slotIndex device slot.
6643 */
6644 public void resetIms(int slotIndex) {
6645 enforceModifyPermission();
6646
6647 final long identity = Binder.clearCallingIdentity();
6648 try {
6649 if (mImsResolver == null) {
6650 // may happen if the does not support IMS.
6651 return;
6652 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006653 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006654 } finally {
6655 Binder.restoreCallingIdentity(identity);
6656 }
6657 }
6658
6659 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006660 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6661 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006662 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006663 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006664 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006665
6666 final long identity = Binder.clearCallingIdentity();
6667 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006668 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006669 // may happen if the device does not support IMS.
6670 return;
6671 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006672 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006673 } finally {
6674 Binder.restoreCallingIdentity(identity);
6675 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006676 }
6677
6678 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006679 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6680 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006681 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006682 public void disableIms(int slotId) {
6683 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006684
6685 final long identity = Binder.clearCallingIdentity();
6686 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006687 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006688 // may happen if the device does not support IMS.
6689 return;
6690 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006691 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006692 } finally {
6693 Binder.restoreCallingIdentity(identity);
6694 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006695 }
6696
6697 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006698 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6699 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006700 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006701 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006702 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006703 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006704
6705 final long identity = Binder.clearCallingIdentity();
6706 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006707 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006708 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6709 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006710 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006711 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006712 } finally {
6713 Binder.restoreCallingIdentity(identity);
6714 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006715 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006716 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006717 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6718 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006719 @Override
6720 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006721 enforceModifyPermission();
6722
6723 final long identity = Binder.clearCallingIdentity();
6724 try {
6725 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006726 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006727 } finally {
6728 Binder.restoreCallingIdentity(identity);
6729 }
6730 }
6731
6732 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006733 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006734 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006735 */
6736 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6737 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006738
6739 final long identity = Binder.clearCallingIdentity();
6740 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006741 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006742 // may happen if the device does not support IMS.
6743 return null;
6744 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006745 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006746 } finally {
6747 Binder.restoreCallingIdentity(identity);
6748 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006749 }
6750
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006751 /**
6752 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006753 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006754 */
6755 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6756 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006757
6758 final long identity = Binder.clearCallingIdentity();
6759 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006760 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006761 // may happen if the device does not support IMS.
6762 return null;
6763 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006764 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006765 } finally {
6766 Binder.restoreCallingIdentity(identity);
6767 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006768 }
6769
Brad Ebinger884c07b2018-02-15 16:17:40 -08006770 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006771 * Sets the ImsService Package Name that Telephony will bind to.
6772 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006773 * @param slotIndex the slot ID that the ImsService should bind for.
6774 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006775 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006776 * @param featureTypes An integer array of feature types associated with a packageName.
6777 * @param packageName The name of the package that the current configuration will be replaced
6778 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006779 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006780 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006781 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6782 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006783 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006785 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006787 final long identity = Binder.clearCallingIdentity();
6788 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006789 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006790 // may happen if the device does not support IMS.
6791 return false;
6792 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006793 Map<Integer, String> featureConfig = new HashMap<>();
6794 for (int featureType : featureTypes) {
6795 featureConfig.put(featureType, packageName);
6796 }
6797 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6798 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006799 } finally {
6800 Binder.restoreCallingIdentity(identity);
6801 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006802 }
6803
6804 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006805 * Clears any carrier ImsService overrides for the slot index specified that were previously
6806 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6807 *
6808 * This should only be used for testing.
6809 *
6810 * @param slotIndex the slot ID that the ImsService should bind for.
6811 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6812 */
6813 @Override
6814 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006815 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6816 "clearCarrierImsServiceOverride");
6817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006818 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006819
6820 final long identity = Binder.clearCallingIdentity();
6821 try {
6822 if (mImsResolver == null) {
6823 // may happen if the device does not support IMS.
6824 return false;
6825 }
6826 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6827 } finally {
6828 Binder.restoreCallingIdentity(identity);
6829 }
6830 }
6831
6832 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006833 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006834 *
6835 * @param slotId The slot that the ImsService is associated with.
6836 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6837 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006838 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006839 * @return the package name of the ImsService configuration.
6840 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006841 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6842 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006843 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006844 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6845 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006846
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006847 final long identity = Binder.clearCallingIdentity();
6848 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006849 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006850 // may happen if the device does not support IMS.
6851 return "";
6852 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006853 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006854 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6855 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006856 } finally {
6857 Binder.restoreCallingIdentity(identity);
6858 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006859 }
6860
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006861 /**
6862 * Get the MmTelFeature state associated with the requested subscription id.
6863 * @param subId The subscription that the MmTelFeature is associated with.
6864 * @param callback A callback with an integer containing the
6865 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6866 */
6867 @Override
6868 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6869 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006870 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6871 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6872 "IMS not available on device.");
6873 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006874 final long token = Binder.clearCallingIdentity();
6875 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006876 int slotId = getSlotIndex(subId);
6877 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6878 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6879 + subId + "'");
6880 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6881 }
6882 verifyImsMmTelConfiguredOrThrow(slotId);
6883 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6884 try {
6885 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6886 } catch (RemoteException e) {
6887 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6888 + "Ignore");
6889 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006890 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006891 } catch (ImsException e) {
6892 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006893 } finally {
6894 Binder.restoreCallingIdentity(token);
6895 }
6896 }
6897
Daniel Brightbb5840b2021-01-12 15:48:18 -08006898 /**
6899 * Sets the ims registration state on all valid {@link Phone}s.
6900 */
6901 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006902 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006903
6904 final long identity = Binder.clearCallingIdentity();
6905 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006906 // NOTE: Before S, this method only set the default phone.
6907 for (final Phone phone : PhoneFactory.getPhones()) {
6908 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6909 phone.setImsRegistrationState(registered);
6910 }
6911 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006912 } finally {
6913 Binder.restoreCallingIdentity(identity);
6914 }
Wink Saville36469e72014-06-11 15:17:00 -07006915 }
6916
6917 /**
Stuart Scott54788802015-03-30 13:18:01 -07006918 * Set the network selection mode to automatic.
6919 *
6920 */
6921 @Override
6922 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006923 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6924 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006925
6926 final long identity = Binder.clearCallingIdentity();
6927 try {
shilufc958392020-01-20 11:36:01 -08006928 if (!isActiveSubscription(subId)) {
6929 return;
6930 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006931 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006932 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6933 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006934 } finally {
6935 Binder.restoreCallingIdentity(identity);
6936 }
Stuart Scott54788802015-03-30 13:18:01 -07006937 }
6938
Jack Yud10cdd42020-09-28 20:28:01 -07006939 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006940 * Ask the radio to connect to the input network and change selection mode to manual.
6941 *
6942 * @param subId the id of the subscription.
6943 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6944 * the operator to attach to.
6945 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6946 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6947 * normal network selection next time.
6948 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006949 */
6950 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006951 public boolean setNetworkSelectionModeManual(
6952 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6954 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006955
Jack Yu285100e2022-12-02 22:48:35 -08006956 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006957 if (!isActiveSubscription(subId)) {
6958 return false;
6959 }
6960
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006961 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006962 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006963 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006964 if (DBG) {
6965 log("setNetworkSelectionModeManual: subId: " + subId
6966 + " operator: " + operatorInfo);
6967 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006968 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6969 } finally {
6970 Binder.restoreCallingIdentity(identity);
6971 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006972 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006973 /**
shilu84f6e8b2019-12-19 13:58:01 -08006974 * Get the manual network selection
6975 *
6976 * @param subId the id of the subscription.
6977 *
6978 * @return the previously saved user selected PLMN
6979 */
6980 @Override
6981 public String getManualNetworkSelectionPlmn(int subId) {
6982 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006983 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6984 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006985
6986 final long identity = Binder.clearCallingIdentity();
6987 try {
6988 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006989 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006990 }
6991
6992 final Phone phone = getPhone(subId);
6993 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006994 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006995 }
6996 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6997 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006998 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006999 } finally {
7000 Binder.restoreCallingIdentity(identity);
7001 }
7002 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07007003
7004 /**
7005 * Scans for available networks.
7006 */
7007 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007008 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
7009 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7011 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08007012 LocationAccessPolicy.LocationPermissionResult locationResult =
7013 LocationAccessPolicy.checkLocationPermission(mApp,
7014 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7015 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007016 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007017 .setCallingPid(Binder.getCallingPid())
7018 .setCallingUid(Binder.getCallingUid())
7019 .setMethod("getCellNetworkScanResults")
7020 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007021 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7022 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007023 .build());
7024 switch (locationResult) {
7025 case DENIED_HARD:
7026 throw new SecurityException("Not allowed to access scan results -- location");
7027 case DENIED_SOFT:
7028 return null;
7029 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007030
Pengquan Menga1bb6272018-09-06 09:59:22 -07007031 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007032 try {
7033 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07007034 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007035 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007036 } finally {
7037 Binder.restoreCallingIdentity(identity);
7038 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07007039 }
7040
7041 /**
Shuo Qian4a594052020-01-23 11:59:30 -08007042 * Get the call forwarding info, given the call forwarding reason.
7043 */
7044 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007045 public void getCallForwarding(int subId, int callForwardingReason,
7046 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007047 enforceReadPrivilegedPermission("getCallForwarding");
7048 long identity = Binder.clearCallingIdentity();
7049 try {
7050 if (DBG) {
7051 log("getCallForwarding: subId " + subId
7052 + " callForwardingReason" + callForwardingReason);
7053 }
Hall Liu27d24262020-09-18 19:04:59 -07007054
7055 Phone phone = getPhone(subId);
7056 if (phone == null) {
7057 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07007058 callback.onError(
7059 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07007060 } catch (RemoteException e) {
7061 // ignore
7062 }
7063 return;
7064 }
7065
7066 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
7067 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
7068 @Override
7069 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
7070 try {
7071 callback.onCallForwardingInfoAvailable(info);
7072 } catch (RemoteException e) {
7073 // ignore
7074 }
7075 }
7076
7077 @Override
7078 public void onError(int error) {
7079 try {
7080 callback.onError(error);
7081 } catch (RemoteException e) {
7082 // ignore
7083 }
7084 }
7085 });
7086 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007087 } finally {
7088 Binder.restoreCallingIdentity(identity);
7089 }
7090 }
7091
7092 /**
7093 * Sets the voice call forwarding info including status (enable/disable), call forwarding
7094 * reason, the number to forward, and the timeout before the forwarding is attempted.
7095 */
7096 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007097 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
7098 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007099 enforceModifyPermission();
7100 long identity = Binder.clearCallingIdentity();
7101 try {
7102 if (DBG) {
7103 log("setCallForwarding: subId " + subId
7104 + " callForwardingInfo" + callForwardingInfo);
7105 }
Hall Liu27d24262020-09-18 19:04:59 -07007106
7107 Phone phone = getPhone(subId);
7108 if (phone == null) {
7109 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07007110 callback.accept(
7111 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07007112 } catch (RemoteException e) {
7113 // ignore
7114 }
7115 return;
7116 }
7117
7118 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
7119 FunctionalUtils.ignoreRemoteException(callback::accept));
7120
7121 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08007122 } finally {
7123 Binder.restoreCallingIdentity(identity);
7124 }
7125 }
7126
7127 /**
Hall Liu27d24262020-09-18 19:04:59 -07007128 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007129 */
7130 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007131 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08007132 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08007133 long identity = Binder.clearCallingIdentity();
7134 try {
Hall Liu27d24262020-09-18 19:04:59 -07007135 Phone phone = getPhone(subId);
7136 if (phone == null) {
7137 try {
7138 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7139 } catch (RemoteException e) {
7140 // ignore
7141 }
7142 return;
7143 }
SongFerngWang0e767992021-03-31 22:08:45 +08007144 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7145 PersistableBundle c = configManager.getConfigForSubId(subId);
7146 boolean requireUssd = c.getBoolean(
7147 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007148
Shuo Qian4a594052020-01-23 11:59:30 -08007149 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08007150 if (requireUssd) {
7151 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7152 getSubscriptionCarrierId(subId));
7153 String newUssdCommand = "";
7154 try {
7155 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007156 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007157 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
7158 } catch (NullPointerException e) {
7159 loge("Failed to generate USSD number" + e);
7160 }
7161 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7162 mMainThreadHandler, callback, carrierXmlParser,
7163 CarrierXmlParser.SsEntry.SSAction.QUERY);
7164 final String ussdCommand = newUssdCommand;
7165 Executors.newSingleThreadExecutor().execute(() -> {
7166 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7167 });
7168 } else {
7169 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
7170 callback::accept);
7171 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
7172 }
Shuo Qian4a594052020-01-23 11:59:30 -08007173 } finally {
7174 Binder.restoreCallingIdentity(identity);
7175 }
7176 }
7177
7178 /**
Hall Liu27d24262020-09-18 19:04:59 -07007179 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08007180 */
7181 @Override
Hall Liu27d24262020-09-18 19:04:59 -07007182 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08007183 enforceModifyPermission();
7184 long identity = Binder.clearCallingIdentity();
7185 try {
Hall Liu27d24262020-09-18 19:04:59 -07007186 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
7187
7188 Phone phone = getPhone(subId);
7189 if (phone == null) {
7190 try {
7191 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
7192 } catch (RemoteException e) {
7193 // ignore
7194 }
7195 return;
7196 }
7197
SongFerngWang0e767992021-03-31 22:08:45 +08007198 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
7199 PersistableBundle c = configManager.getConfigForSubId(subId);
7200 boolean requireUssd = c.getBoolean(
7201 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07007202
SongFerngWang0e767992021-03-31 22:08:45 +08007203 if (DBG) log("getCallWaitingStatus: subId " + subId);
7204 if (requireUssd) {
7205 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7206 getSubscriptionCarrierId(subId));
7207 CarrierXmlParser.SsEntry.SSAction ssAction =
7208 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7209 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7210 String newUssdCommand = "";
7211 try {
7212 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007213 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007214 .makeCommand(ssAction, null);
7215 } catch (NullPointerException e) {
7216 loge("Failed to generate USSD number" + e);
7217 }
7218 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7219 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7220 final String ussdCommand = newUssdCommand;
7221 Executors.newSingleThreadExecutor().execute(() -> {
7222 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7223 });
7224 } else {
7225 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7226 FunctionalUtils.ignoreRemoteException(callback::accept));
7227
7228 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7229 }
Shuo Qian4a594052020-01-23 11:59:30 -08007230 } finally {
7231 Binder.restoreCallingIdentity(identity);
7232 }
7233 }
7234
7235 /**
yinxub1bed742017-04-17 11:45:04 -07007236 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007237 *
yinxub1bed742017-04-17 11:45:04 -07007238 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007239 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7240 * location related information which will be sent if the caller already possess
7241 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007242 * @param request contains the radio access networks with bands/channels to scan
7243 * @param messenger callback messenger for scan results or errors
7244 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007245 * @return the id of the requested scan which can be used to stop the scan.
7246 */
7247 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007248 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7249 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007250 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7252 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007253 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007254 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7255 if (!renounceFineLocationAccess) {
7256 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007257 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7258 .setCallingPackage(callingPackage)
7259 .setCallingFeatureId(callingFeatureId)
7260 .setCallingPid(Binder.getCallingPid())
7261 .setCallingUid(Binder.getCallingUid())
7262 .setMethod("requestNetworkScan")
7263 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7264 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7265 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7266 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007267 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007268 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007269 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7270 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007271 if (e != null) {
7272 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7273 throw e;
7274 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007275 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007276 return TelephonyScanManager.INVALID_SCAN_ID;
7277 }
7278 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007279 }
Hall Liu912dfd32019-04-25 14:02:26 -07007280 int callingUid = Binder.getCallingUid();
7281 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007282 final long identity = Binder.clearCallingIdentity();
7283 try {
7284 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007285 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007286 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007287 } finally {
7288 Binder.restoreCallingIdentity(identity);
7289 }
yinxu504e1392017-04-12 16:03:22 -07007290 }
7291
Hall Liub2ac8ef2019-02-28 15:56:23 -08007292 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007293 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007294 boolean hasCarrierPriv;
7295 final long identity = Binder.clearCallingIdentity();
7296 try {
7297 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7298 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7299 } finally {
7300 Binder.restoreCallingIdentity(identity);
7301 }
Hall Liu558027f2019-05-15 19:14:05 -07007302 boolean hasNetworkScanPermission =
7303 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007304 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007305
7306 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7307 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7308 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007309 }
7310
7311 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7312 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007313 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7314 return new SecurityException("Specific channels must not be"
7315 + " scanned without location access.");
7316 }
7317 }
7318 }
7319
Hall Liub2ac8ef2019-02-28 15:56:23 -08007320 return null;
7321 }
7322
yinxu504e1392017-04-12 16:03:22 -07007323 /**
7324 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007325 *
7326 * @param subId id of the subscription
7327 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007328 */
7329 @Override
7330 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7332 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007333
Hall Liu912dfd32019-04-25 14:02:26 -07007334 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007335 final long identity = Binder.clearCallingIdentity();
7336 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007337 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007338 } finally {
7339 Binder.restoreCallingIdentity(identity);
7340 }
yinxu504e1392017-04-12 16:03:22 -07007341 }
7342
7343 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007344 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007345 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007346 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007347 */
7348 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007349 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007350 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007351 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007352 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007353
7354 final long identity = Binder.clearCallingIdentity();
7355 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007356 if (DBG) log("getAllowedNetworkTypesBitmask");
7357 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7358 int networkTypesBitmask = (result != null ? result[0] : -1);
7359 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7360 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007361 } finally {
7362 Binder.restoreCallingIdentity(identity);
7363 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007364 }
7365
7366 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007367 * Get the allowed network types for certain reason.
7368 *
7369 * @param subId the id of the subscription.
7370 * @param reason the reason the allowed network type change is taking place
7371 * @return the allowed network types.
7372 */
7373 @Override
7374 public long getAllowedNetworkTypesForReason(int subId,
7375 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007376 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007377 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007378 final long identity = Binder.clearCallingIdentity();
7379 try {
7380 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
7381 } finally {
7382 Binder.restoreCallingIdentity(identity);
7383 }
7384 }
7385
7386 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007387 * Enable/Disable E-UTRA-NR Dual Connectivity
7388 * @param subId subscription id of the sim card
7389 * @param nrDualConnectivityState expected NR dual connectivity state
7390 * This can be passed following states
7391 * <ol>
7392 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7393 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7394 * <li>Disable NR dual connectivity and force secondary cell to be released
7395 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7396 * </ol>
7397 * @return operation result.
7398 */
7399 @Override
7400 public int setNrDualConnectivityState(int subId,
7401 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7403 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007404 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007405 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7406 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7407 }
7408
Sooraj Sasindran37444802020-08-11 10:40:43 -07007409 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7410 final long identity = Binder.clearCallingIdentity();
7411 try {
7412 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7413 nrDualConnectivityState, subId,
7414 workSource);
7415 if (DBG) log("enableNRDualConnectivity result: " + result);
7416 return result;
7417 } finally {
7418 Binder.restoreCallingIdentity(identity);
7419 }
7420 }
7421
7422 /**
7423 * Is E-UTRA-NR Dual Connectivity enabled
7424 * @return true if dual connectivity is enabled else false
7425 */
7426 @Override
7427 public boolean isNrDualConnectivityEnabled(int subId) {
7428 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007429 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007430 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007431 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007432 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7433 return false;
7434 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007435 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7436 final long identity = Binder.clearCallingIdentity();
7437 try {
7438 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7439 null, subId, workSource);
7440 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7441 return isEnabled;
7442 } finally {
7443 Binder.restoreCallingIdentity(identity);
7444 }
7445 }
7446
7447 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007448 * Set the allowed network types of the device and
7449 * provide the reason triggering the allowed network change.
7450 *
7451 * @param subId the id of the subscription.
7452 * @param reason the reason the allowed network type change is taking place
7453 * @param allowedNetworkTypes the allowed network types.
7454 * @return true on success; false on any failure.
7455 */
7456 @Override
7457 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007458 @TelephonyManager.AllowedNetworkTypesReason int reason,
7459 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7461 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007462 // If the caller only has carrier privileges, then they should not be able to override
7463 // any network types which were set for security reasons.
7464 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7465 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007466 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007467 throw new SecurityException(
7468 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007469 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007470 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08007471 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007472 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007473 return false;
7474 }
7475 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7476 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007477 return false;
7478 }
7479
Jack Yu5b494332023-01-23 18:18:04 +00007480 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7481 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007482
Jack Yue37dd262022-12-16 11:53:37 -08007483 Phone phone = getPhone(subId);
7484 if (phone == null) {
7485 return false;
7486 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007487
Jack Yue37dd262022-12-16 11:53:37 -08007488 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007489 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007490 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007491 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007492
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007493 final long identity = Binder.clearCallingIdentity();
7494 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007495 Boolean success = (Boolean) sendRequest(
7496 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7497 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7498
7499 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7500 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007501 } finally {
7502 Binder.restoreCallingIdentity(identity);
7503 }
7504 }
7505
7506 /**
Miaoa84611c2019-03-15 09:21:10 +08007507 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007508 *
Miaoa84611c2019-03-15 09:21:10 +08007509 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007510 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007511 * @hide
7512 */
7513 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007514 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007515 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007516 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007517 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007518 try {
Miaoa84611c2019-03-15 09:21:10 +08007519 if (phone != null) {
7520 return phone.hasMatchedTetherApnSetting();
7521 } else {
7522 return false;
7523 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007524 } finally {
7525 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007526 }
Junda Liu475951f2014-11-07 16:45:03 -08007527 }
7528
7529 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007530 * Get the user enabled state of Mobile Data.
7531 *
7532 * TODO: remove and use isUserDataEnabled.
7533 * This can't be removed now because some vendor codes
7534 * calls through ITelephony directly while they should
7535 * use TelephonyManager.
7536 *
7537 * @return true on enabled
7538 */
7539 @Override
7540 public boolean getDataEnabled(int subId) {
7541 return isUserDataEnabled(subId);
7542 }
7543
7544 /**
7545 * Get whether mobile data is enabled per user setting.
7546 *
7547 * There are other factors deciding whether mobile data is actually enabled, but they are
7548 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007549 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007550 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7551 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007552 *
7553 * @return {@code true} if data is enabled else {@code false}
7554 */
7555 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007556 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007557 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007558 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007559 try {
7560 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7561 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007562 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007563 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7564 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007565 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007566 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007567 mApp, subId, functionName);
7568
Robert Greenwalt646120a2014-05-23 11:54:03 -07007569 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007570
7571 final long identity = Binder.clearCallingIdentity();
7572 try {
Jack Yu285100e2022-12-02 22:48:35 -08007573 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007574 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7575 Phone phone = PhoneFactory.getPhone(phoneId);
7576 if (phone != null) {
7577 boolean retVal = phone.isUserDataEnabled();
7578 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7579 return retVal;
7580 } else {
7581 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7582 return false;
7583 }
7584 } finally {
7585 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007586 }
7587 }
7588
7589 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007590 * Checks if the device is capable of mobile data by considering whether whether the
7591 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7592 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007593 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007594 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007595 */
7596 @Override
7597 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007598 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007599 try {
7600 try {
7601 mApp.enforceCallingOrSelfPermission(
7602 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007603 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007604 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007605 try {
7606 mApp.enforceCallingOrSelfPermission(
7607 android.Manifest.permission.READ_PHONE_STATE,
7608 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007609 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007610 mApp.enforceCallingOrSelfPermission(
7611 permission.READ_BASIC_PHONE_STATE, functionName);
7612 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007613 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007614 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007615 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007616 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007617
7618 final long identity = Binder.clearCallingIdentity();
7619 try {
Jack Yu285100e2022-12-02 22:48:35 -08007620 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007621 Phone phone = PhoneFactory.getPhone(phoneId);
7622 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007623 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007624 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007625 return retVal;
7626 } else {
7627 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7628 return false;
7629 }
7630 } finally {
7631 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007632 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007633 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007634
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007635 /**
7636 * Check if data is enabled for a specific reason
7637 * @param subId Subscription index
7638 * @param reason the reason the data enable change is taking place
7639 * @return {@code true} if the overall data is enabled; {@code false} if not.
7640 */
7641 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007642 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007643 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007644 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007645 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007646 try {
7647 mApp.enforceCallingOrSelfPermission(
7648 android.Manifest.permission.ACCESS_NETWORK_STATE,
7649 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007650 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007651 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7652 functionName);
7653 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007654 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007655 try {
7656 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007657 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007658 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007660 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007661 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007662 }
7663
7664
7665 final long identity = Binder.clearCallingIdentity();
7666 try {
Jack Yu285100e2022-12-02 22:48:35 -08007667 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007668 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007669 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007670 + " reason=" + reason);
7671 }
7672 Phone phone = PhoneFactory.getPhone(phoneId);
7673 if (phone != null) {
7674 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007675 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007676 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007677 return retVal;
7678 } else {
7679 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007680 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007681 + subId + " retVal=false");
7682 }
7683 return false;
7684 }
7685 } finally {
7686 Binder.restoreCallingIdentity(identity);
7687 }
7688 }
7689
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007690 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007691 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007692 // No permission needed; this only lets the caller inspect their own status.
7693 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007694 }
Junda Liu29340342014-07-10 15:23:27 -07007695
7696 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007697 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007698 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007699 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7700 }
7701
7702 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7703 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007704 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007705 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007706 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7707 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007708 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7709 if (cpt == null) {
7710 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007711 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7712 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007713 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007714 }
7715
7716 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007717 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007718 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007719 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007720 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007721 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007722 Phone phone = getPhone(subId);
7723 if (phone == null) {
7724 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7725 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7726 }
7727 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7728 if (cpt == null) {
7729 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007730 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7731 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007732 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007733 }
7734
7735 @Override
7736 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007737 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007738 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7739 }
7740
7741 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007742 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007743 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007744 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007745 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007746 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7747 Phone phone = PhoneFactory.getPhone(phoneId);
7748 if (phone == null) {
7749 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007750 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007751 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7752 if (cpt == null) {
7753 continue;
7754 }
7755 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007756 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7757 break;
7758 }
7759 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007760 return result;
Junda Liu29340342014-07-10 15:23:27 -07007761 }
Derek Tan89e89d42014-07-08 17:00:10 -07007762
7763 @Override
Junda Liue64de782015-04-16 17:19:16 -07007764 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007765 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007766 Phone phone = PhoneFactory.getPhone(phoneId);
7767 if (phone == null) {
7768 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007769 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007770 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7771 if (cpt == null) {
7772 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007773 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007774 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007775 }
7776
Amith Yamasani6e118872016-02-19 12:53:51 -08007777 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007778 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007779 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007780 Phone phone = PhoneFactory.getPhone(phoneId);
7781 if (phone == null) {
7782 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007783 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007784 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7785 if (cpt == null) {
7786 return Collections.emptyList();
7787 }
7788 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007789 }
7790
chen xuf7e9fe82019-05-09 19:31:02 -07007791 @Override
7792 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007793 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007794 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007795 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007796 try {
7797 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7798 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7799 }
7800 } finally {
7801 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007802 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007803 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007804 }
7805
Rambo Wang6812ffb2022-03-15 16:54:17 -07007806 @Override
7807 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7808 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7809
7810 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7811 if (phone == null) {
7812 return null;
7813 }
7814 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7815 if (cpt == null) {
7816 return null;
7817 }
7818 return cpt.getCarrierServicePackageName();
7819 }
7820
Wink Savilleb564aae2014-10-23 10:18:09 -07007821 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007822 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007823 UiccPort port = phone == null ? null : phone.getUiccPort();
7824 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007825 return null;
7826 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007827 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007828 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007829 return null;
7830 }
7831 return iccId;
7832 }
7833
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007834 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007835 public void setCallComposerStatus(int subId, int status) {
7836 enforceModifyPermission();
7837
7838 final long identity = Binder.clearCallingIdentity();
7839 try {
7840 Phone phone = getPhone(subId);
7841 if (phone != null) {
7842 Phone defaultPhone = phone.getImsPhone();
7843 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7844 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7845 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007846 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7847 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007848 }
7849 }
Shuo Qian284ae752020-12-22 19:10:14 -08007850 } catch (ImsException e) {
7851 throw new ServiceSpecificException(e.getCode());
7852 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007853 Binder.restoreCallingIdentity(identity);
7854 }
7855 }
7856
7857 @Override
7858 public int getCallComposerStatus(int subId) {
7859 enforceReadPrivilegedPermission("getCallComposerStatus");
7860
7861 final long identity = Binder.clearCallingIdentity();
7862 try {
7863 Phone phone = getPhone(subId);
7864 if (phone != null) {
7865 Phone defaultPhone = phone.getImsPhone();
7866 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7867 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7868 return imsPhone.getCallComposerStatus();
7869 }
7870 }
7871 } finally {
7872 Binder.restoreCallingIdentity(identity);
7873 }
7874 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7875 }
7876
7877 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007878 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7879 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007880 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007881 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007882
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007883 final long identity = Binder.clearCallingIdentity();
7884 try {
7885 final String iccId = getIccId(subId);
7886 final Phone phone = getPhone(subId);
7887 if (phone == null) {
7888 return false;
7889 }
7890 final String subscriberId = phone.getSubscriberId();
7891
7892 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007893 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007894 + subscriberId + " to " + number);
7895 }
7896
7897 if (TextUtils.isEmpty(iccId)) {
7898 return false;
7899 }
7900
7901 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7902
7903 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7904 if (alphaTag == null) {
7905 editor.remove(alphaTagPrefKey);
7906 } else {
7907 editor.putString(alphaTagPrefKey, alphaTag);
7908 }
7909
7910 // Record both the line number and IMSI for this ICCID, since we need to
7911 // track all merged IMSIs based on line number
7912 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7913 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7914 if (number == null) {
7915 editor.remove(numberPrefKey);
7916 editor.remove(subscriberPrefKey);
7917 } else {
7918 editor.putString(numberPrefKey, number);
7919 editor.putString(subscriberPrefKey, subscriberId);
7920 }
7921
7922 editor.commit();
7923 return true;
7924 } finally {
7925 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007926 }
Derek Tan7226c842014-07-02 17:42:23 -07007927 }
7928
7929 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007930 public String getLine1NumberForDisplay(int subId, String callingPackage,
7931 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007932 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007933 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007934 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007935 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007936 return null;
7937 }
Derek Tan97ebb422014-09-05 16:55:38 -07007938
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007939 final long identity = Binder.clearCallingIdentity();
7940 try {
7941 String iccId = getIccId(subId);
7942 if (iccId != null) {
7943 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7944 if (DBG_MERGE) {
7945 log("getLine1NumberForDisplay returning "
7946 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7947 }
7948 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007950 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7951 return null;
7952 } finally {
7953 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007954 }
Derek Tan7226c842014-07-02 17:42:23 -07007955 }
7956
7957 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007958 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7959 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007960 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007961 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007962 return null;
7963 }
Derek Tan97ebb422014-09-05 16:55:38 -07007964
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007965 final long identity = Binder.clearCallingIdentity();
7966 try {
7967 String iccId = getIccId(subId);
7968 if (iccId != null) {
7969 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7970 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7971 }
7972 return null;
7973 } finally {
7974 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007975 }
Derek Tan7226c842014-07-02 17:42:23 -07007976 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007977
7978 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007979 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7980 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007981 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7982 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007983 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007984 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007985 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007986 return null;
7987 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007988
Jordan Liub49b04b2019-05-06 14:45:15 -07007989 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7990 // the process, where TelephonyManager was instantiated.
7991 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007992 final long identity = Binder.clearCallingIdentity();
7993 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007994 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007995 final TelephonyManager tele = TelephonyManager.from(context);
7996 final SubscriptionManager sub = SubscriptionManager.from(context);
7997
7998 // Figure out what subscribers are currently active
7999 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008000
Jordan Liub49b04b2019-05-06 14:45:15 -07008001 // Only consider subs which match the current subId
8002 // This logic can be simplified. See b/131189269 for progress.
8003 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008004 activeSubscriberIds.add(tele.getSubscriberId(subId));
8005 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008006
8007 // First pass, find a number override for an active subscriber
8008 String mergeNumber = null;
8009 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
8010 for (String key : prefs.keySet()) {
8011 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
8012 final String subscriberId = (String) prefs.get(key);
8013 if (activeSubscriberIds.contains(subscriberId)) {
8014 final String iccId = key.substring(
8015 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
8016 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
8017 mergeNumber = (String) prefs.get(numberKey);
8018 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008019 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008020 + " for active subscriber " + subscriberId);
8021 }
8022 if (!TextUtils.isEmpty(mergeNumber)) {
8023 break;
8024 }
8025 }
8026 }
8027 }
8028
8029 // Shortcut when no active merged subscribers
8030 if (TextUtils.isEmpty(mergeNumber)) {
8031 return null;
8032 }
8033
8034 // Second pass, find all subscribers under that line override
8035 final ArraySet<String> result = new ArraySet<>();
8036 for (String key : prefs.keySet()) {
8037 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
8038 final String number = (String) prefs.get(key);
8039 if (mergeNumber.equals(number)) {
8040 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
8041 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
8042 final String subscriberId = (String) prefs.get(subscriberKey);
8043 if (!TextUtils.isEmpty(subscriberId)) {
8044 result.add(subscriberId);
8045 }
8046 }
8047 }
8048 }
8049
8050 final String[] resultArray = result.toArray(new String[result.size()]);
8051 Arrays.sort(resultArray);
8052 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08008053 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008054 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
8055 }
8056 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07008057 } finally {
8058 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08008059 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08008060 }
8061
8062 @Override
zoey chen38003472019-12-13 17:16:31 +08008063 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
8064 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07008065
8066 final long identity = Binder.clearCallingIdentity();
8067 try {
8068 final TelephonyManager telephonyManager = mApp.getSystemService(
8069 TelephonyManager.class);
8070 String subscriberId = telephonyManager.getSubscriberId(subId);
8071 if (subscriberId == null) {
8072 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08008073 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07008074 + subId);
8075 }
8076 return null;
8077 }
8078
Jack Yu285100e2022-12-02 22:48:35 -08008079 ParcelUuid groupUuid;
8080 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008081 final SubscriptionInfo info = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008082 .getSubscriptionInfo(subId);
8083 groupUuid = info.getGroupUuid();
8084 } else {
8085 final SubscriptionInfo info = mSubscriptionController
8086 .getSubscriptionInfo(subId);
8087 groupUuid = info.getGroupUuid();
8088 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07008089 // If it doesn't belong to any group, return just subscriberId of itself.
8090 if (groupUuid == null) {
8091 return new String[]{subscriberId};
8092 }
8093
8094 // Get all subscriberIds from the group.
8095 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08008096 List<SubscriptionInfo> groupInfos;
8097 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008098 groupInfos = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008099 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8100 mApp.getAttributionTag());
8101 } else {
8102 groupInfos = mSubscriptionController
8103 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
8104 mApp.getAttributionTag());
8105 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07008106 for (SubscriptionInfo subInfo : groupInfos) {
8107 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
8108 if (subscriberId != null) {
8109 mergedSubscriberIds.add(subscriberId);
8110 }
8111 }
8112
8113 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
8114 } finally {
8115 Binder.restoreCallingIdentity(identity);
8116
8117 }
8118 }
8119
8120 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008121 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008122 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08008123 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008124
8125 final long identity = Binder.clearCallingIdentity();
8126 try {
8127 final Phone phone = getPhone(subId);
8128 return phone == null ? false : phone.setOperatorBrandOverride(brand);
8129 } finally {
8130 Binder.restoreCallingIdentity(identity);
8131 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07008132 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05008133
8134 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008135 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008136 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
8137 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08008138 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
8139 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008140
8141 final long identity = Binder.clearCallingIdentity();
8142 try {
8143 final Phone phone = getPhone(subId);
8144 if (phone == null) {
8145 return false;
8146 }
8147 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
8148 cdmaNonRoamingList);
8149 } finally {
8150 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08008151 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08008152 }
8153
8154 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00008155 @Deprecated
8156 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
8157 enforceModifyPermission();
8158
8159 int returnValue = 0;
8160 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07008161 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00008162 if(result.exception == null) {
8163 if (result.result != null) {
8164 byte[] responseData = (byte[])(result.result);
8165 if(responseData.length > oemResp.length) {
8166 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
8167 responseData.length + "bytes. Buffer Size is " +
8168 oemResp.length + "bytes.");
8169 }
8170 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
8171 returnValue = responseData.length;
8172 }
8173 } else {
8174 CommandException ex = (CommandException) result.exception;
8175 returnValue = ex.getCommandError().ordinal();
8176 if(returnValue > 0) returnValue *= -1;
8177 }
8178 } catch (RuntimeException e) {
8179 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
8180 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
8181 if(returnValue > 0) returnValue *= -1;
8182 }
8183
8184 return returnValue;
8185 }
8186
8187 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07008188 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008189 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07008190 try {
8191 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008192 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07008193 mApp, phone.getSubId(), "getRadioAccessFamily");
8194 } catch (SecurityException e) {
8195 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
8196 throw e;
8197 }
chen xub97461a2018-10-26 14:17:57 -07008198 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08008199 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07008200 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08008201 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008202 final long identity = Binder.clearCallingIdentity();
8203 try {
chen xub97461a2018-10-26 14:17:57 -07008204 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008205 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07008206 mApp, phone.getSubId(), "getRadioAccessFamily");
8207 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008208 } finally {
8209 Binder.restoreCallingIdentity(identity);
8210 }
chen xub97461a2018-10-26 14:17:57 -07008211 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008212 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008213
8214 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008215 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008216 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008217 try {
8218 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8219 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008220 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008221 }
8222 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008223 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008224 }
8225 RoleManager rm = mApp.getSystemService(RoleManager.class);
8226 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8227 if (!dialerRoleHolders.contains(callingPackage)) {
8228 throw new SecurityException("App must be the dialer role holder to"
8229 + " upload a call composer pic");
8230 }
8231
8232 Executors.newSingleThreadExecutor().execute(() -> {
8233 ByteArrayOutputStream output = new ByteArrayOutputStream(
8234 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8235 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8236 boolean readUntilEnd = false;
8237 int totalBytesRead = 0;
8238 byte[] buffer = new byte[16 * 1024];
8239 while (true) {
8240 int numRead;
8241 try {
8242 numRead = input.read(buffer);
8243 } catch (IOException e) {
8244 try {
8245 fd.checkError();
8246 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8247 null);
8248 } catch (IOException e1) {
8249 // This means that the other side closed explicitly with an error. If this
8250 // happens, log and ignore.
8251 loge("Remote end of call composer picture pipe closed: " + e1);
8252 }
8253 break;
8254 }
8255 if (numRead == -1) {
8256 readUntilEnd = true;
8257 break;
8258 }
8259 totalBytesRead += numRead;
8260 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8261 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8262 try {
8263 input.close();
8264 } catch (IOException e) {
8265 // ignore
8266 }
8267 break;
8268 }
8269 output.write(buffer, 0, numRead);
8270 }
8271 // Generally, the remote end will close the file descriptors. The only case where we
8272 // close is above, where the picture size is too big.
8273
8274 try {
8275 fd.checkError();
8276 } catch (IOException e) {
8277 loge("Remote end for call composer closed with an error: " + e);
8278 return;
8279 }
8280
Hall Liuaa4211e2021-01-20 15:43:39 -08008281 if (!readUntilEnd) {
8282 loge("Did not finish reading entire image; aborting");
8283 return;
8284 }
Hall Liu82694d52020-12-11 18:22:04 -08008285
Hall Liuaa4211e2021-01-20 15:43:39 -08008286 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8287 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8288 new CallComposerPictureTransfer.Factory() {},
8289 imageData,
8290 (result) -> {
8291 if (result.first != null) {
8292 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8293 Bundle outputResult = new Bundle();
8294 outputResult.putParcelable(
8295 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8296 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8297 outputResult);
8298 } else {
8299 callback.send(result.second, null);
8300 }
8301 }
8302 );
Hall Liu82694d52020-12-11 18:22:04 -08008303 });
8304 }
8305
8306 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008307 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008308 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008309 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008310
8311 final long identity = Binder.clearCallingIdentity();
8312 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008313 ImsManager.getInstance(defaultPhone.getContext(),
8314 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008315 } finally {
8316 Binder.restoreCallingIdentity(identity);
8317 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008318 }
8319
8320 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008321 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008322 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008323 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8324 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008325 return false;
8326 }
Svet Ganovb320e182015-04-16 12:30:10 -07008327
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008328 final long identity = Binder.clearCallingIdentity();
8329 try {
8330 // Check the user preference and the system-level IMS setting. Even if the user has
8331 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8332 // In the long run, we may instead need to check if there exists a connection service
8333 // which can support video calling.
8334 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008335 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008336 return imsManager.isVtEnabledByPlatform()
8337 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8338 && imsManager.isVtEnabledByUser();
8339 } finally {
8340 Binder.restoreCallingIdentity(identity);
8341 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008342 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008343
Andrew Leea1239f22015-03-02 17:44:07 -08008344 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008345 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8346 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008347 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008348 mApp, subId, callingPackage, callingFeatureId,
8349 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008350 return false;
8351 }
8352
8353 final long identity = Binder.clearCallingIdentity();
8354 try {
8355 CarrierConfigManager configManager =
8356 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008357 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008358 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8359 } finally {
8360 Binder.restoreCallingIdentity(identity);
8361 }
Andrew Leea1239f22015-03-02 17:44:07 -08008362 }
8363
8364 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008365 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008366 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008367 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008368 return false;
8369 }
8370
8371 final long identity = Binder.clearCallingIdentity();
8372 try {
8373 CarrierConfigManager configManager =
8374 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008375 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008376 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8377 } finally {
8378 Binder.restoreCallingIdentity(identity);
8379 }
Andrew Leea1239f22015-03-02 17:44:07 -08008380 }
8381
Andrew Lee9431b832015-03-09 18:46:45 -07008382 @Override
8383 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008384 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008385 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008386 }
8387
8388 @Override
8389 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008390 final long identity = Binder.clearCallingIdentity();
8391 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008392 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008393 } finally {
8394 Binder.restoreCallingIdentity(identity);
8395 }
Andrew Lee9431b832015-03-09 18:46:45 -07008396 }
8397
Hall Liuf6668912018-10-31 17:05:23 -07008398 /**
8399 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8400 * support for the feature and device firmware support.
8401 *
8402 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8403 */
8404 @Override
8405 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008406 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008407 final Phone phone = getPhone(subscriptionId);
8408 if (phone == null) {
8409 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8410 return false;
8411 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008412 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008413 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008414 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
8415 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008416 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008417 return isCarrierSupported && isDeviceSupported;
8418 } finally {
8419 Binder.restoreCallingIdentity(identity);
8420 }
Hall Liu98187582018-01-22 19:15:32 -08008421 }
8422
Hall Liuf6668912018-10-31 17:05:23 -07008423 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008424 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8425 * RTT setting, will return true if the device and carrier both support RTT.
8426 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008427 */
8428 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008429 final long identity = Binder.clearCallingIdentity();
8430 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00008431 boolean isRttSupported = isRttSupported(subscriptionId);
8432 boolean isUserRttSettingOn = Settings.Secure.getInt(
8433 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8434 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8435 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8436 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008437 } finally {
8438 Binder.restoreCallingIdentity(identity);
8439 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008440 }
8441
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008442 @Deprecated
8443 @Override
8444 public String getDeviceId(String callingPackage) {
8445 return getDeviceIdWithFeature(callingPackage, null);
8446 }
8447
Sanket Padawe7310cc72015-01-14 09:53:20 -08008448 /**
8449 * Returns the unique device ID of phone, for example, the IMEI for
8450 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8451 *
8452 * <p>Requires Permission:
8453 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8454 */
8455 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008456 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008457 try {
8458 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8459 } catch (SecurityException se) {
8460 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8461 throw new SecurityException("Package " + callingPackage + " does not belong to "
8462 + Binder.getCallingUid());
8463 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008464 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008465 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008466 return null;
8467 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008468 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008469 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008470 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008471 return null;
8472 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008473
8474 final long identity = Binder.clearCallingIdentity();
8475 try {
8476 return phone.getDeviceId();
8477 } finally {
8478 Binder.restoreCallingIdentity(identity);
8479 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008480 }
8481
Ping Sunc67b7c22016-03-02 19:16:45 +08008482 /**
8483 * {@hide}
8484 * Returns the IMS Registration Status on a particular subid
8485 *
8486 * @param subId
8487 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008488 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008489 Phone phone = getPhone(subId);
8490 if (phone != null) {
8491 return phone.isImsRegistered();
8492 } else {
8493 return false;
8494 }
8495 }
8496
Santos Cordon7a1885b2015-02-03 11:15:19 -08008497 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008498 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008499 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008500 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008501 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008502 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8503 }
8504 final long identity = Binder.clearCallingIdentity();
8505 try {
8506 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8507 } finally {
8508 Binder.restoreCallingIdentity(identity);
8509 }
8510 }
8511
8512 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008513 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008514 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008515 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008516 mApp,
8517 subscriptionId,
8518 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8519 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07008520 final long identity = Binder.clearCallingIdentity();
8521 try {
8522 Phone phone = getPhone(subscriptionId);
8523 if (phone == null) {
8524 return null;
8525 }
8526 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8527 } finally {
8528 Binder.restoreCallingIdentity(identity);
8529 }
8530 }
8531
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008532 /**
8533 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008534 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008535 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008536 final long identity = Binder.clearCallingIdentity();
8537 try {
8538 Phone phone = getPhone(subId);
8539 if (phone != null) {
8540 return phone.isWifiCallingEnabled();
8541 } else {
8542 return false;
8543 }
8544 } finally {
8545 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008546 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008547 }
8548
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008549 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008550 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008551 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008552 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008553 final long identity = Binder.clearCallingIdentity();
8554 try {
8555 Phone phone = getPhone(subId);
8556 if (phone != null) {
8557 return phone.isVideoEnabled();
8558 } else {
8559 return false;
8560 }
8561 } finally {
8562 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008563 }
8564 }
8565
8566 /**
8567 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8568 * defined in {@link ImsRegistrationImplBase}.
8569 */
8570 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008571 final long identity = Binder.clearCallingIdentity();
8572 try {
8573 Phone phone = getPhone(subId);
8574 if (phone != null) {
8575 return phone.getImsRegistrationTech();
8576 } else {
8577 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8578 }
8579 } finally {
8580 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008581 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008582 }
8583
Stuart Scott8eef64f2015-04-08 15:13:54 -07008584 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008585 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008586 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07008587 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8588 return;
8589 }
Kai Shif70f46f2021-03-03 13:59:46 -08008590 Phone defaultPhone = getDefaultPhone();
8591 if (defaultPhone != null) {
8592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8593 mApp, getDefaultPhone().getSubId(), "factoryReset");
8594 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008595 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008596
Svet Ganovcc087f82015-05-12 20:35:54 -07008597 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008598 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8599 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008600 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008601 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008602 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008603 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008604 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008605 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08008606 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008607 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008608 // There has been issues when Sms raw table somehow stores orphan
8609 // fragments. They lead to garbled message when new fragments come
8610 // in and combined with those stale ones. In case this happens again,
8611 // user can reset all network settings which will clean up this table.
8612 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008613 // Clean up IMS settings as well here.
8614 int slotId = getSlotIndex(subId);
8615 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8616 ImsManager.getInstance(mApp, slotId).factoryReset();
8617 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008618
Kai Shif70f46f2021-03-03 13:59:46 -08008619 if (defaultPhone == null) {
8620 return;
8621 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008622 // Erase modem config if erase modem on network setting is enabled.
8623 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8624 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8625 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008626 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008627 }
Kai Shif70f46f2021-03-03 13:59:46 -08008628
8629 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008630 } finally {
8631 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008632 }
8633 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008634
SongFerngWangfd89b102021-05-27 22:44:54 +08008635 @VisibleForTesting
8636 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8637 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8638 return;
8639 }
8640 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8641 RILConstants.PREFERRED_NETWORK_MODE);
8642 SubscriptionManager.setSubscriptionProperty(subId,
8643 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8644 "user=" + defaultNetworkType);
8645 phone.loadAllowedNetworksFromSubscriptionDatabase();
8646 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8647 defaultNetworkType, null);
8648 }
8649
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008650 private void cleanUpSmsRawTable(Context context) {
8651 ContentResolver resolver = context.getContentResolver();
8652 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8653 resolver.delete(uri, null, null);
8654 }
8655
Narayan Kamath1c496c22015-04-16 14:40:19 +01008656 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008657 public String getSimLocaleForSubscriber(int subId) {
8658 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8659 final Phone phone = getPhone(subId);
8660 if (phone == null) {
8661 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008662 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008663 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008664 final long identity = Binder.clearCallingIdentity();
8665 try {
Jack Yu285100e2022-12-02 22:48:35 -08008666 SubscriptionInfo info;
8667 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008668 info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
Jack Yu285100e2022-12-02 22:48:35 -08008669 phone.getContext().getOpPackageName(),
8670 phone.getContext().getAttributionTag());
8671 if (info == null) {
8672 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8673 return null;
8674 }
8675 } else {
8676 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
8677 phone.getContext().getOpPackageName(),
8678 phone.getContext().getAttributionTag());
8679 if (info == null) {
8680 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8681 return null;
8682 }
chen xu6291c472019-02-04 12:55:53 -08008683 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008684 // Try and fetch the locale from the carrier properties or from the SIM language
8685 // preferences (EF-PL and EF-LI)...
8686 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008687 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008688 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8689 if (localeFromDefaultSim != null) {
8690 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8691 if (DBG) log("Using locale from subId: " + subId + " locale: "
8692 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008693 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008694 } else {
8695 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008696 }
8697 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008698
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008699 // The SIM language preferences only store a language (e.g. fr = French), not an
8700 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8701 // the SIM and carrier preferences does not include a country we add the country
8702 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008703 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008704 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008705 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008706 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008707 }
8708
8709 if (DBG) log("No locale found - returning null");
8710 return null;
8711 } finally {
8712 Binder.restoreCallingIdentity(identity);
8713 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008714 }
8715
tom hsu0b59d292022-09-29 23:49:21 +08008716 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008717 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008718 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008719 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008720 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008721 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8722 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008723 Locale.forLanguageTag(localeTag).getCountry())) {
8724 return localeTag;
8725 }
8726 }
8727 return inputLocale.toLanguageTag();
8728 }
8729
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008730 /**
8731 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8732 */
8733 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08008734 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008735 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Jack Yu285100e2022-12-02 22:48:35 -08008736 mApp.getOpPackageName(), mApp.getAttributionTag());
8737 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008738 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08008739 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008740 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008741
Gary Jian3aa9a762022-01-24 16:41:19 +08008742 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8743 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008744
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008745 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008746 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8747 * representing the state of the modem.
8748 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008749 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8750 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008751 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008752 */
8753 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008754 public void requestModemActivityInfo(ResultReceiver result) {
8755 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008756 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008757
8758 final long identity = Binder.clearCallingIdentity();
8759 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008760 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008761 } finally {
8762 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008763 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008764 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008765
Gary Jian76280a42022-12-07 16:18:33 +08008766 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008767 // less than total activity duration.
8768 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8769 if (info == null) {
8770 return false;
8771 }
8772 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008773 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008774 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8775
Hall Liu49656c02020-10-09 19:00:11 -07008776 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8777
Siddharth Rayb8114062018-06-17 15:02:38 -07008778 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008779 && (info.getSleepTimeMillis() <= activityDurationMs)
8780 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008781 }
8782
Gary Jian3aa9a762022-01-24 16:41:19 +08008783 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8784 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8785 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8786 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8787
8788 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8789 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8790 }
8791
8792 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8793 mLastModemActivityInfo.setReceiveTimeMillis(
8794 rat,
8795 freq,
8796 info.getReceiveTimeMillis(rat, freq)
8797 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8798 }
8799
8800 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8801 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8802 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8803 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8804
8805 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8806 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8807 }
8808 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8809 mLastModemActivityInfo.setReceiveTimeMillis(
8810 rat,
8811 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8812 }
8813
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008814 /**
8815 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8816 * @param info recent ModemActivityInfo
8817 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008818 private void mergeModemActivityInfo(ModemActivityInfo info) {
8819 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008820 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008821 boolean matched;
8822 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8823 matched = false;
8824 int rat = info.getSpecificInfoRat(i);
8825 int freq = info.getSpecificInfoFrequencyRange(i);
8826 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8827 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8828 //if it already exists
8829 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8830 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8831 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8832 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8833 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8834 updateLastModemActivityInfo(info, rat, freq);
8835 matched = true;
8836 }
8837 } else {
8838 updateLastModemActivityInfo(info, rat);
8839 matched = true;
8840 }
8841 }
8842 }
8843
8844 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008845 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008846 new ActivityStatsTechSpecificInfo(
8847 rat,
8848 freq,
8849 info.getTransmitTimeMillis(rat, freq),
8850 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008851 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008852 }
8853 }
8854 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8855 mLastModemActivitySpecificInfo =
8856 new ActivityStatsTechSpecificInfo[merged.size()];
8857 merged.toArray(mLastModemActivitySpecificInfo);
8858
8859 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8860 mLastModemActivityInfo.setSleepTimeMillis(
8861 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008862 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008863 mLastModemActivityInfo.setIdleTimeMillis(
8864 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008865 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008866
8867 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008868 new ModemActivityInfo(
8869 mLastModemActivityInfo.getTimestampMillis(),
8870 mLastModemActivityInfo.getSleepTimeMillis(),
8871 mLastModemActivityInfo.getIdleTimeMillis(),
8872 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008873 }
8874
8875 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8876 ActivityStatsTechSpecificInfo[] info) {
8877 int infoSize = info.length;
8878 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8879 for (int i = 0; i < infoSize; i++) {
8880 ret[i] = new ActivityStatsTechSpecificInfo(
8881 info[i].getRat(), info[i].getFrequencyRange(),
8882 info[i].getTransmitTimeMillis(),
8883 (int) info[i].getReceiveTimeMillis());
8884 }
8885 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008886 }
8887
Jack Yu85bd38a2015-11-09 11:34:32 -08008888 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008889 * Returns the service state information on specified subscription.
8890 */
8891 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008892 public ServiceState getServiceStateForSubscriber(int subId,
8893 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8894 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008895 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008896 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008897 return null;
8898 }
8899
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008900 boolean hasFinePermission = false;
8901 boolean hasCoarsePermission = false;
8902 if (!renounceFineLocationAccess) {
8903 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8904 LocationAccessPolicy.checkLocationPermission(mApp,
8905 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8906 .setCallingPackage(callingPackage)
8907 .setCallingFeatureId(callingFeatureId)
8908 .setCallingPid(Binder.getCallingPid())
8909 .setCallingUid(Binder.getCallingUid())
8910 .setMethod("getServiceStateForSubscriber")
8911 .setLogAsInfo(true)
8912 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8913 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8914 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8915 .build());
8916 hasFinePermission =
8917 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8918 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008919
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008920 if (!renounceCoarseLocationAccess) {
8921 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8922 LocationAccessPolicy.checkLocationPermission(mApp,
8923 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8924 .setCallingPackage(callingPackage)
8925 .setCallingFeatureId(callingFeatureId)
8926 .setCallingPid(Binder.getCallingPid())
8927 .setCallingUid(Binder.getCallingUid())
8928 .setMethod("getServiceStateForSubscriber")
8929 .setLogAsInfo(true)
8930 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8931 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8932 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8933 .build());
8934 hasCoarsePermission =
8935 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8936 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008937
Jack Yu479f40e2020-10-27 21:29:25 -07008938 final Phone phone = getPhone(subId);
8939 if (phone == null) {
8940 return null;
8941 }
8942
Jordan Liu0f2bc442020-11-18 16:47:37 -08008943 final long identity = Binder.clearCallingIdentity();
8944
Jack Yu479f40e2020-10-27 21:29:25 -07008945 boolean isCallingPackageDataService = phone.getDataServicePackages()
8946 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008947 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008948 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008949 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008950 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008951 .getSubscriptionInfoInternal(subId);
8952 if (subInfo == null || !subInfo.isActive()) {
8953 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8954 + "subId=" + subId);
8955 return null;
8956 }
8957 } else {
8958 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8959 callingFeatureId)) {
8960 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8961 + "subId=" + subId);
8962 return null;
8963 }
Jordan Liuc437b192020-08-17 10:59:12 -07008964 }
8965
Hall Liuf19c44f2018-11-27 14:38:17 -08008966 ServiceState ss = phone.getServiceState();
8967
8968 // Scrub out the location info in ServiceState depending on what level of access
8969 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008970 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008971 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8972 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008973 } finally {
8974 Binder.restoreCallingIdentity(identity);
8975 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008976 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008977
8978 /**
8979 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8980 *
8981 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8982 * voicemail ringtone.
8983 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8984 * PhoneAccount.
8985 */
8986 @Override
8987 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008988 final long identity = Binder.clearCallingIdentity();
8989 try {
8990 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8991 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008992 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008993 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008994
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008995 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8996 } finally {
8997 Binder.restoreCallingIdentity(identity);
8998 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008999 }
9000
9001 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009002 * Sets the per-account voicemail ringtone.
9003 *
9004 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9005 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9006 *
9007 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9008 * voicemail ringtone.
9009 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
9010 * PhoneAccount.
9011 */
9012 @Override
9013 public void setVoicemailRingtoneUri(String callingPackage,
9014 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009015 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009016 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009017 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9018 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009019 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9020 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9021 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009022 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009023
9024 final long identity = Binder.clearCallingIdentity();
9025 try {
9026 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9027 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009028 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009029 }
9030 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
9031 } finally {
9032 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009033 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009034 }
9035
9036 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08009037 * Returns whether vibration is set for voicemail notification in Phone settings.
9038 *
9039 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
9040 * voicemail vibration setting.
9041 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
9042 */
9043 @Override
9044 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009045 final long identity = Binder.clearCallingIdentity();
9046 try {
9047 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
9048 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009049 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009050 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009052 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
9053 } finally {
9054 Binder.restoreCallingIdentity(identity);
9055 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08009056 }
9057
Youhan Wange64578a2016-05-02 15:32:42 -07009058 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009059 * Sets the per-account voicemail vibration.
9060 *
9061 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
9062 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9063 *
9064 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
9065 * voicemail vibration setting.
9066 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
9067 * specific PhoneAccount.
9068 */
9069 @Override
9070 public void setVoicemailVibrationEnabled(String callingPackage,
9071 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009072 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009073 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07009074 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
9075 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9077 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
9078 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009079 }
9080
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009081 final long identity = Binder.clearCallingIdentity();
9082 try {
9083 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
9084 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009085 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009086 }
9087 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
9088 } finally {
9089 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009090 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08009091 }
9092
9093 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009094 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
9095 *
9096 * @throws SecurityException if the caller does not have the required permission
9097 */
arunvoddud7401012022-12-15 16:08:12 +00009098 @VisibleForTesting
9099 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07009100 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07009101 message);
Youhan Wange64578a2016-05-02 15:32:42 -07009102 }
9103
9104 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009105 * Make sure either called from same process as self (phone) or IPC caller has send SMS
9106 * permission.
9107 *
9108 * @throws SecurityException if the caller does not have the required permission
9109 */
9110 private void enforceSendSmsPermission() {
9111 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
9112 }
9113
9114 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00009115 * Make sure either called from same process as self (phone) or IPC caller has interact across
9116 * users permission.
9117 *
9118 * @throws SecurityException if the caller does not have the required permission
9119 */
9120 private void enforceInteractAcrossUsersPermission(String message) {
9121 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
9122 }
9123
9124 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009125 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009126 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009127 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009128 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08009129 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009130 final long identity = Binder.clearCallingIdentity();
9131 try {
9132 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009133 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009134 if (componentName == null) {
9135 throw new SecurityException(
9136 "Caller not current active visual voicemail package[null]");
9137 }
9138 String vvmPackage = componentName.getPackageName();
9139 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00009140 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009141 }
9142 } finally {
9143 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08009144 }
9145 }
9146
9147 /**
Youhan Wange64578a2016-05-02 15:32:42 -07009148 * Return the application ID for the app type.
9149 *
9150 * @param subId the subscription ID that this request applies to.
9151 * @param appType the uicc app type.
9152 * @return Application ID for specificied app type, or null if no uicc.
9153 */
9154 @Override
9155 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009156 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07009157 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009158
9159 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07009160 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009161 if (phone == null) {
9162 return null;
9163 }
9164 String aid = null;
9165 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009166 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009167 .getApplicationByType(appType).getAid();
9168 } catch (Exception e) {
9169 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
9170 }
9171 return aid;
9172 } finally {
9173 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07009174 }
Youhan Wange64578a2016-05-02 15:32:42 -07009175 }
9176
Youhan Wang4001d252016-05-11 10:29:41 -07009177 /**
9178 * Return the Electronic Serial Number.
9179 *
9180 * @param subId the subscription ID that this request applies to.
9181 * @return ESN or null if error.
9182 */
9183 @Override
9184 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009185 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07009186 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009187
9188 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07009189 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009190 if (phone == null) {
9191 return null;
9192 }
9193 String esn = null;
9194 try {
9195 esn = phone.getEsn();
9196 } catch (Exception e) {
9197 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
9198 }
9199 return esn;
9200 } finally {
9201 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07009202 }
Youhan Wang4001d252016-05-11 10:29:41 -07009203 }
9204
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009205 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009206 * Return the Preferred Roaming List Version.
9207 *
9208 * @param subId the subscription ID that this request applies to.
9209 * @return PRLVersion or null if error.
9210 */
9211 @Override
9212 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009213 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07009214 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009215
9216 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009217 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009218 if (phone == null) {
9219 return null;
9220 }
9221 String cdmaPrlVersion = null;
9222 try {
9223 cdmaPrlVersion = phone.getCdmaPrlVersion();
9224 } catch (Exception e) {
9225 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9226 }
9227 return cdmaPrlVersion;
9228 } finally {
9229 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009230 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009231 }
9232
9233 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009234 * Get snapshot of Telephony histograms
9235 * @return List of Telephony histograms
9236 * @hide
9237 */
9238 @Override
9239 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009240 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9241 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009242
9243 final long identity = Binder.clearCallingIdentity();
9244 try {
9245 return RIL.getTelephonyRILTimingHistograms();
9246 } finally {
9247 Binder.restoreCallingIdentity(identity);
9248 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009249 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009250
9251 /**
9252 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009253 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9254 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009255 * Require system privileges. In the future we may add this to carrier APIs.
9256 *
Michele Berionne482f8202018-11-27 18:57:59 -08009257 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009258 */
9259 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009260 @TelephonyManager.SetCarrierRestrictionResult
9261 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009262 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07009263 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009264
Michele Berionne482f8202018-11-27 18:57:59 -08009265 if (carrierRestrictionRules == null) {
9266 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009267 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009268
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009269 final long identity = Binder.clearCallingIdentity();
9270 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009271 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009272 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009273 } finally {
9274 Binder.restoreCallingIdentity(identity);
9275 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009276 }
9277
9278 /**
9279 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009280 * Get the allowed carrier list and the excluded carrier list, including the priority between
9281 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009282 * Require system privileges. In the future we may add this to carrier APIs.
9283 *
Michele Berionne482f8202018-11-27 18:57:59 -08009284 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009285 */
9286 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009287 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009288 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07009289 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009290
9291 final long identity = Binder.clearCallingIdentity();
9292 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009293 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9294 if (response instanceof CarrierRestrictionRules) {
9295 return (CarrierRestrictionRules) response;
9296 }
9297 // Response is an Exception of some kind,
9298 // which is signalled to the user as a NULL retval
9299 return null;
9300 } catch (Exception e) {
9301 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9302 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009303 } finally {
9304 Binder.restoreCallingIdentity(identity);
9305 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009306 }
9307
fionaxu59545b42016-05-25 15:53:37 -07009308 /**
arunvoddud7401012022-12-15 16:08:12 +00009309 * Fetches the carrier restriction status of the device and sends the status to the caller
9310 * through the callback.
9311 *
9312 * @param callback The callback that will be used to send the result.
9313 * @throws SecurityException if the caller does not have the required permission/privileges or
9314 * the caller is not allowlisted.
9315 */
9316 @Override
9317 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9318 enforceReadPermission("getCarrierRestrictionStatus");
9319 int carrierId = validateCallerAndGetCarrierId(packageName);
9320 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
9321 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9322 throw new SecurityException("Not an authorized caller");
9323 }
9324 final long identity = Binder.clearCallingIdentity();
9325 try {
9326 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
9327 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
9328 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9329 } finally {
9330 Binder.restoreCallingIdentity(identity);
9331 }
9332 }
9333
9334 @VisibleForTesting
9335 public int validateCallerAndGetCarrierId(String packageName) {
9336 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9337 return allowListInfo.validateCallerAndGetCarrierId(packageName);
9338 }
9339
9340 /**
fionaxu59545b42016-05-25 15:53:37 -07009341 * Action set from carrier signalling broadcast receivers to enable/disable radio
9342 * @param subId the subscription ID that this action applies to.
9343 * @param enabled control enable or disable radio.
9344 * {@hide}
9345 */
9346 @Override
9347 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9348 enforceModifyPermission();
9349 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009350
9351 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009352 if (phone == null) {
9353 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9354 return;
9355 }
9356 try {
9357 phone.carrierActionSetRadioEnabled(enabled);
9358 } catch (Exception e) {
9359 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009360 } finally {
9361 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009362 }
9363 }
9364
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009365 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009366 * Enable or disable Voice over NR (VoNR)
9367 * @param subId the subscription ID that this action applies to.
9368 * @param enabled enable or disable VoNR.
9369 * @return operation result.
9370 */
9371 @Override
9372 public int setVoNrEnabled(int subId, boolean enabled) {
9373 enforceModifyPermission();
9374 final Phone phone = getPhone(subId);
9375
9376 final long identity = Binder.clearCallingIdentity();
9377 if (phone == null) {
9378 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9379 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9380 }
9381
9382 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9383 try {
9384 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9385 workSource);
9386 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009387
9388 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9389 if (DBG) {
9390 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9391 }
9392 SubscriptionManager.setSubscriptionProperty(
9393 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9394 (enabled ? "1" : "0"));
9395 }
9396
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009397 return result;
9398 } finally {
9399 Binder.restoreCallingIdentity(identity);
9400 }
9401 }
9402
9403 /**
9404 * Is voice over NR enabled
9405 * @return true if VoNR is enabled else false
9406 */
9407 @Override
9408 public boolean isVoNrEnabled(int subId) {
9409 enforceReadPrivilegedPermission("isVoNrEnabled");
9410 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9411 final long identity = Binder.clearCallingIdentity();
9412 try {
9413 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9414 null, subId, workSource);
9415 if (DBG) log("isVoNrEnabled: " + isEnabled);
9416 return isEnabled;
9417 } finally {
9418 Binder.restoreCallingIdentity(identity);
9419 }
9420 }
9421
9422 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009423 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9424 * network status based on which carrier apps could apply actions accordingly,
9425 * enable/disable default url handler for example.
9426 *
9427 * @param subId the subscription ID that this action applies to.
9428 * @param report control start/stop reporting the default network status.
9429 * {@hide}
9430 */
9431 @Override
9432 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9433 enforceModifyPermission();
9434 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009435
9436 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009437 if (phone == null) {
9438 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9439 return;
9440 }
9441 try {
9442 phone.carrierActionReportDefaultNetworkStatus(report);
9443 } catch (Exception e) {
9444 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009445 } finally {
9446 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009447 }
9448 }
9449
9450 /**
fionaxud9622282017-07-17 17:51:30 -07009451 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9452 * @param subId the subscription ID that this action applies to.
9453 * {@hide}
9454 */
9455 @Override
9456 public void carrierActionResetAll(int subId) {
9457 enforceModifyPermission();
9458 final Phone phone = getPhone(subId);
9459 if (phone == null) {
9460 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9461 return;
9462 }
9463 try {
9464 phone.carrierActionResetAll();
9465 } catch (Exception e) {
9466 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9467 }
9468 }
9469
9470 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009471 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9472 * bug report is being generated.
9473 */
9474 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009475 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009476 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9477 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009478 writer.println("Permission Denial: can't dump Phone from pid="
9479 + Binder.getCallingPid()
9480 + ", uid=" + Binder.getCallingUid()
9481 + "without permission "
9482 + android.Manifest.permission.DUMP);
9483 return;
9484 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009485 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009486 }
Jack Yueb89b242016-06-22 13:27:47 -07009487
Brad Ebingerdac2f002018-04-03 15:17:52 -07009488 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009489 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9490 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9491 @NonNull String[] args) {
9492 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9493 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009494 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009495 }
9496
Jack Yueb89b242016-06-22 13:27:47 -07009497 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009498 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009499 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009500 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009501 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009502 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009503 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009504 */
9505 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009506 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009507 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009508 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9509 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9510 try {
9511 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009512 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009513 } catch (SecurityException se) {
9514 enforceModifyPermission();
9515 }
9516 } else {
9517 enforceModifyPermission();
9518 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009519
9520 final long identity = Binder.clearCallingIdentity();
9521 try {
9522 Phone phone = getPhone(subId);
9523 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009524 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9525 phone.carrierActionSetMeteredApnsEnabled(enabled);
9526 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009527 phone.getDataSettingsManager().setDataEnabled(
9528 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009529 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009530 }
9531 } finally {
9532 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009533 }
9534 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009535
9536 /**
9537 * Get Client request stats
9538 * @return List of Client Request Stats
9539 * @hide
9540 */
9541 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009542 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9543 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009544 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009545 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009546 return null;
9547 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009548 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009549
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009550 final long identity = Binder.clearCallingIdentity();
9551 try {
9552 if (phone != null) {
9553 return phone.getClientRequestStats();
9554 }
9555
9556 return null;
9557 } finally {
9558 Binder.restoreCallingIdentity(identity);
9559 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009560 }
9561
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009562 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009563 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009564 if (uid == Process.ROOT_UID && packageName == null) {
9565 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9566 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9567 // exception. ROOT_UID seems not to have a valid package name returned by
9568 // PackageManager, so just fake it here to avoid issues when running telephony shell
9569 // commands that plumb through the RIL as root, like so:
9570 // $ adb root
9571 // $ adb shell cmd phone ...
9572 packageName = "root";
9573 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009574 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009575 }
Jack Yueb4124c2017-02-16 15:32:43 -08009576
9577 /**
Grace Chen70990072017-03-24 17:21:30 -07009578 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009579 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009580 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009581 * @param state State of SIM (power down, power up, pass through)
9582 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9583 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9584 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009585 *
9586 **/
9587 @Override
Grace Chen70990072017-03-24 17:21:30 -07009588 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009589 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009590 Phone phone = PhoneFactory.getPhone(slotIndex);
9591
vagdeviaf9a5b92018-08-15 16:01:53 -07009592 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9593
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009594 final long identity = Binder.clearCallingIdentity();
9595 try {
9596 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009597 phone.setSimPowerState(state, null, workSource);
9598 }
9599 } finally {
9600 Binder.restoreCallingIdentity(identity);
9601 }
9602 }
9603
9604 /**
9605 * Set SIM card power state.
9606 *
9607 * @param slotIndex SIM slot id.
9608 * @param state State of SIM (power down, power up, pass through)
9609 * @param callback callback to trigger after success or failure
9610 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9611 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9612 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9613 *
9614 **/
9615 @Override
9616 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9617 IIntegerConsumer callback) {
9618 enforceModifyPermission();
9619 Phone phone = PhoneFactory.getPhone(slotIndex);
9620
9621 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9622
9623 final long identity = Binder.clearCallingIdentity();
9624 try {
9625 if (phone != null) {
9626 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9627 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009628 }
9629 } finally {
9630 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009631 }
9632 }
Shuo Qiandd210312017-04-12 22:11:33 +00009633
Tyler Gunn65d45c22017-06-05 11:22:26 -07009634 private boolean isUssdApiAllowed(int subId) {
9635 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009636 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009637 if (configManager == null) {
9638 return false;
9639 }
9640 PersistableBundle pb = configManager.getConfigForSubId(subId);
9641 if (pb == null) {
9642 return false;
9643 }
9644 return pb.getBoolean(
9645 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9646 }
9647
Shuo Qiandd210312017-04-12 22:11:33 +00009648 /**
9649 * Check if phone is in emergency callback mode
9650 * @return true if phone is in emergency callback mode
9651 * @param subId sub id
9652 */
goneil9c5f4872017-12-05 14:07:56 -08009653 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009654 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009655 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00009656 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009657
9658 final long identity = Binder.clearCallingIdentity();
9659 try {
9660 if (phone != null) {
9661 return phone.isInEcm();
9662 } else {
9663 return false;
9664 }
9665 } finally {
9666 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009667 }
9668 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009669
9670 /**
9671 * Get the current signal strength information for the given subscription.
9672 * Because this information is not updated when the device is in a low power state
9673 * it should not be relied-upon to be current.
9674 * @param subId Subscription index
9675 * @return the most recent cached signal strength info from the modem
9676 */
9677 @Override
9678 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009679 final long identity = Binder.clearCallingIdentity();
9680 try {
9681 Phone p = getPhone(subId);
9682 if (p == null) {
9683 return null;
9684 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009685
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009686 return p.getSignalStrength();
9687 } finally {
9688 Binder.restoreCallingIdentity(identity);
9689 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009690 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009691
Pengquan Meng77b7f132018-08-22 14:49:57 -07009692 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009693 * Get the current modem radio state for the given slot.
9694 * @param slotIndex slot index.
9695 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009696 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009697 * @return the current radio power state from the modem
9698 */
9699 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009700 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009701 Phone phone = PhoneFactory.getPhone(slotIndex);
9702 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009703 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9704 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009705 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9706 }
9707
9708 final long identity = Binder.clearCallingIdentity();
9709 try {
9710 return phone.getRadioPowerState();
9711 } finally {
9712 Binder.restoreCallingIdentity(identity);
9713 }
9714 }
9715 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9716 }
9717
9718 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009719 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9720 *
9721 * <p>Requires one of the following permissions:
9722 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009723 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009724 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9725 * privileges.
9726 *
9727 * @param subId subscription id
9728 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9729 * {@code false}.
9730 */
9731 @Override
9732 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009733 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009734 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009735 try {
9736 mApp.enforceCallingOrSelfPermission(
9737 android.Manifest.permission.ACCESS_NETWORK_STATE,
9738 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009739 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009740 mApp.enforceCallingOrSelfPermission(
9741 permission.READ_BASIC_PHONE_STATE, functionName);
9742 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009743 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009744 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009745 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009746 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009747
Pengquan Menga1bb6272018-09-06 09:59:22 -07009748 boolean isEnabled = false;
9749 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009750 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009751 Phone phone = getPhone(subId);
9752 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009753 } finally {
9754 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009755 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009756 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009757 }
9758
9759
9760 /**
9761 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9762 *
9763 * <p> Requires permission:
9764 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9765 * privileges.
9766 *
9767 * @param subId subscription id
9768 * @param isEnabled {@code true} means enable, {@code false} means disable.
9769 */
9770 @Override
9771 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9773 mApp, subId, "setDataRoamingEnabled");
9774
Pengquan Menga1bb6272018-09-06 09:59:22 -07009775 final long identity = Binder.clearCallingIdentity();
9776 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009777 Phone phone = getPhone(subId);
9778 if (phone != null) {
9779 phone.setDataRoamingEnabled(isEnabled);
9780 }
9781 } finally {
9782 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009783 }
9784 }
9785
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009786 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009787 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009788 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009789 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009790 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009791
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009792 boolean isAllowed = true;
9793 final long identity = Binder.clearCallingIdentity();
9794 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009795 Phone phone = getPhone(subId);
9796 if (phone != null) {
9797 isAllowed = phone.isCspPlmnEnabled();
9798 }
9799 } finally {
9800 Binder.restoreCallingIdentity(identity);
9801 }
9802 return isAllowed;
9803 }
9804
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009805 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9806 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009807 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009808 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009809 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009810 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9811 if (phone == null) {
9812 return false;
9813 }
9814 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9815 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9816 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009817 }
9818
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009819 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009820 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009821 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009822 mApp.getSystemService(AppOpsManager.class)
9823 .checkPackage(Binder.getCallingUid(), callingPackage);
9824
Jordan Liu1e142fc2019-04-22 15:10:43 -07009825 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009826 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009827 try {
9828 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009829 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009830 } catch (SecurityException e) {
9831 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9832 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009833 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009834 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009835 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009836 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009837 }
sandeepjsb6c87872021-09-27 15:34:44 +00009838 // checking compatibility, if calling app's target SDK is T and beyond.
9839 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9840 Binder.getCallingUid())) {
9841 isIccIdAccessRestricted = true;
9842 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009843 final long identity = Binder.clearCallingIdentity();
9844 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009845 UiccController uiccController = UiccController.getInstance();
9846 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009847 if (hasReadPermission) {
9848 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009849 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009850
9851 // Remove private info if the caller doesn't have access
9852 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9853 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009854 //setting the value after compatibility check
9855 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009856 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9857 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009858 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009859 if (card == null) {
9860 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009861 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009862 continue;
9863 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009864 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9865 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009866 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009867 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009868 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009869 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9870 for (UiccPortInfo portInfo : portInfos) {
9871 UiccPort port = uiccController.getUiccPortForSlot(
9872 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9873 if (port == null) {
9874 // assume no access if port is null
9875 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9876 continue;
9877 }
9878 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9879 uiccPortInfos.add(portInfo);
9880 } else {
9881 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9882 }
9883 }
9884 filteredInfos.add(new UiccCardInfo(
9885 cardInfo.isEuicc(),
9886 cardInfo.getCardId(),
9887 null,
9888 cardInfo.getPhysicalSlotIndex(),
9889 cardInfo.isRemovable(),
9890 cardInfo.isMultipleEnabledProfilesSupported(),
9891 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009892 }
9893 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009894 } finally {
9895 Binder.restoreCallingIdentity(identity);
9896 }
9897 }
9898
sandeepjsb6c87872021-09-27 15:34:44 +00009899 /**
9900 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9901 * generally private and require carrier privileges to view.
9902 *
9903 * @hide
9904 */
9905 @NonNull
9906 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9907 List<UiccPortInfo> portinfo = new ArrayList<>();
9908 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9909 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9910 }
9911 return new UiccCardInfo(
9912 cardInfo.isEuicc(),
9913 cardInfo.getCardId(),
9914 null,
9915 cardInfo.getPhysicalSlotIndex(),
9916 cardInfo.isRemovable(),
9917 cardInfo.isMultipleEnabledProfilesSupported(),
9918 portinfo
9919 );
9920 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009921
sandeepjsb6c87872021-09-27 15:34:44 +00009922 /**
9923 * @hide
9924 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9925 * These values are generally private and require carrier privileges to view.
9926 */
9927 @NonNull
9928 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9929 return new UiccPortInfo(
9930 UiccPortInfo.ICCID_REDACTED,
9931 portInfo.getPortIndex(),
9932 portInfo.getLogicalSlotIndex(),
9933 portInfo.isActive()
9934 );
9935 }
9936 @Override
9937 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009938 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009939 mApp.getSystemService(AppOpsManager.class)
9940 .checkPackage(Binder.getCallingUid(), callingPackage);
9941
sandeepjsb6c87872021-09-27 15:34:44 +00009942 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009943
Aman Guptaf3c90b32022-03-17 04:54:16 +00009944 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9945 // we are reading iccId which is PII data.
9946 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009947
9948 // checking compatibility, if calling app's target SDK is T and beyond.
9949 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9950 Binder.getCallingUid())) {
9951 isLogicalSlotAccessRestricted = true;
9952 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009953 final long identity = Binder.clearCallingIdentity();
9954 try {
9955 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009956 if (slots == null || slots.length == 0) {
9957 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009958 return null;
9959 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009960 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9961 for (int i = 0; i < slots.length; i++) {
9962 UiccSlot slot = slots[i];
9963 if (slot == null) {
9964 continue;
9965 }
9966
Jordan Liu7be7e652019-05-06 18:55:02 +00009967 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009968 UiccCard card = slot.getUiccCard();
9969 if (card != null) {
9970 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009971 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009972 cardId = slot.getEid();
9973 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009974 // If cardId is null, use iccId of default port as cardId.
9975 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009976 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009977 }
9978
Jordan Liu857451f2019-05-09 16:35:35 -07009979 if (cardId != null) {
9980 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9981 // if cardId is an EID, it's all digits so this is fine
9982 cardId = IccUtils.stripTrailingFs(cardId);
9983 }
9984
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009985 int cardState = 0;
9986 switch (slot.getCardState()) {
9987 case CARDSTATE_ABSENT:
9988 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9989 break;
9990 case CARDSTATE_PRESENT:
9991 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9992 break;
9993 case CARDSTATE_ERROR:
9994 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9995 break;
9996 case CARDSTATE_RESTRICTED:
9997 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9998 break;
9999 default:
10000 break;
10001
10002 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010003 List<UiccPortInfo> portInfos = new ArrayList<>();
10004 int[] portIndexes = slot.getPortList();
10005 for (int portIdx : portIndexes) {
10006 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +000010007 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +000010008 portInfos.add(new UiccPortInfo(iccId, portIdx,
10009 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010010 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010011 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010012 slot.isEuicc(),
10013 cardId,
10014 cardState,
Jordan Liua2619582019-02-14 12:56:40 -080010015 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010016 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +000010017 //setting the value after compatibility check
10018 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010019 }
10020 return infos;
10021 } finally {
10022 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -070010023 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010024 }
10025
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010026 /* Returns null if doesn't have read permission or carrier privilege access. */
10027 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
10028 boolean hasReadPermission) {
10029 String iccId = slot.getIccId(portIndex);
10030 if (hasReadPermission) { // if has read permission
10031 return iccId;
10032 } else {
10033 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
10034 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
10035 // if no read permission, checking carrier privilege access
10036 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
10037 return iccId;
10038 }
10039 }
10040 }
10041 // No read permission or carrier privilege access.
10042 return UiccPortInfo.ICCID_REDACTED;
10043 }
10044
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010045 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010046 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010047 public boolean switchSlots(int[] physicalSlots) {
10048 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010049
10050 final long identity = Binder.clearCallingIdentity();
10051 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010052 List<UiccSlotMapping> slotMappings = new ArrayList<>();
10053 for (int i = 0; i < physicalSlots.length; i++) {
10054 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
10055 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
10056 physicalSlots[i], i));
10057 }
10058 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010059 } finally {
10060 Binder.restoreCallingIdentity(identity);
10061 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000010062 }
Jack Yu4c988042018-02-27 15:30:01 -080010063
10064 @Override
sandeepjsb6c87872021-09-27 15:34:44 +000010065 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
10066 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
10067 enforceModifyPermission();
10068
10069 final long identity = Binder.clearCallingIdentity();
10070 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +000010071 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +000010072 } finally {
10073 Binder.restoreCallingIdentity(identity);
10074 }
10075 }
10076
10077 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -080010078 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -080010079 final long identity = Binder.clearCallingIdentity();
10080 try {
10081 return UiccController.getInstance().getCardIdForDefaultEuicc();
10082 } finally {
10083 Binder.restoreCallingIdentity(identity);
10084 }
10085 }
10086
Pengquan Meng85728fb2018-03-12 16:31:21 -070010087 /**
goneil47ffb6e2018-04-06 15:40:58 -070010088 * A test API to reload the UICC profile.
10089 *
10090 * <p>Requires that the calling app has permission
10091 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
10092 * @hide
10093 */
10094 @Override
10095 public void refreshUiccProfile(int subId) {
10096 enforceModifyPermission();
10097
10098 final long identity = Binder.clearCallingIdentity();
10099 try {
10100 Phone phone = getPhone(subId);
10101 if (phone == null) {
10102 return;
10103 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010104 UiccPort uiccPort = phone.getUiccPort();
10105 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -070010106 return;
10107 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010108 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -070010109 if (uiccProfile == null) {
10110 return;
10111 }
10112 uiccProfile.refresh();
10113 } finally {
10114 Binder.restoreCallingIdentity(identity);
10115 }
10116 }
10117
10118 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -070010119 * Returns false if the mobile data is disabled by default, otherwise return true.
10120 */
10121 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010122 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010123 }
10124
10125 /**
10126 * Returns true if the data roaming is enabled by default, i.e the system property
10127 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
10128 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
10129 */
10130 private boolean getDefaultDataRoamingEnabled(int subId) {
10131 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010132 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -070010133 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -070010134 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
10135 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
10136 return isDataRoamingEnabled;
10137 }
10138
10139 /**
10140 * Returns the default network type for the given {@code subId}, if the default network type is
10141 * not set, return {@link Phone#PREFERRED_NT_MODE}.
10142 */
10143 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +090010144 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -080010145 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +090010146 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
10147 return list.get(phoneId);
10148 }
10149 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -070010150 }
fionaxua13278b2018-03-21 00:08:13 -070010151
10152 @Override
10153 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -070010154 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -070010155 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010156
10157 final long identity = Binder.clearCallingIdentity();
10158 try {
10159 final Phone phone = getPhone(subId);
10160 if (phone == null) {
10161 loge("setCarrierTestOverride fails with invalid subId: " + subId);
10162 return;
10163 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -080010164 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
10165 if (cpt != null) {
10166 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
10167 }
10168 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -070010169 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
10170 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -070010171 if (carrierPrivilegeRules == null) {
10172 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
10173 } else {
10174 mCarrierPrivilegeTestOverrideSubIds.add(subId);
10175 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010176 } finally {
10177 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010178 }
fionaxua13278b2018-03-21 00:08:13 -070010179 }
10180
10181 @Override
10182 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -070010183 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -080010184
10185 final long identity = Binder.clearCallingIdentity();
10186 try {
10187 final Phone phone = getPhone(subId);
10188 if (phone == null) {
10189 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
10190 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
10191 }
10192 return phone.getCarrierIdListVersion();
10193 } finally {
10194 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -070010195 }
fionaxua13278b2018-03-21 00:08:13 -070010196 }
Malcolm Chen2c63d402018-08-14 16:00:53 -070010197
10198 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010199 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
10200 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010201 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010202 mApp, subId, callingPackage, callingFeatureId,
10203 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010204 return -1;
10205 }
10206
10207 final long identity = Binder.clearCallingIdentity();
10208 try {
10209 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10210 } finally {
10211 Binder.restoreCallingIdentity(identity);
10212 }
10213 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010214
10215 @Override
10216 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010217 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010218 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010219 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010220
10221 final long identity = Binder.clearCallingIdentity();
10222 try {
10223 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10224 } finally {
10225 Binder.restoreCallingIdentity(identity);
10226 }
10227 }
10228
10229 @Override
10230 public boolean setCdmaRoamingMode(int subId, int mode) {
10231 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10232 mApp, subId, "setCdmaRoamingMode");
10233
10234 final long identity = Binder.clearCallingIdentity();
10235 try {
10236 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10237 } finally {
10238 Binder.restoreCallingIdentity(identity);
10239 }
10240 }
10241
10242 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010243 public int getCdmaSubscriptionMode(int subId) {
10244 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010245 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010246 mApp, subId, "getCdmaSubscriptionMode");
10247
10248 final long identity = Binder.clearCallingIdentity();
10249 try {
10250 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10251 } finally {
10252 Binder.restoreCallingIdentity(identity);
10253 }
10254 }
10255
10256 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010257 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10259 mApp, subId, "setCdmaSubscriptionMode");
10260
10261 final long identity = Binder.clearCallingIdentity();
10262 try {
10263 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10264 } finally {
10265 Binder.restoreCallingIdentity(identity);
10266 }
10267 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010268
sqianc5eccab2018-10-19 18:46:41 -070010269 @Override
sqian8c685422019-02-22 15:55:18 -080010270 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010271 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010272 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010273 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10274 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010275 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10276 }
10277 final long identity = Binder.clearCallingIdentity();
10278 try {
sqian854d44b2018-12-12 16:48:18 -080010279 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10280 for (Phone phone: PhoneFactory.getPhones()) {
10281 if (phone.getEmergencyNumberTracker() != null
10282 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10283 emergencyNumberListInternal.put(
10284 phone.getSubId(),
10285 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10286 }
sqian11b7a0e2018-12-05 18:48:28 -080010287 }
sqian854d44b2018-12-12 16:48:18 -080010288 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010289 } finally {
10290 Binder.restoreCallingIdentity(identity);
10291 }
sqianc5eccab2018-10-19 18:46:41 -070010292 }
10293
10294 @Override
sqian8c685422019-02-22 15:55:18 -080010295 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010296 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010297 if (!exactMatch) {
10298 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010299 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010300 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010301 }
10302 final long identity = Binder.clearCallingIdentity();
10303 try {
sqian854d44b2018-12-12 16:48:18 -080010304 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010305 //Note: we ignore passed in param exactMatch. We can remove it once
10306 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010307 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010308 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010309 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010310 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010311 }
sqian11b7a0e2018-12-05 18:48:28 -080010312 }
10313 return false;
10314 } finally {
10315 Binder.restoreCallingIdentity(identity);
10316 }
10317 }
10318
sqianf4ca7ed2019-01-15 18:32:07 -080010319 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010320 * Start emergency callback mode for GsmCdmaPhone for testing.
10321 */
10322 @Override
10323 public void startEmergencyCallbackMode() {
10324 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10325 "startEmergencyCallbackMode");
10326 enforceModifyPermission();
10327 final long identity = Binder.clearCallingIdentity();
10328 try {
10329 for (Phone phone : PhoneFactory.getPhones()) {
10330 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10331 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10332 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10333 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10334 gsmCdmaPhone.obtainMessage(
10335 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10336 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10337 }
10338 }
10339 } finally {
10340 Binder.restoreCallingIdentity(identity);
10341 }
10342 }
10343
10344 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010345 * Update emergency number list for test mode.
10346 */
10347 @Override
10348 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10349 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10350 "updateEmergencyNumberListTestMode");
10351
10352 final long identity = Binder.clearCallingIdentity();
10353 try {
10354 for (Phone phone: PhoneFactory.getPhones()) {
10355 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10356 if (tracker != null) {
10357 tracker.executeEmergencyNumberTestModeCommand(action, num);
10358 }
10359 }
10360 } finally {
10361 Binder.restoreCallingIdentity(identity);
10362 }
10363 }
10364
10365 /**
10366 * Get the full emergency number list for test mode.
10367 */
10368 @Override
10369 public List<String> getEmergencyNumberListTestMode() {
10370 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10371 "getEmergencyNumberListTestMode");
10372
10373 final long identity = Binder.clearCallingIdentity();
10374 try {
10375 Set<String> emergencyNumbers = new HashSet<>();
10376 for (Phone phone: PhoneFactory.getPhones()) {
10377 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10378 if (tracker != null) {
10379 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10380 emergencyNumbers.add(num.getNumber());
10381 }
10382 }
10383 }
10384 return new ArrayList<>(emergencyNumbers);
10385 } finally {
10386 Binder.restoreCallingIdentity(identity);
10387 }
10388 }
10389
chen xud6b45bd2018-10-30 22:27:10 -070010390 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010391 public int getEmergencyNumberDbVersion(int subId) {
10392 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10393
10394 final long identity = Binder.clearCallingIdentity();
10395 try {
10396 final Phone phone = getPhone(subId);
10397 if (phone == null) {
10398 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10399 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10400 }
10401 return phone.getEmergencyNumberDbVersion();
10402 } finally {
10403 Binder.restoreCallingIdentity(identity);
10404 }
10405 }
10406
10407 @Override
10408 public void notifyOtaEmergencyNumberDbInstalled() {
10409 enforceModifyPermission();
10410
10411 final long identity = Binder.clearCallingIdentity();
10412 try {
10413 for (Phone phone: PhoneFactory.getPhones()) {
10414 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10415 if (tracker != null) {
10416 tracker.updateOtaEmergencyNumberDatabase();
10417 }
10418 }
10419 } finally {
10420 Binder.restoreCallingIdentity(identity);
10421 }
10422 }
10423
10424 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010425 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010426 enforceActiveEmergencySessionPermission();
10427
10428 final long identity = Binder.clearCallingIdentity();
10429 try {
10430 for (Phone phone: PhoneFactory.getPhones()) {
10431 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10432 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010433 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10434 }
10435 }
10436 } finally {
10437 Binder.restoreCallingIdentity(identity);
10438 }
10439 }
10440
10441 @Override
10442 public void resetOtaEmergencyNumberDbFilePath() {
10443 enforceActiveEmergencySessionPermission();
10444
10445 final long identity = Binder.clearCallingIdentity();
10446 try {
10447 for (Phone phone: PhoneFactory.getPhones()) {
10448 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10449 if (tracker != null) {
10450 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010451 }
10452 }
10453 } finally {
10454 Binder.restoreCallingIdentity(identity);
10455 }
10456 }
10457
10458 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010459 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10460 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10461 Phone phone = getPhone(subId);
10462 if (phone == null) {
10463 return null;
10464 }
10465 final long identity = Binder.clearCallingIdentity();
10466 try {
10467 UiccProfile profile = UiccController.getInstance()
10468 .getUiccProfileForPhone(phone.getPhoneId());
10469 if (profile != null) {
10470 return profile.getCertsFromCarrierPrivilegeAccessRules();
10471 }
10472 } finally {
10473 Binder.restoreCallingIdentity(identity);
10474 }
10475 return null;
10476 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010477
10478 /**
10479 * Enable or disable a modem stack.
10480 */
10481 @Override
10482 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10483 enforceModifyPermission();
10484
10485 final long identity = Binder.clearCallingIdentity();
10486 try {
10487 Phone phone = PhoneFactory.getPhone(slotIndex);
10488 if (phone == null) {
10489 return false;
10490 } else {
10491 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10492 }
10493 } finally {
10494 Binder.restoreCallingIdentity(identity);
10495 }
10496 }
Michelecea4cf22018-12-21 15:00:11 -080010497
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010498 /**
10499 * Whether a modem stack is enabled or not.
10500 */
10501 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010502 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10503 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010504 Phone phone = PhoneFactory.getPhone(slotIndex);
10505 if (phone == null) return false;
10506
10507 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010508 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10509 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010510 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10511 }
10512
10513 final long identity = Binder.clearCallingIdentity();
10514 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010515 try {
10516 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10517 } catch (NoSuchElementException ex) {
10518 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10519 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010520 } finally {
10521 Binder.restoreCallingIdentity(identity);
10522 }
10523 }
10524
Michelecea4cf22018-12-21 15:00:11 -080010525 @Override
Michele0ea7d782019-03-19 14:58:42 -070010526 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010527 enforceModifyPermission();
10528
10529 final long identity = Binder.clearCallingIdentity();
10530 try {
10531 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010532 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010533 .commit();
10534 } finally {
10535 Binder.restoreCallingIdentity(identity);
10536 }
10537 }
10538
10539 @Override
Michele0ea7d782019-03-19 14:58:42 -070010540 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010541 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010542 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010543 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10544 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010545 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010546 }
Michelecea4cf22018-12-21 15:00:11 -080010547
10548 final long identity = Binder.clearCallingIdentity();
10549 try {
Michele0ea7d782019-03-19 14:58:42 -070010550 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010551 } finally {
10552 Binder.restoreCallingIdentity(identity);
10553 }
10554 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010555
Michele0ea7d782019-03-19 14:58:42 -070010556 @TelephonyManager.IsMultiSimSupportedResult
10557 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010558 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10559 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10560 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010561 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10562 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010563 }
10564 // Check if the hardware supports multisim functionality. If usage of multisim is not
10565 // supported by the modem, indicate that it is restricted.
10566 PhoneCapability staticCapability =
10567 mPhoneConfigurationManager.getStaticPhoneCapability();
10568 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010569 loge("isMultiSimSupportedInternal: no static configuration available");
10570 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010571 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010572 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010573 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10574 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010575 }
10576 // Check if support of multiple SIMs is restricted by carrier
10577 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010578 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010579 }
10580
Michele0ea7d782019-03-19 14:58:42 -070010581 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010582 }
10583
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010584 /**
10585 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010586 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10587 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10588 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010589 * @param numOfSims number of active sims we want to switch to
10590 */
10591 @Override
10592 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010593 if (numOfSims == 1) {
10594 enforceModifyPermission();
10595 } else {
10596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10597 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10598 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010599 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010600
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010601 try {
Michele30b57b22019-03-01 12:01:14 -080010602 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010603 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010604 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10605 return;
10606 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010607 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10608 } finally {
10609 Binder.restoreCallingIdentity(identity);
10610 }
10611 }
10612
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010613 @Override
10614 public boolean isApplicationOnUicc(int subId, int appType) {
10615 enforceReadPrivilegedPermission("isApplicationOnUicc");
10616 Phone phone = getPhone(subId);
10617 if (phone == null) {
10618 return false;
10619 }
10620 final long identity = Binder.clearCallingIdentity();
10621 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010622 UiccPort uiccPort = phone.getUiccPort();
10623 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010624 return false;
10625 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010626 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010627 if (uiccProfile == null) {
10628 return false;
10629 }
10630 if (TelephonyManager.APPTYPE_SIM <= appType
10631 && appType <= TelephonyManager.APPTYPE_ISIM) {
10632 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10633 }
10634 return false;
10635 } finally {
10636 Binder.restoreCallingIdentity(identity);
10637 }
10638 }
10639
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010640 /**
chen xub4baa772019-04-03 10:23:41 -070010641 * Get whether making changes to modem configurations will trigger reboot.
10642 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010643 */
10644 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010645 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10646 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010647 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010648 mApp, subId, callingPackage, callingFeatureId,
10649 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010650 return false;
10651 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010652 final long identity = Binder.clearCallingIdentity();
10653 try {
10654 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10655 } finally {
10656 Binder.restoreCallingIdentity(identity);
10657 }
10658 }
10659
Nathan Harold29f5f052019-02-15 13:41:57 -080010660 private void updateModemStateMetrics() {
10661 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10662 // TODO: check the state for each modem if the api is ready.
10663 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10664 }
10665
Pengquan Meng3889a572019-01-23 11:16:29 -080010666 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010667 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010668 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010669 // Verify that the callingPackage belongs to the calling UID
10670 mApp.getSystemService(AppOpsManager.class)
10671 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010672 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010673 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010674 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010675 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10676 if (slotInfos != null) {
10677 for (int i = 0; i < slotInfos.length; i++) {
10678 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10679 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10680 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10681 portInfo.getLogicalSlotIndex()));
10682 }
10683 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010684 }
10685 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010686 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010687 } finally {
10688 Binder.restoreCallingIdentity(identity);
10689 }
10690 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010691
10692 /**
10693 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010694 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010695 */
jimsunf9ec1622022-09-13 21:18:43 +080010696 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010697 @Override
10698 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010699 return getHalVersion(HAL_SERVICE_RADIO);
10700 }
10701
10702 /**
10703 * Get the HAL Version of a specific service
10704 */
10705 @Override
10706 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010707 Phone phone = getDefaultPhone();
10708 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010709 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010710 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10711 return hv.major * 100 + hv.minor;
10712 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010713
10714 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010715 * Get the current calling package name.
10716 * @return the current calling package name
10717 */
10718 @Override
10719 public String getCurrentPackageName() {
10720 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10721 }
10722
10723 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010724 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10725 * corresponding network requests on a subId.
10726 *
10727 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010728 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010729 * 2) APN is un-metered for this subscription, or
10730 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010731 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010732 *
10733 * @return whether data is allowed for a apn type.
10734 *
10735 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010736 */
10737 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010738 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010739 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10740 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010741
10742 // Now that all security checks passes, perform the operation as ourselves.
10743 final long identity = Binder.clearCallingIdentity();
10744 try {
10745 Phone phone = getPhone(subId);
10746 if (phone == null) return false;
10747
Jack Yu27422a52022-03-21 10:38:05 -070010748 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010749 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010750 isMetered = phone.getDataNetworkController().getDataConfigManager()
10751 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10752 phone.getServiceState().getDataRoaming());
10753 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010754 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010755 } finally {
10756 Binder.restoreCallingIdentity(identity);
10757 }
10758 }
10759
10760 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010761 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010762 enforceReadPrivilegedPermission("isApnMetered");
10763
10764 // Now that all security checks passes, perform the operation as ourselves.
10765 final long identity = Binder.clearCallingIdentity();
10766 try {
10767 Phone phone = getPhone(subId);
10768 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010769 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10770 DataUtils.apnTypeToNetworkCapability(apnType),
10771 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010772 } finally {
10773 Binder.restoreCallingIdentity(identity);
10774 }
10775 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010776
10777 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010778 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10779 int subscriptionId, IBooleanConsumer resultCallback) {
10780 enforceModifyPermission();
10781 long token = Binder.clearCallingIdentity();
10782 try {
10783 Phone phone = getPhone(subscriptionId);
10784 if (phone == null) {
10785 try {
10786 if (resultCallback != null) {
10787 resultCallback.accept(false);
10788 }
10789 } catch (RemoteException e) {
10790 // ignore
10791 }
10792 return;
10793 }
10794 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10795 Pair.create(specifiers, (x) -> {
10796 try {
10797 if (resultCallback != null) {
10798 resultCallback.accept(x);
10799 }
10800 } catch (RemoteException e) {
10801 // ignore
10802 }
10803 });
10804 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10805 } finally {
10806 Binder.restoreCallingIdentity(token);
10807 }
10808 }
10809
10810 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010811 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10812 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010813 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010814 mApp, subId, "getSystemSelectionChannels");
10815 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10816 final long identity = Binder.clearCallingIdentity();
10817 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010818 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10819 if (result instanceof IllegalStateException) {
10820 throw (IllegalStateException) result;
10821 }
10822 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010823 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10824 return specifiers;
10825 } finally {
10826 Binder.restoreCallingIdentity(identity);
10827 }
10828 }
10829
10830 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010831 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010832 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010833 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010834 }
10835
10836 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010837 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10838 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010839 if (callingPackage == null) {
10840 callingPackage = getCurrentPackageName();
10841 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010842 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10843 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010844 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10845 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010846 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10847 }
10848 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10849 Intent intent = new Intent();
10850 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10851 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10852 // Bring up choose default SMS subscription dialog right now
10853 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10854 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10855 mApp.startActivity(intent);
10856 }
chen xud5ca2d52019-05-28 15:20:57 -070010857
10858 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010859 public void showSwitchToManagedProfileDialog() {
10860 enforceModifyPermission();
10861
10862 Intent intent = new Intent();
10863 intent.setClass(mApp, ErrorDialogActivity.class);
10864 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10865 mApp.startActivity(intent);
10866 }
10867
10868 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010869 public String getMmsUAProfUrl(int subId) {
10870 //TODO investigate if this API should require proper permission check in R b/133791609
10871 final long identity = Binder.clearCallingIdentity();
10872 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010873 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10874 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10875 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10876 return carrierUAProfUrl;
10877 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010878 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10879 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010880 } finally {
10881 Binder.restoreCallingIdentity(identity);
10882 }
10883 }
10884
10885 @Override
10886 public String getMmsUserAgent(int subId) {
10887 //TODO investigate if this API should require proper permission check in R b/133791609
10888 final long identity = Binder.clearCallingIdentity();
10889 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010890 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10891 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10892 if (!TextUtils.isEmpty(carrierUserAgent)) {
10893 return carrierUserAgent;
10894 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010895 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10896 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010897 } finally {
10898 Binder.restoreCallingIdentity(identity);
10899 }
10900 }
Jack Yub07d4972019-05-28 16:12:25 -070010901
10902 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010903 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10904 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010905
Jack Yub07d4972019-05-28 16:12:25 -070010906 final long identity = Binder.clearCallingIdentity();
10907 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010908 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010909 if (phone == null) return false;
10910
Ling Maf188d502022-09-16 15:22:36 -070010911 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010912 } finally {
10913 Binder.restoreCallingIdentity(identity);
10914 }
10915 }
10916
10917 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010918 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010919 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010920 enforceModifyPermission();
10921
changbettyd5c246e2019-12-24 15:40:37 +080010922 final long identity = Binder.clearCallingIdentity();
10923 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010924 Phone phone = getPhone(subscriptionId);
10925 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010926
Ling Maf188d502022-09-16 15:22:36 -070010927 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010928 } finally {
10929 Binder.restoreCallingIdentity(identity);
10930 }
10931 }
10932
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010933 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010934 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010935 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10936 * otherwise.
10937 */
10938 @Override
10939 public void setCepEnabled(boolean isCepEnabled) {
10940 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10941
10942 final long identity = Binder.clearCallingIdentity();
10943 try {
10944 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10945 for (Phone phone : PhoneFactory.getPhones()) {
10946 Phone defaultPhone = phone.getImsPhone();
10947 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10948 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10949 ImsPhoneCallTracker imsPhoneCallTracker =
10950 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10951 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10952 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10953 + imsPhone.getMsisdn());
10954 }
10955 }
10956 } finally {
10957 Binder.restoreCallingIdentity(identity);
10958 }
10959 }
allenwtsu46dcc572020-01-08 18:24:03 +080010960
10961 /**
10962 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10963 *
10964 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10965 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10966 * before being read.
10967 */
10968 @Override
10969 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10970 isCompressed) {
10971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10972 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010973 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10974 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10975 }
10976 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010977 // ProvisioningManager can not handle ServiceSpecificException.
10978 // Throw the IllegalStateException and annotate ProvisioningManager.
10979 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010980 }
10981
10982 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010983 try {
Hui Wang761a6682020-10-31 05:12:53 +000010984 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10985 } finally {
10986 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010987 }
10988 }
zoey chene02881a2019-12-30 16:11:23 +080010989
10990 @Override
10991 public boolean isIccLockEnabled(int subId) {
10992 enforceReadPrivilegedPermission("isIccLockEnabled");
10993
10994 // Now that all security checks passes, perform the operation as ourselves.
10995 final long identity = Binder.clearCallingIdentity();
10996 try {
10997 Phone phone = getPhone(subId);
10998 if (phone != null && phone.getIccCard() != null) {
10999 return phone.getIccCard().getIccLockEnabled();
11000 } else {
11001 return false;
11002 }
11003 } finally {
11004 Binder.restoreCallingIdentity(identity);
11005 }
11006 }
11007
11008 /**
11009 * Set the ICC pin lock enabled or disabled.
11010 *
11011 * @return an integer representing the status of IccLock enabled or disabled in the following
11012 * three cases:
11013 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
11014 * successfully.
11015 * - Positive number and zero for remaining password attempts.
11016 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11017 *
11018 */
11019 @Override
11020 public int setIccLockEnabled(int subId, boolean enabled, String password) {
11021 enforceModifyPermission();
11022
11023 Phone phone = getPhone(subId);
11024 if (phone == null) {
11025 return 0;
11026 }
11027 // Now that all security checks passes, perform the operation as ourselves.
11028 final long identity = Binder.clearCallingIdentity();
11029 try {
11030 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
11031 new Pair<Boolean, String>(enabled, password), phone, null);
11032 return attemptsRemaining;
11033
11034 } catch (Exception e) {
11035 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
11036 } finally {
11037 Binder.restoreCallingIdentity(identity);
11038 }
11039 return 0;
11040 }
11041
11042 /**
11043 * Change the ICC password used in ICC pin lock.
11044 *
11045 * @return an integer representing the status of IccLock changed in the following three cases:
11046 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
11047 * - Positive number and zero for remaining password attempts.
11048 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
11049 *
11050 */
11051 @Override
11052 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
11053 enforceModifyPermission();
11054
11055 Phone phone = getPhone(subId);
11056 if (phone == null) {
11057 return 0;
11058 }
11059 // Now that all security checks passes, perform the operation as ourselves.
11060 final long identity = Binder.clearCallingIdentity();
11061 try {
11062 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
11063 new Pair<String, String>(oldPassword, newPassword), phone, null);
11064 return attemptsRemaining;
11065
11066 } catch (Exception e) {
11067 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
11068 } finally {
11069 Binder.restoreCallingIdentity(identity);
11070 }
11071 return 0;
11072 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080011073
11074 /**
11075 * Request for receiving user activity notification
11076 */
11077 @Override
11078 public void requestUserActivityNotification() {
11079 if (!mNotifyUserActivity.get()
11080 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
11081 mNotifyUserActivity.set(true);
11082 }
11083 }
11084
11085 /**
11086 * Called when userActivity is signalled in the power manager.
11087 * This is safe to call from any thread, with any window manager locks held or not.
11088 */
11089 @Override
11090 public void userActivity() {
11091 // ***************************************
11092 // * Inherited from PhoneWindowManager *
11093 // ***************************************
11094 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
11095 // WITH ITS LOCKS HELD.
11096 //
11097 // This code must be VERY careful about the locks
11098 // it acquires.
11099 // In fact, the current code acquires way too many,
11100 // and probably has lurking deadlocks.
11101
11102 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
11103 throw new SecurityException("Only the OS may call notifyUserActivity()");
11104 }
11105
11106 if (mNotifyUserActivity.getAndSet(false)) {
11107 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
11108 USER_ACTIVITY_NOTIFICATION_DELAY);
11109 }
11110 }
Malcolm Chen4639c562020-04-13 11:59:40 -070011111
11112 @Override
11113 public boolean canConnectTo5GInDsdsMode() {
11114 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
11115 }
Jack Yud10cdd42020-09-28 20:28:01 -070011116
11117 @Override
11118 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
11119 String callingFeatureId) {
11120 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
11121 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
11122 throw new SecurityException("Requires READ_PHONE_STATE permission.");
11123 }
11124
11125 Phone phone = getPhone(subId);
11126 if (phone == null) {
11127 throw new RuntimeException("phone is not available");
11128 }
11129 // Now that all security checks passes, perform the operation as ourselves.
11130 final long identity = Binder.clearCallingIdentity();
11131 try {
11132 return phone.getEquivalentHomePlmns();
11133 } finally {
11134 Binder.restoreCallingIdentity(identity);
11135 }
11136 }
Daniel Bright59e67312020-11-13 11:49:37 -080011137
11138 @Override
11139 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011140 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
11141 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080011142 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080011143 if (radioInterfaceCapabilities == null) {
11144 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080011145 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080011146 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080011147 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011148
Hui Wang641e81c2020-10-12 12:14:23 -070011149 @Override
11150 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
11151 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000011152 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
11153 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11154 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
11155 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11156 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070011157 if (DBG) {
11158 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
11159 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
11160 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
11161 }
11162
11163 if (!SubscriptionManager.isValidSubscriptionId(subId)
11164 || appType < TelephonyManager.APPTYPE_UNKNOWN
11165 || appType > TelephonyManager.APPTYPE_ISIM
11166 || nafUrl == null || securityProtocol == null || callback == null) {
11167 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
11168 if (callback != null) {
11169 try {
11170 callback.onAuthenticationFailure(
11171 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
11172 } catch (RemoteException exception) {
11173 log("Fail to notify onAuthenticationFailure due to " + exception);
11174 }
11175 return;
11176 }
11177 }
11178
11179 final long token = Binder.clearCallingIdentity();
11180 try {
11181 getGbaManager(subId).bootstrapAuthenticationRequest(
11182 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011183 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070011184 } finally {
11185 Binder.restoreCallingIdentity(token);
11186 }
11187 }
11188
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011189 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011190 * Attempts to set the radio power state for all phones for thermal reason.
11191 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011192 * requested radio power state will actually be set. See {@link
11193 * PhoneInternalInterface#setRadioPowerForReason} for more details.
11194 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011195 * @param enable {@code true} if trying to turn radio on.
11196 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
11197 * false}.
11198 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011199 private boolean setRadioPowerForThermal(boolean enable) {
11200 boolean isPhoneAvailable = false;
11201 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
11202 Phone phone = PhoneFactory.getPhone(i);
11203 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011204 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011205 isPhoneAvailable = true;
11206 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011207 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011208
11209 // return true if successfully informed the phone object about the thermal radio power
11210 // request.
11211 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011212 }
11213
11214 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011215 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011216 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11217 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11218 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11219 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11220 throw new IllegalArgumentException("modem does not support data throttling");
11221 }
11222
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011223 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11224 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011225 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011226 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11227 }
11228
Sarah Chinecc78c42022-03-31 21:16:48 -070011229 setDataEnabledForReason(
11230 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011231
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011232 if (isDataThrottlingSupported) {
11233 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011234 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011235 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11236 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11237 } else if (thermalMitigationResult
11238 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011239 log("Modem likely does not support data throttling on secondary carrier. Data " +
11240 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11241 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011242 }
11243 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011244 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011245
11246 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011247 }
11248
Jack Nudelman644b91a2021-03-12 14:09:48 -080011249 private static List<String> getThermalMitigationAllowlist(Context context) {
11250 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11251 for (String pckg : context.getResources()
11252 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11253 sThermalMitigationAllowlistedPackages.add(pckg);
11254 }
11255 }
11256
11257 return sThermalMitigationAllowlistedPackages;
11258 }
11259
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011260 private boolean isAnyPhoneInEmergencyState() {
11261 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11262 if (tm.isInEmergencyCall()) {
11263 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11264 return true;
11265 }
11266 for (Phone phone : PhoneFactory.getPhones()) {
11267 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11268 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011269 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11270 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011271 return true;
11272 }
11273 }
11274
11275 return false;
11276 }
11277
Jack Nudelman644b91a2021-03-12 14:09:48 -080011278 /**
11279 * Used by shell commands to add an authorized package name for thermal mitigation.
11280 * @param packageName name of package to be allowlisted
11281 * @param context
11282 */
11283 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11284 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11285 sThermalMitigationAllowlistedPackages.add(packageName);
11286 }
11287
11288 /**
11289 * Used by shell commands to remove an authorized package name for thermal mitigation.
11290 * @param packageName name of package to remove from allowlist
11291 * @param context
11292 */
11293 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11294 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11295 sThermalMitigationAllowlistedPackages.remove(packageName);
11296 }
11297
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011298 /**
11299 * Thermal mitigation request to control functionalities at modem.
11300 *
11301 * @param subId the id of the subscription.
11302 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011303 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011304 *
11305 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11306 */
11307 @Override
11308 @ThermalMitigationResult
11309 public int sendThermalMitigationRequest(
11310 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011311 ThermalMitigationRequest thermalMitigationRequest,
11312 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011313 enforceModifyPermission();
11314
Jack Nudelman644b91a2021-03-12 14:09:48 -080011315 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11316 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11317 .contains(callingPackage)) {
11318 throw new SecurityException("Calling package must be configured in the device config. "
11319 + "calling package: " + callingPackage);
11320 }
11321
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011322 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11323 final long identity = Binder.clearCallingIdentity();
11324
11325 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11326 try {
11327 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11328 switch (thermalMitigationAction) {
11329 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11330 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011331 handleDataThrottlingRequest(subId,
11332 thermalMitigationRequest.getDataThrottlingRequest(),
11333 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011334 break;
11335 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11336 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11337 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11338 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11339 }
11340
11341 // Ensure that radio is on. If not able to power on due to phone being
11342 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011343 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011344 thermalMitigationResult =
11345 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11346 break;
11347 }
11348
11349 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011350 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011351 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11352 break;
11353 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11354 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11355 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11356 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11357 }
11358
11359 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11360 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011361 Phone phone = getPhone(subId);
11362 if (phone == null) {
11363 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011364 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011365 break;
11366 }
11367
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011368 TelephonyConnectionService service =
11369 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011370 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011371 Log.e(LOG_TAG, "An emergency call is pending");
11372 thermalMitigationResult =
11373 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11374 break;
11375 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011376 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011377 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011378 break;
11379 }
11380 } else {
11381 thermalMitigationResult =
11382 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11383 break;
11384 }
11385
11386 // Turn radio off. If not able to power off due to phone being unavailable,
11387 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011388 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011389 thermalMitigationResult =
11390 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11391 break;
11392 }
11393 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011394 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011395 break;
11396 default:
11397 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11398 + "not exist. Requested action: " + thermalMitigationAction);
11399 }
11400 } catch (IllegalArgumentException e) {
11401 throw e;
11402 } catch (Exception e) {
11403 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11404 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11405 } finally {
11406 Binder.restoreCallingIdentity(identity);
11407 }
11408
11409 if (DBG) {
11410 log("thermalMitigationRequest returning with thermalMitigationResult: "
11411 + thermalMitigationResult);
11412 }
11413
11414 return thermalMitigationResult;
11415 }
Hui Wang641e81c2020-10-12 12:14:23 -070011416
11417 /**
11418 * Set the GbaService Package Name that Telephony will bind to.
11419 *
11420 * @param subId The sim that the GbaService is associated with.
11421 * @param packageName The name of the package to be replaced with.
11422 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11423 */
11424 @Override
11425 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11426 enforceModifyPermission();
11427
11428 final long identity = Binder.clearCallingIdentity();
11429 try {
11430 return getGbaManager(subId).overrideServicePackage(packageName);
11431 } finally {
11432 Binder.restoreCallingIdentity(identity);
11433 }
11434 }
11435
11436 /**
11437 * Return the package name of the currently bound GbaService.
11438 *
11439 * @param subId The sim that the GbaService is associated with.
11440 * @return the package name of the GbaService configuration, null if GBA is not supported.
11441 */
11442 @Override
11443 public String getBoundGbaService(int subId) {
11444 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11445
11446 final long identity = Binder.clearCallingIdentity();
11447 try {
11448 return getGbaManager(subId).getServicePackage();
11449 } finally {
11450 Binder.restoreCallingIdentity(identity);
11451 }
11452 }
11453
11454 /**
11455 * Set the release time for telephony to unbind GbaService.
11456 *
11457 * @param subId The sim that the GbaService is associated with.
11458 * @param interval The release time to unbind GbaService by millisecond.
11459 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11460 */
11461 @Override
11462 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11463 enforceModifyPermission();
11464
11465 final long identity = Binder.clearCallingIdentity();
11466 try {
11467 return getGbaManager(subId).overrideReleaseTime(interval);
11468 } finally {
11469 Binder.restoreCallingIdentity(identity);
11470 }
11471 }
11472
11473 /**
11474 * Return the release time for telephony to unbind GbaService.
11475 *
11476 * @param subId The sim that the GbaService is associated with.
11477 * @return The release time to unbind GbaService by millisecond.
11478 */
11479 @Override
11480 public int getGbaReleaseTime(int subId) {
11481 enforceReadPrivilegedPermission("getGbaReleaseTime");
11482
11483 final long identity = Binder.clearCallingIdentity();
11484 try {
11485 return getGbaManager(subId).getReleaseTime();
11486 } finally {
11487 Binder.restoreCallingIdentity(identity);
11488 }
11489 }
11490
11491 private GbaManager getGbaManager(int subId) {
11492 GbaManager instance = GbaManager.getInstance(subId);
11493 if (instance == null) {
11494 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11495 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11496 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11497 }
11498 return instance;
11499 }
Hui Wang761a6682020-10-31 05:12:53 +000011500
11501 /**
11502 * indicate whether the device and the carrier can support
11503 * RCS VoLTE single registration.
11504 */
11505 @Override
11506 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011507 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11508 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11509 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11510 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011511
11512 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11513 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11514 }
11515
11516 final long identity = Binder.clearCallingIdentity();
11517 try {
11518 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11519 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011520 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11521 if (isCapable != null) {
11522 return isCapable;
11523 }
Hui Wang761a6682020-10-31 05:12:53 +000011524 }
Hui Wang67af90e2021-06-04 16:57:15 -070011525 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11526 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011527 } finally {
11528 Binder.restoreCallingIdentity(identity);
11529 }
11530 }
11531
11532 /**
11533 * Register RCS provisioning callback.
11534 */
11535 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011536 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011537 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011538 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011539 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011540 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11541 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011542
11543 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11544 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11545 }
11546 if (!isImsAvailableOnDevice()) {
11547 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11548 "IMS not available on device.");
11549 }
11550
11551 final long identity = Binder.clearCallingIdentity();
11552 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011553 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011554 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011555 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11556 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011557 }
Hui Wang761a6682020-10-31 05:12:53 +000011558 } finally {
11559 Binder.restoreCallingIdentity(identity);
11560 }
11561 }
11562
11563 /**
11564 * Unregister RCS provisioning callback.
11565 */
11566 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011567 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011568 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011569 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011570 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011571 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11572 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011573
11574 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11575 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11576 }
11577 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011578 // operation failed silently
11579 Rlog.w(LOG_TAG, "IMS not available on device.");
11580 return;
Hui Wang761a6682020-10-31 05:12:53 +000011581 }
11582
11583 final long identity = Binder.clearCallingIdentity();
11584 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011585 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011586 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011587 } finally {
11588 Binder.restoreCallingIdentity(identity);
11589 }
11590 }
11591
11592 /**
11593 * trigger RCS reconfiguration.
11594 */
11595 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011596 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11597 "triggerRcsReconfiguration",
11598 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011599
11600 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11601 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11602 }
11603 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011604 // ProvisioningManager can not handle ServiceSpecificException.
11605 // Throw the IllegalStateException and annotate ProvisioningManager.
11606 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000011607 }
11608
11609 final long identity = Binder.clearCallingIdentity();
11610 try {
11611 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11612 } finally {
11613 Binder.restoreCallingIdentity(identity);
11614 }
11615 }
11616
11617 /**
11618 * Provide the client configuration parameters of the RCS application.
11619 */
11620 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011621 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11622 "setRcsClientConfiguration",
11623 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011624
11625 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11626 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11627 }
11628 if (!isImsAvailableOnDevice()) {
11629 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11630 "IMS not available on device.");
11631 }
11632
11633 final long identity = Binder.clearCallingIdentity();
11634
11635 try {
11636 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11637 if (configBinder == null) {
11638 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011639 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11640 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011641 } else {
11642 configBinder.setRcsClientConfiguration(rcc);
11643 }
joonhunshin3e154242021-09-17 06:33:39 +000011644
11645 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11646 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011647 } catch (RemoteException e) {
11648 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011649 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11650 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011651 } finally {
11652 Binder.restoreCallingIdentity(identity);
11653 }
11654 }
11655
11656 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011657 * Enables or disables the test mode for RCS VoLTE single registration.
11658 */
11659 @Override
11660 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11661 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11662 "setRcsSingleRegistrationTestModeEnabled");
11663
11664 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11665 }
11666
11667 /**
11668 * Gets the test mode for RCS VoLTE single registration.
11669 */
11670 @Override
11671 public boolean getRcsSingleRegistrationTestModeEnabled() {
11672 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11673 "getRcsSingleRegistrationTestModeEnabled");
11674
11675 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11676 }
11677
11678 /**
Hui Wang761a6682020-10-31 05:12:53 +000011679 * Overrides the config of RCS VoLTE single registration enabled for the device.
11680 */
11681 @Override
11682 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11683 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11684 "setDeviceSingleRegistrationEnabledOverride");
11685 enforceModifyPermission();
11686
11687 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11688 : Boolean.parseBoolean(enabledStr);
11689 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011690 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011691 }
11692
11693 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011694 * Sends a device to device communication message. Only usable via shell.
11695 * @param message message to send.
11696 * @param value message value.
11697 */
11698 @Override
11699 public void sendDeviceToDeviceMessage(int message, int value) {
11700 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011701 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011702 enforceModifyPermission();
11703
11704 final long identity = Binder.clearCallingIdentity();
11705 try {
11706 TelephonyConnectionService service =
11707 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11708 if (service == null) {
11709 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11710 return;
11711 }
11712 service.sendTestDeviceToDeviceMessage(message, value);
11713 } finally {
11714 Binder.restoreCallingIdentity(identity);
11715 }
11716 }
11717
Tyler Gunnbabbda02021-02-10 11:05:02 -080011718 /**
11719 * Sets the specified device to device transport active.
11720 * @param transport The transport to set active.
11721 */
11722 @Override
11723 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11724 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11725 "setActiveDeviceToDeviceTransport");
11726 enforceModifyPermission();
11727
11728 final long identity = Binder.clearCallingIdentity();
11729 try {
11730 TelephonyConnectionService service =
11731 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11732 if (service == null) {
11733 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11734 return;
11735 }
11736 service.setActiveDeviceToDeviceTransport(transport);
11737 } finally {
11738 Binder.restoreCallingIdentity(identity);
11739 }
11740 }
Tyler Gunn92479152021-01-20 16:30:10 -080011741
Tyler Gunnd4339262021-05-03 14:46:49 -070011742 @Override
11743 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11744 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11745 "setDeviceToDeviceForceEnabled");
11746
11747 final long identity = Binder.clearCallingIdentity();
11748 try {
11749 Arrays.stream(PhoneFactory.getPhones()).forEach(
11750 p -> {
11751 Phone thePhone = p.getImsPhone();
11752 if (thePhone != null && thePhone instanceof ImsPhone) {
11753 ImsPhone imsPhone = (ImsPhone) thePhone;
11754 CallTracker tracker = imsPhone.getCallTracker();
11755 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11756 ImsPhoneCallTracker imsPhoneCallTracker =
11757 (ImsPhoneCallTracker) tracker;
11758 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11759 }
11760 }
11761 }
11762 );
11763 } finally {
11764 Binder.restoreCallingIdentity(identity);
11765 }
11766 }
11767
Tyler Gunn92479152021-01-20 16:30:10 -080011768 /**
Hui Wang761a6682020-10-31 05:12:53 +000011769 * Gets the config of RCS VoLTE single registration enabled for the device.
11770 */
11771 @Override
11772 public boolean getDeviceSingleRegistrationEnabled() {
11773 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11774 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11775 }
11776
11777 /**
11778 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11779 */
11780 @Override
11781 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11782 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11783 "setCarrierSingleRegistrationEnabledOverride");
11784 enforceModifyPermission();
11785
11786 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11787 : Boolean.parseBoolean(enabledStr);
11788 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11789 subId, enabled);
11790 }
11791
11792 /**
11793 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11794 */
11795 @Override
11796 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11797 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11798 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11799 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011800
11801 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011802 * Overrides the ims feature validation result
11803 */
11804 @Override
11805 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11806 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11807 "setImsFeatureValidationOverride");
11808
11809 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11810 : Boolean.parseBoolean(enabledStr);
11811 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11812 subId, enabled);
11813 }
11814
11815 /**
11816 * Gets the ims feature validation override value
11817 */
11818 @Override
11819 public boolean getImsFeatureValidationOverride(int subId) {
11820 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11821 "getImsFeatureValidationOverride");
11822 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11823 }
11824
11825 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011826 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11827 * their mobile plan.
11828 */
11829 @Override
11830 public String getMobileProvisioningUrl() {
11831 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11832 final long identity = Binder.clearCallingIdentity();
11833 try {
11834 return getDefaultPhone().getMobileProvisioningUrl();
11835 } finally {
11836 Binder.restoreCallingIdentity(identity);
11837 }
11838 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011839
James.cf Linbcdf8b32021-01-14 16:44:13 +080011840 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011841 * Get the EAB contact from the EAB database.
11842 */
11843 @Override
11844 public String getContactFromEab(String contact) {
11845 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11846 enforceModifyPermission();
11847 final long identity = Binder.clearCallingIdentity();
11848 try {
11849 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11850 } finally {
11851 Binder.restoreCallingIdentity(identity);
11852 }
11853 }
11854
11855 /**
Calvin Pana1434322021-07-01 19:27:01 +080011856 * Get the EAB capability from the EAB database.
11857 */
11858 @Override
11859 public String getCapabilityFromEab(String contact) {
11860 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11861 enforceModifyPermission();
11862 final long identity = Binder.clearCallingIdentity();
11863 try {
11864 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11865 } finally {
11866 Binder.restoreCallingIdentity(identity);
11867 }
11868 }
11869
11870 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011871 * Remove the EAB contacts from the EAB database.
11872 */
11873 @Override
11874 public int removeContactFromEab(int subId, String contacts) {
11875 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11876 enforceModifyPermission();
11877 final long identity = Binder.clearCallingIdentity();
11878 try {
11879 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11880 } finally {
11881 Binder.restoreCallingIdentity(identity);
11882 }
11883 }
11884
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011885 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011886 public boolean getDeviceUceEnabled() {
11887 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11888 final long identity = Binder.clearCallingIdentity();
11889 try {
11890 return mApp.getDeviceUceEnabled();
11891 } finally {
11892 Binder.restoreCallingIdentity(identity);
11893 }
11894 }
11895
11896 @Override
11897 public void setDeviceUceEnabled(boolean isEnabled) {
11898 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11899 final long identity = Binder.clearCallingIdentity();
11900 try {
11901 mApp.setDeviceUceEnabled(isEnabled);
11902 } finally {
11903 Binder.restoreCallingIdentity(identity);
11904 }
11905 }
11906
Brad Ebinger14d467f2021-02-12 06:18:28 +000011907 /**
11908 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11909 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11910 */
11911 // Used for SHELL command only right now.
11912 @Override
11913 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11914 List<String> featureTags) {
11915 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11916 "addUceRegistrationOverrideShell");
11917 final long identity = Binder.clearCallingIdentity();
11918 try {
11919 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11920 new ArraySet<>(featureTags));
11921 } catch (ImsException e) {
11922 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11923 } finally {
11924 Binder.restoreCallingIdentity(identity);
11925 }
11926 }
11927
11928 /**
11929 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11930 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11931 */
11932 // Used for SHELL command only right now.
11933 @Override
11934 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11935 List<String> featureTags) {
11936 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11937 "removeUceRegistrationOverrideShell");
11938 final long identity = Binder.clearCallingIdentity();
11939 try {
11940 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11941 new ArraySet<>(featureTags));
11942 } catch (ImsException e) {
11943 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11944 } finally {
11945 Binder.restoreCallingIdentity(identity);
11946 }
11947 }
11948
11949 /**
11950 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11951 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11952 */
11953 // Used for SHELL command only right now.
11954 @Override
11955 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11956 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11957 "clearUceRegistrationOverrideShell");
11958 final long identity = Binder.clearCallingIdentity();
11959 try {
11960 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11961 } catch (ImsException e) {
11962 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11963 } finally {
11964 Binder.restoreCallingIdentity(identity);
11965 }
11966 }
11967
11968 /**
11969 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11970 */
11971 // Used for SHELL command only right now.
11972 @Override
11973 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11974 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11975 "getLatestRcsContactUceCapabilityShell");
11976 final long identity = Binder.clearCallingIdentity();
11977 try {
11978 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11979 } catch (ImsException e) {
11980 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11981 } finally {
11982 Binder.restoreCallingIdentity(identity);
11983 }
11984 }
11985
11986 /**
11987 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11988 * device does not have an active PUBLISH.
11989 */
11990 // Used for SHELL command only right now.
11991 @Override
11992 public String getLastUcePidfXmlShell(int subId) {
11993 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11994 final long identity = Binder.clearCallingIdentity();
11995 try {
11996 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11997 } catch (ImsException e) {
11998 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11999 } finally {
12000 Binder.restoreCallingIdentity(identity);
12001 }
12002 }
12003
James.cf Line8713a42021-04-29 16:04:26 +080012004 /**
12005 * Remove UCE requests cannot be sent to the network status.
12006 */
12007 // Used for SHELL command only right now.
12008 @Override
12009 public boolean removeUceRequestDisallowedStatus(int subId) {
12010 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
12011 final long identity = Binder.clearCallingIdentity();
12012 try {
12013 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
12014 } catch (ImsException e) {
12015 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12016 } finally {
12017 Binder.restoreCallingIdentity(identity);
12018 }
12019 }
12020
James.cf Lin18bb9002021-05-25 01:37:38 +080012021 /**
12022 * Remove UCE requests cannot be sent to the network status.
12023 */
12024 // Used for SHELL command only.
12025 @Override
12026 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
12027 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
12028 final long identity = Binder.clearCallingIdentity();
12029 try {
12030 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
12031 } catch (ImsException e) {
12032 throw new ServiceSpecificException(e.getCode(), e.getMessage());
12033 } finally {
12034 Binder.restoreCallingIdentity(identity);
12035 }
12036 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000012037
James.cf Lin4b784aa2021-01-31 03:25:15 +080012038 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012039 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12040 String callingPackage) {
12041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12042 mApp, subId, "setSignalStrengthUpdateRequest");
12043
12044 final int callingUid = Binder.getCallingUid();
12045 // Verify that tha callingPackage belongs to the calling UID
12046 mApp.getSystemService(AppOpsManager.class)
12047 .checkPackage(callingUid, callingPackage);
12048
Rambo Wang3607f502021-02-01 21:51:40 -080012049 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012050
12051 final long identity = Binder.clearCallingIdentity();
12052 try {
12053 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
12054 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12055
12056 if (result instanceof IllegalStateException) {
12057 throw (IllegalStateException) result;
12058 }
12059 } finally {
12060 Binder.restoreCallingIdentity(identity);
12061 }
12062 }
12063
12064 @Override
12065 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
12066 String callingPackage) {
12067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
12068 mApp, subId, "clearSignalStrengthUpdateRequest");
12069
12070 final int callingUid = Binder.getCallingUid();
12071 // Verify that tha callingPackage belongs to the calling UID
12072 mApp.getSystemService(AppOpsManager.class)
12073 .checkPackage(callingUid, callingPackage);
12074
12075 final long identity = Binder.clearCallingIdentity();
12076 try {
12077 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
12078 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
12079
12080 if (result instanceof IllegalStateException) {
12081 throw (IllegalStateException) result;
12082 }
12083 } finally {
12084 Binder.restoreCallingIdentity(identity);
12085 }
12086 }
12087
Rambo Wang3607f502021-02-01 21:51:40 -080012088 private static void validateSignalStrengthUpdateRequest(Context context,
12089 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012090 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
12091 // phone/system process do not have further restriction on request
12092 return;
12093 }
12094
12095 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080012096 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012097 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080012098 context.enforceCallingOrSelfPermission(
12099 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
12100 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012101 }
12102
12103 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000012104 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012105 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080012106 || info.isEnabled()) {
12107 throw new IllegalArgumentException(
12108 "Only system can set hide fields in SignalThresholdInfo");
12109 }
12110
12111 // Thresholds length for each RAN need in range. This has been validated in
12112 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
12113 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
12114 final int[] thresholds = info.getThresholds();
12115 Objects.requireNonNull(thresholds);
12116 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
12117 || thresholds.length
12118 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
12119 throw new IllegalArgumentException(
12120 "thresholds length is out of range: " + thresholds.length);
12121 }
12122 }
12123 }
SongFerngWang8236caa2021-01-17 21:51:44 +080012124
12125 /**
12126 * Gets the current phone capability.
12127 *
12128 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
12129 * @return the PhoneCapability which describes the data connection capability of modem.
12130 * It's used to evaluate possible phone config change, for example from single
12131 * SIM device to multi-SIM device.
12132 */
12133 @Override
12134 public PhoneCapability getPhoneCapability() {
12135 enforceReadPrivilegedPermission("getPhoneCapability");
12136 final long identity = Binder.clearCallingIdentity();
12137 try {
12138 return mPhoneConfigurationManager.getCurrentPhoneCapability();
12139 } finally {
12140 Binder.restoreCallingIdentity(identity);
12141 }
12142 }
Michele Berionne5e411512020-11-13 02:36:59 +000012143
12144 /**
12145 * Prepare TelephonyManager for an unattended reboot. The reboot is
12146 * required to be done shortly after the API is invoked.
12147 */
12148 @Override
12149 @TelephonyManager.PrepareUnattendedRebootResult
12150 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012151 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000012152 enforceRebootPermission();
12153
12154 final long identity = Binder.clearCallingIdentity();
12155 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000012156 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000012157 } finally {
12158 Binder.restoreCallingIdentity(identity);
12159 }
12160 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012161
12162 /**
12163 * Request to get the current slicing configuration including URSP rules and
12164 * NSSAIs (configured, allowed and rejected).
12165 *
12166 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
12167 */
12168 @Override
12169 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000012170 TelephonyPermissions
12171 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
12172 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080012173
12174 final long identity = Binder.clearCallingIdentity();
12175 try {
12176 Phone phone = getDefaultPhone();
12177 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
12178 } finally {
12179 Binder.restoreCallingIdentity(identity);
12180 }
12181 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012182
12183 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070012184 * Check whether the given premium capability is available for purchase from the carrier.
12185 *
12186 * @param capability The premium capability to check.
12187 * @param subId The subId to check the premium capability for.
12188 *
12189 * @return Whether the given premium capability is available to purchase.
12190 */
12191 @Override
12192 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
12193 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12194 mApp, "isPremiumCapabilityAvailableForPurchase")) {
12195 log("Premium capability "
12196 + TelephonyManager.convertPremiumCapabilityToString(capability)
12197 + " is not available for purchase due to missing permissions.");
12198 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
12199 + "permission READ_BASIC_PHONE_STATE.");
12200 }
12201
12202 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080012203 if (phone == null) {
12204 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12205 return false;
12206 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012207 final long identity = Binder.clearCallingIdentity();
12208 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070012209 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012210 .isPremiumCapabilityAvailableForPurchase(capability);
12211 } finally {
12212 Binder.restoreCallingIdentity(identity);
12213 }
12214 }
12215
12216 /**
12217 * Purchase the given premium capability from the carrier.
12218 *
12219 * @param capability The premium capability to purchase.
12220 * @param callback The result of the purchase request.
12221 * @param subId The subId to purchase the premium capability for.
12222 */
12223 @Override
12224 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12225 log("purchasePremiumCapability: capability="
12226 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12227 + getCurrentPackageName());
12228
12229 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12230 mApp, "purchasePremiumCapability")) {
12231 log("purchasePremiumCapability "
12232 + TelephonyManager.convertPremiumCapabilityToString(capability)
12233 + " failed due to missing permissions.");
12234 throw new SecurityException("purchasePremiumCapability requires permission "
12235 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012236 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12237 mApp, "purchasePremiumCapability")) {
12238 log("purchasePremiumCapability "
12239 + TelephonyManager.convertPremiumCapabilityToString(capability)
12240 + " failed due to missing permissions.");
12241 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012242 }
12243
12244 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012245 if (phone == null) {
12246 try {
12247 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12248 callback.accept(result);
12249 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12250 } catch (RemoteException e) {
12251 String logStr = "Purchase premium capability "
12252 + TelephonyManager.convertPremiumCapabilityToString(capability)
12253 + " failed due to RemoteException handling null phone: " + e;
12254 if (DBG) log(logStr);
12255 AnomalyReporter.reportAnomaly(
12256 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12257 }
12258 return;
12259 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012260
12261 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012262 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012263 callingProcess = mApp.getPackageManager().getApplicationInfo(
12264 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012265 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012266 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012267 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012268
12269 boolean isVisible = false;
12270 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12271 if (am != null) {
12272 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12273 if (processes != null) {
12274 for (ActivityManager.RunningAppProcessInfo process : processes) {
12275 log("purchasePremiumCapability: process " + process.processName
12276 + "has importance " + process.importance);
12277 if (process.processName.equals(callingProcess) && process.importance
12278 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12279 isVisible = true;
12280 break;
12281 }
12282 }
12283 }
12284 }
12285
12286 if (!isVisible) {
12287 try {
12288 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12289 callback.accept(result);
12290 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12291 } catch (RemoteException e) {
12292 String logStr = "Purchase premium capability "
12293 + TelephonyManager.convertPremiumCapabilityToString(capability)
12294 + " failed due to RemoteException handling background application: " + e;
12295 if (DBG) log(logStr);
12296 AnomalyReporter.reportAnomaly(
12297 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12298 }
12299 return;
12300 }
12301
Sarah Chin71b3a852022-09-28 15:54:19 -070012302 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012303 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012304 }
12305
12306 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012307 * Register an IMS connection state callback
12308 */
12309 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012310 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12311 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012312 if (feature == ImsFeature.FEATURE_MMTEL) {
12313 // ImsMmTelManager
12314 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12315 TelephonyPermissions
12316 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12317 mApp, subId, "registerImsStateCallback");
12318 } else if (feature == ImsFeature.FEATURE_RCS) {
12319 // ImsRcsManager or SipDelegateManager
12320 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12321 Binder.getCallingUid(), "registerImsStateCallback",
12322 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12323 Manifest.permission.READ_PRECISE_PHONE_STATE,
12324 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12325 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12326 }
12327
12328 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12329 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12330 "IMS not available on device.");
12331 }
12332
12333 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12334 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12335 }
12336
12337 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12338 if (controller == null) {
12339 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12340 "IMS not available on device.");
12341 }
12342
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012343 if (callingPackage == null) {
12344 callingPackage = getCurrentPackageName();
12345 }
12346
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012347 final long token = Binder.clearCallingIdentity();
12348 try {
12349 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012350 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012351 } catch (ImsException e) {
12352 throw new ServiceSpecificException(e.getCode());
12353 } finally {
12354 Binder.restoreCallingIdentity(token);
12355 }
12356 }
12357
12358 /**
12359 * Unregister an IMS connection state callback
12360 */
12361 @Override
12362 public void unregisterImsStateCallback(IImsStateCallback cb) {
12363 final long token = Binder.clearCallingIdentity();
12364 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12365 if (controller == null) {
12366 return;
12367 }
12368 try {
12369 controller.unregisterImsStateCallback(cb);
12370 } finally {
12371 Binder.restoreCallingIdentity(token);
12372 }
12373 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012374
12375 /**
12376 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12377 *
12378 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
12379 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
12380 * SecurityException.
12381 * If there is current registered network this value will be same as the registered cell
12382 * identity. If the device goes out of service the previous cell identity is cached and
12383 * will be returned. If the cache age of the Cell identity is more than 24 hours
12384 * it will be cleared and null will be returned.
12385 *
12386 */
12387 @Override
12388 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12389 String callingFeatureId) {
12390 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12391 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12392 LocationAccessPolicy.checkLocationPermission(mApp,
12393 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12394 .setCallingPackage(callingPackage)
12395 .setCallingFeatureId(callingFeatureId)
12396 .setCallingPid(Binder.getCallingPid())
12397 .setCallingUid(Binder.getCallingUid())
12398 .setMethod("getLastKnownCellIdentity")
12399 .setLogAsInfo(true)
12400 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12401 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12402 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12403 .build());
12404
12405 boolean hasFinePermission =
12406 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12407 if (!hasFinePermission
12408 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12409 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012410 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012411 }
12412
12413 final long identity = Binder.clearCallingIdentity();
12414 try {
12415 Phone phone = getPhone(subId);
12416 if (phone == null) return null;
12417 ServiceStateTracker sst = phone.getServiceStateTracker();
12418 if (sst == null) return null;
12419 return sst.getLastKnownCellIdentity();
12420 } finally {
12421 Binder.restoreCallingIdentity(identity);
12422 }
12423 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012424
jimsun3b9ccac2021-10-26 15:01:23 +080012425 /**
12426 * Sets the modem service class Name that Telephony will bind to.
12427 *
12428 * @param serviceName The class name of the modem service.
12429 * @return true if the operation is succeed, otherwise false.
12430 */
12431 public boolean setModemService(String serviceName) {
12432 Log.d(LOG_TAG, "setModemService - " + serviceName);
12433 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012435 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12436 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012437 return mPhoneConfigurationManager.setModemService(serviceName);
12438 }
12439
12440 /**
12441 * Return the class name of the currently bounded modem service.
12442 *
12443 * @return the class name of the modem service.
12444 */
12445 public String getModemService() {
12446 String result;
12447 Log.d(LOG_TAG, "getModemService");
12448 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12449 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012450 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012451 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12452 "getModemService");
12453 result = mPhoneConfigurationManager.getModemService();
12454 Log.d(LOG_TAG, "result = " + result);
12455 return result;
12456 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012457
12458 @Override
12459 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12460 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12461 mApp.enforceCallingOrSelfPermission(
12462 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12463 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12464
12465 final long identity = Binder.clearCallingIdentity();
12466 try {
12467 Phone phone = getPhone(subId);
12468 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012469 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12470 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012471 phone.setVoiceServiceStateOverride(hasService);
12472 } finally {
12473 Binder.restoreCallingIdentity(identity);
12474 }
12475 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012476
12477 /**
12478 * set removable eSIM as default eUICC.
12479 *
12480 * @hide
12481 */
12482 @Override
12483 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12484 enforceModifyPermission();
12485 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12486
12487 final long identity = Binder.clearCallingIdentity();
12488 try {
12489 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12490 } finally {
12491 Binder.restoreCallingIdentity(identity);
12492 }
12493 }
12494
12495 /**
12496 * Returns whether the removable eSIM is default eUICC or not.
12497 *
12498 * @hide
12499 */
12500 @Override
12501 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12502 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12503 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12504
12505 final long identity = Binder.clearCallingIdentity();
12506 try {
12507 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12508 } finally {
12509 Binder.restoreCallingIdentity(identity);
12510 }
12511 }
12512
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012513 /**
12514 * Get the component name of the default app to direct respond-via-message intent for the
12515 * user associated with this subscription, update the cache if there is no respond-via-message
12516 * application currently configured for this user.
12517 * @return component name of the app and class to direct Respond Via Message intent to, or
12518 * {@code null} if the functionality is not supported.
12519 * @hide
12520 */
12521 @Override
12522 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12523 boolean updateIfNeeded) {
12524 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012525
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012526 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12527
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012528 UserHandle userHandle = null;
12529 final long identity = Binder.clearCallingIdentity();
12530 try {
12531 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12532 } finally {
12533 Binder.restoreCallingIdentity(identity);
12534 }
12535 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12536 updateIfNeeded, userHandle);
12537 }
Jack Yuf5badd92022-12-08 00:50:53 -080012538
12539 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012540 * Set whether the device is able to connect with null ciphering or integrity
12541 * algorithms. This is a global setting and will apply to all active subscriptions
12542 * and all new subscriptions after this.
12543 *
12544 * @param enabled when true, null cipher and integrity algorithms are allowed.
12545 * @hide
12546 */
12547 @Override
12548 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12549 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12550 enforceModifyPermission();
12551 checkForNullCipherAndIntegritySupport();
12552
12553 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12554 // for listening to these preference changes and applying them immediately.
12555 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12556 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12557 editor.apply();
12558
12559 for (Phone phone: PhoneFactory.getPhones()) {
12560 phone.handleNullCipherEnabledChange();
12561 }
12562 }
12563
12564
12565 /**
12566 * Get whether the device is able to connect with null ciphering or integrity
12567 * algorithms. Note that this retrieves the phone-global preference and not
12568 * the state of the radio.
12569 *
12570 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12571 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12572 * version for this feature.
12573 * @hide
12574 */
12575 @Override
12576 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12577 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12578 enforceReadPermission();
12579 checkForNullCipherAndIntegritySupport();
12580 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12581 }
12582
12583 private void checkForNullCipherAndIntegritySupport() {
12584 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12585 throw new UnsupportedOperationException(
12586 "Null cipher and integrity operations require HAL 2.1 or above");
12587 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012588 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12589 throw new UnsupportedOperationException(
12590 "Null cipher and integrity operations unsupported by modem");
12591 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012592 }
12593
12594 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012595 * Get the SIM state for the slot index.
12596 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12597 *
12598 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12599 */
12600 @Override
12601 @SimState
12602 public int getSimStateForSlotIndex(int slotIndex) {
12603 IccCardConstants.State simState;
12604 if (slotIndex < 0) {
12605 simState = IccCardConstants.State.UNKNOWN;
12606 } else {
12607 Phone phone = null;
12608 try {
12609 phone = PhoneFactory.getPhone(slotIndex);
12610 } catch (IllegalStateException e) {
12611 // ignore
12612 }
12613 if (phone == null) {
12614 simState = IccCardConstants.State.UNKNOWN;
12615 } else {
12616 IccCard icc = phone.getIccCard();
12617 if (icc == null) {
12618 simState = IccCardConstants.State.UNKNOWN;
12619 } else {
12620 simState = icc.getState();
12621 }
12622 }
12623 }
12624 return simState.ordinal();
12625 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012626
12627 /**
12628 * Get current cell broadcast ranges.
12629 */
12630 @Override
12631 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12632 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12633 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12634 "getCellBroadcastIdRanges");
12635 final long identity = Binder.clearCallingIdentity();
12636 try {
12637 return getPhone(subId).getCellBroadcastIdRanges();
12638 } finally {
12639 Binder.restoreCallingIdentity(identity);
12640 }
12641 }
12642
12643 /**
12644 * Set reception of cell broadcast messages with the list of the given ranges
12645 *
12646 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12647 */
12648 @Override
12649 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12650 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12651 @Nullable IIntegerConsumer callback) {
12652 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12653 "setCellBroadcastIdRanges");
12654 final long identity = Binder.clearCallingIdentity();
12655 try {
12656 Phone phone = getPhoneFromSubId(subId);
12657 if (DBG) {
12658 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12659 }
12660 phone.setCellBroadcastIdRanges(ranges, result -> {
12661 if (callback != null) {
12662 try {
12663 callback.accept(result);
12664 } catch (RemoteException e) {
12665 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12666 }
12667 }
12668 });
12669 } finally {
12670 Binder.restoreCallingIdentity(identity);
12671 }
12672 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012673
12674 /**
12675 * Returns whether the device supports the domain selection service.
12676 *
12677 * @return {@code true} if the device supports the domain selection service.
12678 */
12679 @Override
12680 public boolean isDomainSelectionSupported() {
12681 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12682 "isDomainSelectionSupported");
12683
12684 final long identity = Binder.clearCallingIdentity();
12685 try {
12686 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12687 } finally {
12688 Binder.restoreCallingIdentity(identity);
12689 }
12690 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012691
12692 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012693 * Enable or disable the satellite modem. If the satellite modem is enabled, this will also
12694 * disable the cellular modem, and if the satellite modem is disabled, this will also re-enable
12695 * the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012696 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012697 * @param subId The subId to set satellite enabled for.
12698 * @param enable {@code true} to enable the satellite modem and {@code false} to disable.
12699 * @param callback The callback to get the error code of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012700 *
12701 * @throws SecurityException if the caller doesn't have the required permission.
12702 */
12703 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012704 public void setSatelliteEnabled(int subId, boolean enable, @NonNull IIntegerConsumer callback) {
12705 enforceSatelliteCommunicationPermission("setSatelliteEnabled");
12706 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012707 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012708 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12709 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012710 }
Sarah Chin503828c2023-02-01 23:54:20 -080012711
12712 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012713 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012714 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
12715 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012716 }
12717
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012718 Phone phone = getPhoneOrDefault(validSubId, "setSatelliteEnabled");
Sarah Chin503828c2023-02-01 23:54:20 -080012719 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012720 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12721 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012722 }
12723
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012724 Pair<Boolean, Consumer<Integer>> arg = new Pair<>(enable, result);
12725 sendRequestAsync(CMD_SET_SATELLITE_ENABLED, arg, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012726 }
12727
12728 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012729 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012730 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012731 * @param subId The subId to check whether satellite is enabled for.
12732 * @param result The result receiver that returns whether the satellite modem is enabled
12733 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012734 *
12735 * @throws SecurityException if the caller doesn't have the required permission.
12736 */
12737 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012738 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12739 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012740 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012741 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12742 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012743 }
Sarah Chin503828c2023-02-01 23:54:20 -080012744
12745 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012746 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012747 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
12748 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012749 }
12750
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012751 Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteEnabled");
Sarah Chin503828c2023-02-01 23:54:20 -080012752 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012753 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12754 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012755 }
12756
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012757 sendRequest(CMD_IS_SATELLITE_ENABLED, result, subId);
Sarah Chin503828c2023-02-01 23:54:20 -080012758 }
12759
12760 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012761 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012762 *
12763 * @param subId The subId to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012764 * @param result The result receiver that returns whether the satellite service is supported on
12765 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012766 */
12767 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012768 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012769 synchronized (mIsSatelliteSupportedLock) {
12770 if (mIsSatelliteSupported != null) {
12771 /* We have already successfully queried the satellite modem. */
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012772 Bundle bundle = new Bundle();
12773 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, mIsSatelliteSupported);
12774 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, bundle);
12775 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012776 }
12777 }
Sarah Chin503828c2023-02-01 23:54:20 -080012778
12779 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012780 Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteSupported");
Sarah Chin503828c2023-02-01 23:54:20 -080012781 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012782 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12783 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012784 }
12785
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012786 sendRequestAsync(CMD_IS_SATELLITE_SUPPORTED, result, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012787 }
12788
12789 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012790 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012791 *
12792 * @param subId The subId to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012793 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12794 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012795 *
12796 * @throws SecurityException if the caller doesn't have required permission.
12797 */
12798 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012799 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12800 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012801 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012802 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12803 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012804 }
Sarah Chin503828c2023-02-01 23:54:20 -080012805
12806 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012807 Phone phone = getPhoneOrDefault(validSubId, "requestSatelliteCapabilities");
Sarah Chin503828c2023-02-01 23:54:20 -080012808 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012809 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12810 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012811 }
12812
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012813 sendRequestAsync(CMD_GET_SATELLITE_CAPABILITIES, result, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012814 }
12815
12816 /**
Sarah Chineccfbd12023-01-20 19:00:35 -080012817 * Start receiving satellite position updates.
12818 * This can be called by the pointing UI when the user starts pointing to the satellite.
12819 * Modem should continue to report the pointing input as the device or satellite moves.
12820 *
12821 * @param subId The subId to start satellite position updates for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012822 * @param errorCallback The callback to get the error code of the request.
Sarah Chineccfbd12023-01-20 19:00:35 -080012823 * @param callback The callback to notify of changes in satellite position.
Sarah Chin503828c2023-02-01 23:54:20 -080012824 *
12825 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012826 */
12827 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012828 public void startSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012829 @NonNull ISatelliteStateListener callback) {
Sarah Chinf75afa72023-02-01 01:32:19 -080012830 enforceSatelliteCommunicationPermission("startSatellitePositionUpdates");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012831 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012832 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012833 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12834 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012835 }
Sarah Chinf75afa72023-02-01 01:32:19 -080012836
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012837 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012838 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012839 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
12840 return;
Sarah Chinf75afa72023-02-01 01:32:19 -080012841 }
12842
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012843 Phone phone = getPhoneOrDefault(validSubId, "startSatellitePositionUpdates");
Sarah Chineccfbd12023-01-20 19:00:35 -080012844 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012845 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12846 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012847 }
12848
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012849 if (mSatellitePositionUpdateHandlers.containsKey(callback.asBinder())) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012850 if (DBG) {
12851 log("startSatellitePositionUpdates: callback already registered: "
12852 + callback.asBinder());
12853 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012854 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
12855 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012856 }
12857
12858 SatellitePositionUpdateHandler handler =
12859 new SatellitePositionUpdateHandler(callback, Looper.getMainLooper());
12860 phone.registerForSatellitePointingInfoChanged(handler,
12861 SatellitePositionUpdateHandler.EVENT_POSITION_UPDATE, null);
12862 phone.registerForSatelliteMessagesTransferComplete(handler,
12863 SatellitePositionUpdateHandler.EVENT_MESSAGE_TRANSFER_STATE_UPDATE, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012864 mSatellitePositionUpdateHandlers.put(callback.asBinder(), handler);
Sarah Chineccfbd12023-01-20 19:00:35 -080012865
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012866 sendRequestAsync(CMD_START_SATELLITE_POSITION_UPDATES, result, phone, null);
Sarah Chineccfbd12023-01-20 19:00:35 -080012867 }
12868
12869 /**
12870 * Stop receiving satellite position updates.
12871 * This can be called by the pointing UI when the user stops pointing to the satellite.
12872 *
12873 * @param subId The subId to stop satellite position updates for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012874 * @param errorCallback The callback to get the error code of the request.
12875 * @param callback The callback that was passed to {@link
12876 * #startSatellitePositionUpdates(int, IIntegerConsumer, ISatelliteStateListener)}
Sarah Chin503828c2023-02-01 23:54:20 -080012877 *
12878 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012879 */
12880 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012881 public void stopSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012882 @NonNull ISatelliteStateListener callback) {
Sarah Chinf75afa72023-02-01 01:32:19 -080012883 enforceSatelliteCommunicationPermission("stopSatellitePositionUpdates");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012884 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012885 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012886 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12887 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012888 }
Sarah Chinf75afa72023-02-01 01:32:19 -080012889
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012890 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012891 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012892 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
12893 return;
Sarah Chinf75afa72023-02-01 01:32:19 -080012894 }
12895
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012896 Phone phone = getPhoneOrDefault(validSubId, "stopSatellitePositionUpdates");
Sarah Chineccfbd12023-01-20 19:00:35 -080012897 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012898 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12899 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012900 }
12901
12902 SatellitePositionUpdateHandler handler =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012903 mSatellitePositionUpdateHandlers.remove(callback.asBinder());
Sarah Chineccfbd12023-01-20 19:00:35 -080012904 if (handler == null) {
12905 loge("stopSatellitePositionUpdates: No SatellitePositionArgument");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012906 result.accept(SatelliteManager.SATELLITE_INVALID_ARGUMENTS);
12907 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012908 } else {
12909 phone.unregisterForSatellitePointingInfoChanged(handler);
12910 phone.unregisterForSatelliteMessagesTransferComplete(handler);
12911 }
12912
12913 if (!mSatellitePositionUpdateHandlers.isEmpty()) {
12914 log("stopSatellitePositionUpdates: other listeners still exist.");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012915 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
12916 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012917 }
12918
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012919 sendRequestAsync(CMD_STOP_SATELLITE_POSITION_UPDATES, result, phone, null);
Sarah Chineccfbd12023-01-20 19:00:35 -080012920 }
12921
12922 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012923 * Request to get the maximum number of characters per text message on satellite.
12924 *
12925 * @param subId The subId of the subscription.
12926 * @param result The result receiver that returns the maximum number of characters per text
12927 * message on satellite if the request is successful or an error code
12928 * if the request failed.
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012929 *
12930 * @throws SecurityException if the caller doesn't have the required permission.
12931 */
12932 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012933 public void requestMaxCharactersPerSatelliteTextMessage(int subId,
12934 @NonNull ResultReceiver result) {
12935 enforceSatelliteCommunicationPermission("requestMaxCharactersPerSatelliteTextMessage");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012936 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012937 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12938 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012939 }
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012940
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012941 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012942 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012943 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
12944 return;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012945 }
12946
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012947 Phone phone = getPhoneOrDefault(validSubId, "requestMaxCharactersPerSatelliteTextMessage");
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012948 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012949 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12950 return;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012951 }
12952
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012953 sendRequestAsync(CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG, result, phone, null);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012954 }
12955
12956 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012957 * Register the subscription with a satellite provider.
12958 * This is needed to register the subscription if the provider allows dynamic registration.
12959 *
12960 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012961 * @param token The token to be used as a unique identifier for provisioning with satellite
12962 * gateway.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012963 * @param callback The callback to get the error code of the request.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012964 * @return The signal transport used by the caller to cancel the provision request,
12965 * or {@code null} if the request failed.
12966 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012967 * @throws SecurityException if the caller doesn't have the required permission.
12968 */
12969 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012970 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
12971 @NonNull String token, @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012972 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012973 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012974 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012975 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012976 return null;
12977 }
12978
12979 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012980 Phone phone = getPhoneOrDefault(validSubId, "provisionSatelliteService");
12981 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012982 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012983 return null;
12984 }
12985
12986 if (mSatelliteProvisionCallbacks.containsKey(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012987 result.accept(SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012988 return null;
12989 }
12990
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012991 if (isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012992 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012993 return null;
12994 }
12995
12996 sendRequestAsync(CMD_PROVISION_SATELLITE_SERVICE,
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012997 new ProvisionSatelliteServiceArgument(token, result, validSubId), phone, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012998
12999 ICancellationSignal cancelTransport = CancellationSignal.createTransport();
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013000 CancellationSignal.fromTransport(cancelTransport).setOnCancelListener(() -> {
13001 sendRequestAsync(CMD_DEPROVISION_SATELLITE_SERVICE,
13002 new ProvisionSatelliteServiceArgument(token, null, validSubId),
13003 phone, null);
13004 });
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013005 return cancelTransport;
13006 }
13007
13008 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013009 * Unregister the device/subscription with the satellite provider.
13010 * This is needed if the provider allows dynamic registration. Once deprovisioned,
13011 * {@link SatelliteCallback.SatelliteProvisionStateListener#onSatelliteProvisionStateChanged}
13012 * should report as deprovisioned.
13013 *
13014 * @param subId The subId of the subscription to be deprovisioned.
13015 * @param token The token of the device/subscription to be deprovisioned.
13016 * @param callback The callback to get the error code of the request.
13017 *
13018 * @throws SecurityException if the caller doesn't have the required permission.
13019 */
13020 @Override
13021 public void deprovisionSatelliteService(int subId,
13022 @NonNull String token, @NonNull IIntegerConsumer callback) {
13023 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
13024 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
13025 if (!isSatelliteSupported()) {
13026 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
13027 return;
13028 }
13029
13030 final int validSubId = getValidSatelliteSubId(subId);
13031 if (!isSatelliteProvisioned(validSubId)) {
13032 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
13033 return;
13034 }
13035
13036 Phone phone = getPhoneOrDefault(validSubId, "deprovisionSatelliteService");
13037 if (phone == null) {
13038 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13039 return;
13040 }
13041
13042 sendRequestAsync(CMD_DEPROVISION_SATELLITE_SERVICE,
13043 new ProvisionSatelliteServiceArgument(token, result, validSubId), phone, null);
13044 }
13045
13046 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013047 * Register for the satellite provision state change.
13048 *
13049 * @param subId The subId of the subscription associated with the satellite service.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013050 * @param errorCallback The callback to get the error code of the request.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013051 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013052 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013053 * @throws SecurityException if the caller doesn't have the required permission.
13054 */
13055 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013056 public void registerForSatelliteProvisionStateChanged(int subId,
13057 @NonNull IIntegerConsumer errorCallback, @NonNull ISatelliteStateListener callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013058 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013059 registerForSatelliteProvisionStateChangedInternal(subId, errorCallback, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013060 }
13061
13062 /**
13063 * Unregister for the satellite provision state change.
13064 *
13065 * @param subId The subId of the subscription associated with the satellite service.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013066 * @param errorCallback The callback to get the error code of the request.
13067 * @param callback The callback that was passed to {@link
13068 * #registerForSatelliteProvisionStateChanged(int, IIntegerConsumer, ISatelliteStateListener)}.
13069 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013070 * @throws SecurityException if the caller doesn't have the required permission.
13071 */
13072 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013073 public void unregisterForSatelliteProvisionStateChanged(int subId,
13074 @NonNull IIntegerConsumer errorCallback, @NonNull ISatelliteStateListener callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013075 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013076 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013077 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013078 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
13079 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013080 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013081
13082 final int validSubId = getValidSatelliteSubId(subId);
13083 SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler =
13084 mSatelliteProvisionStateChangedHandlers.get(validSubId);
13085 if (satelliteProvisionStateChangedHandler != null) {
13086 if (satelliteProvisionStateChangedHandler.removeListener(callback)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013087 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
13088 return;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013089 }
13090 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013091 result.accept(SatelliteManager.SATELLITE_INVALID_ARGUMENTS);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013092 }
13093
13094 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013095 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013096 *
13097 * @param subId The subId of the subscription associated with the satellite service.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013098 * @param result The result receiver that returns whether the device is provisioned with a
13099 * satellite provider if the request is successful or an error code if the
13100 * request failed.
13101 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013102 * @throws SecurityException if the caller doesn't have the required permission.
13103 */
13104 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013105 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
13106 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013107 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013108 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
13109 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013110 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013111
13112 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013113 Bundle bundle = new Bundle();
13114 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_PROVISIONED,
13115 isSatelliteProvisioned(validSubId));
13116 result.send(SatelliteManager.SATELLITE_ERROR_NONE, bundle);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013117 }
13118
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013119 /**
13120 * Register for listening to satellite state changes.
13121 *
13122 * @param subId - The subId to start listening to satellite state changes for.
13123 * @param callback - The callback to handle the satellite state change event.
13124 * @return The result of the operation.
13125 * @throws SecurityException if the caller doesn't have the required permission.
13126 */
13127 @Override
13128 @SatelliteManager.SatelliteError
13129 public int registerForSatelliteModemStateChange(int subId,
13130 @NonNull ISatelliteStateListener callback) {
13131 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChange");
13132
13133 final int validSubId = getValidSatelliteSubId(subId);
13134 Phone phone = getPhoneOrDefault(
13135 validSubId, "registerForSatelliteModemStateChange");
13136 if (phone == null) {
13137 return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13138 }
13139
13140 SatelliteStateListenerHandler satelliteStateListenerHandler =
13141 mSatelliteStateListenerHandlers.get(validSubId);
13142 if (satelliteStateListenerHandler == null) {
13143 satelliteStateListenerHandler = new SatelliteStateListenerHandler(
13144 Looper.getMainLooper(), validSubId);
13145 phone.registerForSatelliteModemStateChange(satelliteStateListenerHandler,
13146 SatelliteStateListenerHandler.EVENT_SATELLITE_MODEM_STATE_CHANGE, null);
13147 phone.registerForPendingMessageCount(satelliteStateListenerHandler,
13148 SatelliteStateListenerHandler.EVENT_PENDING_MESSAGE_COUNT, null);
13149 }
13150
13151 satelliteStateListenerHandler.addListener(callback);
13152 mSatelliteStateListenerHandlers.put(validSubId, satelliteStateListenerHandler);
13153 return SatelliteManager.SATELLITE_ERROR_NONE;
13154 }
13155
13156 /**
13157 * Unregister from listening to satellite state changes.
13158 *
13159 * @param subId - The subId to stop listening to satellite state changes for.
13160 * @param callback - The callback that was passed to
13161 * {@link #registerForSatelliteModemStateChange(int, ISatelliteStateListener)}
13162 * @return The result of the operation.
13163 *
13164 * @throws SecurityException if the caller doesn't have the required permission.
13165 */
13166 @Override
13167 @SatelliteManager.SatelliteError
13168 public int unregisterForSatelliteModemStateChange(int subId,
13169 @NonNull ISatelliteStateListener callback) {
13170 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChange");
13171
13172 final int validSubId = getValidSatelliteSubId(subId);
13173 SatelliteStateListenerHandler satelliteStateListenerHandler =
13174 mSatelliteStateListenerHandlers.get(validSubId);
13175 if (satelliteStateListenerHandler != null) {
13176 if (satelliteStateListenerHandler.removeListener(callback)) {
13177 return SatelliteManager.SATELLITE_ERROR_NONE;
13178 }
13179 }
13180 return SatelliteManager.SATELLITE_INVALID_ARGUMENTS;
13181 }
13182
13183 /**
13184 * Register to receive incoming datagrams over satellite.
13185 *
13186 * @param subId - The subId to start receiving datagrams over satellite.
13187 * @param datagramType - type of datagram
13188 * @param callback - The callback to handle incoming datagrams over satellite.
13189 * @return The result of the operation.
13190 * @throws SecurityException if the caller doesn't have the required permission.
13191 */
13192 @Override
13193 @SatelliteManager.SatelliteError
13194 public int registerForSatelliteDatagram(int subId,
13195 @SatelliteManager.DatagramType int datagramType,
13196 @NonNull ISatelliteStateListener callback) {
13197 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
13198
13199 final int validSubId = getValidSatelliteSubId(subId);
13200 Phone phone = getPhoneOrDefault(
13201 validSubId, "registerForSatelliteDatagram");
13202 if (phone == null) {
13203 return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13204 }
13205
13206 SatelliteDatagramListenerHandler satelliteDatagramListenerHandler =
13207 mSatelliteDatagramListenerHandlers.get(validSubId);
13208 if (satelliteDatagramListenerHandler == null) {
13209 satelliteDatagramListenerHandler = new SatelliteDatagramListenerHandler(
13210 Looper.getMainLooper(), validSubId);
13211 phone.registerForNewSatelliteDatagram(satelliteDatagramListenerHandler,
13212 SatelliteDatagramListenerHandler.EVENT_SATELLITE_DATAGRAMS_RECEIVED, null);
13213 }
13214
13215 satelliteDatagramListenerHandler.addListener(callback);
13216 mSatelliteDatagramListenerHandlers.put(validSubId, satelliteDatagramListenerHandler);
13217 return SatelliteManager.SATELLITE_ERROR_NONE;
13218 }
13219
13220 /**
13221 * Unregister to stop receiving incoming datagrams over satellite.
13222 *
13223 * @param subId - The subId to stop listening incoming datagrams over satellite.
13224 * @param callback - The callback that was passed to
13225 * {@link #registerForSatelliteDatagram(int, int, ISatelliteStateListener)}
13226 * @return The result of the operation.
13227 *
13228 * @throws SecurityException if the caller doesn't have the required permission.
13229 */
13230 @Override
13231 @SatelliteManager.SatelliteError
13232 public int unregisterForSatelliteDatagram(int subId,
13233 @NonNull ISatelliteStateListener callback) {
13234 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
13235
13236 final int validSubId = getValidSatelliteSubId(subId);
13237 SatelliteDatagramListenerHandler satelliteDatagramListenerHandler =
13238 mSatelliteDatagramListenerHandlers.get(validSubId);
13239 if (satelliteDatagramListenerHandler != null) {
13240 if (satelliteDatagramListenerHandler.removeListener(callback)) {
13241 return SatelliteManager.SATELLITE_ERROR_NONE;
13242 }
13243 }
13244 return SatelliteManager.SATELLITE_INVALID_ARGUMENTS;
13245 }
13246
13247
13248 /**
13249 * Poll pending satellite datagrams over satellite.
13250 * @param subId - The subId of the subscription used for receiving datagrams.
13251 * @return The result of the operation.
13252 * @throws SecurityException if the caller doesn't have the required permission.
13253 */
13254 @Override
13255 @SatelliteManager.SatelliteError
13256 public int pollPendingSatelliteDatagrams(int subId) {
13257 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
13258
13259 final int validSubId = getValidSatelliteSubId(subId);
13260 if (!isSatelliteProvisioned(validSubId)) {
13261 return SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED;
13262 }
13263
13264 Phone phone = getPhoneOrDefault(validSubId, "pollPendingSatelliteDatagrams");
13265 if (phone == null) {
13266 return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13267 }
13268
13269 int result = (int) sendRequest(CMD_POLL_PENDING_SATELLITE_DATAGRAMS, null, validSubId);
13270 if (DBG) log("pollPendingSatelliteDatagrams result: " + result);
13271 return result;
13272 }
13273
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000013274 /**
13275 * Send datagram over satellite.
13276 * @param subId - The subId of the subscription used to send datagram
13277 * @param datagramType - type of datagram
13278 * @param datagram - datagram to send over satellite
13279 * @param callback - The callback that will be used to send result of the operation.
13280 * @throws SecurityException if the caller doesn't have the required permission.
13281 */
13282 @Override
13283 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
13284 SatelliteDatagram datagram, IIntegerConsumer callback) {
13285 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
13286 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
13287
13288 final int validSubId = getValidSatelliteSubId(subId);
13289 if (!isSatelliteProvisioned(validSubId)) {
13290 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
13291 return;
13292 }
13293
13294 Phone phone = getPhoneOrDefault(validSubId, "sendSatelliteDatagram");
13295 if (phone == null) {
13296 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13297 return;
13298 }
13299
13300 // check if we need to start PointingUI.
13301
13302 sendRequestAsync(CMD_SEND_SATELLITE_DATAGRAM,
13303 new SendSatelliteDatagramArgument(datagramType, datagram, result),
13304 phone, null);
13305 }
13306
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013307 private void handleCmdProvisionSatelliteService(@NonNull ProvisionSatelliteServiceArgument arg,
13308 @NonNull Phone phone, Message onCompleted) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013309 if (!mSatelliteProvisionCallbacks.containsKey(arg.subId)) {
13310 mSatelliteProvisionCallbacks.put(arg.subId, arg.callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013311 phone.provisionSatelliteService(onCompleted, arg.token);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013312 } else {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013313 arg.callback.accept(SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013314 }
13315 }
13316
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013317 private void handleEventProvisionSatelliteServiceDone(
13318 @NonNull ProvisionSatelliteServiceArgument arg,
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013319 @SatelliteManager.SatelliteError int result) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013320 log("handleEventProvisionSatelliteServiceDone: result="
13321 + result + ", subId=" + arg.subId);
13322
13323 Consumer<Integer> callback = mSatelliteProvisionCallbacks.remove(arg.subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013324 if (callback == null) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013325 loge("handleEventProvisionSatelliteServiceDone: callback is null for subId="
13326 + arg.subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013327 return;
13328 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013329 callback.accept(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013330
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013331 if (result == SatelliteManager.SATELLITE_ERROR_NONE) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013332 setSatelliteProvisioned(arg.subId, true);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013333 }
13334
13335 /**
13336 * We need to update satellite provision status in SubscriptionController
13337 * or SatelliteController.
13338 * TODO (b/267826133) we need to do this for all subscriptions on the device.
13339 */
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013340 registerForSatelliteProvisionStateChangedInternal(arg.subId, null, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013341 }
13342
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013343 private void handleCmdDeprovisionSatelliteService(
13344 @NonNull ProvisionSatelliteServiceArgument arg,
13345 @NonNull Phone phone, Message onCompleted) {
13346 if (arg == null) {
13347 loge("handleCmdDeprovisionSatelliteService: arg is null");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013348 return;
13349 }
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013350 if (phone == null) {
13351 loge("handleCmdDeprovisionSatelliteService: phone is null");
13352 if (arg.callback != null) {
13353 arg.callback.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13354 }
13355 return;
13356 }
13357 phone.deprovisionSatelliteService(onCompleted, arg.token);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013358 }
13359
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013360 private void handleEventDeprovisionSatelliteServiceDone(
13361 @NonNull ProvisionSatelliteServiceArgument arg,
13362 @SatelliteManager.SatelliteError int result) {
13363 if (arg == null) {
13364 loge("handleEventDeprovisionSatelliteServiceDone: arg is null");
13365 return;
13366 }
13367 log("handleEventDeprovisionSatelliteServiceDone: result="
13368 + result + ", subId=" + arg.subId);
13369
13370 if (arg.callback != null) {
13371 arg.callback.accept(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013372 }
13373
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013374 if (result == SatelliteManager.SATELLITE_ERROR_NONE) {
13375 setSatelliteProvisioned(arg.subId, false);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013376 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013377 }
13378
13379 private Phone getPhoneOrDefault(int subId, String caller) {
13380 Phone phone = getPhone(subId);
13381 if (phone == null) {
13382 loge(caller + " called with invalid subId: " + subId
13383 + ". Retrying with default phone.");
13384 phone = getDefaultPhone();
13385 if (phone == null) {
13386 loge(caller + " failed with no phone object.");
13387 }
13388 }
13389 return phone;
13390 }
13391
13392 /**
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013393 * Check if satellite is provisioned for a subscription or the device.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013394 *
13395 * Note: this is the version without permission check for telephony internal use only. The
13396 * caller need to take care of the permission check.
13397 */
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013398 private boolean isSatelliteProvisioned(int subId) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013399 if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
13400 if (mSubscriptionController == null) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013401 loge("isSatelliteProvisioned mSubscriptionController is null");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013402 return false;
13403 }
13404
13405 String strResult = mSubscriptionController.getSubscriptionProperty(
13406 subId, SubscriptionManager.SATELLITE_ENABLED);
13407 if (strResult != null) {
13408 int intResult = Integer.parseInt(strResult);
13409 return (intResult == 1) ? true : false;
13410 }
13411 } else {
13412 //TODO (b/267826133): check via SatelliteController
13413 }
13414 return false;
13415 }
13416
13417 /**
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013418 * Set satellite provisioned for a subscription or the device.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013419 *
13420 * The permission {@link android.Manifest.permission#MODIFY_PHONE_STATE} will be enforced by
13421 * {@link SubscriptionController} when setting satellite enabled for an active subscription.
13422 * Otherwise, {@link android.Manifest.permission#SATELLITE_COMMUNICATION} will be enforced.
13423 */
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013424 private synchronized void setSatelliteProvisioned(int subId, boolean isEnabled) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013425 if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
13426 if (mSubscriptionController == null) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013427 loge("setSatelliteProvisioned mSubscriptionController is null");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013428 return;
13429 }
13430 mSubscriptionController.setSubscriptionProperty(
13431 subId, SubscriptionManager.SATELLITE_ENABLED, isEnabled ? "1" : "0");
13432 } else {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013433 //TODO (b/267826133): set via SatelliteController
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013434 }
13435 }
13436
13437 private int getValidSatelliteSubId(int subId) {
13438 if (mSubscriptionController == null) {
13439 loge("getValidSatelliteSubId mSubscriptionController is null. "
13440 + "Use DEFAULT_SUBSCRIPTION_ID for subId=" + subId);
13441 return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
13442 }
13443 final long identity = Binder.clearCallingIdentity();
13444 try {
13445 Context context = getDefaultPhone().getContext();
13446 if (mSubscriptionController.isActiveSubId(
13447 subId, context.getOpPackageName(), context.getAttributionTag())) {
13448 return subId;
13449 }
13450 } finally {
13451 Binder.restoreCallingIdentity(identity);
13452 }
13453 if (DBG) log("getValidSatelliteSubId: use DEFAULT_SUBSCRIPTION_ID for subId=" + subId);
13454 return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
13455 }
13456
13457 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013458 * If we have not successfully queried the satellite modem for its satellite service support,
13459 * we will retry the query one more time. Otherwise, we will return the queried result.
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013460 */
13461 private boolean isSatelliteSupported() {
13462 synchronized (mIsSatelliteSupportedLock) {
13463 if (mIsSatelliteSupported != null) {
13464 /* We have already successfully queried the satellite modem. */
13465 return mIsSatelliteSupported;
13466 }
13467 }
13468 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013469 * We have not successfully checked whether the modem supports satellite service.
13470 * Thus, we need to retry it now.
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013471 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013472 requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
13473 mSatelliteSupportedReceiver);
13474 return false;
13475 }
13476
13477 /**
13478 * Get the {@link SatelliteManager.SatelliteError} from the provided result.
13479 * @param ar AsyncResult used to determine the error code.
13480 * @param caller The satellite request.
13481 * @param checkResult Whether to check if the result exists.
13482 * @return The {@link SatelliteManager.SatelliteError} error code from the request.
13483 */
13484 @SatelliteManager.SatelliteError private int getSatelliteError(@NonNull AsyncResult ar,
13485 @NonNull String caller, boolean checkResult) {
13486 int errorCode;
13487 if (ar.exception == null) {
13488 errorCode = SatelliteManager.SATELLITE_ERROR_NONE;
13489 if (checkResult && ar.result == null) {
13490 loge(caller + ": result is null");
13491 errorCode = SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13492 }
13493 } else {
13494 errorCode = SatelliteManager.SATELLITE_ERROR;
13495 if (ar.exception instanceof CommandException) {
13496 CommandException.Error error =
13497 ((CommandException) (ar.exception)).getCommandError();
13498 errorCode = RILUtils.convertToSatelliteError(error);
13499 loge(caller + " CommandException: " + ar.exception);
13500 } else {
13501 loge(caller + " unknown exception: " + ar.exception);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013502 }
13503 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013504 log(caller + " error: " + errorCode);
13505 return errorCode;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013506 }
13507
13508 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013509 * Register for the satellite provision state change.
13510 *
13511 * @param subId The subId of the subscription associated with the satellite service.
13512 * @param errorCallback The callback to get the error code of the request.
13513 * @param callback The callback to handle the satellite provision state changed event.
13514 */
13515 private void registerForSatelliteProvisionStateChangedInternal(int subId,
13516 @Nullable IIntegerConsumer errorCallback, @Nullable ISatelliteStateListener callback) {
13517 Consumer<Integer> result = null;
13518 if (errorCallback != null) {
13519 result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
13520 }
13521 if (!isSatelliteSupported()) {
13522 if (result != null) {
13523 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
13524 }
13525 return;
13526 }
13527
13528 final int validSubId = getValidSatelliteSubId(subId);
13529 Phone phone = getPhoneOrDefault(validSubId, "registerForSatelliteProvisionStateChanged");
13530 if (phone == null) {
13531 if (result != null) {
13532 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13533 }
13534 return;
13535 }
13536
13537 SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler =
13538 mSatelliteProvisionStateChangedHandlers.get(validSubId);
13539 if (satelliteProvisionStateChangedHandler == null) {
13540 satelliteProvisionStateChangedHandler = new SatelliteProvisionStateChangedHandler(
13541 Looper.getMainLooper(), validSubId);
13542 phone.registerForSatelliteProvisionStateChanged(satelliteProvisionStateChangedHandler,
13543 SatelliteProvisionStateChangedHandler.EVENT_PROVISION_STATE_CHANGED, null);
13544 }
13545
13546 if (callback != null) {
13547 satelliteProvisionStateChangedHandler.addListener(callback);
13548 }
13549 mSatelliteProvisionStateChangedHandlers.put(
13550 validSubId, satelliteProvisionStateChangedHandler);
13551 if (result != null) {
13552 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
13553 }
13554 }
13555
13556 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000013557 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
13558 *
13559 * <p>This method behaves in one of the following ways:
13560 * <ul>
13561 * <li>return true : if the calling package has the appop permission {@link
13562 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
13563 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
13564 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
13565 * Owner device identifier access check, or the calling package has carrier privileges</>
13566 * <li>throw SecurityException: if the caller does not meet any of the requirements.
13567 * </ul>
13568 */
13569 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
13570 String callingPackage, @Nullable String callingFeatureId, String message) {
13571 for (Phone phone : PhoneFactory.getPhones()) {
13572 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
13573 phone.getSubId(), callingPackage, callingFeatureId, message)) {
13574 return true;
13575 }
13576 }
13577 return false;
13578 }
arunvoddud7401012022-12-15 16:08:12 +000013579
13580 /**
Jack Yufa8ed012023-02-11 15:42:28 -080013581 * @return The subscription manager service instance.
13582 */
13583 public SubscriptionManagerService getSubscriptionManagerService() {
13584 return SubscriptionManagerService.getInstance();
13585 }
13586
13587 /**
arunvoddud7401012022-12-15 16:08:12 +000013588 * Class binds the consumer[callback] and carrierId.
13589 */
13590 private static class CallerCallbackInfo {
13591 private final Consumer<Integer> mConsumer;
13592 private final int mCarrierId;
13593
13594 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
13595 mConsumer = consumer;
13596 mCarrierId = carrierId;
13597 }
13598
13599 public Consumer<Integer> getConsumer() {
13600 return mConsumer;
13601 }
13602
13603 public int getCarrierId() {
13604 return mCarrierId;
13605 }
13606 }
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000013607
13608 private static SatelliteDatagram[] convertToSatelliteDatagramArray(byte[][] datagrams) {
13609 // Convert 2D byte array into SatelliteDatagramArray.
13610 SatelliteDatagram[] satelliteDatagramArray =
13611 new SatelliteDatagram[datagrams.length];
13612 for (int i = 0; i < datagrams.length; i++) {
13613 satelliteDatagramArray[i] = new SatelliteDatagram(datagrams[i]);
13614 }
13615 return satelliteDatagramArray;
13616 }
Jack Yufa8ed012023-02-11 15:42:28 -080013617}