blob: b90d288c42f7eafb92e063882f2e3c8fc54354b4 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000020import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080021import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Hall Liud892bec2018-11-30 14:51:45 -080022
Shuo Qianccbaf742021-02-22 18:32:21 -080023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
24import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070025import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000027import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070028
Brad Ebinger34c09a52021-02-17 23:23:21 +000029import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080030import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080031import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070032import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000033import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080034import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080036import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070037import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000038import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080039import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000040import android.compat.annotation.ChangeId;
41import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070042import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070043import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.content.Context;
45import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070046import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070047import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070048import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.net.Uri;
50import android.os.AsyncResult;
51import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080052import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Bundle;
54import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070055import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080056import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080057import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.os.Looper;
59import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070060import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080061import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070062import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070063import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080064import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080065import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070066import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070067import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080068import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070070import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070071import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070072import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070073import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080074import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070075import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000076import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090077import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080078import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080079import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070080import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080081import android.telephony.AccessNetworkConstants;
82import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070083import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070084import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080085import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070086import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080087import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070088import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080089import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060090import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -070091import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080092import android.telephony.CellIdentityCdma;
93import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070095import android.telephony.CellInfoGsm;
96import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070097import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080098import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070099import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700100import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700101import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800102import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700103import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800104import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700105import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800106import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800107import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700108import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800109import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700110import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800111import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800112import android.telephony.SignalStrengthUpdateRequest;
113import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800114import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800115import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800116import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700117import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700118import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800119import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800120import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800121import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800122import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000123import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000124import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000125import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700126import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700127import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800128import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800129import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700130import android.telephony.gba.GbaAuthRequest;
131import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700132import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800133import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000134import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000135import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700136import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000137import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700138import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800139import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700140import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800141import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700142import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000143import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700144import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800145import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800146import android.telephony.ims.stub.ImsRegistrationImplBase;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800147import android.telephony.satellite.ISatelliteDatagramCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800148import android.telephony.satellite.ISatelliteProvisionStateCallback;
149import android.telephony.satellite.ISatelliteStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800150import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800151import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000152import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800153import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800154import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800155import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800157import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700158import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800160import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800161
Andrew Lee312e8172014-10-23 17:01:36 -0700162import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800163import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800164import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800165import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800166import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700167import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700168import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700169import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800170import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800171import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700172import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700173import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800174import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700175import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800176import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800177import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800178import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700179import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000180import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700181import com.android.internal.telephony.IIntegerConsumer;
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +0000182import com.android.internal.telephony.ILongConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800183import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700184import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800185import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800186import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800187import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700188import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700189import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700190import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700192import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800193import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700194import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700195import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700196import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700197import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800198import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800199import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700200import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000201import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700202import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700203import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800204import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800205import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800206import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700207import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000208import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800209import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700210import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800211import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700212import com.android.internal.telephony.imsphone.ImsPhone;
213import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000214import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800215import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000216import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800217import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
218import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700219import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700220import com.android.internal.telephony.uicc.IccIoResult;
221import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800222import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700223import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800224import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700225import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000226import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800227import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000228import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800229import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000230import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700231import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700232import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800233import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800234import com.android.phone.callcomposer.CallComposerPictureManager;
235import com.android.phone.callcomposer.CallComposerPictureTransfer;
236import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700237import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700238import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000239import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700240import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800241import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700242import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700243import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800244import com.android.services.telephony.TelecomAccountRegistry;
245import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800246import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800247
Hall Liu82694d52020-12-11 18:22:04 -0800248import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700249import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800250import java.io.IOException;
251import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700252import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800254import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000255import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800256import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800257import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800258import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800259import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100260import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800261import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700262import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800263import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800264import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700265import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800266import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800267import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800268import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269
270/**
271 * Implementation of the ITelephony interface.
272 */
Santos Cordon117fee72014-05-16 17:56:12 -0700273public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274 private static final String LOG_TAG = "PhoneInterfaceManager";
275 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
276 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800277 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700278
279 // Message codes used with mMainThreadHandler
280 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700281 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
282 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700283 private static final int CMD_OPEN_CHANNEL = 9;
284 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
285 private static final int CMD_CLOSE_CHANNEL = 11;
286 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800287 private static final int CMD_NV_READ_ITEM = 13;
288 private static final int EVENT_NV_READ_ITEM_DONE = 14;
289 private static final int CMD_NV_WRITE_ITEM = 15;
290 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
291 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
292 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700293 private static final int CMD_RESET_MODEM_CONFIG = 19;
294 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800295 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
296 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800297 private static final int CMD_SEND_ENVELOPE = 25;
298 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000299 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
300 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700301 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
302 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
303 private static final int CMD_EXCHANGE_SIM_IO = 31;
304 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800305 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
306 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700307 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
308 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700309 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
310 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700311 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
312 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
313 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
314 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700315 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
316 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
317 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
318 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700319 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800320 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
321 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000322 private static final int CMD_SWITCH_SLOTS = 50;
323 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700324 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
325 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
326 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
327 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
328 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
329 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
330 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
331 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700332 private static final int CMD_GET_ALL_CELL_INFO = 60;
333 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
334 private static final int CMD_GET_CELL_LOCATION = 62;
335 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700336 private static final int CMD_MODEM_REBOOT = 64;
337 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700338 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
339 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800340 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
341 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700342 private static final int CMD_GET_MODEM_STATUS = 70;
343 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700344 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
345 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700346 private static final int CMD_ERASE_MODEM_CONFIG = 74;
347 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800348 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
349 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
350 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
351 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800352 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
353 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800354 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800355 private static final int CMD_GET_CALL_FORWARDING = 83;
356 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
357 private static final int CMD_SET_CALL_FORWARDING = 85;
358 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
359 private static final int CMD_GET_CALL_WAITING = 87;
360 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
361 private static final int CMD_SET_CALL_WAITING = 89;
362 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700363 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
364 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
365 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
366 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700367 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
368 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800369 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
370 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800371 private static final int CMD_SET_DATA_THROTTLING = 99;
372 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800373 private static final int CMD_SET_SIM_POWER = 101;
374 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800375 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
376 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
377 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
378 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800379 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
380 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000381 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800382 private static final int CMD_GET_SLICING_CONFIG = 110;
383 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800384 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700385 private static final int CMD_ENABLE_VONR = 113;
386 private static final int EVENT_ENABLE_VONR_DONE = 114;
387 private static final int CMD_IS_VONR_ENABLED = 115;
388 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700389 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
390 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000391
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800392 // Parameters of select command.
393 private static final int SELECT_COMMAND = 0xA4;
394 private static final int SELECT_P1 = 0x04;
395 private static final int SELECT_P2 = 0;
396 private static final int SELECT_P3 = 0x10;
397
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000398 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
399 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
400
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401 /** The singleton instance. */
402 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800403 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404
Sarah Chin4beb2b72023-02-14 14:47:54 -0800405 private final PhoneGlobals mApp;
406 private final CallManager mCM;
407 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000408
409 private final SatelliteController mSatelliteController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800410 private final UserManager mUserManager;
411 private final AppOpsManager mAppOps;
412 private final MainThreadHandler mMainThreadHandler;
Jack Yue37dd262022-12-16 11:53:37 -0800413 private final SubscriptionController mSubscriptionController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800414 private final SharedPreferences mTelephonySharedPreferences;
415 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800416 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417
Peter Wangdafb9ac2020-01-15 14:13:38 -0800418 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800419 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800420 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
421
Sarah Chin4beb2b72023-02-14 14:47:54 -0800422 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800423
Derek Tan97ebb422014-09-05 16:55:38 -0700424 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
425 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800426 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800427 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700428
Michelecea4cf22018-12-21 15:00:11 -0800429 // String to store multi SIM allowed
430 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
431
Derek Tan740e1672017-06-27 14:56:27 -0700432 // The AID of ISD-R.
433 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
434
yinxub1bed742017-04-17 11:45:04 -0700435 private NetworkScanRequestTracker mNetworkScanRequestTracker;
436
David Kelly5e06a7f2018-03-12 14:10:59 +0000437 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
438 private static final int MANUFACTURER_CODE_LENGTH = 8;
439
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800440 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800441 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800442
Sarah Chin2ec39f62022-08-31 17:03:26 -0700443 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
444 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
445
Derek Tan89e89d42014-07-08 17:00:10 -0700446 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700447 * Experiment flag to enable erase modem config on reset network, default value is false
448 */
449 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
450 "reset_network_erase_modem_config_enabled";
451
Rambo Wang0f050d82021-02-12 11:43:36 -0800452 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800453
Gary Jian76280a42022-12-07 16:18:33 +0800454 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
455
sandeepjsb6c87872021-09-27 15:34:44 +0000456 /**
457 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
458 * one ICCID active at the same time.
459 * Apps should use below API signatures if targeting SDK is T and beyond.
460 *
461 * @hide
462 */
463 @ChangeId
464 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
465 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800466
Naina Nallurid63128d2019-09-17 14:10:30 -0700467 /**
Chen Xu540470b2021-12-14 17:15:47 -0800468 * Apps targeting on Android T and beyond will get exception whenever icc close channel
469 * operation fails.
470 */
471 @ChangeId
472 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
473 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
474
475 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 * A request object to use for transmitting data to an ICC.
477 */
478 private static final class IccAPDUArgument {
479 public int channel, cla, command, p1, p2, p3;
480 public String data;
481
482 public IccAPDUArgument(int channel, int cla, int command,
483 int p1, int p2, int p3, String data) {
484 this.channel = channel;
485 this.cla = cla;
486 this.command = command;
487 this.p1 = p1;
488 this.p2 = p2;
489 this.p3 = p3;
490 this.data = data;
491 }
492 }
493
494 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700495 * A request object to use for transmitting data to an ICC.
496 */
497 private static final class ManualNetworkSelectionArgument {
498 public OperatorInfo operatorInfo;
499 public boolean persistSelection;
500
501 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
502 this.operatorInfo = operatorInfo;
503 this.persistSelection = persistSelection;
504 }
505 }
506
Sarah Chin71b3a852022-09-28 15:54:19 -0700507 private static final class PurchasePremiumCapabilityArgument {
508 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700509 public @NonNull IIntegerConsumer callback;
510
511 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800512 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700513 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700514 this.callback = callback;
515 }
516 }
517
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700518 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700519 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
520 * request after sending. The main thread will notify the request when it is complete.
521 */
522 private static final class MainThreadRequest {
523 /** The argument to use for the request */
524 public Object argument;
525 /** The result of the request that is run on the main thread */
526 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800527 // The subscriber id that this request applies to. Defaults to
528 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
529 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700530
Nathan Harold92bed182018-10-12 18:16:49 -0700531 // In cases where subId is unavailable, the caller needs to specify the phone.
532 public Phone phone;
533
vagdeviaf9a5b92018-08-15 16:01:53 -0700534 public WorkSource workSource;
535
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700536 public MainThreadRequest(Object argument) {
537 this.argument = argument;
538 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800539
Nathan Harold92bed182018-10-12 18:16:49 -0700540 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
541 this.argument = argument;
542 if (phone != null) {
543 this.phone = phone;
544 }
545 this.workSource = workSource;
546 }
547
vagdeviaf9a5b92018-08-15 16:01:53 -0700548 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800549 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800550 if (subId != null) {
551 this.subId = subId;
552 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700553 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800554 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700555 }
556
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800557 private static final class IncomingThirdPartyCallArgs {
558 public final ComponentName component;
559 public final String callId;
560 public final String callerDisplayName;
561
562 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
563 String callerDisplayName) {
564 this.component = component;
565 this.callId = callId;
566 this.callerDisplayName = callerDisplayName;
567 }
568 }
569
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700570 /**
571 * A handler that processes messages on the main thread in the phone process. Since many
572 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
573 * inbound binder threads to the main thread in the phone process. The Binder thread
574 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
575 * on, which will be notified when the operation completes and will contain the result of the
576 * request.
577 *
578 * <p>If a MainThreadRequest object is provided in the msg.obj field,
579 * note that request.result must be set to something non-null for the calling thread to
580 * unblock.
581 */
582 private final class MainThreadHandler extends Handler {
583 @Override
584 public void handleMessage(Message msg) {
585 MainThreadRequest request;
586 Message onCompleted;
587 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000588 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700589 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800590 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700591
592 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 case CMD_HANDLE_USSD_REQUEST: {
594 request = (MainThreadRequest) msg.obj;
595 final Phone phone = getPhoneFromRequest(request);
596 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800597 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700598 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700599
Pengquan Menga1bb6272018-09-06 09:59:22 -0700600 if (!isUssdApiAllowed(request.subId)) {
601 // Carrier does not support use of this API, return failure.
602 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
603 UssdResponse response = new UssdResponse(ussdRequest, null);
604 Bundle returnData = new Bundle();
605 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
606 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700607
Pengquan Menga1bb6272018-09-06 09:59:22 -0700608 request.result = true;
609 notifyRequester(request);
610 return;
611 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700612
Pengquan Menga1bb6272018-09-06 09:59:22 -0700613 try {
614 request.result = phone != null
615 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
616 } catch (CallStateException cse) {
617 request.result = false;
618 }
619 // Wake up the requesting thread
620 notifyRequester(request);
621 break;
pkanwar32d516d2016-10-14 19:37:38 -0700622 }
623
Yorke Lee716f67e2015-06-17 15:39:16 -0700624 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700625 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700626 final Phone phone = getPhoneFromRequest(request);
627 request.result = phone != null ?
628 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
629 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700630 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700631 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700632 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700633 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700634
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700635 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700637 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000638 uiccPort = getUiccPortFromRequest(request);
639 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700640 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800641 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700642 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700643 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700644 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800645 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000646 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800647 iccArgument.channel, iccArgument.cla, iccArgument.command,
648 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
649 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700650 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 break;
652
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700653 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 ar = (AsyncResult) msg.obj;
655 request = (MainThreadRequest) ar.userObj;
656 if (ar.exception == null && ar.result != null) {
657 request.result = ar.result;
658 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800659 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 if (ar.result == null) {
661 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800662 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800664 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 } else {
666 loge("iccTransmitApduLogicalChannel: Unknown exception");
667 }
668 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700669 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700670 break;
671
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700672 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
673 request = (MainThreadRequest) msg.obj;
674 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000675 uiccPort = getUiccPortFromRequest(request);
676 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700677 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800678 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700679 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700680 } else {
681 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800682 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000683 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800684 iccArgument.cla, iccArgument.command, iccArgument.p1,
685 iccArgument.p2,
686 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700687 }
688 break;
689
690 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
691 ar = (AsyncResult) msg.obj;
692 request = (MainThreadRequest) ar.userObj;
693 if (ar.exception == null && ar.result != null) {
694 request.result = ar.result;
695 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800696 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700697 if (ar.result == null) {
698 loge("iccTransmitApduBasicChannel: Empty response");
699 } else if (ar.exception instanceof CommandException) {
700 loge("iccTransmitApduBasicChannel: CommandException: " +
701 ar.exception);
702 } else {
703 loge("iccTransmitApduBasicChannel: Unknown exception");
704 }
705 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700706 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 break;
708
709 case CMD_EXCHANGE_SIM_IO:
710 request = (MainThreadRequest) msg.obj;
711 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000712 uiccPort = getUiccPortFromRequest(request);
713 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700714 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800715 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700716 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700717 } else {
718 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
719 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000720 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700721 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
722 iccArgument.data, onCompleted);
723 }
724 break;
725
726 case EVENT_EXCHANGE_SIM_IO_DONE:
727 ar = (AsyncResult) msg.obj;
728 request = (MainThreadRequest) ar.userObj;
729 if (ar.exception == null && ar.result != null) {
730 request.result = ar.result;
731 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800732 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700733 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700734 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700735 break;
736
Derek Tan4d5e5c12014-02-04 11:54:58 -0800737 case CMD_SEND_ENVELOPE:
738 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000739 uiccPort = getUiccPortFromRequest(request);
740 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700741 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800742 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700743 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700744 } else {
745 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800746 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700747 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800748 break;
749
750 case EVENT_SEND_ENVELOPE_DONE:
751 ar = (AsyncResult) msg.obj;
752 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700753 if (ar.exception == null && ar.result != null) {
754 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800755 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800756 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700757 if (ar.result == null) {
758 loge("sendEnvelopeWithStatus: Empty response");
759 } else if (ar.exception instanceof CommandException) {
760 loge("sendEnvelopeWithStatus: CommandException: " +
761 ar.exception);
762 } else {
763 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
764 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800765 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700766 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800767 break;
768
Shishir Agrawal566b7612013-10-28 14:41:00 -0700769 case CMD_OPEN_CHANNEL:
770 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000771 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800772 IccLogicalChannelRequest openChannelRequest =
773 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000774 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700775 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800776 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800777 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700778 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700779 } else {
780 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800781 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
782 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700783 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700784 break;
785
786 case EVENT_OPEN_CHANNEL_DONE:
787 ar = (AsyncResult) msg.obj;
788 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700789 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700790 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700791 int[] result = (int[]) ar.result;
792 int channelId = result[0];
793 byte[] selectResponse = null;
794 if (result.length > 1) {
795 selectResponse = new byte[result.length - 1];
796 for (int i = 1; i < result.length; ++i) {
797 selectResponse[i - 1] = (byte) result[i];
798 }
799 }
800 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800801 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800802
803 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700804 if (uiccPort == null) {
805 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
806 } else {
807 IccLogicalChannelRequest channelRequest =
808 (IccLogicalChannelRequest) request.argument;
809 channelRequest.channel = channelId;
810 uiccPort.onLogicalChannelOpened(channelRequest);
811 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700812 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700813 if (ar.result == null) {
814 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700815 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700816 if (ar.exception != null) {
817 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
818 }
819
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700820 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700821 if (ar.exception instanceof CommandException) {
822 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800823 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700824 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700825 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700826 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700827 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700828 }
829 }
830 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800831 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700832 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700833 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700834 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700835 break;
836
837 case CMD_CLOSE_CHANNEL:
838 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000839 uiccPort = getUiccPortFromRequest(request);
840 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700841 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800842 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800843 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800844 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700845 } else {
846 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000847 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700848 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700849 break;
850
851 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800852 ar = (AsyncResult) msg.obj;
853 request = (MainThreadRequest) ar.userObj;
854 if (ar.exception == null) {
855 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800856 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700857 if (uiccPort == null) {
858 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
859 } else {
860 final int channelId = (Integer) request.argument;
861 uiccPort.onLogicalChannelClosed(channelId);
862 }
Chen Xu540470b2021-12-14 17:15:47 -0800863 } else {
864 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800865 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800866 if (ar.exception instanceof CommandException) {
867 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
868 CommandException.Error error =
869 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800870 if (error == CommandException.Error.INVALID_ARGUMENTS) {
871 // should only throw exceptions from the binder threads.
872 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800873 "iccCloseLogicalChannel: invalid argument ");
874 }
875 } else {
876 loge("iccCloseLogicalChannel: Unknown exception");
877 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800878 request.result = (exception != null) ? exception :
879 new IllegalStateException(
880 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800881 }
882 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800883 break;
884
885 case CMD_NV_READ_ITEM:
886 request = (MainThreadRequest) msg.obj;
887 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800888 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
889 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800890 break;
891
892 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700893 ar = (AsyncResult) msg.obj;
894 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800895 if (ar.exception == null && ar.result != null) {
896 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700897 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800898 request.result = "";
899 if (ar.result == null) {
900 loge("nvReadItem: Empty response");
901 } else if (ar.exception instanceof CommandException) {
902 loge("nvReadItem: CommandException: " +
903 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700904 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800905 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700906 }
907 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700908 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700909 break;
910
Jake Hambye994d462014-02-03 13:10:13 -0800911 case CMD_NV_WRITE_ITEM:
912 request = (MainThreadRequest) msg.obj;
913 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
914 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800915 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700916 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800917 break;
918
919 case EVENT_NV_WRITE_ITEM_DONE:
920 handleNullReturnEvent(msg, "nvWriteItem");
921 break;
922
923 case CMD_NV_WRITE_CDMA_PRL:
924 request = (MainThreadRequest) msg.obj;
925 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800926 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800927 break;
928
929 case EVENT_NV_WRITE_CDMA_PRL_DONE:
930 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
931 break;
932
chen xu6dac5ab2018-10-26 17:39:23 -0700933 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800934 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700935 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800936 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800937 break;
938
chen xu6dac5ab2018-10-26 17:39:23 -0700939 case EVENT_RESET_MODEM_CONFIG_DONE:
940 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800941 break;
942
Sooraj Sasindran37444802020-08-11 10:40:43 -0700943 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
944 request = (MainThreadRequest) msg.obj;
945 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
946 request);
947 Phone phone = getPhoneFromRequest(request);
948 if (phone != null) {
949 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
950 } else {
951 loge("isNRDualConnectivityEnabled: No phone object");
952 request.result = false;
953 notifyRequester(request);
954 }
955 break;
956 }
957
958 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
959 ar = (AsyncResult) msg.obj;
960 request = (MainThreadRequest) ar.userObj;
961 if (ar.exception == null && ar.result != null) {
962 request.result = ar.result;
963 } else {
964 // request.result must be set to something non-null
965 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700966 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700967 request.result = ar.result;
968 } else {
969 request.result = false;
970 }
971 if (ar.result == null) {
972 loge("isNRDualConnectivityEnabled: Empty response");
973 } else if (ar.exception instanceof CommandException) {
974 loge("isNRDualConnectivityEnabled: CommandException: "
975 + ar.exception);
976 } else {
977 loge("isNRDualConnectivityEnabled: Unknown exception");
978 }
979 }
980 notifyRequester(request);
981 break;
982
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700983 case CMD_IS_VONR_ENABLED: {
984 request = (MainThreadRequest) msg.obj;
985 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
986 request);
987 Phone phone = getPhoneFromRequest(request);
988 if (phone != null) {
989 phone.isVoNrEnabled(onCompleted, request.workSource);
990 } else {
991 loge("isVoNrEnabled: No phone object");
992 request.result = false;
993 notifyRequester(request);
994 }
995 break;
996 }
997
998 case EVENT_IS_VONR_ENABLED_DONE:
999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
1001 if (ar.exception == null && ar.result != null) {
1002 request.result = ar.result;
1003 } else {
1004 // request.result must be set to something non-null
1005 // for the calling thread to unblock
1006 if (ar.result != null) {
1007 request.result = ar.result;
1008 } else {
1009 request.result = false;
1010 }
1011 if (ar.result == null) {
1012 loge("isVoNrEnabled: Empty response");
1013 } else if (ar.exception instanceof CommandException) {
1014 loge("isVoNrEnabled: CommandException: "
1015 + ar.exception);
1016 } else {
1017 loge("isVoNrEnabled: Unknown exception");
1018 }
1019 }
1020 notifyRequester(request);
1021 break;
1022
Sooraj Sasindran37444802020-08-11 10:40:43 -07001023 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1024 request = (MainThreadRequest) msg.obj;
1025 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1026 Phone phone = getPhoneFromRequest(request);
1027 if (phone != null) {
1028 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1029 request.workSource);
1030 } else {
1031 loge("enableNrDualConnectivity: No phone object");
1032 request.result =
1033 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1034 notifyRequester(request);
1035 }
1036 break;
1037 }
1038
1039 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1040 ar = (AsyncResult) msg.obj;
1041 request = (MainThreadRequest) ar.userObj;
1042 if (ar.exception == null) {
1043 request.result =
1044 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1045 } else {
1046 request.result =
1047 TelephonyManager
1048 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1049 if (ar.exception instanceof CommandException) {
1050 CommandException.Error error =
1051 ((CommandException) (ar.exception)).getCommandError();
1052 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1053 request.result =
1054 TelephonyManager
1055 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001056 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1057 request.result =
1058 TelephonyManager
1059 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001060 }
1061 loge("enableNrDualConnectivity" + ": CommandException: "
1062 + ar.exception);
1063 } else {
1064 loge("enableNrDualConnectivity" + ": Unknown exception");
1065 }
1066 }
1067 notifyRequester(request);
1068 break;
1069 }
1070
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001071 case CMD_ENABLE_VONR: {
1072 request = (MainThreadRequest) msg.obj;
1073 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1074 Phone phone = getPhoneFromRequest(request);
1075 if (phone != null) {
1076 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1077 request.workSource);
1078 } else {
1079 loge("setVoNrEnabled: No phone object");
1080 request.result =
1081 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1082 notifyRequester(request);
1083 }
1084 break;
1085 }
1086
1087 case EVENT_ENABLE_VONR_DONE: {
1088 ar = (AsyncResult) msg.obj;
1089 request = (MainThreadRequest) ar.userObj;
1090 if (ar.exception == null) {
1091 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1092 } else {
1093 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1094 if (ar.exception instanceof CommandException) {
1095 CommandException.Error error =
1096 ((CommandException) (ar.exception)).getCommandError();
1097 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1098 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1099 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1100 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1101 } else {
1102 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1103 }
1104 loge("setVoNrEnabled" + ": CommandException: "
1105 + ar.exception);
1106 } else {
1107 loge("setVoNrEnabled" + ": Unknown exception");
1108 }
1109 }
1110 notifyRequester(request);
1111 break;
1112 }
1113
SongFerngWang3ef3e072020-12-21 16:41:52 +08001114 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001115 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001116 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1117 request);
1118 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001119 break;
1120
SongFerngWang3ef3e072020-12-21 16:41:52 +08001121 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001122 ar = (AsyncResult) msg.obj;
1123 request = (MainThreadRequest) ar.userObj;
1124 if (ar.exception == null && ar.result != null) {
1125 request.result = ar.result; // Integer
1126 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301127 // request.result must be set to something non-null
1128 // for the calling thread to unblock
1129 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001130 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001131 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001132 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001133 loge("getAllowedNetworkTypesBitmask: CommandException: "
1134 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001135 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001136 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001137 }
1138 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001139 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001140 break;
1141
SongFerngWang3ef3e072020-12-21 16:41:52 +08001142 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001143 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001144 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1145 request);
1146 Pair<Integer, Long> reasonWithNetworkTypes =
1147 (Pair<Integer, Long>) request.argument;
1148 getPhoneFromRequest(request).setAllowedNetworkTypes(
1149 reasonWithNetworkTypes.first,
1150 reasonWithNetworkTypes.second,
1151 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001152 break;
1153
SongFerngWang3ef3e072020-12-21 16:41:52 +08001154 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1155 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001156 break;
1157
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001158 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1159 request = (MainThreadRequest)msg.obj;
1160 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001161 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001162 break;
1163
1164 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1165 ar = (AsyncResult)msg.obj;
1166 request = (MainThreadRequest)ar.userObj;
1167 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001168 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001169 break;
1170
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001171 case CMD_SET_VOICEMAIL_NUMBER:
1172 request = (MainThreadRequest) msg.obj;
1173 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1174 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001175 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1176 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001177 break;
1178
1179 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1180 handleNullReturnEvent(msg, "setVoicemailNumber");
1181 break;
1182
Stuart Scott54788802015-03-30 13:18:01 -07001183 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1184 request = (MainThreadRequest) msg.obj;
1185 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1186 request);
1187 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1188 break;
1189
1190 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1191 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1192 break;
1193
Shishir Agrawal302c8692015-06-19 13:49:39 -07001194 case CMD_PERFORM_NETWORK_SCAN:
1195 request = (MainThreadRequest) msg.obj;
1196 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1197 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1198 break;
1199
Hall Liu27d24262020-09-18 19:04:59 -07001200 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001201 request = (MainThreadRequest) msg.obj;
1202 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001203 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1204 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1205 request.argument;
1206 int callForwardingReason = args.first;
1207 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001208 break;
Hall Liu27d24262020-09-18 19:04:59 -07001209 }
1210 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001211 ar = (AsyncResult) msg.obj;
1212 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001213 TelephonyManager.CallForwardingInfoCallback callback =
1214 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1215 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001216 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001217 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001218 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1219 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1220 // Service Class is a bit mask per 3gpp 27.007. Search for
1221 // any service for voice call.
1222 if ((callForwardInfo.serviceClass
1223 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001224 callForwardingInfo = new CallForwardingInfo(
1225 callForwardInfo.status
1226 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001227 callForwardInfo.reason,
1228 callForwardInfo.number,
1229 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001230 break;
1231 }
1232 }
1233 // Didn't find a call forward info for voice call.
1234 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001235 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1236 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001237 }
Hall Liu27d24262020-09-18 19:04:59 -07001238 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001239 } else {
1240 if (ar.result == null) {
1241 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1242 }
1243 if (ar.exception != null) {
1244 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1245 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001246 int errorCode = TelephonyManager
1247 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001248 if (ar.exception instanceof CommandException) {
1249 CommandException.Error error =
1250 ((CommandException) (ar.exception)).getCommandError();
1251 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001252 errorCode = TelephonyManager
1253 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001254 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001255 errorCode = TelephonyManager
1256 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001257 }
1258 }
Hall Liu27d24262020-09-18 19:04:59 -07001259 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001260 }
Shuo Qian4a594052020-01-23 11:59:30 -08001261 break;
Hall Liu27d24262020-09-18 19:04:59 -07001262 }
Shuo Qian4a594052020-01-23 11:59:30 -08001263
Hall Liu27d24262020-09-18 19:04:59 -07001264 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001265 request = (MainThreadRequest) msg.obj;
1266 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001267 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001268 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001269 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1270 request.argument).first;
1271 request.phone.setCallForwardingOption(
1272 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001273 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001274 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001275 callForwardingInfoToSet.getReason(),
1276 callForwardingInfoToSet.getNumber(),
1277 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1278 break;
Hall Liu27d24262020-09-18 19:04:59 -07001279 }
Shuo Qian4a594052020-01-23 11:59:30 -08001280
Hall Liu27d24262020-09-18 19:04:59 -07001281 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001282 ar = (AsyncResult) msg.obj;
1283 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001284 Consumer<Integer> callback =
1285 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1286 request.argument).second;
1287 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001288 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001289 int errorCode = TelephonyManager.CallForwardingInfoCallback
1290 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001291 if (ar.exception instanceof CommandException) {
1292 CommandException.Error error =
1293 ((CommandException) (ar.exception)).getCommandError();
1294 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001295 errorCode = TelephonyManager.CallForwardingInfoCallback
1296 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001297 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001298 errorCode = TelephonyManager.CallForwardingInfoCallback
1299 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001300 }
1301 }
1302 callback.accept(errorCode);
1303 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001304 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001305 }
Shuo Qian4a594052020-01-23 11:59:30 -08001306 break;
Hall Liu27d24262020-09-18 19:04:59 -07001307 }
Shuo Qian4a594052020-01-23 11:59:30 -08001308
Hall Liu27d24262020-09-18 19:04:59 -07001309 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001310 request = (MainThreadRequest) msg.obj;
1311 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1312 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1313 break;
Hall Liu27d24262020-09-18 19:04:59 -07001314 }
Shuo Qian4a594052020-01-23 11:59:30 -08001315
Hall Liu27d24262020-09-18 19:04:59 -07001316 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001317 ar = (AsyncResult) msg.obj;
1318 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001319 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001320 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001321 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001322 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001323 // Service Class is a bit mask per 3gpp 27.007.
1324 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001325 if (callForwardResults.length > 1
1326 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001327 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001328 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001329 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1330 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001331 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001332 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001333 }
1334 } else {
1335 if (ar.result == null) {
1336 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1337 }
1338 if (ar.exception != null) {
1339 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1340 }
1341 if (ar.exception instanceof CommandException) {
1342 CommandException.Error error =
1343 ((CommandException) (ar.exception)).getCommandError();
1344 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001345 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001346 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001347 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1348 callWaitingStatus =
1349 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001350 }
1351 }
1352 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001353 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001354 break;
Hall Liu27d24262020-09-18 19:04:59 -07001355 }
Shuo Qian4a594052020-01-23 11:59:30 -08001356
Hall Liu27d24262020-09-18 19:04:59 -07001357 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001358 request = (MainThreadRequest) msg.obj;
1359 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001360 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1361 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001362 break;
Hall Liu27d24262020-09-18 19:04:59 -07001363 }
Shuo Qian4a594052020-01-23 11:59:30 -08001364
Hall Liu27d24262020-09-18 19:04:59 -07001365 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001366 ar = (AsyncResult) msg.obj;
1367 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001368 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1369 Consumer<Integer> callback =
1370 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1371 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001372 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001373 if (ar.exception instanceof CommandException) {
1374 CommandException.Error error =
1375 ((CommandException) (ar.exception)).getCommandError();
1376 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1377 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001378 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1379 callback.accept(
1380 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001381 } else {
1382 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1383 }
1384 } else {
1385 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1386 }
1387 } else {
1388 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1389 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001390 }
Shuo Qian4a594052020-01-23 11:59:30 -08001391 break;
Hall Liu27d24262020-09-18 19:04:59 -07001392 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001393 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1394 ar = (AsyncResult) msg.obj;
1395 request = (MainThreadRequest) ar.userObj;
1396 CellNetworkScanResult cellScanResult;
1397 if (ar.exception == null && ar.result != null) {
1398 cellScanResult = new CellNetworkScanResult(
1399 CellNetworkScanResult.STATUS_SUCCESS,
1400 (List<OperatorInfo>) ar.result);
1401 } else {
1402 if (ar.result == null) {
1403 loge("getCellNetworkScanResults: Empty response");
1404 }
1405 if (ar.exception != null) {
1406 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1407 }
1408 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1409 if (ar.exception instanceof CommandException) {
1410 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001411 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001412 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1413 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1414 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1415 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1416 }
1417 }
1418 cellScanResult = new CellNetworkScanResult(errorCode, null);
1419 }
1420 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001421 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001422 break;
1423
1424 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1425 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001426 ManualNetworkSelectionArgument selArg =
1427 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001428 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1429 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001430 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1431 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001432 break;
1433
1434 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001435 ar = (AsyncResult) msg.obj;
1436 request = (MainThreadRequest) ar.userObj;
1437 if (ar.exception == null) {
1438 request.result = true;
1439 } else {
1440 request.result = false;
1441 loge("setNetworkSelectionModeManual " + ar.exception);
1442 }
1443 notifyRequester(request);
1444 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001445 break;
1446
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001447 case CMD_GET_MODEM_ACTIVITY_INFO:
1448 request = (MainThreadRequest) msg.obj;
1449 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001450 if (defaultPhone != null) {
1451 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001452 } else {
1453 ResultReceiver result = (ResultReceiver) request.argument;
1454 Bundle bundle = new Bundle();
1455 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001456 new ModemActivityInfo(0, 0, 0,
1457 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001458 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001459 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001460 break;
1461
Hall Liud0f208c2020-10-14 16:54:44 -07001462 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001463 ar = (AsyncResult) msg.obj;
1464 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001465 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001466 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001467 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001468 if (mLastModemActivityInfo == null) {
1469 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1470 mLastModemActivitySpecificInfo[0] =
1471 new ActivityStatsTechSpecificInfo(
1472 0,
1473 0,
1474 new int[ModemActivityInfo.getNumTxPowerLevels()],
1475 0);
1476 mLastModemActivityInfo =
1477 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1478 }
1479
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001480 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001481 // Update the last modem activity info and the result of the request.
1482 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1483 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001484 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001485 } else {
1486 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001487 }
Kai Shi917fdc62022-11-28 14:01:02 -08001488 // This is needed to decouple ret from mLastModemActivityInfo
1489 // We don't want to return mLastModemActivityInfo which is updated
1490 // inside mergeModemActivityInfo()
1491 ret = new ModemActivityInfo(
1492 mLastModemActivityInfo.getTimestampMillis(),
1493 mLastModemActivityInfo.getSleepTimeMillis(),
1494 mLastModemActivityInfo.getIdleTimeMillis(),
1495 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001496
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001497 } else {
1498 if (ar.result == null) {
1499 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001500 error = TelephonyManager.ModemActivityInfoException
1501 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001502 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001503 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001504 error = TelephonyManager.ModemActivityInfoException
1505 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001506 } else {
1507 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001508 error = TelephonyManager.ModemActivityInfoException
1509 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001510 }
1511 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001512 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001513 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001514 bundle.putParcelable(
1515 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001516 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001517 } else {
1518 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1519 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001520 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001521 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001522 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001523 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001524
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001525 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001526 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001527 CarrierRestrictionRules argument =
1528 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001529 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001530 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001531 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001532 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001533
1534 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1535 ar = (AsyncResult) msg.obj;
1536 request = (MainThreadRequest) ar.userObj;
1537 if (ar.exception == null && ar.result != null) {
1538 request.result = ar.result;
1539 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001540 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1541 if (ar.exception instanceof CommandException) {
1542 loge("setAllowedCarriers: CommandException: " + ar.exception);
1543 CommandException.Error error =
1544 ((CommandException) (ar.exception)).getCommandError();
1545 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1546 request.result =
1547 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1548 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001549 } else {
1550 loge("setAllowedCarriers: Unknown exception");
1551 }
1552 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001553 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001554 break;
1555
1556 case CMD_GET_ALLOWED_CARRIERS:
1557 request = (MainThreadRequest) msg.obj;
1558 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001559 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001560 break;
1561
1562 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1563 ar = (AsyncResult) msg.obj;
1564 request = (MainThreadRequest) ar.userObj;
1565 if (ar.exception == null && ar.result != null) {
1566 request.result = ar.result;
1567 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001568 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001569 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001570 if (ar.result == null) {
1571 loge("getAllowedCarriers: Empty response");
1572 } else if (ar.exception instanceof CommandException) {
1573 loge("getAllowedCarriers: CommandException: " +
1574 ar.exception);
1575 } else {
1576 loge("getAllowedCarriers: Unknown exception");
1577 }
1578 }
arunvoddud7401012022-12-15 16:08:12 +00001579 if (request.argument != null) {
1580 // This is for the implementation of carrierRestrictionStatus.
1581 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1582 Consumer<Integer> callback = callbackInfo.getConsumer();
1583 int callerCarrierId = callbackInfo.getCarrierId();
1584 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1585 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1586 CarrierRestrictionRules carrierRestrictionRules =
1587 (CarrierRestrictionRules) ar.result;
1588 int carrierId = -1;
1589 try {
1590 CarrierIdentifier carrierIdentifier =
1591 carrierRestrictionRules.getAllowedCarriers().get(0);
1592 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1593 carrierIdentifier);
1594 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1595 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1596 }
1597 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1598 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1599 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001600 lockStatus = TelephonyManager
1601 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001602 }
1603 } else {
1604 Rlog.e(LOG_TAG,
1605 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1606 }
1607 callback.accept(lockStatus);
1608 } else {
1609 // This is for the implementation of getAllowedCarriers.
1610 notifyRequester(request);
1611 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001612 break;
1613
Nathan Haroldb3014052017-01-25 15:57:32 -08001614 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1615 ar = (AsyncResult) msg.obj;
1616 request = (MainThreadRequest) ar.userObj;
1617 if (ar.exception == null && ar.result != null) {
1618 request.result = ar.result;
1619 } else {
1620 request.result = new IllegalArgumentException(
1621 "Failed to retrieve Forbidden Plmns");
1622 if (ar.result == null) {
1623 loge("getForbiddenPlmns: Empty response");
1624 } else {
1625 loge("getForbiddenPlmns: Unknown exception");
1626 }
1627 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001628 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001629 break;
1630
1631 case CMD_GET_FORBIDDEN_PLMNS:
1632 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001633 uiccPort = getUiccPortFromRequest(request);
1634 if (uiccPort == null) {
1635 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001636 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001637 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001638 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001639 break;
1640 }
1641 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001642 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001643 if (uiccApp == null) {
1644 loge("getForbiddenPlmns() no app with specified type -- "
1645 + appType);
1646 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001647 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001648 break;
1649 } else {
1650 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1651 + " specified type -- " + appType);
1652 }
1653 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1654 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001655 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001656 break;
1657
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001658 case CMD_SWITCH_SLOTS:
1659 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001660 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001661 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001662 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001663 break;
1664
1665 case EVENT_SWITCH_SLOTS_DONE:
1666 ar = (AsyncResult) msg.obj;
1667 request = (MainThreadRequest) ar.userObj;
1668 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001669 notifyRequester(request);
1670 break;
1671 case CMD_GET_NETWORK_SELECTION_MODE:
1672 request = (MainThreadRequest) msg.obj;
1673 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1674 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1675 break;
1676
1677 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1678 ar = (AsyncResult) msg.obj;
1679 request = (MainThreadRequest) ar.userObj;
1680 if (ar.exception != null) {
1681 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1682 } else {
1683 int mode = ((int[]) ar.result)[0];
1684 if (mode == 0) {
1685 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1686 } else {
1687 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1688 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001689 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001690 notifyRequester(request);
1691 break;
1692 case CMD_GET_CDMA_ROAMING_MODE:
1693 request = (MainThreadRequest) msg.obj;
1694 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1695 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1696 break;
1697 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1698 ar = (AsyncResult) msg.obj;
1699 request = (MainThreadRequest) ar.userObj;
1700 if (ar.exception != null) {
1701 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1702 } else {
1703 request.result = ((int[]) ar.result)[0];
1704 }
1705 notifyRequester(request);
1706 break;
1707 case CMD_SET_CDMA_ROAMING_MODE:
1708 request = (MainThreadRequest) msg.obj;
1709 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1710 int mode = (int) request.argument;
1711 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1712 break;
1713 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1714 ar = (AsyncResult) msg.obj;
1715 request = (MainThreadRequest) ar.userObj;
1716 request.result = ar.exception == null;
1717 notifyRequester(request);
1718 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001719 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1720 request = (MainThreadRequest) msg.obj;
1721 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1722 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1723 break;
1724 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1725 ar = (AsyncResult) msg.obj;
1726 request = (MainThreadRequest) ar.userObj;
1727 if (ar.exception != null) {
1728 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1729 } else {
1730 request.result = ((int[]) ar.result)[0];
1731 }
1732 notifyRequester(request);
1733 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001734 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1735 request = (MainThreadRequest) msg.obj;
1736 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1737 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001738 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1739 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001740 break;
1741 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1742 ar = (AsyncResult) msg.obj;
1743 request = (MainThreadRequest) ar.userObj;
1744 request.result = ar.exception == null;
1745 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001746 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001747 case CMD_GET_ALL_CELL_INFO:
1748 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001749 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001750 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001751 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001752 case EVENT_GET_ALL_CELL_INFO_DONE:
1753 ar = (AsyncResult) msg.obj;
1754 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001755 // If a timeout occurs, the response will be null
1756 request.result = (ar.exception == null && ar.result != null)
1757 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001758 synchronized (request) {
1759 request.notifyAll();
1760 }
1761 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001762 case CMD_REQUEST_CELL_INFO_UPDATE:
1763 request = (MainThreadRequest) msg.obj;
1764 request.phone.requestCellInfoUpdate(request.workSource,
1765 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1766 break;
1767 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1768 ar = (AsyncResult) msg.obj;
1769 request = (MainThreadRequest) ar.userObj;
1770 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1771 try {
1772 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001773 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001774 cb.onError(
1775 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1776 ar.exception.getClass().getName(),
1777 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001778 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001779 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001780 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001781 } else {
1782 // use the result as returned
1783 cb.onCellInfo((List<CellInfo>) ar.result);
1784 }
1785 } catch (RemoteException re) {
1786 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1787 }
1788 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001789 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001790 request = (MainThreadRequest) msg.obj;
1791 WorkSource ws = (WorkSource) request.argument;
1792 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001793 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001794 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001795 }
1796 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001797 ar = (AsyncResult) msg.obj;
1798 request = (MainThreadRequest) ar.userObj;
1799 if (ar.exception == null) {
1800 request.result = ar.result;
1801 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001802 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001803 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001804 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001805 }
1806
1807 synchronized (request) {
1808 request.notifyAll();
1809 }
1810 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001811 }
chen xu6dac5ab2018-10-26 17:39:23 -07001812 case CMD_MODEM_REBOOT:
1813 request = (MainThreadRequest) msg.obj;
1814 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001815 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001816 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001817 case EVENT_CMD_MODEM_REBOOT_DONE:
1818 handleNullReturnEvent(msg, "rebootModem");
1819 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001820 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001821 request = (MainThreadRequest) msg.obj;
1822 boolean enable = (boolean) request.argument;
1823 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001824 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001825 PhoneConfigurationManager.getInstance()
1826 .enablePhone(request.phone, enable, onCompleted);
1827 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001828 }
Michele Berionne5e411512020-11-13 02:36:59 +00001829 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001830 ar = (AsyncResult) msg.obj;
1831 request = (MainThreadRequest) ar.userObj;
1832 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001833 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001834 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001835 if ((boolean) request.result) {
1836 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1837 updateModemStateMetrics();
1838 } else {
1839 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1840 + ar.exception);
1841 }
1842 notifyRequester(request);
1843 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001844 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001845 case CMD_GET_MODEM_STATUS:
1846 request = (MainThreadRequest) msg.obj;
1847 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1848 PhoneConfigurationManager.getInstance()
1849 .getPhoneStatusFromModem(request.phone, onCompleted);
1850 break;
1851 case EVENT_GET_MODEM_STATUS_DONE:
1852 ar = (AsyncResult) msg.obj;
1853 request = (MainThreadRequest) ar.userObj;
1854 int id = request.phone.getPhoneId();
1855 if (ar.exception == null && ar.result != null) {
1856 request.result = ar.result;
1857 //update the cache as modem status has changed
1858 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1859 (boolean) request.result);
1860 } else {
1861 // Return true if modem status cannot be retrieved. For most cases,
1862 // modem status is on. And for older version modems, GET_MODEM_STATUS
1863 // and disable modem are not supported. Modem is always on.
1864 // TODO: this should be fixed in R to support a third
1865 // status UNKNOWN b/131631629
1866 request.result = true;
1867 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1868 + ar.exception);
1869 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001870 notifyRequester(request);
1871 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001872 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1873 request = (MainThreadRequest) msg.obj;
1874 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1875 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1876 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1877 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1878 break;
1879 }
1880 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1881 ar = (AsyncResult) msg.obj;
1882 request = (MainThreadRequest) ar.userObj;
1883 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1884 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1885 args.second.accept(ar.exception == null);
1886 notifyRequester(request);
1887 break;
1888 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001889 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1890 request = (MainThreadRequest) msg.obj;
1891 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1892 Phone phone = getPhoneFromRequest(request);
1893 if (phone != null) {
1894 phone.getSystemSelectionChannels(onCompleted);
1895 } else {
1896 loge("getSystemSelectionChannels: No phone object");
1897 request.result = new ArrayList<RadioAccessSpecifier>();
1898 notifyRequester(request);
1899 }
1900 break;
1901 }
1902 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1903 ar = (AsyncResult) msg.obj;
1904 request = (MainThreadRequest) ar.userObj;
1905 if (ar.exception == null && ar.result != null) {
1906 request.result = ar.result;
1907 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001908 request.result = new IllegalStateException(
1909 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001910 if (ar.result == null) {
1911 loge("getSystemSelectionChannels: Empty response");
1912 } else {
1913 loge("getSystemSelectionChannels: Unknown exception");
1914 }
1915 }
1916 notifyRequester(request);
1917 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001918 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1919 ar = (AsyncResult) msg.obj;
1920 request = (MainThreadRequest) ar.userObj;
1921 if (ar.exception == null && ar.result != null) {
1922 request.result = ar.result;
1923 } else {
1924 request.result = -1;
1925 loge("Failed to set Forbidden Plmns");
1926 if (ar.result == null) {
1927 loge("setForbidenPlmns: Empty response");
1928 } else if (ar.exception != null) {
1929 loge("setForbiddenPlmns: Exception: " + ar.exception);
1930 request.result = -1;
1931 } else {
1932 loge("setForbiddenPlmns: Unknown exception");
1933 }
1934 }
1935 notifyRequester(request);
1936 break;
1937 case CMD_SET_FORBIDDEN_PLMNS:
1938 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001939 uiccPort = getUiccPortFromRequest(request);
1940 if (uiccPort == null) {
1941 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001942 request.result = -1;
1943 notifyRequester(request);
1944 break;
1945 }
1946 Pair<Integer, List<String>> setFplmnsArgs =
1947 (Pair<Integer, List<String>>) request.argument;
1948 appType = setFplmnsArgs.first;
1949 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001950 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001951 if (uiccApp == null) {
1952 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1953 request.result = -1;
1954 loge("Failed to get UICC App");
1955 notifyRequester(request);
1956 } else {
1957 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1958 ((SIMRecords) uiccApp.getIccRecords())
1959 .setForbiddenPlmns(onCompleted, fplmns);
1960 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001961 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001962 case CMD_ERASE_MODEM_CONFIG:
1963 request = (MainThreadRequest) msg.obj;
1964 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1965 defaultPhone.eraseModemConfig(onCompleted);
1966 break;
1967 case EVENT_ERASE_MODEM_CONFIG_DONE:
1968 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001969 break;
zoey chene02881a2019-12-30 16:11:23 +08001970
Kai Shif70f46f2021-03-03 13:59:46 -08001971 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1972 request = (MainThreadRequest) msg.obj;
1973 request.result = defaultPhone.eraseDataInSharedPreferences();
1974 notifyRequester(request);
1975 break;
1976
zoey chene02881a2019-12-30 16:11:23 +08001977 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1978 request = (MainThreadRequest) msg.obj;
1979 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1980 Pair<String, String> changed = (Pair<String, String>) request.argument;
1981 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1982 changed.first, changed.second, onCompleted);
1983 break;
1984 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1985 ar = (AsyncResult) msg.obj;
1986 request = (MainThreadRequest) ar.userObj;
1987 if (ar.exception == null) {
1988 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001989 // If the operation is successful, update the PIN storage
1990 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1991 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001992 UiccController.getInstance().getPinStorage()
1993 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001994 } else {
1995 request.result = msg.arg1;
1996 }
1997 notifyRequester(request);
1998 break;
1999
Michele Berionne5e411512020-11-13 02:36:59 +00002000 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002001 request = (MainThreadRequest) msg.obj;
2002 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2003 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2004 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2005 enabled.first, enabled.second, onCompleted);
2006 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002007 }
zoey chene02881a2019-12-30 16:11:23 +08002008 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2009 ar = (AsyncResult) msg.obj;
2010 request = (MainThreadRequest) ar.userObj;
2011 if (ar.exception == null) {
2012 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002013 // If the operation is successful, update the PIN storage
2014 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2015 int phoneId = getPhoneFromRequest(request).getPhoneId();
2016 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002017 UiccController.getInstance().getPinStorage()
2018 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002019 } else {
2020 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2021 }
zoey chene02881a2019-12-30 16:11:23 +08002022 } else {
2023 request.result = msg.arg1;
2024 }
Michele Berionne5e411512020-11-13 02:36:59 +00002025
2026
zoey chene02881a2019-12-30 16:11:23 +08002027 notifyRequester(request);
2028 break;
2029
Peter Wangdafb9ac2020-01-15 14:13:38 -08002030 case MSG_NOTIFY_USER_ACTIVITY:
2031 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002032 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002033 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2034 getDefaultPhone().getContext().sendBroadcastAsUser(
2035 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2036 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002037
2038 case CMD_SET_DATA_THROTTLING: {
2039 request = (MainThreadRequest) msg.obj;
2040 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2041 DataThrottlingRequest dataThrottlingRequest =
2042 (DataThrottlingRequest) request.argument;
2043 Phone phone = getPhoneFromRequest(request);
2044 if (phone != null) {
2045 phone.setDataThrottling(onCompleted,
2046 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2047 dataThrottlingRequest.getCompletionDurationMillis());
2048 } else {
2049 loge("setDataThrottling: No phone object");
2050 request.result =
2051 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2052 notifyRequester(request);
2053 }
2054
2055 break;
2056 }
2057 case EVENT_SET_DATA_THROTTLING_DONE:
2058 ar = (AsyncResult) msg.obj;
2059 request = (MainThreadRequest) ar.userObj;
2060
2061 if (ar.exception == null) {
2062 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2063 } else if (ar.exception instanceof CommandException) {
2064 loge("setDataThrottling: CommandException: " + ar.exception);
2065 CommandException.Error error =
2066 ((CommandException) (ar.exception)).getCommandError();
2067
2068 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2069 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002070 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002071 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2072 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002073 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2074 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002075 } else {
2076 request.result =
2077 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2078 }
2079 } else {
2080 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2081 }
2082 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2083 notifyRequester(request);
2084 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002085
2086 case CMD_SET_SIM_POWER: {
2087 request = (MainThreadRequest) msg.obj;
2088 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2089 request = (MainThreadRequest) msg.obj;
2090 int stateToSet =
2091 ((Pair<Integer, IIntegerConsumer>)
2092 request.argument).first;
2093 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2094 break;
2095 }
2096 case EVENT_SET_SIM_POWER_DONE: {
2097 ar = (AsyncResult) msg.obj;
2098 request = (MainThreadRequest) ar.userObj;
2099 IIntegerConsumer callback =
2100 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2101 if (ar.exception != null) {
2102 loge("setSimPower exception: " + ar.exception);
2103 int errorCode = TelephonyManager.CallForwardingInfoCallback
2104 .RESULT_ERROR_UNKNOWN;
2105 if (ar.exception instanceof CommandException) {
2106 CommandException.Error error =
2107 ((CommandException) (ar.exception)).getCommandError();
2108 if (error == CommandException.Error.SIM_ERR) {
2109 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2110 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2111 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2112 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2113 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2114 } else {
2115 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2116 }
2117 }
2118 try {
2119 callback.accept(errorCode);
2120 } catch (RemoteException e) {
2121 // Ignore if the remote process is no longer available to call back.
2122 Log.w(LOG_TAG, "setSimPower: callback not available.");
2123 }
2124 } else {
2125 try {
2126 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2127 } catch (RemoteException e) {
2128 // Ignore if the remote process is no longer available to call back.
2129 Log.w(LOG_TAG, "setSimPower: callback not available.");
2130 }
2131 }
2132 break;
2133 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002134 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2135 request = (MainThreadRequest) msg.obj;
2136
2137 final Phone phone = getPhoneFromRequest(request);
2138 if (phone == null || phone.getServiceStateTracker() == null) {
2139 request.result = new IllegalStateException("Phone or SST is null");
2140 notifyRequester(request);
2141 break;
2142 }
2143
2144 Pair<Integer, SignalStrengthUpdateRequest> pair =
2145 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2146 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2147 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002148 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002149 request.subId, pair.first /*callingUid*/,
2150 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002151 break;
2152 }
2153 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2154 ar = (AsyncResult) msg.obj;
2155 request = (MainThreadRequest) ar.userObj;
2156 // request.result will be the exception of ar if present, true otherwise.
2157 // Be cautious not to leave result null which will wait() forever
2158 request.result = ar.exception != null ? ar.exception : true;
2159 notifyRequester(request);
2160 break;
2161 }
2162 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2163 request = (MainThreadRequest) msg.obj;
2164
2165 Phone phone = getPhoneFromRequest(request);
2166 if (phone == null || phone.getServiceStateTracker() == null) {
2167 request.result = new IllegalStateException("Phone or SST is null");
2168 notifyRequester(request);
2169 break;
2170 }
2171
2172 Pair<Integer, SignalStrengthUpdateRequest> pair =
2173 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2174 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2175 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002176 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002177 request.subId, pair.first /*callingUid*/,
2178 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002179 break;
2180 }
2181 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2182 ar = (AsyncResult) msg.obj;
2183 request = (MainThreadRequest) ar.userObj;
2184 request.result = ar.exception != null ? ar.exception : true;
2185 notifyRequester(request);
2186 break;
2187 }
Jordan Liu109698e2020-11-24 14:50:34 -08002188
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002189 case CMD_GET_SLICING_CONFIG: {
2190 request = (MainThreadRequest) msg.obj;
2191 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2192 request.phone.getSlicingConfig(onCompleted);
2193 break;
2194 }
2195 case EVENT_GET_SLICING_CONFIG_DONE: {
2196 ar = (AsyncResult) msg.obj;
2197 request = (MainThreadRequest) ar.userObj;
2198 ResultReceiver result = (ResultReceiver) request.argument;
2199
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002200 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002201 Bundle bundle = new Bundle();
2202 int resultCode = 0;
2203 if (ar.exception != null) {
2204 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2205 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002206 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002207 } else if (ar.result == null) {
2208 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002209 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002210 } else {
2211 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002212 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2213 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002214 }
2215
2216 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002217 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002218 }
2219 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2220 result.send(resultCode, bundle);
2221 notifyRequester(request);
2222 break;
2223 }
2224
Sarah Chin71b3a852022-09-28 15:54:19 -07002225 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002226 request = (MainThreadRequest) msg.obj;
2227 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002228 PurchasePremiumCapabilityArgument arg =
2229 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002230 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chinb8218c22023-01-04 13:35:29 -08002231 arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002232 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002233 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002234
Sarah Chin71b3a852022-09-28 15:54:19 -07002235 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002236 ar = (AsyncResult) msg.obj;
2237 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002238 PurchasePremiumCapabilityArgument arg =
2239 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002240 try {
2241 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002242 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002243 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002244 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002245 + ", result= "
2246 + TelephonyManager.convertPurchaseResultToString(result));
2247 } catch (RemoteException e) {
2248 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002249 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002250 + " failed: " + e;
2251 if (DBG) log(logStr);
2252 AnomalyReporter.reportAnomaly(
2253 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2254 }
2255 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002256 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002257
Michele Berionne5e411512020-11-13 02:36:59 +00002258 case CMD_PREPARE_UNATTENDED_REBOOT:
2259 request = (MainThreadRequest) msg.obj;
2260 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002261 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002262 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002263 notifyRequester(request);
2264 break;
2265
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 default:
2267 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2268 break;
2269 }
2270 }
Jake Hambye994d462014-02-03 13:10:13 -08002271
Pengquan Menga1bb6272018-09-06 09:59:22 -07002272 private void notifyRequester(MainThreadRequest request) {
2273 synchronized (request) {
2274 request.notifyAll();
2275 }
2276 }
2277
Jake Hambye994d462014-02-03 13:10:13 -08002278 private void handleNullReturnEvent(Message msg, String command) {
2279 AsyncResult ar = (AsyncResult) msg.obj;
2280 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2281 if (ar.exception == null) {
2282 request.result = true;
2283 } else {
2284 request.result = false;
2285 if (ar.exception instanceof CommandException) {
2286 loge(command + ": CommandException: " + ar.exception);
2287 } else {
2288 loge(command + ": Unknown exception");
2289 }
2290 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002291 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002292 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293 }
2294
2295 /**
2296 * Posts the specified command to be executed on the main thread,
2297 * waits for the request to complete, and returns the result.
2298 * @see #sendRequestAsync
2299 */
2300 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002301 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2302 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002303 }
2304
2305 /**
2306 * Posts the specified command to be executed on the main thread,
2307 * waits for the request to complete, and returns the result.
2308 * @see #sendRequestAsync
2309 */
2310 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2311 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002312 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002313 }
2314
2315 /**
2316 * Posts the specified command to be executed on the main thread,
2317 * waits for the request to complete, and returns the result.
2318 * @see #sendRequestAsync
2319 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002320 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002321 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2322 }
2323
2324 /**
2325 * Posts the specified command to be executed on the main thread,
2326 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2327 * if not timeout or null otherwise.
2328 * @see #sendRequestAsync
2329 */
2330 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2331 long timeoutInMs) {
2332 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002333 }
2334
2335 /**
2336 * Posts the specified command to be executed on the main thread,
2337 * waits for the request to complete, and returns the result.
2338 * @see #sendRequestAsync
2339 */
Nathan Harold92bed182018-10-12 18:16:49 -07002340 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002341 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002342 }
2343
2344 /**
2345 * Posts the specified command to be executed on the main thread,
2346 * waits for the request to complete, and returns the result.
2347 * @see #sendRequestAsync
2348 */
2349 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002350 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2351 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002352 }
2353
2354 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002355 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2356 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2357 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002358 * @see #sendRequestAsync
2359 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002360 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2361 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2363 throw new RuntimeException("This method will deadlock if called from the main thread.");
2364 }
2365
Nathan Harold92bed182018-10-12 18:16:49 -07002366 MainThreadRequest request = null;
2367 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2368 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2369 } else if (phone != null) {
2370 request = new MainThreadRequest(argument, phone, workSource);
2371 } else {
2372 request = new MainThreadRequest(argument, subId, workSource);
2373 }
2374
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 Message msg = mMainThreadHandler.obtainMessage(command, request);
2376 msg.sendToTarget();
2377
Rambo Wang0f050d82021-02-12 11:43:36 -08002378
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002380 if (timeoutInMs >= 0) {
2381 // Wait for at least timeoutInMs before returning null request result
2382 long now = SystemClock.elapsedRealtime();
2383 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002384 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002385 try {
2386 request.wait(deadline - now);
2387 } catch (InterruptedException e) {
2388 // Do nothing, go back and check if request is completed or timeout
2389 } finally {
2390 now = SystemClock.elapsedRealtime();
2391 }
2392 }
2393 } else {
2394 // Wait for the request to complete
2395 while (request.result == null) {
2396 try {
2397 request.wait();
2398 } catch (InterruptedException e) {
2399 // Do nothing, go back and wait until the request is complete
2400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002401 }
2402 }
2403 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002404 if (request.result == null) {
2405 Log.wtf(LOG_TAG,
2406 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2407 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 return request.result;
2409 }
2410
2411 /**
2412 * Asynchronous ("fire and forget") version of sendRequest():
2413 * Posts the specified command to be executed on the main thread, and
2414 * returns immediately.
2415 * @see #sendRequest
2416 */
2417 private void sendRequestAsync(int command) {
2418 mMainThreadHandler.sendEmptyMessage(command);
2419 }
2420
2421 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002422 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002423 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002424 */
2425 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002426 sendRequestAsync(command, argument, null, null);
2427 }
2428
2429 /**
2430 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2431 * @see {@link #sendRequest(int,Object)}
2432 */
2433 private void sendRequestAsync(
2434 int command, Object argument, Phone phone, WorkSource workSource) {
2435 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002436 Message msg = mMainThreadHandler.obtainMessage(command, request);
2437 msg.sendToTarget();
2438 }
2439
2440 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 * Initialize the singleton PhoneInterfaceManager instance.
2442 * This is only done once, at startup, from PhoneApp.onCreate().
2443 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002444 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 synchronized (PhoneInterfaceManager.class) {
2446 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002447 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 } else {
2449 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2450 }
2451 return sInstance;
2452 }
2453 }
2454
2455 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002456 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002459 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002460 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002461 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2463 mMainThreadHandler = new MainThreadHandler();
Jack Yue37dd262022-12-16 11:53:37 -08002464 if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) {
2465 mSubscriptionController = SubscriptionController.getInstance();
2466 } else {
2467 mSubscriptionController = null;
2468 }
Sarah Chin4beb2b72023-02-14 14:47:54 -08002469 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002470 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002471 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002472 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002473 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002474 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 publish();
arunvoddud7401012022-12-15 16:08:12 +00002476 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 }
2478
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002479 @VisibleForTesting
2480 public SharedPreferences getSharedPreferences() {
2481 return mTelephonySharedPreferences;
2482 }
2483
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002484 /**
2485 * Get the default phone for this device.
2486 */
2487 @VisibleForTesting
2488 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002489 Phone thePhone = getPhone(getDefaultSubscription());
2490 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2491 }
2492
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 private void publish() {
2494 if (DBG) log("publish: " + this);
2495
Peter Wangc035ce42020-01-08 21:00:22 -08002496 TelephonyFrameworkInitializer
2497 .getTelephonyServiceManager()
2498 .getTelephonyServiceRegisterer()
2499 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 }
2501
Stuart Scott584921c2015-01-15 17:10:34 -08002502 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002503 if (request.phone != null) {
2504 return request.phone;
2505 } else {
2506 return getPhoneFromSubId(request.subId);
2507 }
2508 }
2509
2510 private Phone getPhoneFromSubId(int subId) {
2511 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2512 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002513 }
2514
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002515 /**
2516 * Get phone object associated with a subscription.
2517 * Return default phone if phone object associated with subscription is null
2518 * @param subId - subscriptionId
2519 * @return phone object associated with a subscription or default phone if null.
2520 */
Ling Mac28f0212023-03-24 16:07:15 -07002521 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002522 Phone phone = getPhoneFromSubId(subId);
2523 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002524 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002525 phone = getDefaultPhone();
2526 }
2527 return phone;
2528 }
2529
Rambo Wange53e07d2022-05-10 13:01:13 -07002530 @Nullable
2531 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002532 Phone phone = getPhoneFromRequest(request);
2533 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002534 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002535 }
2536
Ling Mac28f0212023-03-24 16:07:15 -07002537 /**
2538 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2539 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2540 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2541 * @return The Phone associated the sub Id
2542 */
2543 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002544 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002546
Kai Shif70f46f2021-03-03 13:59:46 -08002547 private void sendEraseModemConfig(@NonNull Phone phone) {
2548 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2549 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2550 }
2551
2552 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2553 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2554 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002555 }
2556
Peter Wang44b186e2020-01-13 23:33:09 -08002557 private boolean isImsAvailableOnDevice() {
2558 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2559 if (pm == null) {
2560 // For some reason package manger is not available.. This will fail internally anyway,
2561 // so do not throw error and allow.
2562 return true;
2563 }
2564 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2565 }
2566
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002567 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002568 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002569 }
2570
Wink Savilleb564aae2014-10-23 10:18:09 -07002571 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572 if (DBG) log("dial: " + number);
2573 // No permission check needed here: This is just a wrapper around the
2574 // ACTION_DIAL intent, which is available to any app since it puts up
2575 // the UI before it does anything.
2576
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002577 final long identity = Binder.clearCallingIdentity();
2578 try {
2579 String url = createTelUrl(number);
2580 if (url == null) {
2581 return;
2582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002583
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002584 // PENDING: should we just silently fail if phone is offhook or ringing?
2585 PhoneConstants.State state = mCM.getState(subId);
2586 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2587 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2588 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2589 mApp.startActivity(intent);
2590 }
2591 } finally {
2592 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002593 }
2594 }
2595
2596 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002597 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002598 }
2599
Wink Savilleb564aae2014-10-23 10:18:09 -07002600 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002601 if (DBG) log("call: " + number);
2602
2603 // This is just a wrapper around the ACTION_CALL intent, but we still
2604 // need to do a permission check since we're calling startActivity()
2605 // from the context of the phone app.
2606 enforceCallPermission();
2607
Jordan Liu1617b712019-07-10 15:06:26 -07002608 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002609 != AppOpsManager.MODE_ALLOWED) {
2610 return;
2611 }
2612
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613 final long identity = Binder.clearCallingIdentity();
2614 try {
2615 String url = createTelUrl(number);
2616 if (url == null) {
2617 return;
2618 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002619
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002620 boolean isValid = false;
2621 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2622 if (slist != null) {
2623 for (SubscriptionInfo subInfoRecord : slist) {
2624 if (subInfoRecord.getSubscriptionId() == subId) {
2625 isValid = true;
2626 break;
2627 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002628 }
Wink Saville08874612014-08-31 19:19:58 -07002629 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002630 if (!isValid) {
2631 return;
2632 }
Wink Saville08874612014-08-31 19:19:58 -07002633
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002634 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2635 intent.putExtra(SUBSCRIPTION_KEY, subId);
2636 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2637 mApp.startActivity(intent);
2638 } finally {
2639 Binder.restoreCallingIdentity(identity);
2640 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002641 }
2642
Wink Savilleb564aae2014-10-23 10:18:09 -07002643 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002644 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002645 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2646 }
2647
Wink Savilleb564aae2014-10-23 10:18:09 -07002648 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002649 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002650 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2651 }
2652
Wink Savilleb564aae2014-10-23 10:18:09 -07002653 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002654 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655
2656 final long identity = Binder.clearCallingIdentity();
2657 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002658 Phone phone = getPhone(subId);
2659 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002660 checkSimPin.start();
2661 return checkSimPin.unlockSim(null, pin);
2662 } finally {
2663 Binder.restoreCallingIdentity(identity);
2664 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665 }
2666
Wink Savilleb564aae2014-10-23 10:18:09 -07002667 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002668 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002669
2670 final long identity = Binder.clearCallingIdentity();
2671 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002672 Phone phone = getPhone(subId);
2673 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002674 checkSimPuk.start();
2675 return checkSimPuk.unlockSim(puk, pin);
2676 } finally {
2677 Binder.restoreCallingIdentity(identity);
2678 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002679 }
2680
2681 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002682 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002683 * a synchronous one.
2684 */
2685 private static class UnlockSim extends Thread {
2686
2687 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002688 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002689
2690 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002691 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2692 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693
2694 // For replies from SimCard interface
2695 private Handler mHandler;
2696
2697 // For async handler to identify request type
2698 private static final int SUPPLY_PIN_COMPLETE = 100;
2699
Michele Berionne5e411512020-11-13 02:36:59 +00002700 UnlockSim(int phoneId, IccCard simCard) {
2701 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002702 mSimCard = simCard;
2703 }
2704
2705 @Override
2706 public void run() {
2707 Looper.prepare();
2708 synchronized (UnlockSim.this) {
2709 mHandler = new Handler() {
2710 @Override
2711 public void handleMessage(Message msg) {
2712 AsyncResult ar = (AsyncResult) msg.obj;
2713 switch (msg.what) {
2714 case SUPPLY_PIN_COMPLETE:
2715 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2716 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002717 mRetryCount = msg.arg1;
2718 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002719 CommandException.Error error = null;
2720 if (ar.exception instanceof CommandException) {
2721 error = ((CommandException) (ar.exception))
2722 .getCommandError();
2723 }
2724 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002725 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002726 } else if (error == CommandException.Error.ABORTED) {
2727 /* When UiccCardApp dispose, handle message and return
2728 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002729 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002730 } else {
2731 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2732 }
2733 } else {
2734 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2735 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002736 mDone = true;
2737 UnlockSim.this.notifyAll();
2738 }
2739 break;
2740 }
2741 }
2742 };
2743 UnlockSim.this.notifyAll();
2744 }
2745 Looper.loop();
2746 }
2747
2748 /*
2749 * Use PIN or PUK to unlock SIM card
2750 *
2751 * If PUK is null, unlock SIM card with PIN
2752 *
2753 * If PUK is not null, unlock SIM card with PUK and set PIN code
2754 */
Wink Saville9de0f752013-10-22 19:04:03 -07002755 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002756
2757 while (mHandler == null) {
2758 try {
2759 wait();
2760 } catch (InterruptedException e) {
2761 Thread.currentThread().interrupt();
2762 }
2763 }
2764 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2765
2766 if (puk == null) {
2767 mSimCard.supplyPin(pin, callback);
2768 } else {
2769 mSimCard.supplyPuk(puk, pin, callback);
2770 }
2771
2772 while (!mDone) {
2773 try {
2774 Log.d(LOG_TAG, "wait for done");
2775 wait();
2776 } catch (InterruptedException e) {
2777 // Restore the interrupted status
2778 Thread.currentThread().interrupt();
2779 }
2780 }
2781 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002782 int[] resultArray = new int[2];
2783 resultArray[0] = mResult;
2784 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002785
2786 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002787 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002788 }
2789
Wink Saville9de0f752013-10-22 19:04:03 -07002790 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002791 }
2792 }
2793
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002794 /**
2795 * This method has been removed due to privacy and stability concerns.
2796 */
2797 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002798 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002799 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2800 return;
Wink Saville36469e72014-06-11 15:17:00 -07002801 }
2802
Nathan Harold1f889d82020-06-04 17:05:26 -07002803 @Override
2804 public void updateServiceLocationWithPackageName(String callingPackage) {
2805 mApp.getSystemService(AppOpsManager.class)
2806 .checkPackage(Binder.getCallingUid(), callingPackage);
2807
Nathan Haroldf096d982020-11-18 17:18:06 -08002808 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002809 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2810 // Callers targeting S have no business invoking this method.
2811 return;
2812 }
2813
2814 LocationAccessPolicy.LocationPermissionResult locationResult =
2815 LocationAccessPolicy.checkLocationPermission(mApp,
2816 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2817 .setCallingPackage(callingPackage)
2818 .setCallingFeatureId(null)
2819 .setCallingPid(Binder.getCallingPid())
2820 .setCallingUid(Binder.getCallingUid())
2821 .setMethod("updateServiceLocation")
2822 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2823 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2824 .build());
2825 // Apps that lack location permission have no business calling this method;
2826 // however, because no permission was declared in the public API, denials must
2827 // all be "soft".
2828 switch (locationResult) {
2829 case DENIED_HARD: /* fall through */
2830 case DENIED_SOFT:
2831 return;
2832 }
2833
2834 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002835 final long identity = Binder.clearCallingIdentity();
2836 try {
Ling Mac28f0212023-03-24 16:07:15 -07002837 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002838 } finally {
2839 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002840 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002841 }
2842
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002843 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002844 @Override
2845 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002846 return isRadioOnWithFeature(callingPackage, null);
2847 }
2848
2849
2850 @Override
2851 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2852 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2853 callingFeatureId);
2854 }
2855
2856 @Deprecated
2857 @Override
2858 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2859 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002860 }
2861
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002862 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002863 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2864 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002865 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002866 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002867 return false;
2868 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002869
2870 final long identity = Binder.clearCallingIdentity();
2871 try {
2872 return isRadioOnForSubscriber(subId);
2873 } finally {
2874 Binder.restoreCallingIdentity(identity);
2875 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002876 }
2877
2878 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002879 final long identity = Binder.clearCallingIdentity();
2880 try {
2881 final Phone phone = getPhone(subId);
2882 if (phone != null) {
2883 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2884 } else {
2885 return false;
2886 }
2887 } finally {
2888 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002890 }
2891
2892 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002893 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002894 }
Wink Saville36469e72014-06-11 15:17:00 -07002895
Wink Savilleb564aae2014-10-23 10:18:09 -07002896 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002897 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002898
2899 final long identity = Binder.clearCallingIdentity();
2900 try {
2901 final Phone phone = getPhone(subId);
2902 if (phone != null) {
2903 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2904 }
2905 } finally {
2906 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002907 }
Wink Saville36469e72014-06-11 15:17:00 -07002908 }
2909
2910 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002911 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002912 }
2913
Wink Savilleb564aae2014-10-23 10:18:09 -07002914 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002915 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002916
2917 final long identity = Binder.clearCallingIdentity();
2918 try {
2919 final Phone phone = getPhone(subId);
2920 if (phone == null) {
2921 return false;
2922 }
2923 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2924 toggleRadioOnOffForSubscriber(subId);
2925 }
2926 return true;
2927 } finally {
2928 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002929 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 }
Wink Saville36469e72014-06-11 15:17:00 -07002931
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002932 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002933 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002934 /*
2935 * If any of the Radios are available, it will need to be
2936 * shutdown. So return true if any Radio is available.
2937 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938 final long identity = Binder.clearCallingIdentity();
2939 try {
2940 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2941 Phone phone = PhoneFactory.getPhone(i);
2942 if (phone != null && phone.isRadioAvailable()) return true;
2943 }
2944 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2945 return false;
2946 } finally {
2947 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002948 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002949 }
2950
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002952 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002953 enforceModifyPermission();
2954
2955 final long identity = Binder.clearCallingIdentity();
2956 try {
2957 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2958 logv("Shutting down Phone " + i);
2959 shutdownRadioUsingPhoneId(i);
2960 }
2961 } finally {
2962 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002963 }
2964 }
2965
2966 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002967 Phone phone = PhoneFactory.getPhone(phoneId);
2968 if (phone != null && phone.isRadioAvailable()) {
2969 phone.shutdownRadio();
2970 }
2971 }
2972
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002973 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002974 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002975
Ling Ma83dc5ea2023-01-12 15:06:04 -08002976 if (!turnOn) {
2977 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
2978 }
2979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2983 if (defaultPhone != null) {
2984 defaultPhone.setRadioPower(turnOn);
2985 return true;
2986 } else {
2987 loge("There's no default phone.");
2988 return false;
2989 }
2990 } finally {
2991 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002992 }
Wink Saville36469e72014-06-11 15:17:00 -07002993 }
2994
Wink Savilleb564aae2014-10-23 10:18:09 -07002995 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002996 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002997
Ling Ma83dc5ea2023-01-12 15:06:04 -08002998 if (!turnOn) {
2999 log("setRadioPowerForSubscriber off: subId=" + subId
3000 + ",callingPackage=" + getCurrentPackageName());
3001 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002 final long identity = Binder.clearCallingIdentity();
3003 try {
3004 final Phone phone = getPhone(subId);
3005 if (phone != null) {
3006 phone.setRadioPower(turnOn);
3007 return true;
3008 } else {
3009 return false;
3010 }
3011 } finally {
3012 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003013 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003014 }
3015
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003016 /**
3017 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3018 * no reason to power it off. When any of the voters want to power it off, it will be turned
3019 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3020 * powering it off, and these radio off votes will be cleared.
3021 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3022 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3023 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3024 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3025 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3026 * check its vote.
3027 *
3028 * @param subId The subscription ID.
3029 * @param reason The reason for powering off radio.
3030 * @return true on success and false on failure.
3031 */
3032 public boolean requestRadioPowerOffForReason(int subId,
3033 @TelephonyManager.RadioPowerReason int reason) {
3034 enforceModifyPermission();
3035
Ling Ma83dc5ea2023-01-12 15:06:04 -08003036 log("requestRadioPowerOffForReason: subId=" + subId
3037 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003038 final long identity = Binder.clearCallingIdentity();
3039 try {
3040 final Phone phone = getPhone(subId);
3041 if (phone != null) {
3042 phone.setRadioPowerForReason(false, reason);
3043 return true;
3044 } else {
3045 return false;
3046 }
3047 } finally {
3048 Binder.restoreCallingIdentity(identity);
3049 }
3050 }
3051
3052 /**
3053 * Remove the vote on powering off the radio for a reason, as requested by
3054 * {@link requestRadioPowerOffForReason}.
3055 *
3056 * @param subId The subscription ID.
3057 * @param reason The reason for powering off radio.
3058 * @return true on success and false on failure.
3059 */
3060 public boolean clearRadioPowerOffForReason(int subId,
3061 @TelephonyManager.RadioPowerReason int reason) {
3062 enforceModifyPermission();
3063
3064 final long identity = Binder.clearCallingIdentity();
3065 try {
3066 final Phone phone = getPhone(subId);
3067 if (phone != null) {
3068 phone.setRadioPowerForReason(true, reason);
3069 return true;
3070 } else {
3071 return false;
3072 }
3073 } finally {
3074 Binder.restoreCallingIdentity(identity);
3075 }
3076 }
3077
3078 /**
3079 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3080 *
3081 * @param subId The subscription ID.
3082 * @param callingPackage The package making the call.
3083 * @param callingFeatureId The feature in the package.
3084 * @return List of reasons for powering off radio.
3085 */
3086 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3087 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3088
3089 final long identity = Binder.clearCallingIdentity();
3090 List result = new ArrayList();
3091 try {
3092 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3093 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3094 return result;
3095 }
3096
3097 final Phone phone = getPhone(subId);
3098 if (phone != null) {
3099 result.addAll(phone.getRadioPowerOffReasons());
3100 }
3101 } finally {
3102 Binder.restoreCallingIdentity(identity);
3103 }
3104 return result;
3105 }
3106
Wink Saville36469e72014-06-11 15:17:00 -07003107 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003108 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003109 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003110 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003111
3112 final long identity = Binder.clearCallingIdentity();
3113 try {
Jack Yu285100e2022-12-02 22:48:35 -08003114 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003115 final Phone phone = getPhone(subId);
3116 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003117 phone.getDataSettingsManager().setDataEnabled(
3118 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003119 return true;
3120 } else {
3121 return false;
3122 }
3123 } finally {
3124 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003125 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003126 }
3127
Wink Saville36469e72014-06-11 15:17:00 -07003128 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003129 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003130 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003131 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003132
3133 final long identity = Binder.clearCallingIdentity();
3134 try {
Jack Yu285100e2022-12-02 22:48:35 -08003135 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003136 final Phone phone = getPhone(subId);
3137 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003138 phone.getDataSettingsManager().setDataEnabled(
3139 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003140 return true;
3141 } else {
3142 return false;
3143 }
3144 } finally {
3145 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003146 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003147 }
3148
Sanket Padawe356d7632015-06-22 14:03:32 -07003149 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003150 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003151 final long identity = Binder.clearCallingIdentity();
3152 try {
3153 final Phone phone = getPhone(subId);
3154 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003155 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003156 } else {
3157 return false;
3158 }
3159 } finally {
3160 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003161 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003162 }
3163
3164 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003165 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003166 }
3167
pkanwarae03a6b2016-11-06 20:37:09 -08003168 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003169 enforceCallPermission();
3170
3171 final long identity = Binder.clearCallingIdentity();
3172 try {
3173 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3174 return;
3175 }
3176 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3177 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3178 } finally {
3179 Binder.restoreCallingIdentity(identity);
3180 }
pkanwar32d516d2016-10-14 19:37:38 -07003181 };
3182
Wink Savilleb564aae2014-10-23 10:18:09 -07003183 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003184 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003185
3186 final long identity = Binder.clearCallingIdentity();
3187 try {
3188 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3189 return false;
3190 }
3191 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3192 } finally {
3193 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003195 }
3196
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003197 /**
3198 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3199 * tag on getCallState Binder call.
3200 */
3201 @Deprecated
3202 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003203 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003204 if (CompatChanges.isChangeEnabled(
3205 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3206 Binder.getCallingUid())) {
3207 // Do not allow this API to be called on API version 31+, it should only be
3208 // called on old apps using this Binder call directly.
3209 throw new SecurityException("This method can only be used for applications "
3210 + "targeting API version 30 or less.");
3211 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212 final long identity = Binder.clearCallingIdentity();
3213 try {
Ling Mac28f0212023-03-24 16:07:15 -07003214 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3215 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003216 } finally {
3217 Binder.restoreCallingIdentity(identity);
3218 }
3219 }
3220
3221 @Override
3222 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3223 if (CompatChanges.isChangeEnabled(
3224 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3225 Binder.getCallingUid())) {
3226 // Check READ_PHONE_STATE for API version 31+
3227 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3228 featureId, "getCallStateForSubscription")) {
3229 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3230 + "targeting API level 31+.");
3231 }
3232 }
3233 final long identity = Binder.clearCallingIdentity();
3234 try {
3235 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003236 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3237 PhoneConstantConversions.convertCallState(phone.getState());
3238 } finally {
3239 Binder.restoreCallingIdentity(identity);
3240 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003241 }
3242
Sanket Padawe356d7632015-06-22 14:03:32 -07003243 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003244 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003245 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003246 }
3247
3248 @Override
3249 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003250 final long identity = Binder.clearCallingIdentity();
3251 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003252 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003253 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003254 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003255 } else {
3256 return PhoneConstantConversions.convertDataState(
3257 PhoneConstants.DataState.DISCONNECTED);
3258 }
3259 } finally {
3260 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003261 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003262 }
3263
Sanket Padawe356d7632015-06-22 14:03:32 -07003264 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003265 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003266 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003267 }
3268
3269 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003270 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003271 final long identity = Binder.clearCallingIdentity();
3272 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003273 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003274 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003275 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003276 } else {
3277 return TelephonyManager.DATA_ACTIVITY_NONE;
3278 }
3279 } finally {
3280 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003282 }
3283
3284 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003285 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003286 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003287 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003288
3289 LocationAccessPolicy.LocationPermissionResult locationResult =
3290 LocationAccessPolicy.checkLocationPermission(mApp,
3291 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3292 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003293 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003294 .setCallingPid(Binder.getCallingPid())
3295 .setCallingUid(Binder.getCallingUid())
3296 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003297 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003298 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3299 .build());
3300 switch (locationResult) {
3301 case DENIED_HARD:
3302 throw new SecurityException("Not allowed to access cell location");
3303 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003304 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3305 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003306 }
3307
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003308 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003309 final long identity = Binder.clearCallingIdentity();
3310 try {
3311 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003312 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003313 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003314 } finally {
3315 Binder.restoreCallingIdentity(identity);
3316 }
Svetoslav64fad262015-04-14 14:35:21 -07003317 }
3318
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003319 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003320 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003321 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3322 // registered cell info, so return a NULL country instead.
3323 final long identity = Binder.clearCallingIdentity();
3324 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003325 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3326 // Get default phone in this case.
3327 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3328 }
Jack Yu285100e2022-12-02 22:48:35 -08003329 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003330 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003331 if (phone == null) return "";
3332 ServiceStateTracker sst = phone.getServiceStateTracker();
3333 if (sst == null) return "";
3334 LocaleTracker lt = sst.getLocaleTracker();
3335 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003336 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003337 } finally {
3338 Binder.restoreCallingIdentity(identity);
3339 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003340 }
3341
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003342 /**
3343 * This method was removed due to potential issues caused by performing partial
3344 * updates of service state, and lack of a credible use case.
3345 *
3346 * This has the ability to break the telephony implementation by disabling notification of
3347 * changes in device connectivity. DO NOT USE THIS!
3348 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003349 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003350 public void enableLocationUpdates() {
3351 mApp.enforceCallingOrSelfPermission(
3352 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003353 }
3354
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003355 /**
3356 * This method was removed due to potential issues caused by performing partial
3357 * updates of service state, and lack of a credible use case.
3358 *
3359 * This has the ability to break the telephony implementation by disabling notification of
3360 * changes in device connectivity. DO NOT USE THIS!
3361 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003362 @Override
3363 public void disableLocationUpdates() {
3364 mApp.enforceCallingOrSelfPermission(
3365 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003366 }
3367
3368 @Override
3369 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003370 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3371 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003372 try {
3373 mApp.getSystemService(AppOpsManager.class)
3374 .checkPackage(Binder.getCallingUid(), callingPackage);
3375 } catch (SecurityException e) {
3376 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3377 throw e;
3378 }
3379
Nathan Haroldf096d982020-11-18 17:18:06 -08003380 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003381 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3382 throw new SecurityException(
3383 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3384 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003385
Jordan Liu1617b712019-07-10 15:06:26 -07003386 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003387 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3388 return null;
3389 }
Svetoslav64fad262015-04-14 14:35:21 -07003390
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003391 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003392
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003393 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003394 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003395
Nathan Haroldf180aac2018-06-01 18:43:55 -07003396 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3397 for (CellInfo ci : info) {
3398 if (ci instanceof CellInfoGsm) {
3399 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3400 } else if (ci instanceof CellInfoWcdma) {
3401 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3402 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003403 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003404 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003405 }
3406
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003407 private List<CellInfo> getCachedCellInfo() {
3408 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3409 for (Phone phone : PhoneFactory.getPhones()) {
3410 List<CellInfo> info = phone.getAllCellInfo();
3411 if (info != null) cellInfos.addAll(info);
3412 }
3413 return cellInfos;
3414 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003415
3416 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003417 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003418 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003419 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003420
3421 LocationAccessPolicy.LocationPermissionResult locationResult =
3422 LocationAccessPolicy.checkLocationPermission(mApp,
3423 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3424 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003425 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003426 .setCallingPid(Binder.getCallingPid())
3427 .setCallingUid(Binder.getCallingUid())
3428 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003429 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003430 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3431 .build());
3432 switch (locationResult) {
3433 case DENIED_HARD:
3434 throw new SecurityException("Not allowed to access cell info");
3435 case DENIED_SOFT:
3436 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003437 }
3438
Nathan Haroldf096d982020-11-18 17:18:06 -08003439 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003440 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3441 return getCachedCellInfo();
3442 }
3443
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003444 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003445 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003446 final long identity = Binder.clearCallingIdentity();
3447 try {
3448 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3449 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003450 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003451 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003452 if (info != null) cellInfos.addAll(info);
3453 }
3454 return cellInfos;
3455 } finally {
3456 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003457 }
3458 }
3459
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003460 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003461 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3462 String callingFeatureId) {
3463 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3464 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003465 }
3466
3467 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003468 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3469 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003470 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003471 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003472 }
3473
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003474 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3475 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003476 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003477 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003478
3479 LocationAccessPolicy.LocationPermissionResult locationResult =
3480 LocationAccessPolicy.checkLocationPermission(mApp,
3481 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3482 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003483 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003484 .setCallingPid(Binder.getCallingPid())
3485 .setCallingUid(Binder.getCallingUid())
3486 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003487 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3488 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003489 .build());
3490 switch (locationResult) {
3491 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003492 if (TelephonyPermissions
3493 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003494 // Safetynet logging for b/154934934
3495 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3496 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003497 throw new SecurityException("Not allowed to access cell info");
3498 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003499 if (TelephonyPermissions
3500 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003501 // Safetynet logging for b/154934934
3502 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3503 }
Nathan Harold5320c422019-05-09 10:26:08 -07003504 try {
3505 cb.onCellInfo(new ArrayList<CellInfo>());
3506 } catch (RemoteException re) {
3507 // Drop without consequences
3508 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003509 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003510 }
3511
Nathan Harolda939a962019-05-09 10:13:47 -07003512
3513 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003514 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3515
3516 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3517 }
3518
3519 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003520 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003521 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003522 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003523
3524 final long identity = Binder.clearCallingIdentity();
3525 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003526 Phone phone = getPhone(subId);
3527 if (phone == null) {
3528 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3529 } else {
3530 phone.setCellInfoListRate(rateInMillis, workSource);
3531 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003532 } finally {
3533 Binder.restoreCallingIdentity(identity);
3534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003535 }
3536
Shishir Agrawala9f32182016-04-12 12:00:16 -07003537 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003538 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003539 Phone phone = PhoneFactory.getPhone(slotIndex);
3540 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003541 return null;
3542 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003543 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003544 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003545 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003546 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003547 return null;
3548 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003549
3550 final long identity = Binder.clearCallingIdentity();
3551 try {
3552 return phone.getImei();
3553 } finally {
3554 Binder.restoreCallingIdentity(identity);
3555 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003556 }
3557
3558 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003559 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3560 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3561 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3562 callingFeatureId, "getPrimaryImei")) {
3563 throw new SecurityException("Caller does not have permission");
3564 }
3565 final long identity = Binder.clearCallingIdentity();
3566 try {
3567 for (Phone phone : PhoneFactory.getPhones()) {
3568 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3569 return phone.getImei();
3570 }
3571 }
3572 throw new UnsupportedOperationException("Operation not supported");
3573 } finally {
3574 Binder.restoreCallingIdentity(identity);
3575 }
3576 }
3577
3578 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003579 public String getTypeAllocationCodeForSlot(int slotIndex) {
3580 Phone phone = PhoneFactory.getPhone(slotIndex);
3581 String tac = null;
3582 if (phone != null) {
3583 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003584 try {
3585 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3586 } catch (IndexOutOfBoundsException e) {
3587 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3588 return null;
3589 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003590 }
3591 return tac;
3592 }
3593
3594 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003595 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003596 try {
3597 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3598 } catch (SecurityException se) {
3599 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3600 throw new SecurityException("Package " + callingPackage + " does not belong to "
3601 + Binder.getCallingUid());
3602 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003603 Phone phone = PhoneFactory.getPhone(slotIndex);
3604 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003605 return null;
3606 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003607
Jeff Davidson913390f2018-02-23 17:11:49 -08003608 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003609 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003610 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003611 return null;
3612 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003613
3614 final long identity = Binder.clearCallingIdentity();
3615 try {
3616 return phone.getMeid();
3617 } finally {
3618 Binder.restoreCallingIdentity(identity);
3619 }
Jack Yu2af8d712017-03-15 17:14:14 -07003620 }
3621
3622 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003623 public String getManufacturerCodeForSlot(int slotIndex) {
3624 Phone phone = PhoneFactory.getPhone(slotIndex);
3625 String manufacturerCode = null;
3626 if (phone != null) {
3627 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003628 try {
3629 manufacturerCode =
3630 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3631 } catch (IndexOutOfBoundsException e) {
3632 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3633 return null;
3634 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003635 }
3636 return manufacturerCode;
3637 }
3638
3639 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003640 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3641 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003642 Phone phone = PhoneFactory.getPhone(slotIndex);
3643 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003644 return null;
3645 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003646 int subId = phone.getSubId();
3647 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003648 mApp, subId, callingPackage, callingFeatureId,
3649 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003650 return null;
3651 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003652
3653 final long identity = Binder.clearCallingIdentity();
3654 try {
3655 return phone.getDeviceSvn();
3656 } finally {
3657 Binder.restoreCallingIdentity(identity);
3658 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003659 }
3660
fionaxu43304da2017-11-27 22:51:16 -08003661 @Override
3662 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003663 final long identity = Binder.clearCallingIdentity();
3664 try {
3665 final Phone phone = getPhone(subId);
3666 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3667 } finally {
3668 Binder.restoreCallingIdentity(identity);
3669 }
fionaxu43304da2017-11-27 22:51:16 -08003670 }
3671
3672 @Override
3673 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003674 final long identity = Binder.clearCallingIdentity();
3675 try {
3676 final Phone phone = getPhone(subId);
3677 return phone == null ? null : phone.getCarrierName();
3678 } finally {
3679 Binder.restoreCallingIdentity(identity);
3680 }
fionaxu43304da2017-11-27 22:51:16 -08003681 }
3682
calvinpanffe225e2018-11-01 19:43:06 +08003683 @Override
chen xu0026ca62019-03-06 15:28:50 -08003684 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003685 final long identity = Binder.clearCallingIdentity();
3686 try {
3687 final Phone phone = getPhone(subId);
3688 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003689 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003690 } finally {
3691 Binder.restoreCallingIdentity(identity);
3692 }
3693 }
3694
3695 @Override
chen xu0026ca62019-03-06 15:28:50 -08003696 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003697 final long identity = Binder.clearCallingIdentity();
3698 try {
3699 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003700 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003701 } finally {
3702 Binder.restoreCallingIdentity(identity);
3703 }
3704 }
3705
chen xu651eec72018-11-11 19:03:44 -08003706 @Override
chen xu864e11c2018-12-06 22:10:03 -08003707 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3708 if (!isSubscriptionMccMnc) {
3709 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3710 }
chen xu651eec72018-11-11 19:03:44 -08003711 final Phone phone = PhoneFactory.getPhone(slotIndex);
3712 if (phone == null) {
3713 return TelephonyManager.UNKNOWN_CARRIER_ID;
3714 }
3715 final long identity = Binder.clearCallingIdentity();
3716 try {
3717 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3718 } finally {
3719 Binder.restoreCallingIdentity(identity);
3720 }
3721 }
3722
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003723 //
3724 // Internal helper methods.
3725 //
3726
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003727 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003728 * Make sure the caller is the calling package itself
3729 *
3730 * @throws SecurityException if the caller is not the calling package
3731 */
3732 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3733 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003734 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3735 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003736 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003737 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003738 } catch (PackageManager.NameNotFoundException e) {
3739 // packageUid is -1
3740 }
3741 if (packageUid != callingUid) {
3742 throw new SecurityException(message + ": Package " + callingPackage
3743 + " does not belong to " + callingUid);
3744 }
3745 }
3746
3747 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003748 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3749 *
3750 * @throws SecurityException if the caller does not have the required permission
3751 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003752 @VisibleForTesting
3753 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003754 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3755 }
3756
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003757 /**
arunvoddud7401012022-12-15 16:08:12 +00003758 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003759 *
3760 * @throws SecurityException if the caller does not have the required permission
3761 */
3762 @VisibleForTesting
3763 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003764 enforceReadPermission(null);
3765 }
3766
3767 /**
3768 * Make sure the caller has the READ_PHONE_STATE permissions.
3769 *
3770 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3771 */
3772 @VisibleForTesting
3773 public void enforceReadPermission(String msg) {
3774 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003775 }
3776
Shuo Qian3b6ee772019-11-13 17:43:31 -08003777 private void enforceActiveEmergencySessionPermission() {
3778 mApp.enforceCallingOrSelfPermission(
3779 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3780 }
3781
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003782 /**
3783 * Make sure the caller has the CALL_PHONE permission.
3784 *
3785 * @throws SecurityException if the caller does not have the required permission
3786 */
3787 private void enforceCallPermission() {
3788 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3789 }
3790
paulhu5a773602019-08-23 19:17:33 +08003791 private void enforceSettingsPermission() {
3792 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003793 }
3794
Michele Berionne5e411512020-11-13 02:36:59 +00003795 private void enforceRebootPermission() {
3796 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3797 }
3798
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003799 /**
3800 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3801 * @param message - log message to print.
3802 * @throws SecurityException if the caller does not have the required permission
3803 */
3804 private void enforceSatelliteCommunicationPermission(String message) {
3805 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3806 }
3807
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003808 private String createTelUrl(String number) {
3809 if (TextUtils.isEmpty(number)) {
3810 return null;
3811 }
3812
Jake Hambye994d462014-02-03 13:10:13 -08003813 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003814 }
3815
Ihab Awadf9e92732013-12-05 18:02:52 -08003816 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003817 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003818 }
3819
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003820 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003821 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003822 }
3823
Ihab Awadf9e92732013-12-05 18:02:52 -08003824 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003825 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003826 }
3827
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003828 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003829 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003830 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003831 }
3832
Sanket Padawe356d7632015-06-22 14:03:32 -07003833 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003834 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003835 final long identity = Binder.clearCallingIdentity();
3836 try {
3837 final Phone phone = PhoneFactory.getPhone(slotIndex);
3838 if (phone == null) {
3839 return PhoneConstants.PHONE_TYPE_NONE;
3840 } else {
3841 return phone.getPhoneType();
3842 }
3843 } finally {
3844 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003845 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003846 }
3847
3848 /**
3849 * Returns the CDMA ERI icon index to display
3850 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003851 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003852 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3853 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3854 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003855 }
3856
Sanket Padawe356d7632015-06-22 14:03:32 -07003857 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003858 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3859 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003860 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003861 mApp, subId, callingPackage, callingFeatureId,
3862 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003863 return -1;
3864 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003865
3866 final long identity = Binder.clearCallingIdentity();
3867 try {
3868 final Phone phone = getPhone(subId);
3869 if (phone != null) {
3870 return phone.getCdmaEriIconIndex();
3871 } else {
3872 return -1;
3873 }
3874 } finally {
3875 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003876 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003877 }
3878
3879 /**
3880 * Returns the CDMA ERI icon mode,
3881 * 0 - ON
3882 * 1 - FLASHING
3883 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003884 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003885 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3886 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3887 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003888 }
3889
Sanket Padawe356d7632015-06-22 14:03:32 -07003890 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003891 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3892 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003893 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003894 mApp, subId, callingPackage, callingFeatureId,
3895 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003896 return -1;
3897 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003898
3899 final long identity = Binder.clearCallingIdentity();
3900 try {
3901 final Phone phone = getPhone(subId);
3902 if (phone != null) {
3903 return phone.getCdmaEriIconMode();
3904 } else {
3905 return -1;
3906 }
3907 } finally {
3908 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003909 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003910 }
3911
3912 /**
3913 * Returns the CDMA ERI text,
3914 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003915 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003916 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3917 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3918 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003919 }
3920
Sanket Padawe356d7632015-06-22 14:03:32 -07003921 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003922 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3923 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003924 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003925 mApp, subId, callingPackage, callingFeatureId,
3926 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003927 return null;
3928 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003929
3930 final long identity = Binder.clearCallingIdentity();
3931 try {
3932 final Phone phone = getPhone(subId);
3933 if (phone != null) {
3934 return phone.getCdmaEriText();
3935 } else {
3936 return null;
3937 }
3938 } finally {
3939 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003940 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003941 }
3942
3943 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003944 * Returns the CDMA MDN.
3945 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003946 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003947 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003948 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3949 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003950
3951 final long identity = Binder.clearCallingIdentity();
3952 try {
3953 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003954 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003955 return phone.getLine1Number();
3956 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003957 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003958 return null;
3959 }
3960 } finally {
3961 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003962 }
3963 }
3964
3965 /**
3966 * Returns the CDMA MIN.
3967 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003968 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003969 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003970 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3971 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003972
3973 final long identity = Binder.clearCallingIdentity();
3974 try {
3975 final Phone phone = getPhone(subId);
3976 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3977 return phone.getCdmaMin();
3978 } else {
3979 return null;
3980 }
3981 } finally {
3982 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003983 }
3984 }
3985
Hall Liud892bec2018-11-30 14:51:45 -08003986 @Override
3987 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3988 INumberVerificationCallback callback, String callingPackage) {
3989 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3990 != PERMISSION_GRANTED) {
3991 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3992 }
3993 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3994
3995 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3996 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003997 throw new SecurityException("Calling package must be configured in the device config: "
3998 + "calling package: " + callingPackage
3999 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004000 }
4001
4002 if (range == null) {
4003 throw new NullPointerException("Range must be non-null");
4004 }
4005
4006 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004007 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004008
4009 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4010 }
4011
Junda Liuca05d5d2014-08-14 22:36:34 -07004012 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004013 * Returns true if CDMA provisioning needs to run.
4014 */
4015 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004016 final long identity = Binder.clearCallingIdentity();
4017 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004018 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004019 } finally {
4020 Binder.restoreCallingIdentity(identity);
4021 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004022 }
4023
4024 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004025 * Sets the voice mail number of a given subId.
4026 */
4027 @Override
4028 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004029 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4030 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004031
4032 final long identity = Binder.clearCallingIdentity();
4033 try {
4034 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4035 new Pair<String, String>(alphaTag, number), new Integer(subId));
4036 return success;
4037 } finally {
4038 Binder.restoreCallingIdentity(identity);
4039 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004040 }
4041
Ta-wei Yen87c49842016-05-13 21:19:52 -07004042 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004043 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4044 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004045 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4046 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004047 if (!TextUtils.equals(callingPackage, systemDialer)) {
4048 throw new SecurityException("caller must be system dialer");
4049 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004050
4051 final long identity = Binder.clearCallingIdentity();
4052 try {
4053 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4054 if (phoneAccountHandle == null) {
4055 return null;
4056 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004057 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004058 } finally {
4059 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004060 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004061 }
4062
4063 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004064 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4065 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004066 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004068 mApp, subId, callingPackage, callingFeatureId,
4069 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004070 return null;
4071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004072
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004073 final long identity = Binder.clearCallingIdentity();
4074 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004075 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004076 } finally {
4077 Binder.restoreCallingIdentity(identity);
4078 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004079 }
4080
4081 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004082 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4083 VisualVoicemailSmsFilterSettings settings) {
4084 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004085
4086 final long identity = Binder.clearCallingIdentity();
4087 try {
4088 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004089 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004090 } finally {
4091 Binder.restoreCallingIdentity(identity);
4092 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004093 }
4094
4095 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004096 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4097 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004098
4099 final long identity = Binder.clearCallingIdentity();
4100 try {
4101 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004102 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004103 } finally {
4104 Binder.restoreCallingIdentity(identity);
4105 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004106 }
4107
4108 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004109 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4110 String callingPackage, int subId) {
4111 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004112
4113 final long identity = Binder.clearCallingIdentity();
4114 try {
4115 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004116 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004117 } finally {
4118 Binder.restoreCallingIdentity(identity);
4119 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004120 }
4121
4122 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004123 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004124 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004125
4126 final long identity = Binder.clearCallingIdentity();
4127 try {
4128 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004129 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004130 } finally {
4131 Binder.restoreCallingIdentity(identity);
4132 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004133 }
4134
4135 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004136 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4137 String callingAttributionTag, int subId, String number, int port, String text,
4138 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004139 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004140 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004141 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004142 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004143 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4144 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004145 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004146
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004147 /**
fionaxu0152e512016-11-14 13:36:14 -08004148 * Sets the voice activation state of a given subId.
4149 */
4150 @Override
4151 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004152 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4153 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004154
4155 final long identity = Binder.clearCallingIdentity();
4156 try {
4157 final Phone phone = getPhone(subId);
4158 if (phone != null) {
4159 phone.setVoiceActivationState(activationState);
4160 } else {
4161 loge("setVoiceActivationState fails with invalid subId: " + subId);
4162 }
4163 } finally {
4164 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004165 }
4166 }
4167
4168 /**
4169 * Sets the data activation state of a given subId.
4170 */
4171 @Override
4172 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004173 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4174 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004175
4176 final long identity = Binder.clearCallingIdentity();
4177 try {
4178 final Phone phone = getPhone(subId);
4179 if (phone != null) {
4180 phone.setDataActivationState(activationState);
4181 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004182 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004183 }
4184 } finally {
4185 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004186 }
4187 }
4188
4189 /**
4190 * Returns the voice activation state of a given subId.
4191 */
4192 @Override
4193 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004194 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004195
fionaxu0152e512016-11-14 13:36:14 -08004196 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004197 final long identity = Binder.clearCallingIdentity();
4198 try {
4199 if (phone != null) {
4200 return phone.getVoiceActivationState();
4201 } else {
4202 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4203 }
4204 } finally {
4205 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004206 }
4207 }
4208
4209 /**
4210 * Returns the data activation state of a given subId.
4211 */
4212 @Override
4213 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004214 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004215
fionaxu0152e512016-11-14 13:36:14 -08004216 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004217 final long identity = Binder.clearCallingIdentity();
4218 try {
4219 if (phone != null) {
4220 return phone.getDataActivationState();
4221 } else {
4222 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4223 }
4224 } finally {
4225 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004226 }
4227 }
4228
4229 /**
Wink Saville36469e72014-06-11 15:17:00 -07004230 * Returns the unread count of voicemails for a subId
4231 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004232 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004233 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4234 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004235 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004236 mApp, subId, callingPackage, callingFeatureId,
4237 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004238 return 0;
4239 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004240 final long identity = Binder.clearCallingIdentity();
4241 try {
4242 final Phone phone = getPhone(subId);
4243 if (phone != null) {
4244 return phone.getVoiceMessageCount();
4245 } else {
4246 return 0;
4247 }
4248 } finally {
4249 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004251 }
4252
4253 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004254 * returns true, if the device is in a state where both voice and data
4255 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004256 */
4257 @Override
4258 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004259 final long identity = Binder.clearCallingIdentity();
4260 try {
Ling Mac28f0212023-03-24 16:07:15 -07004261 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004262 } finally {
4263 Binder.restoreCallingIdentity(identity);
4264 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004265 }
4266
4267 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004268 * Send the dialer code if called from the current default dialer or the caller has
4269 * carrier privilege.
4270 * @param inputCode The dialer code to send
4271 */
4272 @Override
4273 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004274 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004275 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004276 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4277 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004278 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004279 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004280 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004282
4283 final long identity = Binder.clearCallingIdentity();
4284 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004285 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004286 } finally {
4287 Binder.restoreCallingIdentity(identity);
4288 }
fionaxu235cc5e2017-03-06 22:25:57 -08004289 }
4290
Pengquan Menga1bb6272018-09-06 09:59:22 -07004291 @Override
4292 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004293 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004294 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4295 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004296 final long identity = Binder.clearCallingIdentity();
4297 try {
4298 if (!isActiveSubscription(subId)) {
4299 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4300 }
4301 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4302 } finally {
4303 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004304 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004305 }
4306
Brad Ebinger35c841c2018-10-01 10:40:55 -07004307 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004308 public boolean isInEmergencySmsMode() {
4309 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4310 final long identity = Binder.clearCallingIdentity();
4311 try {
4312 for (Phone phone : PhoneFactory.getPhones()) {
4313 if (phone.isInEmergencySmsMode()) {
4314 return true;
4315 }
4316 }
4317 } finally {
4318 Binder.restoreCallingIdentity(identity);
4319 }
4320 return false;
4321 }
4322
shilu366312e2019-12-17 09:28:10 -08004323 /**
4324 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4325 * @param subId The subscription to use to check the configuration.
4326 * @param c The callback that will be used to send the result.
4327 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004328 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004329 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4330 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004331 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004332 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004333
4334 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4335 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4336 "IMS not available on device.");
4337 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004338 final long token = Binder.clearCallingIdentity();
4339 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004340 int slotId = getSlotIndexOrException(subId);
4341 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004342
4343 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4344 if (controller != null) {
4345 ImsManager imsManager = controller.getImsManager(subId);
4346 if (imsManager != null) {
4347 imsManager.addRegistrationCallbackForSubscription(c, subId);
4348 } else {
4349 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4350 }
4351 } else {
4352 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4353 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004354 } catch (ImsException e) {
4355 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004356 } finally {
4357 Binder.restoreCallingIdentity(token);
4358 }
4359 }
4360
shilu366312e2019-12-17 09:28:10 -08004361 /**
4362 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4363 * @param subId The subscription to use to check the configuration.
4364 * @param c The callback that will be used to send the result.
4365 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004366 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004367 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004368 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004369 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004370 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4371 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4372 }
Meng Wangafbc5852019-09-19 17:37:13 -07004373 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004374
Meng Wangafbc5852019-09-19 17:37:13 -07004375 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004376 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4377 if (controller != null) {
4378 ImsManager imsManager = controller.getImsManager(subId);
4379 if (imsManager != null) {
4380 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4381 } else {
4382 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4383 + "is inactive, ignoring unregister.");
4384 // If the ImsManager is not valid, just return, since the callback
4385 // will already have been removed internally.
4386 }
4387 }
Meng Wangafbc5852019-09-19 17:37:13 -07004388 } finally {
4389 Binder.restoreCallingIdentity(token);
4390 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004391 }
4392
Brad Ebingera34a6c22019-10-22 17:36:18 -07004393 /**
4394 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4395 */
4396 @Override
4397 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4398 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4399 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4400 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4401 "IMS not available on device.");
4402 }
4403 final long token = Binder.clearCallingIdentity();
4404 try {
4405 Phone phone = getPhone(subId);
4406 if (phone == null) {
4407 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4408 + subId + "'");
4409 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4410 }
4411 phone.getImsRegistrationState(regState -> {
4412 try {
4413 consumer.accept((regState == null)
4414 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4415 } catch (RemoteException e) {
4416 // Ignore if the remote process is no longer available to call back.
4417 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4418 }
4419 });
4420 } finally {
4421 Binder.restoreCallingIdentity(token);
4422 }
4423 }
4424
4425 /**
4426 * Get the transport type for the IMS service registration state.
4427 */
4428 @Override
4429 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004430 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004431 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004432 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4433 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4434 "IMS not available on device.");
4435 }
4436 final long token = Binder.clearCallingIdentity();
4437 try {
4438 Phone phone = getPhone(subId);
4439 if (phone == null) {
4440 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4441 + subId + "'");
4442 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4443 }
4444 phone.getImsRegistrationTech(regTech -> {
4445 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4446 int regTechConverted = (regTech == null)
4447 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4448 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4449 regTechConverted);
4450 try {
4451 consumer.accept(regTechConverted);
4452 } catch (RemoteException e) {
4453 // Ignore if the remote process is no longer available to call back.
4454 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4455 }
4456 });
4457 } finally {
4458 Binder.restoreCallingIdentity(token);
4459 }
4460 }
4461
shilu366312e2019-12-17 09:28:10 -08004462 /**
4463 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4464 * @param subId The subscription to use to check the configuration.
4465 * @param c The callback that will be used to send the result.
4466 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004467 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004468 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4469 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004470 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004471 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004472 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4473 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4474 "IMS not available on device.");
4475 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004476 final long token = Binder.clearCallingIdentity();
4477 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004478 int slotId = getSlotIndexOrException(subId);
4479 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004480
4481 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4482 if (controller != null) {
4483 ImsManager imsManager = controller.getImsManager(subId);
4484 if (imsManager != null) {
4485 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4486 } else {
4487 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4488 }
4489 } else {
4490 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4491 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004492 } catch (ImsException e) {
4493 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004494 } finally {
4495 Binder.restoreCallingIdentity(token);
4496 }
4497 }
4498
shilu366312e2019-12-17 09:28:10 -08004499 /**
4500 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4501 * @param subId The subscription to use to check the configuration.
4502 * @param c The callback that will be used to send the result.
4503 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004504 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004505 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004506 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004507 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004508 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4509 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4510 }
Meng Wangafbc5852019-09-19 17:37:13 -07004511
4512 final long token = Binder.clearCallingIdentity();
4513 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004514 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4515 if (controller != null) {
4516 ImsManager imsManager = controller.getImsManager(subId);
4517 if (imsManager != null) {
4518 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4519 } else {
4520 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4521 + " is inactive, ignoring unregister.");
4522 // If the ImsManager is not valid, just return, since the callback
4523 // will already have been removed internally.
4524 }
4525 }
Meng Wangafbc5852019-09-19 17:37:13 -07004526 } finally {
4527 Binder.restoreCallingIdentity(token);
4528 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004529 }
4530
4531 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004532 public boolean isCapable(int subId, int capability, int regTech) {
4533 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004534 final long token = Binder.clearCallingIdentity();
4535 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004536 int slotId = getSlotIndexOrException(subId);
4537 verifyImsMmTelConfiguredOrThrow(slotId);
4538 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4539 } catch (com.android.ims.ImsException e) {
4540 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4541 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004542 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004543 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4544 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004545 } finally {
4546 Binder.restoreCallingIdentity(token);
4547 }
4548 }
4549
4550 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004551 public boolean isAvailable(int subId, int capability, int regTech) {
4552 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004553 final long token = Binder.clearCallingIdentity();
4554 try {
4555 Phone phone = getPhone(subId);
4556 if (phone == null) return false;
4557 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004558 } catch (com.android.ims.ImsException e) {
4559 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4560 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004561 } finally {
4562 Binder.restoreCallingIdentity(token);
4563 }
4564 }
4565
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004566 /**
4567 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4568 * subscription.
4569 * @param subId The subscription to use to check the configuration.
4570 * @param callback The callback that will be used to send the result.
4571 * @param capability The MmTelFeature capability that will be used to send the result.
4572 * @param transportType The transport type of the MmTelFeature capability.
4573 */
4574 @Override
4575 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4576 int transportType) {
4577 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004578 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4579 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4580 "IMS not available on device.");
4581 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004582 final long token = Binder.clearCallingIdentity();
4583 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004584 int slotId = getSlotIndex(subId);
4585 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4586 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4587 + subId + "'");
4588 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4589 }
4590 verifyImsMmTelConfiguredOrThrow(slotId);
4591 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4592 transportType, aBoolean -> {
4593 try {
4594 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4595 } catch (RemoteException e) {
4596 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4597 + "running. Ignore");
4598 }
4599 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004600 } catch (ImsException e) {
4601 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004602 } finally {
4603 Binder.restoreCallingIdentity(token);
4604 }
4605 }
4606
shilu366312e2019-12-17 09:28:10 -08004607 /**
4608 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4609 * @param subId The subscription to use to check the configuration.
4610 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004611 @Override
4612 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004613 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004614 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004615
Brad Ebinger35c841c2018-10-01 10:40:55 -07004616 final long token = Binder.clearCallingIdentity();
4617 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004618 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004619 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004620 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004621 } catch (ImsException e) {
4622 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004623 } finally {
4624 Binder.restoreCallingIdentity(token);
4625 }
4626 }
4627
4628 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004629 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004631 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004632 final long identity = Binder.clearCallingIdentity();
4633 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004634 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004635 // This setting doesn't require an active ImsService connection, so do not verify. The
4636 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004637 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004638 } catch (ImsException e) {
4639 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004640 } finally {
4641 Binder.restoreCallingIdentity(identity);
4642 }
4643 }
4644
shilu366312e2019-12-17 09:28:10 -08004645 /**
4646 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4647 * @param subId The subscription to use to check the configuration.
4648 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004649 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004650 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004651 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004652 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004653 final long identity = Binder.clearCallingIdentity();
4654 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004655 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004656 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004657 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004658 } catch (ImsException e) {
4659 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004660 } finally {
4661 Binder.restoreCallingIdentity(identity);
4662 }
4663 }
4664
4665 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004666 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004668 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004669 final long identity = Binder.clearCallingIdentity();
4670 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004671 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004672 // This setting doesn't require an active ImsService connection, so do not verify. The
4673 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004674 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004675 } catch (ImsException e) {
4676 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004677 } finally {
4678 Binder.restoreCallingIdentity(identity);
4679 }
4680 }
4681
shilu366312e2019-12-17 09:28:10 -08004682 /**
4683 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4684 * @param subId The subscription to use to check the configuration.
4685 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004686 @Override
4687 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004688 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004689 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004690 final long identity = Binder.clearCallingIdentity();
4691 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004692 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004693 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004694 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004695 } catch (ImsException e) {
4696 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004697 } finally {
4698 Binder.restoreCallingIdentity(identity);
4699 }
4700 }
4701
4702 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004703 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004704 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004705 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004706 final long identity = Binder.clearCallingIdentity();
4707 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004708 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004709 // This setting doesn't require an active ImsService connection, so do not verify. The
4710 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004711 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004712 } catch (ImsException e) {
4713 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004714 } finally {
4715 Binder.restoreCallingIdentity(identity);
4716 }
4717 }
4718
shilu366312e2019-12-17 09:28:10 -08004719 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004720 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4721 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4722 * @param subId The subscription to use to check the configuration.
4723 */
4724 @Override
4725 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004726 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004727 mApp, subId, "isCrossSimCallingEnabledByUser");
4728 final long identity = Binder.clearCallingIdentity();
4729 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004730 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004731 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004732 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004733 } catch (ImsException e) {
4734 throw new ServiceSpecificException(e.getCode());
4735 } finally {
4736 Binder.restoreCallingIdentity(identity);
4737 }
4738 }
4739
4740 /**
4741 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4742 * Requires MODIFY_PHONE_STATE permission.
4743 * @param subId The subscription to use to check the configuration.
4744 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4745 * false otherwise
4746 */
4747 @Override
4748 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4750 "setCrossSimCallingEnabled");
4751 final long identity = Binder.clearCallingIdentity();
4752 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004753 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004754 // This setting doesn't require an active ImsService connection, so do not verify. The
4755 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004756 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004757 } catch (ImsException e) {
4758 throw new ServiceSpecificException(e.getCode());
4759 } finally {
4760 Binder.restoreCallingIdentity(identity);
4761 }
4762 }
4763
4764 /**
shilu366312e2019-12-17 09:28:10 -08004765 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4766 * @param subId The subscription to use to check the configuration.
4767 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004768 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004769
Brad Ebinger35c841c2018-10-01 10:40:55 -07004770 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004771 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004772 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004773 final long identity = Binder.clearCallingIdentity();
4774 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004775 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004776 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004777 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004778 } catch (ImsException e) {
4779 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004780 } finally {
4781 Binder.restoreCallingIdentity(identity);
4782 }
4783 }
4784
4785 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004786 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004788 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004789 final long identity = Binder.clearCallingIdentity();
4790 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004791 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004792 // This setting doesn't require an active ImsService connection, so do not verify. The
4793 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004794 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004795 } catch (ImsException e) {
4796 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004797 } finally {
4798 Binder.restoreCallingIdentity(identity);
4799 }
4800 }
4801
4802 @Override
4803 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4804 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4805 "setVoWiFiNonPersistent");
4806 final long identity = Binder.clearCallingIdentity();
4807 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004808 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004809 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004810 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004811 } catch (ImsException e) {
4812 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004813 } finally {
4814 Binder.restoreCallingIdentity(identity);
4815 }
4816 }
4817
shilu366312e2019-12-17 09:28:10 -08004818 /**
4819 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4820 * @param subId The subscription to use to check the configuration.
4821 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004822 @Override
4823 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004824 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004825 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004826 final long identity = Binder.clearCallingIdentity();
4827 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004828 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004829 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004830 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004831 } catch (ImsException e) {
4832 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004833 } finally {
4834 Binder.restoreCallingIdentity(identity);
4835 }
4836 }
4837
4838 @Override
4839 public void setVoWiFiModeSetting(int subId, int mode) {
4840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4841 "setVoWiFiModeSetting");
4842 final long identity = Binder.clearCallingIdentity();
4843 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004844 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004845 // This setting doesn't require an active ImsService connection, so do not verify. The
4846 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004847 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004848 } catch (ImsException e) {
4849 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004850 } finally {
4851 Binder.restoreCallingIdentity(identity);
4852 }
4853 }
4854
4855 @Override
4856 public int getVoWiFiRoamingModeSetting(int subId) {
4857 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4858 final long identity = Binder.clearCallingIdentity();
4859 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004860 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004861 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004862 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004863 } catch (ImsException e) {
4864 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004865 } finally {
4866 Binder.restoreCallingIdentity(identity);
4867 }
4868 }
4869
4870 @Override
4871 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4873 "setVoWiFiRoamingModeSetting");
4874 final long identity = Binder.clearCallingIdentity();
4875 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004876 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004877 // This setting doesn't require an active ImsService connection, so do not verify. The
4878 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004879 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004880 } catch (ImsException e) {
4881 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004882 } finally {
4883 Binder.restoreCallingIdentity(identity);
4884 }
4885 }
4886
4887 @Override
4888 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4889 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4890 "setRttCapabilityEnabled");
4891 final long identity = Binder.clearCallingIdentity();
4892 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004893 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004894 // This setting doesn't require an active ImsService connection, so do not verify. The
4895 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004896 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004897 } catch (ImsException e) {
4898 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004899 } finally {
4900 Binder.restoreCallingIdentity(identity);
4901 }
4902 }
4903
shilu366312e2019-12-17 09:28:10 -08004904 /**
4905 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4906 * @param subId The subscription to use to check the configuration.
4907 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004908 @Override
4909 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004910 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004911 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004912 final long identity = Binder.clearCallingIdentity();
4913 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004914 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004915 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004916 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004917 } catch (ImsException e) {
4918 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004919 } finally {
4920 Binder.restoreCallingIdentity(identity);
4921 }
4922 }
4923
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004924 @Override
4925 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4926 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004927
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004928 final long identity = Binder.clearCallingIdentity();
4929 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004930 if (!isImsAvailableOnDevice()) {
4931 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4932 "IMS not available on device.");
4933 }
4934 int slotId = getSlotIndexOrException(subId);
4935 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004936
4937 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4938 if (controller != null) {
4939 ImsManager imsManager = controller.getImsManager(subId);
4940 if (imsManager != null) {
4941 imsManager.addProvisioningCallbackForSubscription(callback, subId);
4942 } else {
4943 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4944 }
4945 } else {
4946 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4947 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004948 } catch (ImsException e) {
4949 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004950 } finally {
4951 Binder.restoreCallingIdentity(identity);
4952 }
4953 }
4954
4955 @Override
4956 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4957 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004958
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004959 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004960 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4961 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4962 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004963 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004964 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4965 if (controller != null) {
4966 ImsManager imsManager = controller.getImsManager(subId);
4967 if (imsManager != null) {
4968 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
4969 } else {
4970 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4971 + " is inactive, ignoring unregister.");
4972 // If the ImsManager is not valid, just return, since the callback will already
4973 // have been removed internally.
4974 }
4975 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004976 } finally {
4977 Binder.restoreCallingIdentity(identity);
4978 }
4979 }
4980
joonhunshincffb7fc2021-11-28 07:32:01 +00004981 @Override
4982 public void registerFeatureProvisioningChangedCallback(int subId,
4983 IFeatureProvisioningCallback callback) {
4984 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4985 mApp, subId, "registerFeatureProvisioningChangedCallback");
4986
4987 final long identity = Binder.clearCallingIdentity();
4988 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4989 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4990 }
4991
joonhunshin91bc1952022-04-29 08:47:15 +00004992 try {
4993 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4994 if (controller == null) {
4995 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4996 "Device does not support IMS");
4997 }
4998 controller.addFeatureProvisioningChangedCallback(subId, callback);
4999 } finally {
5000 Binder.restoreCallingIdentity(identity);
5001 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005002 }
5003
5004 @Override
5005 public void unregisterFeatureProvisioningChangedCallback(int subId,
5006 IFeatureProvisioningCallback callback) {
5007 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5008 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5009
5010 final long identity = Binder.clearCallingIdentity();
5011 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5012 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5013 }
5014
joonhunshin91bc1952022-04-29 08:47:15 +00005015 try {
5016 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5017 if (controller == null) {
5018 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5019 return;
5020 }
5021 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5022 } finally {
5023 Binder.restoreCallingIdentity(identity);
5024 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005025 }
allenwtsu99c623b2020-01-03 18:24:23 +08005026
5027 private void checkModifyPhoneStatePermission(int subId, String message) {
5028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5029 message);
5030 }
5031
allenwtsu99c623b2020-01-03 18:24:23 +08005032 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005033 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005034 boolean isProvisioned) {
5035 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5036
5037 final long identity = Binder.clearCallingIdentity();
5038 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005039 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5040 if (controller == null) {
5041 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5042 return;
5043 }
5044 controller.setRcsProvisioningStatusForCapability(
5045 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005046 } finally {
5047 Binder.restoreCallingIdentity(identity);
5048 }
allenwtsu99c623b2020-01-03 18:24:23 +08005049 }
5050
5051
5052 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005053 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5054 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5055 mApp, subId, "getRcsProvisioningStatusForCapability");
5056
allenwtsu99c623b2020-01-03 18:24:23 +08005057 final long identity = Binder.clearCallingIdentity();
5058 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005059 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5060 if (controller == null) {
5061 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5062
5063 // device does not support IMS, this method will return true always.
5064 return true;
5065 }
5066 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005067 } finally {
5068 Binder.restoreCallingIdentity(identity);
5069 }
5070 }
5071
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005072 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005073 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5074 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005075 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005076
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005077 final long identity = Binder.clearCallingIdentity();
5078 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005079 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5080 if (controller == null) {
5081 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5082 return;
5083 }
5084 controller.setImsProvisioningStatusForCapability(
5085 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005086 } finally {
5087 Binder.restoreCallingIdentity(identity);
5088 }
5089 }
5090
5091 @Override
5092 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005093 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5094 mApp, subId, "getProvisioningStatusForCapability");
5095
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005096 final long identity = Binder.clearCallingIdentity();
5097 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005098 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5099 if (controller == null) {
5100 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005101
joonhunshin91bc1952022-04-29 08:47:15 +00005102 // device does not support IMS, this method will return true always.
5103 return true;
5104 }
5105 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005106 } finally {
5107 Binder.restoreCallingIdentity(identity);
5108 }
5109 }
5110
5111 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005112 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5113 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5114 mApp, subId, "isProvisioningRequiredForCapability");
5115
5116 final long identity = Binder.clearCallingIdentity();
5117 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005118 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5119 if (controller == null) {
5120 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5121
5122 // device does not support IMS, this method will return false
5123 return false;
5124 }
5125 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005126 } finally {
5127 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005128 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005129 }
5130
5131 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005132 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5133 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5134 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005135
joonhunshincffb7fc2021-11-28 07:32:01 +00005136 final long identity = Binder.clearCallingIdentity();
5137 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005138 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5139 if (controller == null) {
5140 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5141
5142 // device does not support IMS, this method will return false
5143 return false;
5144 }
5145 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005146 } finally {
5147 Binder.restoreCallingIdentity(identity);
5148 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005149 }
5150
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005151 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005152 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005153 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5154 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5155 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005156 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5157 mApp, subId, "getImsProvisioningInt");
5158
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005159 final long identity = Binder.clearCallingIdentity();
5160 try {
5161 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005162 int slotId = getSlotIndex(subId);
5163 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5164 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5165 + subId + "' for key:" + key);
5166 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5167 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005168
joonhunshin91bc1952022-04-29 08:47:15 +00005169 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5170 if (controller == null) {
5171 loge("getImsProvisioningInt: Device does not support IMS");
5172
5173 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5174 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5175 }
5176 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005177 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5178 return retVal;
5179 }
5180
calvinpanb5a34062021-02-08 19:59:36 +08005181 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005182 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005183 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5184 + subId + "' for key:" + key);
5185 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005186 } finally {
5187 Binder.restoreCallingIdentity(identity);
5188 }
5189 }
5190
5191 @Override
5192 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005193 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5194 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5195 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005196 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5197 mApp, subId, "getImsProvisioningString");
5198
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005199 final long identity = Binder.clearCallingIdentity();
5200 try {
5201 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005202 int slotId = getSlotIndex(subId);
5203 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5204 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5205 + subId + "' for key:" + key);
5206 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5207 }
calvinpanb5a34062021-02-08 19:59:36 +08005208 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005209 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005210 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5211 + subId + "' for key:" + key);
5212 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005213 } finally {
5214 Binder.restoreCallingIdentity(identity);
5215 }
5216 }
5217
5218 @Override
5219 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005220 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5221 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5222 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005223 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5224 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005225
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005226 final long identity = Binder.clearCallingIdentity();
5227 try {
5228 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005229 int slotId = getSlotIndex(subId);
5230 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5231 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5232 + subId + "' for key:" + key);
5233 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5234 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005235
joonhunshin91bc1952022-04-29 08:47:15 +00005236 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5237 if (controller == null) {
5238 loge("setImsProvisioningInt: Device does not support IMS");
5239
5240 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5241 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5242 }
5243 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005244 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5245 return retVal;
5246 }
5247
calvinpanb5a34062021-02-08 19:59:36 +08005248 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5249 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005250 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005251 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005252 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005253 } finally {
5254 Binder.restoreCallingIdentity(identity);
5255 }
5256 }
5257
5258 @Override
5259 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005260 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5261 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5262 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005263 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5264 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005265 final long identity = Binder.clearCallingIdentity();
5266 try {
5267 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005268 int slotId = getSlotIndex(subId);
5269 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5270 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5271 + subId + "' for key:" + key);
5272 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5273 }
calvinpanb5a34062021-02-08 19:59:36 +08005274 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5275 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005276 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005277 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005278 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005279 } finally {
5280 Binder.restoreCallingIdentity(identity);
5281 }
5282 }
5283
Brad Ebinger919631e2021-06-02 17:46:35 -07005284 /**
5285 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5286 * for the given slot ID or no ImsResolver instance has been created.
5287 * @param slotId The slot ID that the IMS service is created for.
5288 * @throws ImsException If there is no ImsService configured for this slot.
5289 */
5290 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5291 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5292 ImsFeature.FEATURE_MMTEL)) {
5293 throw new ImsException("This subscription does not support MMTEL over IMS",
5294 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5295 }
5296 }
5297
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005298 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005299 int slotId = SubscriptionManager.getSlotIndex(subId);
5300 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005301 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5302 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005303 }
5304 return slotId;
5305 }
5306
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005307 private int getSlotIndex(int subId) {
5308 int slotId = SubscriptionManager.getSlotIndex(subId);
5309 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5310 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5311 }
5312 return slotId;
5313 }
5314
Wink Saville36469e72014-06-11 15:17:00 -07005315 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005316 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005317 */
5318 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005319 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5320 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005321 try {
5322 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5323 } catch (SecurityException se) {
5324 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5325 throw new SecurityException("Package " + callingPackage + " does not belong to "
5326 + Binder.getCallingUid());
5327 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005328 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005329 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005330 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005331 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005332 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005333 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005334 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005335 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5336 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005337
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005338 final long identity = Binder.clearCallingIdentity();
5339 try {
5340 final Phone phone = getPhone(subId);
5341 if (phone != null) {
5342 return phone.getServiceState().getDataNetworkType();
5343 } else {
5344 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5345 }
5346 } finally {
5347 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005348 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005349 }
5350
5351 /**
5352 * Returns the data network type
5353 */
5354 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005355 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005356 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005357 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005358 }
5359
5360 /**
5361 * Returns the data network type for a subId
5362 */
5363 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005364 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5365 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005366 String functionName = "getDataNetworkTypeForSubscriber";
5367 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5368 mApp, functionName)) {
5369 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5370 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5371 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5372 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005373 }
5374
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005375 final long identity = Binder.clearCallingIdentity();
5376 try {
5377 final Phone phone = getPhone(subId);
5378 if (phone != null) {
5379 return phone.getServiceState().getDataNetworkType();
5380 } else {
5381 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5382 }
5383 } finally {
5384 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005385 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005386 }
5387
5388 /**
Wink Saville36469e72014-06-11 15:17:00 -07005389 * Returns the Voice network type for a subId
5390 */
5391 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005392 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5393 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005394 String functionName = "getVoiceNetworkTypeForSubscriber";
5395 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5396 mApp, functionName)) {
5397 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5398 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5399 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5400 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005401 }
5402
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403 final long identity = Binder.clearCallingIdentity();
5404 try {
5405 final Phone phone = getPhone(subId);
5406 if (phone != null) {
5407 return phone.getServiceState().getVoiceNetworkType();
5408 } else {
5409 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5410 }
5411 } finally {
5412 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005413 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005414 }
5415
5416 /**
5417 * @return true if a ICC card is present
5418 */
5419 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005420 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005421 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005422 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005423 }
5424
5425 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005426 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005427 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005428 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005429 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 final long identity = Binder.clearCallingIdentity();
5431 try {
5432 final Phone phone = PhoneFactory.getPhone(slotIndex);
5433 if (phone != null) {
5434 return phone.getIccCard().hasIccCard();
5435 } else {
5436 return false;
5437 }
5438 } finally {
5439 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005441 }
5442
5443 /**
5444 * Return if the current radio is LTE on CDMA. This
5445 * is a tri-state return value as for a period of time
5446 * the mode may be unknown.
5447 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005448 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005449 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005450 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005451 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005452 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005453 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5454 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5455 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005456 }
5457
Sanket Padawe356d7632015-06-22 14:03:32 -07005458 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005459 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5460 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005461 try {
5462 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5463 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005464 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5465 }
5466
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005467 final long identity = Binder.clearCallingIdentity();
5468 try {
5469 final Phone phone = getPhone(subId);
5470 if (phone == null) {
5471 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5472 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005473 return TelephonyProperties.lte_on_cdma_device()
5474 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475 }
5476 } finally {
5477 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005478 }
Wink Saville36469e72014-06-11 15:17:00 -07005479 }
5480
Wink Saville36469e72014-06-11 15:17:00 -07005481 /**
5482 * {@hide}
5483 * Returns Default subId, 0 in the case of single standby.
5484 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005485 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005486 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005487 }
5488
Shishir Agrawala9f32182016-04-12 12:00:16 -07005489 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005490 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005491 }
5492
Wink Savilleb564aae2014-10-23 10:18:09 -07005493 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005494 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005495 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005496
Pengquan Menge92a50d2018-09-21 15:54:48 -07005497 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08005498 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08005499 return getSubscriptionManagerService().isActiveSubId(subId,
Jack Yu285100e2022-12-02 22:48:35 -08005500 mApp.getOpPackageName(), mApp.getFeatureId());
5501 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005502 return mSubscriptionController.isActiveSubId(subId);
5503 }
5504
Ihab Awadf2177b72013-11-25 13:33:23 -08005505 /**
5506 * @see android.telephony.TelephonyManager.WifiCallingChoices
5507 */
5508 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005509 final long identity = Binder.clearCallingIdentity();
5510 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005511 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005512 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5513 getWhenToMakeWifiCallsDefaultPreference());
5514 } finally {
5515 Binder.restoreCallingIdentity(identity);
5516 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005517 }
5518
5519 /**
5520 * @see android.telephony.TelephonyManager.WifiCallingChoices
5521 */
5522 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 final long identity = Binder.clearCallingIdentity();
5524 try {
5525 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005526 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005527 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5528 } finally {
5529 Binder.restoreCallingIdentity(identity);
5530 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005531 }
5532
Sailesh Nepald1e68152013-12-12 19:08:02 -08005533 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005534 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005535 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005536 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005537
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005538 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5539 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5540 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005541 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005542 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005543 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005544 }
5545 return PhoneFactory.getPhone(phoneId);
5546 }
5547
Shishir Agrawal566b7612013-10-28 14:41:00 -07005548 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005549 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005550 @NonNull IccLogicalChannelRequest request) {
5551 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5552 /*message=*/ "iccOpenLogicalChannel");
5553
5554 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5555 // Verify that the callingPackage in the request belongs to the calling UID
5556 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5557
5558 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005559 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005560
Rambo Wanga1782702021-11-10 20:15:19 -08005561 private Phone getPhoneFromValidIccLogicalChannelRequest(
5562 @NonNull IccLogicalChannelRequest request, String message) {
5563 Phone phone;
5564 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5565 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5566 mApp, request.subId, message);
5567 phone = getPhoneFromSubId(request.subId);
5568 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5569 enforceModifyPermission();
5570 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5571 } else {
5572 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005573 }
Rambo Wanga1782702021-11-10 20:15:19 -08005574 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005575 }
5576
5577 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005578 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005579 final long identity = Binder.clearCallingIdentity();
5580 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005581 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005583 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5584 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005585 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5586 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587 loge("The calling package is not allowed to access ISD-R.");
5588 throw new SecurityException(
5589 "The calling package is not allowed to access ISD-R.");
5590 }
Derek Tan740e1672017-06-27 14:56:27 -07005591 }
Derek Tan740e1672017-06-27 14:56:27 -07005592
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005593 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005594 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5595 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005596 return response;
5597 } finally {
5598 Binder.restoreCallingIdentity(identity);
5599 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005600 }
5601
5602 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005603 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5604 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5605 /*message=*/"iccCloseLogicalChannel");
5606
5607 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5608
5609 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005610 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005611
Rambo Wanga1782702021-11-10 20:15:19 -08005612 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5613 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005614 // before this feature is enabled, this API should only return false if
5615 // the operation fails instead of throwing runtime exception for
5616 // backward-compatibility.
5617 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5618 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005619 final long identity = Binder.clearCallingIdentity();
5620 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005621 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005622 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005623 }
Chen Xue9d737e2022-01-01 23:41:31 -08005624 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005625 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005626 Boolean success = false;
5627 if (result instanceof RuntimeException) {
5628 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005629 if (shouldThrowExceptionOnFailure) {
5630 throw (RuntimeException) result;
5631 } else {
5632 return false;
5633 }
Chen Xue9d737e2022-01-01 23:41:31 -08005634 } else if (result instanceof Boolean) {
5635 success = (Boolean) result;
5636 } else {
5637 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5638 }
Rambo Wanga1782702021-11-10 20:15:19 -08005639 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640 return success;
5641 } finally {
5642 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005643 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005644 }
5645
5646 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005647 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005648 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005649 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5650 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005651 if (DBG) {
5652 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5653 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5654 + p3 + " data=" + data);
5655 }
5656 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5657 command, p1, p2, p3, data);
5658 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005659
Jordan Liu4c733742019-02-28 12:03:40 -08005660 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005661 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005662 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005663 enforceModifyPermission();
5664 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005665 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005666 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5667 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005668 }
5669 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005670 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5671 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005672 }
5673
5674 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5675 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676 final long identity = Binder.clearCallingIdentity();
5677 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005678 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005679 return "";
5680 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005681
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005682 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005683 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5684 null /* workSource */);
5685 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005686
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005687 // Append the returned status code to the end of the response payload.
5688 String s = Integer.toHexString(
5689 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5690 if (response.payload != null) {
5691 s = IccUtils.bytesToHexString(response.payload) + s;
5692 }
5693 return s;
5694 } finally {
5695 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005696 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005697 }
Jake Hambye994d462014-02-03 13:10:13 -08005698
Evan Charltonc66da362014-05-16 14:06:40 -07005699 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005700 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5701 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5703 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005704 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005705 if (DBG) {
5706 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5707 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5708 }
5709 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5710 cla, command, p1, p2, p3, data);
5711 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005712
Jordan Liu4c733742019-02-28 12:03:40 -08005713 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005714 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005715 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005716 enforceModifyPermission();
5717 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5718 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005719 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005720 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5721 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005722 }
5723
5724 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005725 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5726 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005727 }
5728
5729 // open APDU basic channel assuming the caller has sufficient permissions
5730 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5731 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005732 final long identity = Binder.clearCallingIdentity();
5733 try {
5734 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5735 && TextUtils.equals(ISDR_AID, data)) {
5736 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005737 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5738 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005739 if (bestComponent == null
5740 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5741 loge("The calling package is not allowed to select ISD-R.");
5742 throw new SecurityException(
5743 "The calling package is not allowed to select ISD-R.");
5744 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005745 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005746
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005748 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5749 null /* workSource */);
5750 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005751
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005752 // Append the returned status code to the end of the response payload.
5753 String s = Integer.toHexString(
5754 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5755 if (response.payload != null) {
5756 s = IccUtils.bytesToHexString(response.payload) + s;
5757 }
5758 return s;
5759 } finally {
5760 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005761 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005762 }
5763
5764 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005765 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005766 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5768 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005769
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770 final long identity = Binder.clearCallingIdentity();
5771 try {
5772 if (DBG) {
5773 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5774 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5775 }
5776
5777 IccIoResult response =
5778 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5779 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5780 subId);
5781
5782 if (DBG) {
5783 log("Exchange SIM_IO [R]" + response);
5784 }
5785
5786 byte[] result = null;
5787 int length = 2;
5788 if (response.payload != null) {
5789 length = 2 + response.payload.length;
5790 result = new byte[length];
5791 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5792 } else {
5793 result = new byte[length];
5794 }
5795
5796 result[length - 1] = (byte) response.sw2;
5797 result[length - 2] = (byte) response.sw1;
5798 return result;
5799 } finally {
5800 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005801 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005802 }
5803
Nathan Haroldb3014052017-01-25 15:57:32 -08005804 /**
5805 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5806 * on a particular subscription
5807 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005808 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5809 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005810 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005811 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005812 return null;
5813 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005814
5815 final long identity = Binder.clearCallingIdentity();
5816 try {
5817 if (appType != TelephonyManager.APPTYPE_USIM
5818 && appType != TelephonyManager.APPTYPE_SIM) {
5819 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5820 return null;
5821 }
5822 Object response = sendRequest(
5823 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5824 if (response instanceof String[]) {
5825 return (String[]) response;
5826 }
yincheng zhao2737e882019-09-06 17:06:54 -07005827 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005828 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005829 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005830 } finally {
5831 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005832 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005833 }
5834
yincheng zhao2737e882019-09-06 17:06:54 -07005835 /**
5836 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5837 * subscription.
5838 *
5839 * @param subId the id of the subscription.
5840 * @param appType the uicc app type, must be USIM or SIM.
5841 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5842 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005843 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005844 * @return number of fplmns that is successfully written to the SIM.
5845 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005846 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5847 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5849 mApp, subId, "setForbiddenPlmns");
5850
yincheng zhao2737e882019-09-06 17:06:54 -07005851 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5852 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5853 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5854 }
5855 if (fplmns == null) {
5856 throw new IllegalArgumentException("Fplmn List provided is null");
5857 }
5858 for (String fplmn : fplmns) {
5859 if (!CellIdentity.isValidPlmn(fplmn)) {
5860 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5861 }
5862 }
5863 final long identity = Binder.clearCallingIdentity();
5864 try {
5865 Object response = sendRequest(
5866 CMD_SET_FORBIDDEN_PLMNS,
5867 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5868 subId);
5869 return (int) response;
5870 } finally {
5871 Binder.restoreCallingIdentity(identity);
5872 }
5873 }
5874
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005875 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005876 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5878 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005879
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005880 final long identity = Binder.clearCallingIdentity();
5881 try {
5882 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5883 if (response.payload == null) {
5884 return "";
5885 }
Evan Charltonc66da362014-05-16 14:06:40 -07005886
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005887 // Append the returned status code to the end of the response payload.
5888 String s = Integer.toHexString(
5889 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5890 s = IccUtils.bytesToHexString(response.payload) + s;
5891 return s;
5892 } finally {
5893 Binder.restoreCallingIdentity(identity);
5894 }
Evan Charltonc66da362014-05-16 14:06:40 -07005895 }
5896
Jake Hambye994d462014-02-03 13:10:13 -08005897 /**
5898 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5899 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5900 *
5901 * @param itemID the ID of the item to read
5902 * @return the NV item as a String, or null on error.
5903 */
5904 @Override
5905 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005906 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005907 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5908 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005909
5910 final long identity = Binder.clearCallingIdentity();
5911 try {
5912 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005913 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005914 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5915 return value;
5916 } finally {
5917 Binder.restoreCallingIdentity(identity);
5918 }
Jake Hambye994d462014-02-03 13:10:13 -08005919 }
5920
5921 /**
5922 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5923 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5924 *
5925 * @param itemID the ID of the item to read
5926 * @param itemValue the value to write, as a String
5927 * @return true on success; false on any failure
5928 */
5929 @Override
5930 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005931 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5933 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005934
5935 final long identity = Binder.clearCallingIdentity();
5936 try {
5937 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5938 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005939 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005940 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5941 return success;
5942 } finally {
5943 Binder.restoreCallingIdentity(identity);
5944 }
Jake Hambye994d462014-02-03 13:10:13 -08005945 }
5946
5947 /**
5948 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5949 * Used for device configuration by some CDMA operators.
5950 *
5951 * @param preferredRoamingList byte array containing the new PRL
5952 * @return true on success; false on any failure
5953 */
5954 @Override
5955 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005956 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5957 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005958
5959 final long identity = Binder.clearCallingIdentity();
5960 try {
5961 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5962 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5963 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5964 return success;
5965 } finally {
5966 Binder.restoreCallingIdentity(identity);
5967 }
Jake Hambye994d462014-02-03 13:10:13 -08005968 }
5969
5970 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005971 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005972 * Used for device configuration by some CDMA operators.
5973 *
chen xu6dac5ab2018-10-26 17:39:23 -07005974 * @param slotIndex - device slot.
5975 *
Jake Hambye994d462014-02-03 13:10:13 -08005976 * @return true on success; false on any failure
5977 */
5978 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005979 public boolean resetModemConfig(int slotIndex) {
5980 Phone phone = PhoneFactory.getPhone(slotIndex);
5981 if (phone != null) {
5982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5983 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984
chen xu6dac5ab2018-10-26 17:39:23 -07005985 final long identity = Binder.clearCallingIdentity();
5986 try {
5987 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5988 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5989 return success;
5990 } finally {
5991 Binder.restoreCallingIdentity(identity);
5992 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 }
chen xu6dac5ab2018-10-26 17:39:23 -07005994 return false;
5995 }
5996
5997 /**
5998 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5999 *
6000 * @param slotIndex - device slot.
6001 *
6002 * @return true on success; false on any failure
6003 */
6004 @Override
6005 public boolean rebootModem(int slotIndex) {
6006 Phone phone = PhoneFactory.getPhone(slotIndex);
6007 if (phone != null) {
6008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6009 mApp, phone.getSubId(), "rebootModem");
6010
6011 final long identity = Binder.clearCallingIdentity();
6012 try {
6013 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6014 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6015 return success;
6016 } finally {
6017 Binder.restoreCallingIdentity(identity);
6018 }
6019 }
6020 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006021 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006022
Brad Ebinger51f743a2017-01-23 13:50:20 -08006023 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006024 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6025 * {@link #disableIms(int)}.
6026 * @param slotIndex device slot.
6027 */
6028 public void resetIms(int slotIndex) {
6029 enforceModifyPermission();
6030
6031 final long identity = Binder.clearCallingIdentity();
6032 try {
6033 if (mImsResolver == null) {
6034 // may happen if the does not support IMS.
6035 return;
6036 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006037 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006038 } finally {
6039 Binder.restoreCallingIdentity(identity);
6040 }
6041 }
6042
6043 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006044 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6045 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006046 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006047 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006048 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006049
6050 final long identity = Binder.clearCallingIdentity();
6051 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006052 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006053 // may happen if the device does not support IMS.
6054 return;
6055 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006056 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006057 } finally {
6058 Binder.restoreCallingIdentity(identity);
6059 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006060 }
6061
6062 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006063 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6064 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006065 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006066 public void disableIms(int slotId) {
6067 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068
6069 final long identity = Binder.clearCallingIdentity();
6070 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006071 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006072 // may happen if the device does not support IMS.
6073 return;
6074 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006075 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006076 } finally {
6077 Binder.restoreCallingIdentity(identity);
6078 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006079 }
6080
6081 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006082 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6083 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006084 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006085 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006086 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006087 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006088
6089 final long identity = Binder.clearCallingIdentity();
6090 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006091 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006092 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6093 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006094 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006095 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006096 } finally {
6097 Binder.restoreCallingIdentity(identity);
6098 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006099 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006100 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006101 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6102 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006103 @Override
6104 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006105 enforceModifyPermission();
6106
6107 final long identity = Binder.clearCallingIdentity();
6108 try {
6109 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006110 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006111 } finally {
6112 Binder.restoreCallingIdentity(identity);
6113 }
6114 }
6115
6116 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006117 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006118 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006119 */
6120 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6121 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006122
6123 final long identity = Binder.clearCallingIdentity();
6124 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006125 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006126 // may happen if the device does not support IMS.
6127 return null;
6128 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006129 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006130 } finally {
6131 Binder.restoreCallingIdentity(identity);
6132 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006133 }
6134
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006135 /**
6136 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006137 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006138 */
6139 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6140 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006141
6142 final long identity = Binder.clearCallingIdentity();
6143 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006144 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006145 // may happen if the device does not support IMS.
6146 return null;
6147 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006148 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006149 } finally {
6150 Binder.restoreCallingIdentity(identity);
6151 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006152 }
6153
Brad Ebinger884c07b2018-02-15 16:17:40 -08006154 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006155 * Sets the ImsService Package Name that Telephony will bind to.
6156 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006157 * @param slotIndex the slot ID that the ImsService should bind for.
6158 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006159 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006160 * @param featureTypes An integer array of feature types associated with a packageName.
6161 * @param packageName The name of the package that the current configuration will be replaced
6162 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006163 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006164 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006165 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6166 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006167 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006168 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006169 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171 final long identity = Binder.clearCallingIdentity();
6172 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006173 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006174 // may happen if the device does not support IMS.
6175 return false;
6176 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006177 Map<Integer, String> featureConfig = new HashMap<>();
6178 for (int featureType : featureTypes) {
6179 featureConfig.put(featureType, packageName);
6180 }
6181 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6182 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006183 } finally {
6184 Binder.restoreCallingIdentity(identity);
6185 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006186 }
6187
6188 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006189 * Clears any carrier ImsService overrides for the slot index specified that were previously
6190 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6191 *
6192 * This should only be used for testing.
6193 *
6194 * @param slotIndex the slot ID that the ImsService should bind for.
6195 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6196 */
6197 @Override
6198 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006199 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6200 "clearCarrierImsServiceOverride");
6201 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006202 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006203
6204 final long identity = Binder.clearCallingIdentity();
6205 try {
6206 if (mImsResolver == null) {
6207 // may happen if the device does not support IMS.
6208 return false;
6209 }
6210 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6211 } finally {
6212 Binder.restoreCallingIdentity(identity);
6213 }
6214 }
6215
6216 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006217 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006218 *
6219 * @param slotId The slot that the ImsService is associated with.
6220 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6221 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006222 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006223 * @return the package name of the ImsService configuration.
6224 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006225 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6226 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006227 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006228 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6229 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006230
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006231 final long identity = Binder.clearCallingIdentity();
6232 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006233 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006234 // may happen if the device does not support IMS.
6235 return "";
6236 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006237 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006238 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6239 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006240 } finally {
6241 Binder.restoreCallingIdentity(identity);
6242 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006243 }
6244
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006245 /**
6246 * Get the MmTelFeature state associated with the requested subscription id.
6247 * @param subId The subscription that the MmTelFeature is associated with.
6248 * @param callback A callback with an integer containing the
6249 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6250 */
6251 @Override
6252 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6253 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006254 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6255 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6256 "IMS not available on device.");
6257 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006258 final long token = Binder.clearCallingIdentity();
6259 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006260 int slotId = getSlotIndex(subId);
6261 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6262 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6263 + subId + "'");
6264 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6265 }
6266 verifyImsMmTelConfiguredOrThrow(slotId);
6267 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6268 try {
6269 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6270 } catch (RemoteException e) {
6271 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6272 + "Ignore");
6273 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006274 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006275 } catch (ImsException e) {
6276 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006277 } finally {
6278 Binder.restoreCallingIdentity(token);
6279 }
6280 }
6281
Daniel Brightbb5840b2021-01-12 15:48:18 -08006282 /**
6283 * Sets the ims registration state on all valid {@link Phone}s.
6284 */
6285 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006286 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006287
6288 final long identity = Binder.clearCallingIdentity();
6289 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006290 // NOTE: Before S, this method only set the default phone.
6291 for (final Phone phone : PhoneFactory.getPhones()) {
6292 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6293 phone.setImsRegistrationState(registered);
6294 }
6295 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006296 } finally {
6297 Binder.restoreCallingIdentity(identity);
6298 }
Wink Saville36469e72014-06-11 15:17:00 -07006299 }
6300
6301 /**
Stuart Scott54788802015-03-30 13:18:01 -07006302 * Set the network selection mode to automatic.
6303 *
6304 */
6305 @Override
6306 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006307 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6308 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006309
6310 final long identity = Binder.clearCallingIdentity();
6311 try {
shilufc958392020-01-20 11:36:01 -08006312 if (!isActiveSubscription(subId)) {
6313 return;
6314 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006315 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006316 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6317 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006318 } finally {
6319 Binder.restoreCallingIdentity(identity);
6320 }
Stuart Scott54788802015-03-30 13:18:01 -07006321 }
6322
Jack Yud10cdd42020-09-28 20:28:01 -07006323 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006324 * Ask the radio to connect to the input network and change selection mode to manual.
6325 *
6326 * @param subId the id of the subscription.
6327 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6328 * the operator to attach to.
6329 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6330 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6331 * normal network selection next time.
6332 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006333 */
6334 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006335 public boolean setNetworkSelectionModeManual(
6336 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006337 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6338 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006339
Jack Yu285100e2022-12-02 22:48:35 -08006340 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006341 if (!isActiveSubscription(subId)) {
6342 return false;
6343 }
6344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006345 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006346 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006347 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006348 if (DBG) {
6349 log("setNetworkSelectionModeManual: subId: " + subId
6350 + " operator: " + operatorInfo);
6351 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006352 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6353 } finally {
6354 Binder.restoreCallingIdentity(identity);
6355 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006356 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006357 /**
shilu84f6e8b2019-12-19 13:58:01 -08006358 * Get the manual network selection
6359 *
6360 * @param subId the id of the subscription.
6361 *
6362 * @return the previously saved user selected PLMN
6363 */
6364 @Override
6365 public String getManualNetworkSelectionPlmn(int subId) {
6366 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006367 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6368 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006369
6370 final long identity = Binder.clearCallingIdentity();
6371 try {
6372 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006373 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006374 }
6375
6376 final Phone phone = getPhone(subId);
6377 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006378 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006379 }
6380 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6381 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006382 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006383 } finally {
6384 Binder.restoreCallingIdentity(identity);
6385 }
6386 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006387
6388 /**
6389 * Scans for available networks.
6390 */
6391 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006392 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6393 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006394 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6395 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006396 LocationAccessPolicy.LocationPermissionResult locationResult =
6397 LocationAccessPolicy.checkLocationPermission(mApp,
6398 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6399 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006400 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006401 .setCallingPid(Binder.getCallingPid())
6402 .setCallingUid(Binder.getCallingUid())
6403 .setMethod("getCellNetworkScanResults")
6404 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006405 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6406 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006407 .build());
6408 switch (locationResult) {
6409 case DENIED_HARD:
6410 throw new SecurityException("Not allowed to access scan results -- location");
6411 case DENIED_SOFT:
6412 return null;
6413 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006414
Pengquan Menga1bb6272018-09-06 09:59:22 -07006415 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006416 try {
6417 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006418 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006419 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006420 } finally {
6421 Binder.restoreCallingIdentity(identity);
6422 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006423 }
6424
6425 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006426 * Get the call forwarding info, given the call forwarding reason.
6427 */
6428 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006429 public void getCallForwarding(int subId, int callForwardingReason,
6430 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006431 enforceReadPrivilegedPermission("getCallForwarding");
6432 long identity = Binder.clearCallingIdentity();
6433 try {
6434 if (DBG) {
6435 log("getCallForwarding: subId " + subId
6436 + " callForwardingReason" + callForwardingReason);
6437 }
Hall Liu27d24262020-09-18 19:04:59 -07006438
6439 Phone phone = getPhone(subId);
6440 if (phone == null) {
6441 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006442 callback.onError(
6443 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006444 } catch (RemoteException e) {
6445 // ignore
6446 }
6447 return;
6448 }
6449
6450 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6451 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6452 @Override
6453 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6454 try {
6455 callback.onCallForwardingInfoAvailable(info);
6456 } catch (RemoteException e) {
6457 // ignore
6458 }
6459 }
6460
6461 @Override
6462 public void onError(int error) {
6463 try {
6464 callback.onError(error);
6465 } catch (RemoteException e) {
6466 // ignore
6467 }
6468 }
6469 });
6470 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006471 } finally {
6472 Binder.restoreCallingIdentity(identity);
6473 }
6474 }
6475
6476 /**
6477 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6478 * reason, the number to forward, and the timeout before the forwarding is attempted.
6479 */
6480 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006481 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6482 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006483 enforceModifyPermission();
6484 long identity = Binder.clearCallingIdentity();
6485 try {
6486 if (DBG) {
6487 log("setCallForwarding: subId " + subId
6488 + " callForwardingInfo" + callForwardingInfo);
6489 }
Hall Liu27d24262020-09-18 19:04:59 -07006490
6491 Phone phone = getPhone(subId);
6492 if (phone == null) {
6493 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006494 callback.accept(
6495 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006496 } catch (RemoteException e) {
6497 // ignore
6498 }
6499 return;
6500 }
6501
6502 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6503 FunctionalUtils.ignoreRemoteException(callback::accept));
6504
6505 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006506 } finally {
6507 Binder.restoreCallingIdentity(identity);
6508 }
6509 }
6510
6511 /**
Hall Liu27d24262020-09-18 19:04:59 -07006512 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006513 */
6514 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006515 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006516 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006517 long identity = Binder.clearCallingIdentity();
6518 try {
Hall Liu27d24262020-09-18 19:04:59 -07006519 Phone phone = getPhone(subId);
6520 if (phone == null) {
6521 try {
6522 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6523 } catch (RemoteException e) {
6524 // ignore
6525 }
6526 return;
6527 }
SongFerngWang0e767992021-03-31 22:08:45 +08006528 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6529 PersistableBundle c = configManager.getConfigForSubId(subId);
6530 boolean requireUssd = c.getBoolean(
6531 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006532
Shuo Qian4a594052020-01-23 11:59:30 -08006533 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006534 if (requireUssd) {
6535 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6536 getSubscriptionCarrierId(subId));
6537 String newUssdCommand = "";
6538 try {
6539 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006540 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006541 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6542 } catch (NullPointerException e) {
6543 loge("Failed to generate USSD number" + e);
6544 }
6545 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6546 mMainThreadHandler, callback, carrierXmlParser,
6547 CarrierXmlParser.SsEntry.SSAction.QUERY);
6548 final String ussdCommand = newUssdCommand;
6549 Executors.newSingleThreadExecutor().execute(() -> {
6550 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6551 });
6552 } else {
6553 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6554 callback::accept);
6555 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6556 }
Shuo Qian4a594052020-01-23 11:59:30 -08006557 } finally {
6558 Binder.restoreCallingIdentity(identity);
6559 }
6560 }
6561
6562 /**
Hall Liu27d24262020-09-18 19:04:59 -07006563 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006564 */
6565 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006566 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006567 enforceModifyPermission();
6568 long identity = Binder.clearCallingIdentity();
6569 try {
Hall Liu27d24262020-09-18 19:04:59 -07006570 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6571
6572 Phone phone = getPhone(subId);
6573 if (phone == null) {
6574 try {
6575 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6576 } catch (RemoteException e) {
6577 // ignore
6578 }
6579 return;
6580 }
6581
SongFerngWang0e767992021-03-31 22:08:45 +08006582 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6583 PersistableBundle c = configManager.getConfigForSubId(subId);
6584 boolean requireUssd = c.getBoolean(
6585 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006586
SongFerngWang0e767992021-03-31 22:08:45 +08006587 if (DBG) log("getCallWaitingStatus: subId " + subId);
6588 if (requireUssd) {
6589 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6590 getSubscriptionCarrierId(subId));
6591 CarrierXmlParser.SsEntry.SSAction ssAction =
6592 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6593 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6594 String newUssdCommand = "";
6595 try {
6596 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006597 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006598 .makeCommand(ssAction, null);
6599 } catch (NullPointerException e) {
6600 loge("Failed to generate USSD number" + e);
6601 }
6602 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6603 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6604 final String ussdCommand = newUssdCommand;
6605 Executors.newSingleThreadExecutor().execute(() -> {
6606 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6607 });
6608 } else {
6609 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6610 FunctionalUtils.ignoreRemoteException(callback::accept));
6611
6612 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6613 }
Shuo Qian4a594052020-01-23 11:59:30 -08006614 } finally {
6615 Binder.restoreCallingIdentity(identity);
6616 }
6617 }
6618
6619 /**
yinxub1bed742017-04-17 11:45:04 -07006620 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006621 *
yinxub1bed742017-04-17 11:45:04 -07006622 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006623 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6624 * location related information which will be sent if the caller already possess
6625 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006626 * @param request contains the radio access networks with bands/channels to scan
6627 * @param messenger callback messenger for scan results or errors
6628 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006629 * @return the id of the requested scan which can be used to stop the scan.
6630 */
6631 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006632 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6633 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006634 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6636 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006637 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006638 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6639 if (!renounceFineLocationAccess) {
6640 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006641 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6642 .setCallingPackage(callingPackage)
6643 .setCallingFeatureId(callingFeatureId)
6644 .setCallingPid(Binder.getCallingPid())
6645 .setCallingUid(Binder.getCallingUid())
6646 .setMethod("requestNetworkScan")
6647 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6648 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6649 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6650 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006651 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006652 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006653 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6654 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006655 if (e != null) {
6656 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6657 throw e;
6658 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006659 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006660 return TelephonyScanManager.INVALID_SCAN_ID;
6661 }
6662 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006663 }
Hall Liu912dfd32019-04-25 14:02:26 -07006664 int callingUid = Binder.getCallingUid();
6665 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006666 final long identity = Binder.clearCallingIdentity();
6667 try {
6668 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07006669 renounceFineLocationAccess, request, messenger, binder,
6670 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006671 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006672 } finally {
6673 Binder.restoreCallingIdentity(identity);
6674 }
yinxu504e1392017-04-12 16:03:22 -07006675 }
6676
Hall Liub2ac8ef2019-02-28 15:56:23 -08006677 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006678 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006679 boolean hasCarrierPriv;
6680 final long identity = Binder.clearCallingIdentity();
6681 try {
6682 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6683 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6684 } finally {
6685 Binder.restoreCallingIdentity(identity);
6686 }
Hall Liu558027f2019-05-15 19:14:05 -07006687 boolean hasNetworkScanPermission =
6688 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006689 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07006690
6691 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6692 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6693 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006694 }
6695
6696 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6697 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006698 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6699 return new SecurityException("Specific channels must not be"
6700 + " scanned without location access.");
6701 }
6702 }
6703 }
6704
Hall Liub2ac8ef2019-02-28 15:56:23 -08006705 return null;
6706 }
6707
yinxu504e1392017-04-12 16:03:22 -07006708 /**
6709 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006710 *
6711 * @param subId id of the subscription
6712 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006713 */
6714 @Override
6715 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6717 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006718
Hall Liu912dfd32019-04-25 14:02:26 -07006719 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006720 final long identity = Binder.clearCallingIdentity();
6721 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006722 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006723 } finally {
6724 Binder.restoreCallingIdentity(identity);
6725 }
yinxu504e1392017-04-12 16:03:22 -07006726 }
6727
6728 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006729 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006730 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006731 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006732 */
6733 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006734 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006735 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006736 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006737 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006738
6739 final long identity = Binder.clearCallingIdentity();
6740 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006741 if (DBG) log("getAllowedNetworkTypesBitmask");
6742 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6743 int networkTypesBitmask = (result != null ? result[0] : -1);
6744 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6745 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006746 } finally {
6747 Binder.restoreCallingIdentity(identity);
6748 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006749 }
6750
6751 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006752 * Get the allowed network types for certain reason.
6753 *
6754 * @param subId the id of the subscription.
6755 * @param reason the reason the allowed network type change is taking place
6756 * @return the allowed network types.
6757 */
6758 @Override
6759 public long getAllowedNetworkTypesForReason(int subId,
6760 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006761 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006762 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006763 final long identity = Binder.clearCallingIdentity();
6764 try {
Jack Yu7247ac82023-03-02 23:52:10 -08006765 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006766 } finally {
6767 Binder.restoreCallingIdentity(identity);
6768 }
6769 }
6770
6771 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006772 * Enable/Disable E-UTRA-NR Dual Connectivity
6773 * @param subId subscription id of the sim card
6774 * @param nrDualConnectivityState expected NR dual connectivity state
6775 * This can be passed following states
6776 * <ol>
6777 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6778 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6779 * <li>Disable NR dual connectivity and force secondary cell to be released
6780 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6781 * </ol>
6782 * @return operation result.
6783 */
6784 @Override
6785 public int setNrDualConnectivityState(int subId,
6786 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6788 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006789 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006790 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6791 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6792 }
6793
Sooraj Sasindran37444802020-08-11 10:40:43 -07006794 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6795 final long identity = Binder.clearCallingIdentity();
6796 try {
6797 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6798 nrDualConnectivityState, subId,
6799 workSource);
6800 if (DBG) log("enableNRDualConnectivity result: " + result);
6801 return result;
6802 } finally {
6803 Binder.restoreCallingIdentity(identity);
6804 }
6805 }
6806
6807 /**
6808 * Is E-UTRA-NR Dual Connectivity enabled
6809 * @return true if dual connectivity is enabled else false
6810 */
6811 @Override
6812 public boolean isNrDualConnectivityEnabled(int subId) {
6813 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006814 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006815 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006816 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006817 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6818 return false;
6819 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006820 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6821 final long identity = Binder.clearCallingIdentity();
6822 try {
6823 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6824 null, subId, workSource);
6825 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6826 return isEnabled;
6827 } finally {
6828 Binder.restoreCallingIdentity(identity);
6829 }
6830 }
6831
6832 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006833 * Set the allowed network types of the device and
6834 * provide the reason triggering the allowed network change.
6835 *
6836 * @param subId the id of the subscription.
6837 * @param reason the reason the allowed network type change is taking place
6838 * @param allowedNetworkTypes the allowed network types.
6839 * @return true on success; false on any failure.
6840 */
6841 @Override
6842 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006843 @TelephonyManager.AllowedNetworkTypesReason int reason,
6844 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6846 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006847 // If the caller only has carrier privileges, then they should not be able to override
6848 // any network types which were set for security reasons.
6849 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6850 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006851 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006852 throw new SecurityException(
6853 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006854 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006855 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006856 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006857 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08006858 return false;
6859 }
6860 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6861 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006862 return false;
6863 }
6864
Jack Yu5b494332023-01-23 18:18:04 +00006865 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
6866 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006867
Jack Yue37dd262022-12-16 11:53:37 -08006868 Phone phone = getPhone(subId);
6869 if (phone == null) {
6870 return false;
6871 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006872
Jack Yue37dd262022-12-16 11:53:37 -08006873 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006874 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006875 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006876 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006877
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006878 final long identity = Binder.clearCallingIdentity();
6879 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006880 Boolean success = (Boolean) sendRequest(
6881 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6882 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6883
6884 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6885 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006886 } finally {
6887 Binder.restoreCallingIdentity(identity);
6888 }
6889 }
6890
6891 /**
Miaoa84611c2019-03-15 09:21:10 +08006892 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006893 *
Miaoa84611c2019-03-15 09:21:10 +08006894 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006895 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006896 * @hide
6897 */
6898 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006899 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006900 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006901 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006902 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006903 try {
Miaoa84611c2019-03-15 09:21:10 +08006904 if (phone != null) {
6905 return phone.hasMatchedTetherApnSetting();
6906 } else {
6907 return false;
6908 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006909 } finally {
6910 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006911 }
Junda Liu475951f2014-11-07 16:45:03 -08006912 }
6913
6914 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006915 * Get the user enabled state of Mobile Data.
6916 *
6917 * TODO: remove and use isUserDataEnabled.
6918 * This can't be removed now because some vendor codes
6919 * calls through ITelephony directly while they should
6920 * use TelephonyManager.
6921 *
6922 * @return true on enabled
6923 */
6924 @Override
6925 public boolean getDataEnabled(int subId) {
6926 return isUserDataEnabled(subId);
6927 }
6928
6929 /**
6930 * Get whether mobile data is enabled per user setting.
6931 *
6932 * There are other factors deciding whether mobile data is actually enabled, but they are
6933 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006934 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006935 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6936 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006937 *
6938 * @return {@code true} if data is enabled else {@code false}
6939 */
6940 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006941 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006942 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006943 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006944 try {
6945 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6946 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006947 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006948 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6949 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006950 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006951 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006952 mApp, subId, functionName);
6953
Robert Greenwalt646120a2014-05-23 11:54:03 -07006954 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006955
6956 final long identity = Binder.clearCallingIdentity();
6957 try {
Jack Yu285100e2022-12-02 22:48:35 -08006958 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006959 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6960 Phone phone = PhoneFactory.getPhone(phoneId);
6961 if (phone != null) {
6962 boolean retVal = phone.isUserDataEnabled();
6963 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6964 return retVal;
6965 } else {
6966 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6967 return false;
6968 }
6969 } finally {
6970 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006971 }
6972 }
6973
6974 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006975 * Checks if the device is capable of mobile data by considering whether whether the
6976 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6977 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006978 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006979 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006980 */
6981 @Override
6982 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006983 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006984 try {
6985 try {
6986 mApp.enforceCallingOrSelfPermission(
6987 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006988 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006989 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006990 try {
6991 mApp.enforceCallingOrSelfPermission(
6992 android.Manifest.permission.READ_PHONE_STATE,
6993 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006994 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006995 mApp.enforceCallingOrSelfPermission(
6996 permission.READ_BASIC_PHONE_STATE, functionName);
6997 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006998 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006999 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007000 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007001 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007002
7003 final long identity = Binder.clearCallingIdentity();
7004 try {
Jack Yu285100e2022-12-02 22:48:35 -08007005 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007006 Phone phone = PhoneFactory.getPhone(phoneId);
7007 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007008 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007009 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007010 return retVal;
7011 } else {
7012 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7013 return false;
7014 }
7015 } finally {
7016 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007017 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007018 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007019
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007020 /**
7021 * Check if data is enabled for a specific reason
7022 * @param subId Subscription index
7023 * @param reason the reason the data enable change is taking place
7024 * @return {@code true} if the overall data is enabled; {@code false} if not.
7025 */
7026 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007027 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007028 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007029 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007030 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007031 try {
7032 mApp.enforceCallingOrSelfPermission(
7033 android.Manifest.permission.ACCESS_NETWORK_STATE,
7034 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007035 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007036 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7037 functionName);
7038 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007039 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007040 try {
7041 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007042 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007043 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007045 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007046 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007047 }
7048
7049
7050 final long identity = Binder.clearCallingIdentity();
7051 try {
Jack Yu285100e2022-12-02 22:48:35 -08007052 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007053 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007054 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007055 + " reason=" + reason);
7056 }
7057 Phone phone = PhoneFactory.getPhone(phoneId);
7058 if (phone != null) {
7059 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007060 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007061 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007062 return retVal;
7063 } else {
7064 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007065 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007066 + subId + " retVal=false");
7067 }
7068 return false;
7069 }
7070 } finally {
7071 Binder.restoreCallingIdentity(identity);
7072 }
7073 }
7074
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007075 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007076 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007077 // No permission needed; this only lets the caller inspect their own status.
7078 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007079 }
Junda Liu29340342014-07-10 15:23:27 -07007080
7081 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007082 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007083 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007084 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7085 }
7086
7087 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7088 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007089 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007090 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007091 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7092 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007093 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7094 if (cpt == null) {
7095 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007096 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7097 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007098 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007099 }
7100
7101 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007102 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007103 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007104 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007105 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007106 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007107 Phone phone = getPhone(subId);
7108 if (phone == null) {
7109 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7110 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7111 }
7112 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7113 if (cpt == null) {
7114 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007115 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7116 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007117 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007118 }
7119
7120 @Override
7121 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007122 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007123 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7124 }
7125
7126 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007127 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007128 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007129 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007130 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007131 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7132 Phone phone = PhoneFactory.getPhone(phoneId);
7133 if (phone == null) {
7134 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007135 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007136 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7137 if (cpt == null) {
7138 continue;
7139 }
7140 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007141 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7142 break;
7143 }
7144 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007145 return result;
Junda Liu29340342014-07-10 15:23:27 -07007146 }
Derek Tan89e89d42014-07-08 17:00:10 -07007147
7148 @Override
Junda Liue64de782015-04-16 17:19:16 -07007149 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007150 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007151 Phone phone = PhoneFactory.getPhone(phoneId);
7152 if (phone == null) {
7153 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007154 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007155 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7156 if (cpt == null) {
7157 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007158 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007159 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007160 }
7161
Amith Yamasani6e118872016-02-19 12:53:51 -08007162 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007163 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007164 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007165 Phone phone = PhoneFactory.getPhone(phoneId);
7166 if (phone == null) {
7167 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007168 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007169 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7170 if (cpt == null) {
7171 return Collections.emptyList();
7172 }
7173 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007174 }
7175
chen xuf7e9fe82019-05-09 19:31:02 -07007176 @Override
7177 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007178 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007179 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007180 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007181 try {
7182 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7183 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7184 }
7185 } finally {
7186 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007187 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007188 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007189 }
7190
Rambo Wang6812ffb2022-03-15 16:54:17 -07007191 @Override
7192 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7193 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7194
7195 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7196 if (phone == null) {
7197 return null;
7198 }
7199 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7200 if (cpt == null) {
7201 return null;
7202 }
7203 return cpt.getCarrierServicePackageName();
7204 }
7205
Wink Savilleb564aae2014-10-23 10:18:09 -07007206 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007207 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007208 UiccPort port = phone == null ? null : phone.getUiccPort();
7209 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007210 return null;
7211 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007212 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007213 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007214 return null;
7215 }
7216 return iccId;
7217 }
7218
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007219 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007220 public void setCallComposerStatus(int subId, int status) {
7221 enforceModifyPermission();
7222
7223 final long identity = Binder.clearCallingIdentity();
7224 try {
7225 Phone phone = getPhone(subId);
7226 if (phone != null) {
7227 Phone defaultPhone = phone.getImsPhone();
7228 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7229 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7230 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007231 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7232 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007233 }
7234 }
Shuo Qian284ae752020-12-22 19:10:14 -08007235 } catch (ImsException e) {
7236 throw new ServiceSpecificException(e.getCode());
7237 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007238 Binder.restoreCallingIdentity(identity);
7239 }
7240 }
7241
7242 @Override
7243 public int getCallComposerStatus(int subId) {
7244 enforceReadPrivilegedPermission("getCallComposerStatus");
7245
7246 final long identity = Binder.clearCallingIdentity();
7247 try {
7248 Phone phone = getPhone(subId);
7249 if (phone != null) {
7250 Phone defaultPhone = phone.getImsPhone();
7251 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7252 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7253 return imsPhone.getCallComposerStatus();
7254 }
7255 }
7256 } finally {
7257 Binder.restoreCallingIdentity(identity);
7258 }
7259 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7260 }
7261
7262 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007263 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7264 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007265 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007266 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007267
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007268 final long identity = Binder.clearCallingIdentity();
7269 try {
7270 final String iccId = getIccId(subId);
7271 final Phone phone = getPhone(subId);
7272 if (phone == null) {
7273 return false;
7274 }
7275 final String subscriberId = phone.getSubscriberId();
7276
7277 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007278 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007279 + subscriberId + " to " + number);
7280 }
7281
7282 if (TextUtils.isEmpty(iccId)) {
7283 return false;
7284 }
7285
7286 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7287
7288 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7289 if (alphaTag == null) {
7290 editor.remove(alphaTagPrefKey);
7291 } else {
7292 editor.putString(alphaTagPrefKey, alphaTag);
7293 }
7294
7295 // Record both the line number and IMSI for this ICCID, since we need to
7296 // track all merged IMSIs based on line number
7297 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7298 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7299 if (number == null) {
7300 editor.remove(numberPrefKey);
7301 editor.remove(subscriberPrefKey);
7302 } else {
7303 editor.putString(numberPrefKey, number);
7304 editor.putString(subscriberPrefKey, subscriberId);
7305 }
7306
7307 editor.commit();
7308 return true;
7309 } finally {
7310 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007311 }
Derek Tan7226c842014-07-02 17:42:23 -07007312 }
7313
7314 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007315 public String getLine1NumberForDisplay(int subId, String callingPackage,
7316 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007317 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007318 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007319 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007320 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007321 return null;
7322 }
Derek Tan97ebb422014-09-05 16:55:38 -07007323
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007324 final long identity = Binder.clearCallingIdentity();
7325 try {
7326 String iccId = getIccId(subId);
7327 if (iccId != null) {
7328 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7329 if (DBG_MERGE) {
7330 log("getLine1NumberForDisplay returning "
7331 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7332 }
7333 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007334 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007335 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7336 return null;
7337 } finally {
7338 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007339 }
Derek Tan7226c842014-07-02 17:42:23 -07007340 }
7341
7342 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007343 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7344 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007345 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007346 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007347 return null;
7348 }
Derek Tan97ebb422014-09-05 16:55:38 -07007349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007350 final long identity = Binder.clearCallingIdentity();
7351 try {
7352 String iccId = getIccId(subId);
7353 if (iccId != null) {
7354 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7355 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7356 }
7357 return null;
7358 } finally {
7359 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007360 }
Derek Tan7226c842014-07-02 17:42:23 -07007361 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007362
7363 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007364 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7365 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007366 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7367 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007368 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007369 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007370 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007371 return null;
7372 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007373
Jordan Liub49b04b2019-05-06 14:45:15 -07007374 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7375 // the process, where TelephonyManager was instantiated.
7376 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007377 final long identity = Binder.clearCallingIdentity();
7378 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007379 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007380 final TelephonyManager tele = TelephonyManager.from(context);
7381 final SubscriptionManager sub = SubscriptionManager.from(context);
7382
7383 // Figure out what subscribers are currently active
7384 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007385
Jordan Liub49b04b2019-05-06 14:45:15 -07007386 // Only consider subs which match the current subId
7387 // This logic can be simplified. See b/131189269 for progress.
7388 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007389 activeSubscriberIds.add(tele.getSubscriberId(subId));
7390 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007391
7392 // First pass, find a number override for an active subscriber
7393 String mergeNumber = null;
7394 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7395 for (String key : prefs.keySet()) {
7396 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7397 final String subscriberId = (String) prefs.get(key);
7398 if (activeSubscriberIds.contains(subscriberId)) {
7399 final String iccId = key.substring(
7400 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7401 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7402 mergeNumber = (String) prefs.get(numberKey);
7403 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007404 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007405 + " for active subscriber " + subscriberId);
7406 }
7407 if (!TextUtils.isEmpty(mergeNumber)) {
7408 break;
7409 }
7410 }
7411 }
7412 }
7413
7414 // Shortcut when no active merged subscribers
7415 if (TextUtils.isEmpty(mergeNumber)) {
7416 return null;
7417 }
7418
7419 // Second pass, find all subscribers under that line override
7420 final ArraySet<String> result = new ArraySet<>();
7421 for (String key : prefs.keySet()) {
7422 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7423 final String number = (String) prefs.get(key);
7424 if (mergeNumber.equals(number)) {
7425 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7426 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7427 final String subscriberId = (String) prefs.get(subscriberKey);
7428 if (!TextUtils.isEmpty(subscriberId)) {
7429 result.add(subscriberId);
7430 }
7431 }
7432 }
7433 }
7434
7435 final String[] resultArray = result.toArray(new String[result.size()]);
7436 Arrays.sort(resultArray);
7437 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007438 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007439 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7440 }
7441 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007442 } finally {
7443 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007444 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007445 }
7446
7447 @Override
zoey chen38003472019-12-13 17:16:31 +08007448 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7449 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007450
7451 final long identity = Binder.clearCallingIdentity();
7452 try {
7453 final TelephonyManager telephonyManager = mApp.getSystemService(
7454 TelephonyManager.class);
7455 String subscriberId = telephonyManager.getSubscriberId(subId);
7456 if (subscriberId == null) {
7457 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007458 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007459 + subId);
7460 }
7461 return null;
7462 }
7463
Jack Yu285100e2022-12-02 22:48:35 -08007464 ParcelUuid groupUuid;
7465 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08007466 final SubscriptionInfo info = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08007467 .getSubscriptionInfo(subId);
7468 groupUuid = info.getGroupUuid();
7469 } else {
7470 final SubscriptionInfo info = mSubscriptionController
7471 .getSubscriptionInfo(subId);
7472 groupUuid = info.getGroupUuid();
7473 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007474 // If it doesn't belong to any group, return just subscriberId of itself.
7475 if (groupUuid == null) {
7476 return new String[]{subscriberId};
7477 }
7478
7479 // Get all subscriberIds from the group.
7480 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007481 List<SubscriptionInfo> groupInfos;
7482 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08007483 groupInfos = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08007484 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7485 mApp.getAttributionTag());
7486 } else {
7487 groupInfos = mSubscriptionController
7488 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7489 mApp.getAttributionTag());
7490 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007491 for (SubscriptionInfo subInfo : groupInfos) {
7492 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7493 if (subscriberId != null) {
7494 mergedSubscriberIds.add(subscriberId);
7495 }
7496 }
7497
7498 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7499 } finally {
7500 Binder.restoreCallingIdentity(identity);
7501
7502 }
7503 }
7504
7505 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007506 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007507 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007508 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007509
7510 final long identity = Binder.clearCallingIdentity();
7511 try {
7512 final Phone phone = getPhone(subId);
7513 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7514 } finally {
7515 Binder.restoreCallingIdentity(identity);
7516 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007517 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007518
7519 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007520 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007521 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7522 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007523 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7524 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007525
7526 final long identity = Binder.clearCallingIdentity();
7527 try {
7528 final Phone phone = getPhone(subId);
7529 if (phone == null) {
7530 return false;
7531 }
7532 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7533 cdmaNonRoamingList);
7534 } finally {
7535 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007536 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007537 }
7538
7539 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007540 @Deprecated
7541 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7542 enforceModifyPermission();
7543
7544 int returnValue = 0;
7545 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007546 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007547 if(result.exception == null) {
7548 if (result.result != null) {
7549 byte[] responseData = (byte[])(result.result);
7550 if(responseData.length > oemResp.length) {
7551 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7552 responseData.length + "bytes. Buffer Size is " +
7553 oemResp.length + "bytes.");
7554 }
7555 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7556 returnValue = responseData.length;
7557 }
7558 } else {
7559 CommandException ex = (CommandException) result.exception;
7560 returnValue = ex.getCommandError().ordinal();
7561 if(returnValue > 0) returnValue *= -1;
7562 }
7563 } catch (RuntimeException e) {
7564 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7565 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7566 if(returnValue > 0) returnValue *= -1;
7567 }
7568
7569 return returnValue;
7570 }
7571
7572 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007573 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007574 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007575 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007576 if (phone == null) {
7577 return raf;
7578 }
7579
Shuo Qiandee53402020-05-29 14:08:15 -07007580 try {
7581 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007582 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007583 mApp, phone.getSubId(), "getRadioAccessFamily");
7584 } catch (SecurityException e) {
7585 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7586 throw e;
7587 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007588
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007589 final long identity = Binder.clearCallingIdentity();
7590 try {
chen xub97461a2018-10-26 14:17:57 -07007591 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007592 } finally {
7593 Binder.restoreCallingIdentity(identity);
7594 }
chen xub97461a2018-10-26 14:17:57 -07007595 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007596 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007597
7598 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007599 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007600 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007601 try {
7602 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7603 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007604 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007605 }
7606 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007607 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007608 }
7609 RoleManager rm = mApp.getSystemService(RoleManager.class);
7610 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7611 if (!dialerRoleHolders.contains(callingPackage)) {
7612 throw new SecurityException("App must be the dialer role holder to"
7613 + " upload a call composer pic");
7614 }
7615
7616 Executors.newSingleThreadExecutor().execute(() -> {
7617 ByteArrayOutputStream output = new ByteArrayOutputStream(
7618 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7619 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7620 boolean readUntilEnd = false;
7621 int totalBytesRead = 0;
7622 byte[] buffer = new byte[16 * 1024];
7623 while (true) {
7624 int numRead;
7625 try {
7626 numRead = input.read(buffer);
7627 } catch (IOException e) {
7628 try {
7629 fd.checkError();
7630 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7631 null);
7632 } catch (IOException e1) {
7633 // This means that the other side closed explicitly with an error. If this
7634 // happens, log and ignore.
7635 loge("Remote end of call composer picture pipe closed: " + e1);
7636 }
7637 break;
7638 }
7639 if (numRead == -1) {
7640 readUntilEnd = true;
7641 break;
7642 }
7643 totalBytesRead += numRead;
7644 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7645 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7646 try {
7647 input.close();
7648 } catch (IOException e) {
7649 // ignore
7650 }
7651 break;
7652 }
7653 output.write(buffer, 0, numRead);
7654 }
7655 // Generally, the remote end will close the file descriptors. The only case where we
7656 // close is above, where the picture size is too big.
7657
7658 try {
7659 fd.checkError();
7660 } catch (IOException e) {
7661 loge("Remote end for call composer closed with an error: " + e);
7662 return;
7663 }
7664
Hall Liuaa4211e2021-01-20 15:43:39 -08007665 if (!readUntilEnd) {
7666 loge("Did not finish reading entire image; aborting");
7667 return;
7668 }
Hall Liu82694d52020-12-11 18:22:04 -08007669
Hall Liuaa4211e2021-01-20 15:43:39 -08007670 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7671 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7672 new CallComposerPictureTransfer.Factory() {},
7673 imageData,
7674 (result) -> {
7675 if (result.first != null) {
7676 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7677 Bundle outputResult = new Bundle();
7678 outputResult.putParcelable(
7679 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7680 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7681 outputResult);
7682 } else {
7683 callback.send(result.second, null);
7684 }
7685 }
7686 );
Hall Liu82694d52020-12-11 18:22:04 -08007687 });
7688 }
7689
7690 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007691 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007692 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007693 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007694
7695 final long identity = Binder.clearCallingIdentity();
7696 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007697 ImsManager.getInstance(defaultPhone.getContext(),
7698 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007699 } finally {
7700 Binder.restoreCallingIdentity(identity);
7701 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007702 }
7703
7704 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007705 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007706 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007707 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7708 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007709 return false;
7710 }
Svet Ganovb320e182015-04-16 12:30:10 -07007711
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007712 final long identity = Binder.clearCallingIdentity();
7713 try {
7714 // Check the user preference and the system-level IMS setting. Even if the user has
7715 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7716 // In the long run, we may instead need to check if there exists a connection service
7717 // which can support video calling.
7718 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007719 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007720 return imsManager.isVtEnabledByPlatform()
7721 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7722 && imsManager.isVtEnabledByUser();
7723 } finally {
7724 Binder.restoreCallingIdentity(identity);
7725 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007726 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007727
Andrew Leea1239f22015-03-02 17:44:07 -08007728 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007729 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7730 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007731 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007732 mApp, subId, callingPackage, callingFeatureId,
7733 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007734 return false;
7735 }
7736
7737 final long identity = Binder.clearCallingIdentity();
7738 try {
7739 CarrierConfigManager configManager =
7740 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007741 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007742 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7743 } finally {
7744 Binder.restoreCallingIdentity(identity);
7745 }
Andrew Leea1239f22015-03-02 17:44:07 -08007746 }
7747
7748 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007749 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007750 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007751 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007752 return false;
7753 }
7754
7755 final long identity = Binder.clearCallingIdentity();
7756 try {
7757 CarrierConfigManager configManager =
7758 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007759 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007760 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7761 } finally {
7762 Binder.restoreCallingIdentity(identity);
7763 }
Andrew Leea1239f22015-03-02 17:44:07 -08007764 }
7765
Andrew Lee9431b832015-03-09 18:46:45 -07007766 @Override
7767 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007768 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007769 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007770 }
7771
7772 @Override
7773 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007774 final long identity = Binder.clearCallingIdentity();
7775 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007776 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007777 } finally {
7778 Binder.restoreCallingIdentity(identity);
7779 }
Andrew Lee9431b832015-03-09 18:46:45 -07007780 }
7781
Hall Liuf6668912018-10-31 17:05:23 -07007782 /**
7783 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7784 * support for the feature and device firmware support.
7785 *
7786 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7787 */
7788 @Override
7789 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007790 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007791 final Phone phone = getPhone(subscriptionId);
7792 if (phone == null) {
7793 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7794 return false;
7795 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007796 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007797 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007798 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7799 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007800 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007801 return isCarrierSupported && isDeviceSupported;
7802 } finally {
7803 Binder.restoreCallingIdentity(identity);
7804 }
Hall Liu98187582018-01-22 19:15:32 -08007805 }
7806
Hall Liuf6668912018-10-31 17:05:23 -07007807 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007808 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7809 * RTT setting, will return true if the device and carrier both support RTT.
7810 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007811 */
7812 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007813 final long identity = Binder.clearCallingIdentity();
7814 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007815 boolean isRttSupported = isRttSupported(subscriptionId);
7816 boolean isUserRttSettingOn = Settings.Secure.getInt(
7817 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7818 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7819 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7820 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007821 } finally {
7822 Binder.restoreCallingIdentity(identity);
7823 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007824 }
7825
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007826 @Deprecated
7827 @Override
7828 public String getDeviceId(String callingPackage) {
7829 return getDeviceIdWithFeature(callingPackage, null);
7830 }
7831
Sanket Padawe7310cc72015-01-14 09:53:20 -08007832 /**
7833 * Returns the unique device ID of phone, for example, the IMEI for
7834 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7835 *
7836 * <p>Requires Permission:
7837 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7838 */
7839 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007840 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007841 try {
7842 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7843 } catch (SecurityException se) {
7844 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7845 throw new SecurityException("Package " + callingPackage + " does not belong to "
7846 + Binder.getCallingUid());
7847 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007848 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007849 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007850 return null;
7851 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007852 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007853 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007854 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007855 return null;
7856 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007857
7858 final long identity = Binder.clearCallingIdentity();
7859 try {
7860 return phone.getDeviceId();
7861 } finally {
7862 Binder.restoreCallingIdentity(identity);
7863 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007864 }
7865
Ping Sunc67b7c22016-03-02 19:16:45 +08007866 /**
7867 * {@hide}
7868 * Returns the IMS Registration Status on a particular subid
7869 *
7870 * @param subId
7871 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007872 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007873 Phone phone = getPhone(subId);
7874 if (phone != null) {
7875 return phone.isImsRegistered();
7876 } else {
7877 return false;
7878 }
7879 }
7880
Santos Cordon7a1885b2015-02-03 11:15:19 -08007881 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007882 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007883 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007884 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007885 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007886 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7887 }
7888 final long identity = Binder.clearCallingIdentity();
7889 try {
7890 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7891 } finally {
7892 Binder.restoreCallingIdentity(identity);
7893 }
7894 }
7895
7896 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007897 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007898 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007899 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007900 mApp,
7901 subscriptionId,
7902 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
7903 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007904 final long identity = Binder.clearCallingIdentity();
7905 try {
7906 Phone phone = getPhone(subscriptionId);
7907 if (phone == null) {
7908 return null;
7909 }
7910 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7911 } finally {
7912 Binder.restoreCallingIdentity(identity);
7913 }
7914 }
7915
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007916 /**
7917 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007918 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007919 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007920 final long identity = Binder.clearCallingIdentity();
7921 try {
7922 Phone phone = getPhone(subId);
7923 if (phone != null) {
7924 return phone.isWifiCallingEnabled();
7925 } else {
7926 return false;
7927 }
7928 } finally {
7929 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007930 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007931 }
7932
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007933 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007934 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007935 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007936 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007937 final long identity = Binder.clearCallingIdentity();
7938 try {
7939 Phone phone = getPhone(subId);
7940 if (phone != null) {
7941 return phone.isVideoEnabled();
7942 } else {
7943 return false;
7944 }
7945 } finally {
7946 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007947 }
7948 }
7949
7950 /**
7951 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7952 * defined in {@link ImsRegistrationImplBase}.
7953 */
7954 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007955 final long identity = Binder.clearCallingIdentity();
7956 try {
7957 Phone phone = getPhone(subId);
7958 if (phone != null) {
7959 return phone.getImsRegistrationTech();
7960 } else {
7961 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7962 }
7963 } finally {
7964 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007965 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007966 }
7967
Stuart Scott8eef64f2015-04-08 15:13:54 -07007968 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007969 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007970 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007971 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7972 return;
7973 }
Kai Shif70f46f2021-03-03 13:59:46 -08007974 Phone defaultPhone = getDefaultPhone();
7975 if (defaultPhone != null) {
7976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7977 mApp, getDefaultPhone().getSubId(), "factoryReset");
7978 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007979 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007980
Svet Ganovcc087f82015-05-12 20:35:54 -07007981 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007982 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7983 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007984 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007985 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007986 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007987 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007988 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007989 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007990 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007991 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007992 // There has been issues when Sms raw table somehow stores orphan
7993 // fragments. They lead to garbled message when new fragments come
7994 // in and combined with those stale ones. In case this happens again,
7995 // user can reset all network settings which will clean up this table.
7996 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007997 // Clean up IMS settings as well here.
7998 int slotId = getSlotIndex(subId);
7999 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8000 ImsManager.getInstance(mApp, slotId).factoryReset();
8001 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008002
Kai Shif70f46f2021-03-03 13:59:46 -08008003 if (defaultPhone == null) {
8004 return;
8005 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008006 // Erase modem config if erase modem on network setting is enabled.
8007 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8008 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8009 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008010 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008011 }
Kai Shif70f46f2021-03-03 13:59:46 -08008012
8013 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008014 } finally {
8015 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008016 }
8017 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008018
SongFerngWangfd89b102021-05-27 22:44:54 +08008019 @VisibleForTesting
8020 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8021 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8022 return;
8023 }
8024 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8025 RILConstants.PREFERRED_NETWORK_MODE);
8026 SubscriptionManager.setSubscriptionProperty(subId,
8027 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8028 "user=" + defaultNetworkType);
8029 phone.loadAllowedNetworksFromSubscriptionDatabase();
8030 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8031 defaultNetworkType, null);
8032 }
8033
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008034 private void cleanUpSmsRawTable(Context context) {
8035 ContentResolver resolver = context.getContentResolver();
8036 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8037 resolver.delete(uri, null, null);
8038 }
8039
Narayan Kamath1c496c22015-04-16 14:40:19 +01008040 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008041 public String getSimLocaleForSubscriber(int subId) {
8042 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8043 final Phone phone = getPhone(subId);
8044 if (phone == null) {
8045 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008046 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008048 final long identity = Binder.clearCallingIdentity();
8049 try {
Jack Yu285100e2022-12-02 22:48:35 -08008050 SubscriptionInfo info;
8051 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008052 info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
Jack Yu285100e2022-12-02 22:48:35 -08008053 phone.getContext().getOpPackageName(),
8054 phone.getContext().getAttributionTag());
8055 if (info == null) {
8056 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8057 return null;
8058 }
8059 } else {
8060 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
8061 phone.getContext().getOpPackageName(),
8062 phone.getContext().getAttributionTag());
8063 if (info == null) {
8064 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8065 return null;
8066 }
chen xu6291c472019-02-04 12:55:53 -08008067 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008068 // Try and fetch the locale from the carrier properties or from the SIM language
8069 // preferences (EF-PL and EF-LI)...
8070 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008071 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008072 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8073 if (localeFromDefaultSim != null) {
8074 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8075 if (DBG) log("Using locale from subId: " + subId + " locale: "
8076 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008077 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008078 } else {
8079 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008080 }
8081 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008082
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008083 // The SIM language preferences only store a language (e.g. fr = French), not an
8084 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8085 // the SIM and carrier preferences does not include a country we add the country
8086 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008087 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008088 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008089 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008090 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008091 }
8092
8093 if (DBG) log("No locale found - returning null");
8094 return null;
8095 } finally {
8096 Binder.restoreCallingIdentity(identity);
8097 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008098 }
8099
tom hsu0b59d292022-09-29 23:49:21 +08008100 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008101 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008102 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008103 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008104 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008105 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8106 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008107 Locale.forLanguageTag(localeTag).getCountry())) {
8108 return localeTag;
8109 }
8110 }
8111 return inputLocale.toLanguageTag();
8112 }
8113
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008114 /**
8115 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8116 */
8117 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08008118 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008119 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Jack Yu285100e2022-12-02 22:48:35 -08008120 mApp.getOpPackageName(), mApp.getAttributionTag());
8121 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008122 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08008123 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008124 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008125
Gary Jian3aa9a762022-01-24 16:41:19 +08008126 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8127 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008128
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008129 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008130 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8131 * representing the state of the modem.
8132 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008133 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8134 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008135 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008136 */
8137 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008138 public void requestModemActivityInfo(ResultReceiver result) {
8139 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008140 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008141
8142 final long identity = Binder.clearCallingIdentity();
8143 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008144 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008145 } finally {
8146 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008147 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008148 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008149
Gary Jian76280a42022-12-07 16:18:33 +08008150 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008151 // less than total activity duration.
8152 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8153 if (info == null) {
8154 return false;
8155 }
8156 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008157 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008158 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8159
Hall Liu49656c02020-10-09 19:00:11 -07008160 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8161
Siddharth Rayb8114062018-06-17 15:02:38 -07008162 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008163 && (info.getSleepTimeMillis() <= activityDurationMs)
8164 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008165 }
8166
Gary Jian3aa9a762022-01-24 16:41:19 +08008167 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8168 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8169 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8170 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8171
8172 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8173 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8174 }
8175
8176 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8177 mLastModemActivityInfo.setReceiveTimeMillis(
8178 rat,
8179 freq,
8180 info.getReceiveTimeMillis(rat, freq)
8181 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8182 }
8183
8184 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8185 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8186 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8187 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8188
8189 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8190 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8191 }
8192 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8193 mLastModemActivityInfo.setReceiveTimeMillis(
8194 rat,
8195 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8196 }
8197
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008198 /**
8199 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8200 * @param info recent ModemActivityInfo
8201 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008202 private void mergeModemActivityInfo(ModemActivityInfo info) {
8203 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008204 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008205 boolean matched;
8206 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8207 matched = false;
8208 int rat = info.getSpecificInfoRat(i);
8209 int freq = info.getSpecificInfoFrequencyRange(i);
8210 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8211 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8212 //if it already exists
8213 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8214 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8215 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8216 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8217 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8218 updateLastModemActivityInfo(info, rat, freq);
8219 matched = true;
8220 }
8221 } else {
8222 updateLastModemActivityInfo(info, rat);
8223 matched = true;
8224 }
8225 }
8226 }
8227
8228 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008229 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008230 new ActivityStatsTechSpecificInfo(
8231 rat,
8232 freq,
8233 info.getTransmitTimeMillis(rat, freq),
8234 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008235 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008236 }
8237 }
8238 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8239 mLastModemActivitySpecificInfo =
8240 new ActivityStatsTechSpecificInfo[merged.size()];
8241 merged.toArray(mLastModemActivitySpecificInfo);
8242
8243 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8244 mLastModemActivityInfo.setSleepTimeMillis(
8245 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008246 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008247 mLastModemActivityInfo.setIdleTimeMillis(
8248 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008249 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008250
8251 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008252 new ModemActivityInfo(
8253 mLastModemActivityInfo.getTimestampMillis(),
8254 mLastModemActivityInfo.getSleepTimeMillis(),
8255 mLastModemActivityInfo.getIdleTimeMillis(),
8256 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008257 }
8258
8259 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8260 ActivityStatsTechSpecificInfo[] info) {
8261 int infoSize = info.length;
8262 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8263 for (int i = 0; i < infoSize; i++) {
8264 ret[i] = new ActivityStatsTechSpecificInfo(
8265 info[i].getRat(), info[i].getFrequencyRange(),
8266 info[i].getTransmitTimeMillis(),
8267 (int) info[i].getReceiveTimeMillis());
8268 }
8269 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008270 }
8271
Jack Yu85bd38a2015-11-09 11:34:32 -08008272 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008273 * Returns the service state information on specified subscription.
8274 */
8275 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008276 public ServiceState getServiceStateForSubscriber(int subId,
8277 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8278 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008279 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008280 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008281 return null;
8282 }
8283
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008284 boolean hasFinePermission = false;
8285 boolean hasCoarsePermission = false;
8286 if (!renounceFineLocationAccess) {
8287 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8288 LocationAccessPolicy.checkLocationPermission(mApp,
8289 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8290 .setCallingPackage(callingPackage)
8291 .setCallingFeatureId(callingFeatureId)
8292 .setCallingPid(Binder.getCallingPid())
8293 .setCallingUid(Binder.getCallingUid())
8294 .setMethod("getServiceStateForSubscriber")
8295 .setLogAsInfo(true)
8296 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8297 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8298 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8299 .build());
8300 hasFinePermission =
8301 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8302 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008303
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008304 if (!renounceCoarseLocationAccess) {
8305 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8306 LocationAccessPolicy.checkLocationPermission(mApp,
8307 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8308 .setCallingPackage(callingPackage)
8309 .setCallingFeatureId(callingFeatureId)
8310 .setCallingPid(Binder.getCallingPid())
8311 .setCallingUid(Binder.getCallingUid())
8312 .setMethod("getServiceStateForSubscriber")
8313 .setLogAsInfo(true)
8314 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8315 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8316 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8317 .build());
8318 hasCoarsePermission =
8319 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8320 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008321
Jack Yu479f40e2020-10-27 21:29:25 -07008322 final Phone phone = getPhone(subId);
8323 if (phone == null) {
8324 return null;
8325 }
8326
Jordan Liu0f2bc442020-11-18 16:47:37 -08008327 final long identity = Binder.clearCallingIdentity();
8328
Jack Yu479f40e2020-10-27 21:29:25 -07008329 boolean isCallingPackageDataService = phone.getDataServicePackages()
8330 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008331 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008332 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008333 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008334 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008335 .getSubscriptionInfoInternal(subId);
8336 if (subInfo == null || !subInfo.isActive()) {
8337 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8338 + "subId=" + subId);
8339 return null;
8340 }
8341 } else {
8342 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8343 callingFeatureId)) {
8344 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8345 + "subId=" + subId);
8346 return null;
8347 }
Jordan Liuc437b192020-08-17 10:59:12 -07008348 }
8349
Hall Liuf19c44f2018-11-27 14:38:17 -08008350 ServiceState ss = phone.getServiceState();
8351
8352 // Scrub out the location info in ServiceState depending on what level of access
8353 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008354 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008355 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8356 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008357 } finally {
8358 Binder.restoreCallingIdentity(identity);
8359 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008360 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008361
8362 /**
8363 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8364 *
8365 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8366 * voicemail ringtone.
8367 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8368 * PhoneAccount.
8369 */
8370 @Override
8371 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008372 final long identity = Binder.clearCallingIdentity();
8373 try {
8374 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8375 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008376 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008377 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008379 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8380 } finally {
8381 Binder.restoreCallingIdentity(identity);
8382 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008383 }
8384
8385 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008386 * Sets the per-account voicemail ringtone.
8387 *
8388 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8389 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8390 *
8391 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8392 * voicemail ringtone.
8393 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8394 * PhoneAccount.
8395 */
8396 @Override
8397 public void setVoicemailRingtoneUri(String callingPackage,
8398 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008399 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008400 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008401 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8402 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8404 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8405 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008406 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008407
8408 final long identity = Binder.clearCallingIdentity();
8409 try {
8410 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8411 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008412 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008413 }
8414 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8415 } finally {
8416 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008417 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008418 }
8419
8420 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008421 * Returns whether vibration is set for voicemail notification in Phone settings.
8422 *
8423 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8424 * voicemail vibration setting.
8425 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8426 */
8427 @Override
8428 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008429 final long identity = Binder.clearCallingIdentity();
8430 try {
8431 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8432 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008433 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008434 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008436 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8437 } finally {
8438 Binder.restoreCallingIdentity(identity);
8439 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008440 }
8441
Youhan Wange64578a2016-05-02 15:32:42 -07008442 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008443 * Sets the per-account voicemail vibration.
8444 *
8445 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8446 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8447 *
8448 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8449 * voicemail vibration setting.
8450 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8451 * specific PhoneAccount.
8452 */
8453 @Override
8454 public void setVoicemailVibrationEnabled(String callingPackage,
8455 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008456 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008457 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008458 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8459 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8461 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8462 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008463 }
8464
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008465 final long identity = Binder.clearCallingIdentity();
8466 try {
8467 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8468 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008469 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008470 }
8471 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8472 } finally {
8473 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008474 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008475 }
8476
8477 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008478 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8479 *
8480 * @throws SecurityException if the caller does not have the required permission
8481 */
arunvoddud7401012022-12-15 16:08:12 +00008482 @VisibleForTesting
8483 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008484 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008485 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008486 }
8487
8488 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008489 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8490 * permission.
8491 *
8492 * @throws SecurityException if the caller does not have the required permission
8493 */
8494 private void enforceSendSmsPermission() {
8495 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8496 }
8497
8498 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008499 * Make sure either called from same process as self (phone) or IPC caller has interact across
8500 * users permission.
8501 *
8502 * @throws SecurityException if the caller does not have the required permission
8503 */
8504 private void enforceInteractAcrossUsersPermission(String message) {
8505 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8506 }
8507
8508 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008509 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008510 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008511 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008512 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008513 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008514 final long identity = Binder.clearCallingIdentity();
8515 try {
8516 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008517 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008518 if (componentName == null) {
8519 throw new SecurityException(
8520 "Caller not current active visual voicemail package[null]");
8521 }
8522 String vvmPackage = componentName.getPackageName();
8523 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008524 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008525 }
8526 } finally {
8527 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008528 }
8529 }
8530
8531 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008532 * Return the application ID for the app type.
8533 *
8534 * @param subId the subscription ID that this request applies to.
8535 * @param appType the uicc app type.
8536 * @return Application ID for specificied app type, or null if no uicc.
8537 */
8538 @Override
8539 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008540 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008541 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008542
8543 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008544 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008545 if (phone == null) {
8546 return null;
8547 }
8548 String aid = null;
8549 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008550 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008551 .getApplicationByType(appType).getAid();
8552 } catch (Exception e) {
8553 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8554 }
8555 return aid;
8556 } finally {
8557 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008558 }
Youhan Wange64578a2016-05-02 15:32:42 -07008559 }
8560
Youhan Wang4001d252016-05-11 10:29:41 -07008561 /**
8562 * Return the Electronic Serial Number.
8563 *
8564 * @param subId the subscription ID that this request applies to.
8565 * @return ESN or null if error.
8566 */
8567 @Override
8568 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008569 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008570 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008571
8572 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008573 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008574 if (phone == null) {
8575 return null;
8576 }
8577 String esn = null;
8578 try {
8579 esn = phone.getEsn();
8580 } catch (Exception e) {
8581 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8582 }
8583 return esn;
8584 } finally {
8585 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008586 }
Youhan Wang4001d252016-05-11 10:29:41 -07008587 }
8588
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008589 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008590 * Return the Preferred Roaming List Version.
8591 *
8592 * @param subId the subscription ID that this request applies to.
8593 * @return PRLVersion or null if error.
8594 */
8595 @Override
8596 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008597 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008598 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008599
8600 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008601 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008602 if (phone == null) {
8603 return null;
8604 }
8605 String cdmaPrlVersion = null;
8606 try {
8607 cdmaPrlVersion = phone.getCdmaPrlVersion();
8608 } catch (Exception e) {
8609 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8610 }
8611 return cdmaPrlVersion;
8612 } finally {
8613 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008614 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008615 }
8616
8617 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008618 * Get snapshot of Telephony histograms
8619 * @return List of Telephony histograms
8620 * @hide
8621 */
8622 @Override
8623 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8625 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008626
8627 final long identity = Binder.clearCallingIdentity();
8628 try {
8629 return RIL.getTelephonyRILTimingHistograms();
8630 } finally {
8631 Binder.restoreCallingIdentity(identity);
8632 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008633 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008634
8635 /**
8636 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008637 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8638 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008639 * Require system privileges. In the future we may add this to carrier APIs.
8640 *
Michele Berionne482f8202018-11-27 18:57:59 -08008641 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008642 */
8643 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008644 @TelephonyManager.SetCarrierRestrictionResult
8645 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008646 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008647 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008648
Michele Berionne482f8202018-11-27 18:57:59 -08008649 if (carrierRestrictionRules == null) {
8650 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008651 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008652
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008653 final long identity = Binder.clearCallingIdentity();
8654 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008655 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008656 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008657 } finally {
8658 Binder.restoreCallingIdentity(identity);
8659 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008660 }
8661
8662 /**
8663 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008664 * Get the allowed carrier list and the excluded carrier list, including the priority between
8665 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008666 * Require system privileges. In the future we may add this to carrier APIs.
8667 *
Michele Berionne482f8202018-11-27 18:57:59 -08008668 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008669 */
8670 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008671 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008672 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008673 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008674
8675 final long identity = Binder.clearCallingIdentity();
8676 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008677 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8678 if (response instanceof CarrierRestrictionRules) {
8679 return (CarrierRestrictionRules) response;
8680 }
8681 // Response is an Exception of some kind,
8682 // which is signalled to the user as a NULL retval
8683 return null;
8684 } catch (Exception e) {
8685 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8686 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008687 } finally {
8688 Binder.restoreCallingIdentity(identity);
8689 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008690 }
8691
fionaxu59545b42016-05-25 15:53:37 -07008692 /**
arunvoddud7401012022-12-15 16:08:12 +00008693 * Fetches the carrier restriction status of the device and sends the status to the caller
8694 * through the callback.
8695 *
8696 * @param callback The callback that will be used to send the result.
8697 * @throws SecurityException if the caller does not have the required permission/privileges or
8698 * the caller is not allowlisted.
8699 */
8700 @Override
8701 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8702 enforceReadPermission("getCarrierRestrictionStatus");
8703 int carrierId = validateCallerAndGetCarrierId(packageName);
8704 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8705 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8706 throw new SecurityException("Not an authorized caller");
8707 }
8708 final long identity = Binder.clearCallingIdentity();
8709 try {
8710 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8711 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8712 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8713 } finally {
8714 Binder.restoreCallingIdentity(identity);
8715 }
8716 }
8717
8718 @VisibleForTesting
8719 public int validateCallerAndGetCarrierId(String packageName) {
8720 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8721 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8722 }
8723
8724 /**
fionaxu59545b42016-05-25 15:53:37 -07008725 * Action set from carrier signalling broadcast receivers to enable/disable radio
8726 * @param subId the subscription ID that this action applies to.
8727 * @param enabled control enable or disable radio.
8728 * {@hide}
8729 */
8730 @Override
8731 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8732 enforceModifyPermission();
8733 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008734
8735 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008736 if (phone == null) {
8737 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8738 return;
8739 }
8740 try {
8741 phone.carrierActionSetRadioEnabled(enabled);
8742 } catch (Exception e) {
8743 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008744 } finally {
8745 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008746 }
8747 }
8748
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008749 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008750 * Enable or disable Voice over NR (VoNR)
8751 * @param subId the subscription ID that this action applies to.
8752 * @param enabled enable or disable VoNR.
8753 * @return operation result.
8754 */
8755 @Override
8756 public int setVoNrEnabled(int subId, boolean enabled) {
8757 enforceModifyPermission();
8758 final Phone phone = getPhone(subId);
8759
8760 final long identity = Binder.clearCallingIdentity();
8761 if (phone == null) {
8762 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8763 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8764 }
8765
8766 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8767 try {
8768 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8769 workSource);
8770 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008771
8772 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8773 if (DBG) {
8774 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8775 }
8776 SubscriptionManager.setSubscriptionProperty(
8777 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8778 (enabled ? "1" : "0"));
8779 }
8780
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008781 return result;
8782 } finally {
8783 Binder.restoreCallingIdentity(identity);
8784 }
8785 }
8786
8787 /**
8788 * Is voice over NR enabled
8789 * @return true if VoNR is enabled else false
8790 */
8791 @Override
8792 public boolean isVoNrEnabled(int subId) {
8793 enforceReadPrivilegedPermission("isVoNrEnabled");
8794 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8795 final long identity = Binder.clearCallingIdentity();
8796 try {
8797 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8798 null, subId, workSource);
8799 if (DBG) log("isVoNrEnabled: " + isEnabled);
8800 return isEnabled;
8801 } finally {
8802 Binder.restoreCallingIdentity(identity);
8803 }
8804 }
8805
8806 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008807 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8808 * network status based on which carrier apps could apply actions accordingly,
8809 * enable/disable default url handler for example.
8810 *
8811 * @param subId the subscription ID that this action applies to.
8812 * @param report control start/stop reporting the default network status.
8813 * {@hide}
8814 */
8815 @Override
8816 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8817 enforceModifyPermission();
8818 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008819
8820 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008821 if (phone == null) {
8822 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8823 return;
8824 }
8825 try {
8826 phone.carrierActionReportDefaultNetworkStatus(report);
8827 } catch (Exception e) {
8828 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008829 } finally {
8830 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008831 }
8832 }
8833
8834 /**
fionaxud9622282017-07-17 17:51:30 -07008835 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8836 * @param subId the subscription ID that this action applies to.
8837 * {@hide}
8838 */
8839 @Override
8840 public void carrierActionResetAll(int subId) {
8841 enforceModifyPermission();
8842 final Phone phone = getPhone(subId);
8843 if (phone == null) {
8844 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8845 return;
8846 }
8847 try {
8848 phone.carrierActionResetAll();
8849 } catch (Exception e) {
8850 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8851 }
8852 }
8853
8854 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008855 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8856 * bug report is being generated.
8857 */
8858 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008859 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008860 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8861 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008862 writer.println("Permission Denial: can't dump Phone from pid="
8863 + Binder.getCallingPid()
8864 + ", uid=" + Binder.getCallingUid()
8865 + "without permission "
8866 + android.Manifest.permission.DUMP);
8867 return;
8868 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008869 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008870 }
Jack Yueb89b242016-06-22 13:27:47 -07008871
Brad Ebingerdac2f002018-04-03 15:17:52 -07008872 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008873 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8874 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8875 @NonNull String[] args) {
8876 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8877 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008878 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008879 }
8880
Jack Yueb89b242016-06-22 13:27:47 -07008881 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008882 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008883 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008884 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008885 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008886 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008887 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008888 */
8889 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008890 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008891 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008892 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8893 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8894 try {
8895 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008896 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008897 } catch (SecurityException se) {
8898 enforceModifyPermission();
8899 }
8900 } else {
8901 enforceModifyPermission();
8902 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008903
8904 final long identity = Binder.clearCallingIdentity();
8905 try {
8906 Phone phone = getPhone(subId);
8907 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008908 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8909 phone.carrierActionSetMeteredApnsEnabled(enabled);
8910 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008911 phone.getDataSettingsManager().setDataEnabled(
8912 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008913 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008914 }
8915 } finally {
8916 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008917 }
8918 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008919
8920 /**
8921 * Get Client request stats
8922 * @return List of Client Request Stats
8923 * @hide
8924 */
8925 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008926 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8927 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008928 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008929 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008930 return null;
8931 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008932 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008933
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008934 final long identity = Binder.clearCallingIdentity();
8935 try {
8936 if (phone != null) {
8937 return phone.getClientRequestStats();
8938 }
8939
8940 return null;
8941 } finally {
8942 Binder.restoreCallingIdentity(identity);
8943 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008944 }
8945
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008946 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008947 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008948 if (uid == Process.ROOT_UID && packageName == null) {
8949 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8950 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8951 // exception. ROOT_UID seems not to have a valid package name returned by
8952 // PackageManager, so just fake it here to avoid issues when running telephony shell
8953 // commands that plumb through the RIL as root, like so:
8954 // $ adb root
8955 // $ adb shell cmd phone ...
8956 packageName = "root";
8957 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008958 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008959 }
Jack Yueb4124c2017-02-16 15:32:43 -08008960
8961 /**
Grace Chen70990072017-03-24 17:21:30 -07008962 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008963 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008964 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008965 * @param state State of SIM (power down, power up, pass through)
8966 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8967 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8968 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008969 *
8970 **/
8971 @Override
Grace Chen70990072017-03-24 17:21:30 -07008972 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008973 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008974 Phone phone = PhoneFactory.getPhone(slotIndex);
8975
vagdeviaf9a5b92018-08-15 16:01:53 -07008976 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8977
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008978 final long identity = Binder.clearCallingIdentity();
8979 try {
8980 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008981 phone.setSimPowerState(state, null, workSource);
8982 }
8983 } finally {
8984 Binder.restoreCallingIdentity(identity);
8985 }
8986 }
8987
8988 /**
8989 * Set SIM card power state.
8990 *
8991 * @param slotIndex SIM slot id.
8992 * @param state State of SIM (power down, power up, pass through)
8993 * @param callback callback to trigger after success or failure
8994 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8995 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8996 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8997 *
8998 **/
8999 @Override
9000 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9001 IIntegerConsumer callback) {
9002 enforceModifyPermission();
9003 Phone phone = PhoneFactory.getPhone(slotIndex);
9004
9005 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9006
9007 final long identity = Binder.clearCallingIdentity();
9008 try {
9009 if (phone != null) {
9010 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9011 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009012 }
9013 } finally {
9014 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009015 }
9016 }
Shuo Qiandd210312017-04-12 22:11:33 +00009017
Tyler Gunn65d45c22017-06-05 11:22:26 -07009018 private boolean isUssdApiAllowed(int subId) {
9019 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009020 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009021 if (configManager == null) {
9022 return false;
9023 }
9024 PersistableBundle pb = configManager.getConfigForSubId(subId);
9025 if (pb == null) {
9026 return false;
9027 }
9028 return pb.getBoolean(
9029 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9030 }
9031
Shuo Qiandd210312017-04-12 22:11:33 +00009032 /**
Ling Mac28f0212023-03-24 16:07:15 -07009033 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009034 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009035 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009036 */
goneil9c5f4872017-12-05 14:07:56 -08009037 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009038 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009039 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009040 final long identity = Binder.clearCallingIdentity();
9041 try {
Ling Mac28f0212023-03-24 16:07:15 -07009042 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009043 } finally {
9044 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009045 }
9046 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009047
9048 /**
9049 * Get the current signal strength information for the given subscription.
9050 * Because this information is not updated when the device is in a low power state
9051 * it should not be relied-upon to be current.
9052 * @param subId Subscription index
9053 * @return the most recent cached signal strength info from the modem
9054 */
9055 @Override
9056 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009057 final long identity = Binder.clearCallingIdentity();
9058 try {
9059 Phone p = getPhone(subId);
9060 if (p == null) {
9061 return null;
9062 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009063
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009064 return p.getSignalStrength();
9065 } finally {
9066 Binder.restoreCallingIdentity(identity);
9067 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009068 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009069
Pengquan Meng77b7f132018-08-22 14:49:57 -07009070 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009071 * Get the current modem radio state for the given slot.
9072 * @param slotIndex slot index.
9073 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009074 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009075 * @return the current radio power state from the modem
9076 */
9077 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009078 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009079 Phone phone = PhoneFactory.getPhone(slotIndex);
9080 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009081 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9082 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009083 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9084 }
9085
9086 final long identity = Binder.clearCallingIdentity();
9087 try {
9088 return phone.getRadioPowerState();
9089 } finally {
9090 Binder.restoreCallingIdentity(identity);
9091 }
9092 }
9093 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9094 }
9095
9096 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009097 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9098 *
9099 * <p>Requires one of the following permissions:
9100 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009101 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009102 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9103 * privileges.
9104 *
9105 * @param subId subscription id
9106 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9107 * {@code false}.
9108 */
9109 @Override
9110 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009111 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009112 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009113 try {
9114 mApp.enforceCallingOrSelfPermission(
9115 android.Manifest.permission.ACCESS_NETWORK_STATE,
9116 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009117 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009118 mApp.enforceCallingOrSelfPermission(
9119 permission.READ_BASIC_PHONE_STATE, functionName);
9120 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009121 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009122 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009123 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009124 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009125
Pengquan Menga1bb6272018-09-06 09:59:22 -07009126 boolean isEnabled = false;
9127 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009128 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009129 Phone phone = getPhone(subId);
9130 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009131 } finally {
9132 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009133 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009134 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009135 }
9136
9137
9138 /**
9139 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9140 *
9141 * <p> Requires permission:
9142 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9143 * privileges.
9144 *
9145 * @param subId subscription id
9146 * @param isEnabled {@code true} means enable, {@code false} means disable.
9147 */
9148 @Override
9149 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9151 mApp, subId, "setDataRoamingEnabled");
9152
Pengquan Menga1bb6272018-09-06 09:59:22 -07009153 final long identity = Binder.clearCallingIdentity();
9154 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009155 Phone phone = getPhone(subId);
9156 if (phone != null) {
9157 phone.setDataRoamingEnabled(isEnabled);
9158 }
9159 } finally {
9160 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009161 }
9162 }
9163
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009164 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009165 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009166 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009167 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009168 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009169
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009170 boolean isAllowed = true;
9171 final long identity = Binder.clearCallingIdentity();
9172 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009173 Phone phone = getPhone(subId);
9174 if (phone != null) {
9175 isAllowed = phone.isCspPlmnEnabled();
9176 }
9177 } finally {
9178 Binder.restoreCallingIdentity(identity);
9179 }
9180 return isAllowed;
9181 }
9182
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009183 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9184 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009185 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009186 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009187 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009188 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9189 if (phone == null) {
9190 return false;
9191 }
9192 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9193 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9194 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009195 }
9196
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009197 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009198 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009199 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009200 mApp.getSystemService(AppOpsManager.class)
9201 .checkPackage(Binder.getCallingUid(), callingPackage);
9202
Jordan Liu1e142fc2019-04-22 15:10:43 -07009203 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009204 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009205 try {
9206 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009207 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009208 } catch (SecurityException e) {
9209 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9210 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009211 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009212 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009213 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009214 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009215 }
sandeepjsb6c87872021-09-27 15:34:44 +00009216 // checking compatibility, if calling app's target SDK is T and beyond.
9217 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9218 Binder.getCallingUid())) {
9219 isIccIdAccessRestricted = true;
9220 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009221 final long identity = Binder.clearCallingIdentity();
9222 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009223 UiccController uiccController = UiccController.getInstance();
9224 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009225 if (hasReadPermission) {
9226 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009227 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009228
9229 // Remove private info if the caller doesn't have access
9230 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9231 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009232 //setting the value after compatibility check
9233 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009234 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9235 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009236 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009237 if (card == null) {
9238 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009239 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009240 continue;
9241 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009242 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9243 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009244 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009245 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009246 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009247 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9248 for (UiccPortInfo portInfo : portInfos) {
9249 UiccPort port = uiccController.getUiccPortForSlot(
9250 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9251 if (port == null) {
9252 // assume no access if port is null
9253 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9254 continue;
9255 }
9256 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9257 uiccPortInfos.add(portInfo);
9258 } else {
9259 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9260 }
9261 }
9262 filteredInfos.add(new UiccCardInfo(
9263 cardInfo.isEuicc(),
9264 cardInfo.getCardId(),
9265 null,
9266 cardInfo.getPhysicalSlotIndex(),
9267 cardInfo.isRemovable(),
9268 cardInfo.isMultipleEnabledProfilesSupported(),
9269 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009270 }
9271 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009272 } finally {
9273 Binder.restoreCallingIdentity(identity);
9274 }
9275 }
9276
sandeepjsb6c87872021-09-27 15:34:44 +00009277 /**
9278 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9279 * generally private and require carrier privileges to view.
9280 *
9281 * @hide
9282 */
9283 @NonNull
9284 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9285 List<UiccPortInfo> portinfo = new ArrayList<>();
9286 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9287 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9288 }
9289 return new UiccCardInfo(
9290 cardInfo.isEuicc(),
9291 cardInfo.getCardId(),
9292 null,
9293 cardInfo.getPhysicalSlotIndex(),
9294 cardInfo.isRemovable(),
9295 cardInfo.isMultipleEnabledProfilesSupported(),
9296 portinfo
9297 );
9298 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009299
sandeepjsb6c87872021-09-27 15:34:44 +00009300 /**
9301 * @hide
9302 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9303 * These values are generally private and require carrier privileges to view.
9304 */
9305 @NonNull
9306 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9307 return new UiccPortInfo(
9308 UiccPortInfo.ICCID_REDACTED,
9309 portInfo.getPortIndex(),
9310 portInfo.getLogicalSlotIndex(),
9311 portInfo.isActive()
9312 );
9313 }
9314 @Override
9315 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009316 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009317 mApp.getSystemService(AppOpsManager.class)
9318 .checkPackage(Binder.getCallingUid(), callingPackage);
9319
sandeepjsb6c87872021-09-27 15:34:44 +00009320 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009321
Aman Guptaf3c90b32022-03-17 04:54:16 +00009322 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9323 // we are reading iccId which is PII data.
9324 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009325
9326 // checking compatibility, if calling app's target SDK is T and beyond.
9327 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9328 Binder.getCallingUid())) {
9329 isLogicalSlotAccessRestricted = true;
9330 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009331 final long identity = Binder.clearCallingIdentity();
9332 try {
9333 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009334 if (slots == null || slots.length == 0) {
9335 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009336 return null;
9337 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009338 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9339 for (int i = 0; i < slots.length; i++) {
9340 UiccSlot slot = slots[i];
9341 if (slot == null) {
9342 continue;
9343 }
9344
Jordan Liu7be7e652019-05-06 18:55:02 +00009345 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009346 UiccCard card = slot.getUiccCard();
9347 if (card != null) {
9348 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009349 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009350 cardId = slot.getEid();
9351 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009352 // If cardId is null, use iccId of default port as cardId.
9353 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009354 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009355 }
9356
Jordan Liu857451f2019-05-09 16:35:35 -07009357 if (cardId != null) {
9358 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9359 // if cardId is an EID, it's all digits so this is fine
9360 cardId = IccUtils.stripTrailingFs(cardId);
9361 }
9362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009363 int cardState = 0;
9364 switch (slot.getCardState()) {
9365 case CARDSTATE_ABSENT:
9366 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9367 break;
9368 case CARDSTATE_PRESENT:
9369 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9370 break;
9371 case CARDSTATE_ERROR:
9372 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9373 break;
9374 case CARDSTATE_RESTRICTED:
9375 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9376 break;
9377 default:
9378 break;
9379
9380 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009381 List<UiccPortInfo> portInfos = new ArrayList<>();
9382 int[] portIndexes = slot.getPortList();
9383 for (int portIdx : portIndexes) {
9384 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009385 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009386 portInfos.add(new UiccPortInfo(iccId, portIdx,
9387 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009388 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009389 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009390 slot.isEuicc(),
9391 cardId,
9392 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009393 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009394 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009395 //setting the value after compatibility check
9396 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009397 }
9398 return infos;
9399 } finally {
9400 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009401 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009402 }
9403
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009404 /* Returns null if doesn't have read permission or carrier privilege access. */
9405 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9406 boolean hasReadPermission) {
9407 String iccId = slot.getIccId(portIndex);
9408 if (hasReadPermission) { // if has read permission
9409 return iccId;
9410 } else {
9411 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9412 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9413 // if no read permission, checking carrier privilege access
9414 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9415 return iccId;
9416 }
9417 }
9418 }
9419 // No read permission or carrier privilege access.
9420 return UiccPortInfo.ICCID_REDACTED;
9421 }
9422
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009423 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009424 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009425 public boolean switchSlots(int[] physicalSlots) {
9426 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009427
9428 final long identity = Binder.clearCallingIdentity();
9429 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009430 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9431 for (int i = 0; i < physicalSlots.length; i++) {
9432 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9433 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9434 physicalSlots[i], i));
9435 }
9436 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009437 } finally {
9438 Binder.restoreCallingIdentity(identity);
9439 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009440 }
Jack Yu4c988042018-02-27 15:30:01 -08009441
9442 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009443 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9444 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9445 enforceModifyPermission();
9446
9447 final long identity = Binder.clearCallingIdentity();
9448 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009449 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009450 } finally {
9451 Binder.restoreCallingIdentity(identity);
9452 }
9453 }
9454
9455 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009456 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009457 final long identity = Binder.clearCallingIdentity();
9458 try {
9459 return UiccController.getInstance().getCardIdForDefaultEuicc();
9460 } finally {
9461 Binder.restoreCallingIdentity(identity);
9462 }
9463 }
9464
Pengquan Meng85728fb2018-03-12 16:31:21 -07009465 /**
goneil47ffb6e2018-04-06 15:40:58 -07009466 * A test API to reload the UICC profile.
9467 *
9468 * <p>Requires that the calling app has permission
9469 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9470 * @hide
9471 */
9472 @Override
9473 public void refreshUiccProfile(int subId) {
9474 enforceModifyPermission();
9475
9476 final long identity = Binder.clearCallingIdentity();
9477 try {
9478 Phone phone = getPhone(subId);
9479 if (phone == null) {
9480 return;
9481 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009482 UiccPort uiccPort = phone.getUiccPort();
9483 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009484 return;
9485 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009486 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009487 if (uiccProfile == null) {
9488 return;
9489 }
9490 uiccProfile.refresh();
9491 } finally {
9492 Binder.restoreCallingIdentity(identity);
9493 }
9494 }
9495
9496 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009497 * Returns false if the mobile data is disabled by default, otherwise return true.
9498 */
9499 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009500 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009501 }
9502
9503 /**
9504 * Returns true if the data roaming is enabled by default, i.e the system property
9505 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9506 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9507 */
9508 private boolean getDefaultDataRoamingEnabled(int subId) {
9509 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009510 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009511 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009512 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9513 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9514 return isDataRoamingEnabled;
9515 }
9516
9517 /**
9518 * Returns the default network type for the given {@code subId}, if the default network type is
9519 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9520 */
9521 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009522 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009523 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009524 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9525 return list.get(phoneId);
9526 }
9527 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009528 }
fionaxua13278b2018-03-21 00:08:13 -07009529
9530 @Override
9531 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009532 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009533 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009534
9535 final long identity = Binder.clearCallingIdentity();
9536 try {
9537 final Phone phone = getPhone(subId);
9538 if (phone == null) {
9539 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9540 return;
9541 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009542 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9543 if (cpt != null) {
9544 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9545 }
9546 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009547 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9548 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009549 if (carrierPrivilegeRules == null) {
9550 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9551 } else {
9552 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9553 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009554 } finally {
9555 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009556 }
fionaxua13278b2018-03-21 00:08:13 -07009557 }
9558
9559 @Override
Benedict Wong66477622023-02-03 23:30:57 +00009560 public void setCarrierServicePackageOverride(
9561 int subId, String carrierServicePackage, String callingPackage) {
9562 TelephonyPermissions.enforceShellOnly(
9563 Binder.getCallingUid(), "setCarrierServicePackageOverride");
9564
9565 // Verify that the callingPackage belongs to the calling UID
9566 mApp.getSystemService(AppOpsManager.class)
9567 .checkPackage(Binder.getCallingUid(), callingPackage);
9568
9569 final long identity = Binder.clearCallingIdentity();
9570 try {
9571 final Phone phone = getPhone(subId);
9572 if (phone == null || phone.getSubId() != subId) {
9573 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
9574 throw new IllegalArgumentException("No phone for subid");
9575 }
9576 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9577 if (cpt == null) {
9578 loge("setCarrierServicePackageOverride failed with no CPT for phone");
9579 throw new IllegalStateException("No CPT for phone");
9580 }
9581 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
9582 } finally {
9583 Binder.restoreCallingIdentity(identity);
9584 }
9585 }
9586
9587 @Override
fionaxua13278b2018-03-21 00:08:13 -07009588 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009589 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009590
9591 final long identity = Binder.clearCallingIdentity();
9592 try {
9593 final Phone phone = getPhone(subId);
9594 if (phone == null) {
9595 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9596 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9597 }
9598 return phone.getCarrierIdListVersion();
9599 } finally {
9600 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009601 }
fionaxua13278b2018-03-21 00:08:13 -07009602 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009603
9604 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009605 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9606 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009607 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009608 mApp, subId, callingPackage, callingFeatureId,
9609 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009610 return -1;
9611 }
9612
9613 final long identity = Binder.clearCallingIdentity();
9614 try {
9615 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9616 } finally {
9617 Binder.restoreCallingIdentity(identity);
9618 }
9619 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009620
9621 @Override
9622 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009623 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009624 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009625 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -07009626
9627 final long identity = Binder.clearCallingIdentity();
9628 try {
9629 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9630 } finally {
9631 Binder.restoreCallingIdentity(identity);
9632 }
9633 }
9634
9635 @Override
9636 public boolean setCdmaRoamingMode(int subId, int mode) {
9637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9638 mApp, subId, "setCdmaRoamingMode");
9639
9640 final long identity = Binder.clearCallingIdentity();
9641 try {
9642 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9643 } finally {
9644 Binder.restoreCallingIdentity(identity);
9645 }
9646 }
9647
9648 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009649 public int getCdmaSubscriptionMode(int subId) {
9650 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009651 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009652 mApp, subId, "getCdmaSubscriptionMode");
9653
9654 final long identity = Binder.clearCallingIdentity();
9655 try {
9656 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9657 } finally {
9658 Binder.restoreCallingIdentity(identity);
9659 }
9660 }
9661
9662 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009663 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9665 mApp, subId, "setCdmaSubscriptionMode");
9666
9667 final long identity = Binder.clearCallingIdentity();
9668 try {
9669 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9670 } finally {
9671 Binder.restoreCallingIdentity(identity);
9672 }
9673 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009674
sqianc5eccab2018-10-19 18:46:41 -07009675 @Override
sqian8c685422019-02-22 15:55:18 -08009676 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009677 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009678 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009679 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9680 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009681 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9682 }
9683 final long identity = Binder.clearCallingIdentity();
9684 try {
sqian854d44b2018-12-12 16:48:18 -08009685 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9686 for (Phone phone: PhoneFactory.getPhones()) {
9687 if (phone.getEmergencyNumberTracker() != null
9688 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9689 emergencyNumberListInternal.put(
9690 phone.getSubId(),
9691 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9692 }
sqian11b7a0e2018-12-05 18:48:28 -08009693 }
sqian854d44b2018-12-12 16:48:18 -08009694 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009695 } finally {
9696 Binder.restoreCallingIdentity(identity);
9697 }
sqianc5eccab2018-10-19 18:46:41 -07009698 }
9699
9700 @Override
sqian8c685422019-02-22 15:55:18 -08009701 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009702 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009703 if (!exactMatch) {
9704 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009705 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009706 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009707 }
9708 final long identity = Binder.clearCallingIdentity();
9709 try {
sqian854d44b2018-12-12 16:48:18 -08009710 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009711 //Note: we ignore passed in param exactMatch. We can remove it once
9712 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009713 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009714 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009715 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009716 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009717 }
sqian11b7a0e2018-12-05 18:48:28 -08009718 }
9719 return false;
9720 } finally {
9721 Binder.restoreCallingIdentity(identity);
9722 }
9723 }
9724
sqianf4ca7ed2019-01-15 18:32:07 -08009725 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009726 * Start emergency callback mode for GsmCdmaPhone for testing.
9727 */
9728 @Override
9729 public void startEmergencyCallbackMode() {
9730 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9731 "startEmergencyCallbackMode");
9732 enforceModifyPermission();
9733 final long identity = Binder.clearCallingIdentity();
9734 try {
9735 for (Phone phone : PhoneFactory.getPhones()) {
9736 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9737 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9738 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9739 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9740 gsmCdmaPhone.obtainMessage(
9741 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9742 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9743 }
9744 }
9745 } finally {
9746 Binder.restoreCallingIdentity(identity);
9747 }
9748 }
9749
9750 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009751 * Update emergency number list for test mode.
9752 */
9753 @Override
9754 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9755 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9756 "updateEmergencyNumberListTestMode");
9757
9758 final long identity = Binder.clearCallingIdentity();
9759 try {
9760 for (Phone phone: PhoneFactory.getPhones()) {
9761 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9762 if (tracker != null) {
9763 tracker.executeEmergencyNumberTestModeCommand(action, num);
9764 }
9765 }
9766 } finally {
9767 Binder.restoreCallingIdentity(identity);
9768 }
9769 }
9770
9771 /**
9772 * Get the full emergency number list for test mode.
9773 */
9774 @Override
9775 public List<String> getEmergencyNumberListTestMode() {
9776 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9777 "getEmergencyNumberListTestMode");
9778
9779 final long identity = Binder.clearCallingIdentity();
9780 try {
9781 Set<String> emergencyNumbers = new HashSet<>();
9782 for (Phone phone: PhoneFactory.getPhones()) {
9783 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9784 if (tracker != null) {
9785 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9786 emergencyNumbers.add(num.getNumber());
9787 }
9788 }
9789 }
9790 return new ArrayList<>(emergencyNumbers);
9791 } finally {
9792 Binder.restoreCallingIdentity(identity);
9793 }
9794 }
9795
chen xud6b45bd2018-10-30 22:27:10 -07009796 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009797 public int getEmergencyNumberDbVersion(int subId) {
9798 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9799
9800 final long identity = Binder.clearCallingIdentity();
9801 try {
9802 final Phone phone = getPhone(subId);
9803 if (phone == null) {
9804 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9805 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9806 }
9807 return phone.getEmergencyNumberDbVersion();
9808 } finally {
9809 Binder.restoreCallingIdentity(identity);
9810 }
9811 }
9812
9813 @Override
9814 public void notifyOtaEmergencyNumberDbInstalled() {
9815 enforceModifyPermission();
9816
9817 final long identity = Binder.clearCallingIdentity();
9818 try {
9819 for (Phone phone: PhoneFactory.getPhones()) {
9820 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9821 if (tracker != null) {
9822 tracker.updateOtaEmergencyNumberDatabase();
9823 }
9824 }
9825 } finally {
9826 Binder.restoreCallingIdentity(identity);
9827 }
9828 }
9829
9830 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009831 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009832 enforceActiveEmergencySessionPermission();
9833
9834 final long identity = Binder.clearCallingIdentity();
9835 try {
9836 for (Phone phone: PhoneFactory.getPhones()) {
9837 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9838 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009839 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9840 }
9841 }
9842 } finally {
9843 Binder.restoreCallingIdentity(identity);
9844 }
9845 }
9846
9847 @Override
9848 public void resetOtaEmergencyNumberDbFilePath() {
9849 enforceActiveEmergencySessionPermission();
9850
9851 final long identity = Binder.clearCallingIdentity();
9852 try {
9853 for (Phone phone: PhoneFactory.getPhones()) {
9854 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9855 if (tracker != null) {
9856 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009857 }
9858 }
9859 } finally {
9860 Binder.restoreCallingIdentity(identity);
9861 }
9862 }
9863
9864 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009865 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9866 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9867 Phone phone = getPhone(subId);
9868 if (phone == null) {
9869 return null;
9870 }
9871 final long identity = Binder.clearCallingIdentity();
9872 try {
9873 UiccProfile profile = UiccController.getInstance()
9874 .getUiccProfileForPhone(phone.getPhoneId());
9875 if (profile != null) {
9876 return profile.getCertsFromCarrierPrivilegeAccessRules();
9877 }
9878 } finally {
9879 Binder.restoreCallingIdentity(identity);
9880 }
9881 return null;
9882 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009883
9884 /**
9885 * Enable or disable a modem stack.
9886 */
9887 @Override
9888 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9889 enforceModifyPermission();
9890
9891 final long identity = Binder.clearCallingIdentity();
9892 try {
9893 Phone phone = PhoneFactory.getPhone(slotIndex);
9894 if (phone == null) {
9895 return false;
9896 } else {
9897 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9898 }
9899 } finally {
9900 Binder.restoreCallingIdentity(identity);
9901 }
9902 }
Michelecea4cf22018-12-21 15:00:11 -08009903
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009904 /**
9905 * Whether a modem stack is enabled or not.
9906 */
9907 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009908 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9909 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009910 Phone phone = PhoneFactory.getPhone(slotIndex);
9911 if (phone == null) return false;
9912
9913 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009914 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9915 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009916 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9917 }
9918
9919 final long identity = Binder.clearCallingIdentity();
9920 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009921 try {
9922 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9923 } catch (NoSuchElementException ex) {
9924 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9925 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009926 } finally {
9927 Binder.restoreCallingIdentity(identity);
9928 }
9929 }
9930
Michelecea4cf22018-12-21 15:00:11 -08009931 @Override
Michele0ea7d782019-03-19 14:58:42 -07009932 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009933 enforceModifyPermission();
9934
9935 final long identity = Binder.clearCallingIdentity();
9936 try {
9937 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009938 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009939 .commit();
9940 } finally {
9941 Binder.restoreCallingIdentity(identity);
9942 }
9943 }
9944
9945 @Override
Michele0ea7d782019-03-19 14:58:42 -07009946 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009947 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009948 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009949 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9950 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009951 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009952 }
Michelecea4cf22018-12-21 15:00:11 -08009953
9954 final long identity = Binder.clearCallingIdentity();
9955 try {
Michele0ea7d782019-03-19 14:58:42 -07009956 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009957 } finally {
9958 Binder.restoreCallingIdentity(identity);
9959 }
9960 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009961
Michele0ea7d782019-03-19 14:58:42 -07009962 @TelephonyManager.IsMultiSimSupportedResult
9963 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009964 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9965 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9966 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009967 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9968 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009969 }
9970 // Check if the hardware supports multisim functionality. If usage of multisim is not
9971 // supported by the modem, indicate that it is restricted.
9972 PhoneCapability staticCapability =
9973 mPhoneConfigurationManager.getStaticPhoneCapability();
9974 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009975 loge("isMultiSimSupportedInternal: no static configuration available");
9976 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009977 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009978 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009979 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9980 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009981 }
9982 // Check if support of multiple SIMs is restricted by carrier
9983 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009984 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009985 }
9986
Michele0ea7d782019-03-19 14:58:42 -07009987 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009988 }
9989
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009990 /**
9991 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009992 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9993 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9994 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009995 * @param numOfSims number of active sims we want to switch to
9996 */
9997 @Override
9998 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009999 if (numOfSims == 1) {
10000 enforceModifyPermission();
10001 } else {
10002 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10003 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10004 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010005 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010006
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010007 try {
Michele30b57b22019-03-01 12:01:14 -080010008 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010009 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010010 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10011 return;
10012 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010013 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10014 } finally {
10015 Binder.restoreCallingIdentity(identity);
10016 }
10017 }
10018
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010019 @Override
10020 public boolean isApplicationOnUicc(int subId, int appType) {
10021 enforceReadPrivilegedPermission("isApplicationOnUicc");
10022 Phone phone = getPhone(subId);
10023 if (phone == null) {
10024 return false;
10025 }
10026 final long identity = Binder.clearCallingIdentity();
10027 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010028 UiccPort uiccPort = phone.getUiccPort();
10029 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010030 return false;
10031 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010032 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010033 if (uiccProfile == null) {
10034 return false;
10035 }
10036 if (TelephonyManager.APPTYPE_SIM <= appType
10037 && appType <= TelephonyManager.APPTYPE_ISIM) {
10038 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10039 }
10040 return false;
10041 } finally {
10042 Binder.restoreCallingIdentity(identity);
10043 }
10044 }
10045
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010046 /**
chen xub4baa772019-04-03 10:23:41 -070010047 * Get whether making changes to modem configurations will trigger reboot.
10048 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010049 */
10050 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010051 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10052 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010053 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010054 mApp, subId, callingPackage, callingFeatureId,
10055 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010056 return false;
10057 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010058 final long identity = Binder.clearCallingIdentity();
10059 try {
10060 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10061 } finally {
10062 Binder.restoreCallingIdentity(identity);
10063 }
10064 }
10065
Nathan Harold29f5f052019-02-15 13:41:57 -080010066 private void updateModemStateMetrics() {
10067 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10068 // TODO: check the state for each modem if the api is ready.
10069 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10070 }
10071
Pengquan Meng3889a572019-01-23 11:16:29 -080010072 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010073 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010074 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010075 // Verify that the callingPackage belongs to the calling UID
10076 mApp.getSystemService(AppOpsManager.class)
10077 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010078 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010079 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010080 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010081 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10082 if (slotInfos != null) {
10083 for (int i = 0; i < slotInfos.length; i++) {
10084 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10085 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10086 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10087 portInfo.getLogicalSlotIndex()));
10088 }
10089 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010090 }
10091 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010092 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010093 } finally {
10094 Binder.restoreCallingIdentity(identity);
10095 }
10096 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010097
10098 /**
10099 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010100 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010101 */
jimsunf9ec1622022-09-13 21:18:43 +080010102 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010103 @Override
10104 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010105 return getHalVersion(HAL_SERVICE_RADIO);
10106 }
10107
10108 /**
10109 * Get the HAL Version of a specific service
10110 */
10111 @Override
10112 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010113 Phone phone = getDefaultPhone();
10114 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010115 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010116 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10117 return hv.major * 100 + hv.minor;
10118 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010119
10120 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010121 * Get the current calling package name.
10122 * @return the current calling package name
10123 */
10124 @Override
10125 public String getCurrentPackageName() {
10126 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10127 }
10128
10129 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010130 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10131 * corresponding network requests on a subId.
10132 *
10133 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010134 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010135 * 2) APN is un-metered for this subscription, or
10136 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010137 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010138 *
10139 * @return whether data is allowed for a apn type.
10140 *
10141 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010142 */
10143 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010144 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010145 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10146 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010147
10148 // Now that all security checks passes, perform the operation as ourselves.
10149 final long identity = Binder.clearCallingIdentity();
10150 try {
10151 Phone phone = getPhone(subId);
10152 if (phone == null) return false;
10153
Jack Yu27422a52022-03-21 10:38:05 -070010154 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010155 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010156 isMetered = phone.getDataNetworkController().getDataConfigManager()
10157 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10158 phone.getServiceState().getDataRoaming());
10159 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010160 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010161 } finally {
10162 Binder.restoreCallingIdentity(identity);
10163 }
10164 }
10165
10166 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010167 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010168 enforceReadPrivilegedPermission("isApnMetered");
10169
10170 // Now that all security checks passes, perform the operation as ourselves.
10171 final long identity = Binder.clearCallingIdentity();
10172 try {
10173 Phone phone = getPhone(subId);
10174 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010175 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10176 DataUtils.apnTypeToNetworkCapability(apnType),
10177 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010178 } finally {
10179 Binder.restoreCallingIdentity(identity);
10180 }
10181 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010182
10183 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010184 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10185 int subscriptionId, IBooleanConsumer resultCallback) {
10186 enforceModifyPermission();
10187 long token = Binder.clearCallingIdentity();
10188 try {
10189 Phone phone = getPhone(subscriptionId);
10190 if (phone == null) {
10191 try {
10192 if (resultCallback != null) {
10193 resultCallback.accept(false);
10194 }
10195 } catch (RemoteException e) {
10196 // ignore
10197 }
10198 return;
10199 }
10200 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10201 Pair.create(specifiers, (x) -> {
10202 try {
10203 if (resultCallback != null) {
10204 resultCallback.accept(x);
10205 }
10206 } catch (RemoteException e) {
10207 // ignore
10208 }
10209 });
10210 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10211 } finally {
10212 Binder.restoreCallingIdentity(token);
10213 }
10214 }
10215
10216 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010217 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10218 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010219 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010220 mApp, subId, "getSystemSelectionChannels");
10221 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10222 final long identity = Binder.clearCallingIdentity();
10223 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010224 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10225 if (result instanceof IllegalStateException) {
10226 throw (IllegalStateException) result;
10227 }
10228 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010229 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10230 return specifiers;
10231 } finally {
10232 Binder.restoreCallingIdentity(identity);
10233 }
10234 }
10235
10236 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010237 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010238 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010239 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010240 }
10241
10242 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010243 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10244 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010245 if (callingPackage == null) {
10246 callingPackage = getCurrentPackageName();
10247 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010248 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10249 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010250 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10251 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010252 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10253 }
10254 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10255 Intent intent = new Intent();
10256 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10257 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10258 // Bring up choose default SMS subscription dialog right now
10259 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10260 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10261 mApp.startActivity(intent);
10262 }
chen xud5ca2d52019-05-28 15:20:57 -070010263
10264 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010265 public void showSwitchToManagedProfileDialog() {
10266 enforceModifyPermission();
10267
10268 Intent intent = new Intent();
10269 intent.setClass(mApp, ErrorDialogActivity.class);
10270 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10271 mApp.startActivity(intent);
10272 }
10273
10274 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010275 public String getMmsUAProfUrl(int subId) {
10276 //TODO investigate if this API should require proper permission check in R b/133791609
10277 final long identity = Binder.clearCallingIdentity();
10278 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010279 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10280 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10281 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10282 return carrierUAProfUrl;
10283 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010284 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10285 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010286 } finally {
10287 Binder.restoreCallingIdentity(identity);
10288 }
10289 }
10290
10291 @Override
10292 public String getMmsUserAgent(int subId) {
10293 //TODO investigate if this API should require proper permission check in R b/133791609
10294 final long identity = Binder.clearCallingIdentity();
10295 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010296 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10297 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10298 if (!TextUtils.isEmpty(carrierUserAgent)) {
10299 return carrierUserAgent;
10300 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010301 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10302 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010303 } finally {
10304 Binder.restoreCallingIdentity(identity);
10305 }
10306 }
Jack Yub07d4972019-05-28 16:12:25 -070010307
10308 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010309 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10310 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010311
Jack Yub07d4972019-05-28 16:12:25 -070010312 final long identity = Binder.clearCallingIdentity();
10313 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010314 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010315 if (phone == null) return false;
10316
Ling Maf188d502022-09-16 15:22:36 -070010317 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010318 } finally {
10319 Binder.restoreCallingIdentity(identity);
10320 }
10321 }
10322
10323 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010324 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010325 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010326 enforceModifyPermission();
10327
changbettyd5c246e2019-12-24 15:40:37 +080010328 final long identity = Binder.clearCallingIdentity();
10329 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010330 Phone phone = getPhone(subscriptionId);
10331 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010332
Ling Maf188d502022-09-16 15:22:36 -070010333 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010334 } finally {
10335 Binder.restoreCallingIdentity(identity);
10336 }
10337 }
10338
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010339 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010340 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010341 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10342 * otherwise.
10343 */
10344 @Override
10345 public void setCepEnabled(boolean isCepEnabled) {
10346 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10347
10348 final long identity = Binder.clearCallingIdentity();
10349 try {
10350 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10351 for (Phone phone : PhoneFactory.getPhones()) {
10352 Phone defaultPhone = phone.getImsPhone();
10353 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10354 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10355 ImsPhoneCallTracker imsPhoneCallTracker =
10356 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10357 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10358 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10359 + imsPhone.getMsisdn());
10360 }
10361 }
10362 } finally {
10363 Binder.restoreCallingIdentity(identity);
10364 }
10365 }
allenwtsu46dcc572020-01-08 18:24:03 +080010366
10367 /**
10368 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10369 *
10370 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10371 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10372 * before being read.
10373 */
10374 @Override
10375 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10376 isCompressed) {
10377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10378 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010379 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10380 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10381 }
10382 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010383 // ProvisioningManager can not handle ServiceSpecificException.
10384 // Throw the IllegalStateException and annotate ProvisioningManager.
10385 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010386 }
10387
10388 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010389 try {
Hui Wang761a6682020-10-31 05:12:53 +000010390 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10391 } finally {
10392 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010393 }
10394 }
zoey chene02881a2019-12-30 16:11:23 +080010395
10396 @Override
10397 public boolean isIccLockEnabled(int subId) {
10398 enforceReadPrivilegedPermission("isIccLockEnabled");
10399
10400 // Now that all security checks passes, perform the operation as ourselves.
10401 final long identity = Binder.clearCallingIdentity();
10402 try {
10403 Phone phone = getPhone(subId);
10404 if (phone != null && phone.getIccCard() != null) {
10405 return phone.getIccCard().getIccLockEnabled();
10406 } else {
10407 return false;
10408 }
10409 } finally {
10410 Binder.restoreCallingIdentity(identity);
10411 }
10412 }
10413
10414 /**
10415 * Set the ICC pin lock enabled or disabled.
10416 *
10417 * @return an integer representing the status of IccLock enabled or disabled in the following
10418 * three cases:
10419 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10420 * successfully.
10421 * - Positive number and zero for remaining password attempts.
10422 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10423 *
10424 */
10425 @Override
10426 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10427 enforceModifyPermission();
10428
10429 Phone phone = getPhone(subId);
10430 if (phone == null) {
10431 return 0;
10432 }
10433 // Now that all security checks passes, perform the operation as ourselves.
10434 final long identity = Binder.clearCallingIdentity();
10435 try {
10436 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10437 new Pair<Boolean, String>(enabled, password), phone, null);
10438 return attemptsRemaining;
10439
10440 } catch (Exception e) {
10441 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10442 } finally {
10443 Binder.restoreCallingIdentity(identity);
10444 }
10445 return 0;
10446 }
10447
10448 /**
10449 * Change the ICC password used in ICC pin lock.
10450 *
10451 * @return an integer representing the status of IccLock changed in the following three cases:
10452 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10453 * - Positive number and zero for remaining password attempts.
10454 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10455 *
10456 */
10457 @Override
10458 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10459 enforceModifyPermission();
10460
10461 Phone phone = getPhone(subId);
10462 if (phone == null) {
10463 return 0;
10464 }
10465 // Now that all security checks passes, perform the operation as ourselves.
10466 final long identity = Binder.clearCallingIdentity();
10467 try {
10468 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10469 new Pair<String, String>(oldPassword, newPassword), phone, null);
10470 return attemptsRemaining;
10471
10472 } catch (Exception e) {
10473 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10474 } finally {
10475 Binder.restoreCallingIdentity(identity);
10476 }
10477 return 0;
10478 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010479
10480 /**
10481 * Request for receiving user activity notification
10482 */
10483 @Override
10484 public void requestUserActivityNotification() {
10485 if (!mNotifyUserActivity.get()
10486 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10487 mNotifyUserActivity.set(true);
10488 }
10489 }
10490
10491 /**
10492 * Called when userActivity is signalled in the power manager.
10493 * This is safe to call from any thread, with any window manager locks held or not.
10494 */
10495 @Override
10496 public void userActivity() {
10497 // ***************************************
10498 // * Inherited from PhoneWindowManager *
10499 // ***************************************
10500 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10501 // WITH ITS LOCKS HELD.
10502 //
10503 // This code must be VERY careful about the locks
10504 // it acquires.
10505 // In fact, the current code acquires way too many,
10506 // and probably has lurking deadlocks.
10507
10508 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10509 throw new SecurityException("Only the OS may call notifyUserActivity()");
10510 }
10511
10512 if (mNotifyUserActivity.getAndSet(false)) {
10513 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10514 USER_ACTIVITY_NOTIFICATION_DELAY);
10515 }
10516 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010517
10518 @Override
10519 public boolean canConnectTo5GInDsdsMode() {
10520 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10521 }
Jack Yud10cdd42020-09-28 20:28:01 -070010522
10523 @Override
10524 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10525 String callingFeatureId) {
10526 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10527 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10528 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10529 }
10530
10531 Phone phone = getPhone(subId);
10532 if (phone == null) {
10533 throw new RuntimeException("phone is not available");
10534 }
10535 // Now that all security checks passes, perform the operation as ourselves.
10536 final long identity = Binder.clearCallingIdentity();
10537 try {
10538 return phone.getEquivalentHomePlmns();
10539 } finally {
10540 Binder.restoreCallingIdentity(identity);
10541 }
10542 }
Daniel Bright59e67312020-11-13 11:49:37 -080010543
10544 @Override
10545 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010546 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10547 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010548 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010549 if (radioInterfaceCapabilities == null) {
10550 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010551 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010552 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010553 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010554
Hui Wang641e81c2020-10-12 12:14:23 -070010555 @Override
10556 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10557 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010558 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10559 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10560 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10561 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10562 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010563 if (DBG) {
10564 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10565 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10566 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10567 }
10568
10569 if (!SubscriptionManager.isValidSubscriptionId(subId)
10570 || appType < TelephonyManager.APPTYPE_UNKNOWN
10571 || appType > TelephonyManager.APPTYPE_ISIM
10572 || nafUrl == null || securityProtocol == null || callback == null) {
10573 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10574 if (callback != null) {
10575 try {
10576 callback.onAuthenticationFailure(
10577 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10578 } catch (RemoteException exception) {
10579 log("Fail to notify onAuthenticationFailure due to " + exception);
10580 }
10581 return;
10582 }
10583 }
10584
10585 final long token = Binder.clearCallingIdentity();
10586 try {
10587 getGbaManager(subId).bootstrapAuthenticationRequest(
10588 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010589 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070010590 } finally {
10591 Binder.restoreCallingIdentity(token);
10592 }
10593 }
10594
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010595 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010596 * Attempts to set the radio power state for all phones for thermal reason.
10597 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010598 * requested radio power state will actually be set. See {@link
10599 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10600 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010601 * @param enable {@code true} if trying to turn radio on.
10602 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10603 * false}.
10604 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010605 private boolean setRadioPowerForThermal(boolean enable) {
10606 boolean isPhoneAvailable = false;
10607 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10608 Phone phone = PhoneFactory.getPhone(i);
10609 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010610 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010611 isPhoneAvailable = true;
10612 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010613 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010614
10615 // return true if successfully informed the phone object about the thermal radio power
10616 // request.
10617 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010618 }
10619
10620 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010621 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010622 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10623 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10624 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10625 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10626 throw new IllegalArgumentException("modem does not support data throttling");
10627 }
10628
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010629 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10630 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010631 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010632 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10633 }
10634
Sarah Chinecc78c42022-03-31 21:16:48 -070010635 setDataEnabledForReason(
10636 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010637
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010638 if (isDataThrottlingSupported) {
10639 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010640 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010641 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10642 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10643 } else if (thermalMitigationResult
10644 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010645 log("Modem likely does not support data throttling on secondary carrier. Data " +
10646 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10647 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010648 }
10649 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010650 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010651
10652 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010653 }
10654
Jack Nudelman644b91a2021-03-12 14:09:48 -080010655 private static List<String> getThermalMitigationAllowlist(Context context) {
10656 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10657 for (String pckg : context.getResources()
10658 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10659 sThermalMitigationAllowlistedPackages.add(pckg);
10660 }
10661 }
10662
10663 return sThermalMitigationAllowlistedPackages;
10664 }
10665
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010666 private boolean isAnyPhoneInEmergencyState() {
10667 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10668 if (tm.isInEmergencyCall()) {
10669 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10670 return true;
10671 }
10672 for (Phone phone : PhoneFactory.getPhones()) {
10673 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10674 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010675 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10676 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010677 return true;
10678 }
10679 }
10680
10681 return false;
10682 }
10683
Jack Nudelman644b91a2021-03-12 14:09:48 -080010684 /**
10685 * Used by shell commands to add an authorized package name for thermal mitigation.
10686 * @param packageName name of package to be allowlisted
10687 * @param context
10688 */
10689 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10690 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10691 sThermalMitigationAllowlistedPackages.add(packageName);
10692 }
10693
10694 /**
10695 * Used by shell commands to remove an authorized package name for thermal mitigation.
10696 * @param packageName name of package to remove from allowlist
10697 * @param context
10698 */
10699 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10700 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10701 sThermalMitigationAllowlistedPackages.remove(packageName);
10702 }
10703
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010704 /**
10705 * Thermal mitigation request to control functionalities at modem.
10706 *
10707 * @param subId the id of the subscription.
10708 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010709 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010710 *
10711 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10712 */
10713 @Override
10714 @ThermalMitigationResult
10715 public int sendThermalMitigationRequest(
10716 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010717 ThermalMitigationRequest thermalMitigationRequest,
10718 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010719 enforceModifyPermission();
10720
Jack Nudelman644b91a2021-03-12 14:09:48 -080010721 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10722 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10723 .contains(callingPackage)) {
10724 throw new SecurityException("Calling package must be configured in the device config. "
10725 + "calling package: " + callingPackage);
10726 }
10727
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010728 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10729 final long identity = Binder.clearCallingIdentity();
10730
10731 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10732 try {
10733 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10734 switch (thermalMitigationAction) {
10735 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10736 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010737 handleDataThrottlingRequest(subId,
10738 thermalMitigationRequest.getDataThrottlingRequest(),
10739 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010740 break;
10741 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10742 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10743 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10744 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10745 }
10746
10747 // Ensure that radio is on. If not able to power on due to phone being
10748 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010749 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010750 thermalMitigationResult =
10751 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10752 break;
10753 }
10754
10755 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010756 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010757 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10758 break;
10759 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10760 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10761 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10762 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10763 }
10764
10765 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10766 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010767 Phone phone = getPhone(subId);
10768 if (phone == null) {
10769 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010770 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010771 break;
10772 }
10773
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010774 TelephonyConnectionService service =
10775 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010776 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010777 Log.e(LOG_TAG, "An emergency call is pending");
10778 thermalMitigationResult =
10779 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10780 break;
10781 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010782 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010783 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010784 break;
10785 }
10786 } else {
10787 thermalMitigationResult =
10788 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10789 break;
10790 }
10791
10792 // Turn radio off. If not able to power off due to phone being unavailable,
10793 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010794 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010795 thermalMitigationResult =
10796 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10797 break;
10798 }
10799 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010800 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010801 break;
10802 default:
10803 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10804 + "not exist. Requested action: " + thermalMitigationAction);
10805 }
10806 } catch (IllegalArgumentException e) {
10807 throw e;
10808 } catch (Exception e) {
10809 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10810 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10811 } finally {
10812 Binder.restoreCallingIdentity(identity);
10813 }
10814
10815 if (DBG) {
10816 log("thermalMitigationRequest returning with thermalMitigationResult: "
10817 + thermalMitigationResult);
10818 }
10819
10820 return thermalMitigationResult;
10821 }
Hui Wang641e81c2020-10-12 12:14:23 -070010822
10823 /**
10824 * Set the GbaService Package Name that Telephony will bind to.
10825 *
10826 * @param subId The sim that the GbaService is associated with.
10827 * @param packageName The name of the package to be replaced with.
10828 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10829 */
10830 @Override
10831 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10832 enforceModifyPermission();
10833
10834 final long identity = Binder.clearCallingIdentity();
10835 try {
10836 return getGbaManager(subId).overrideServicePackage(packageName);
10837 } finally {
10838 Binder.restoreCallingIdentity(identity);
10839 }
10840 }
10841
10842 /**
10843 * Return the package name of the currently bound GbaService.
10844 *
10845 * @param subId The sim that the GbaService is associated with.
10846 * @return the package name of the GbaService configuration, null if GBA is not supported.
10847 */
10848 @Override
10849 public String getBoundGbaService(int subId) {
10850 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10851
10852 final long identity = Binder.clearCallingIdentity();
10853 try {
10854 return getGbaManager(subId).getServicePackage();
10855 } finally {
10856 Binder.restoreCallingIdentity(identity);
10857 }
10858 }
10859
10860 /**
10861 * Set the release time for telephony to unbind GbaService.
10862 *
10863 * @param subId The sim that the GbaService is associated with.
10864 * @param interval The release time to unbind GbaService by millisecond.
10865 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10866 */
10867 @Override
10868 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10869 enforceModifyPermission();
10870
10871 final long identity = Binder.clearCallingIdentity();
10872 try {
10873 return getGbaManager(subId).overrideReleaseTime(interval);
10874 } finally {
10875 Binder.restoreCallingIdentity(identity);
10876 }
10877 }
10878
10879 /**
10880 * Return the release time for telephony to unbind GbaService.
10881 *
10882 * @param subId The sim that the GbaService is associated with.
10883 * @return The release time to unbind GbaService by millisecond.
10884 */
10885 @Override
10886 public int getGbaReleaseTime(int subId) {
10887 enforceReadPrivilegedPermission("getGbaReleaseTime");
10888
10889 final long identity = Binder.clearCallingIdentity();
10890 try {
10891 return getGbaManager(subId).getReleaseTime();
10892 } finally {
10893 Binder.restoreCallingIdentity(identity);
10894 }
10895 }
10896
10897 private GbaManager getGbaManager(int subId) {
10898 GbaManager instance = GbaManager.getInstance(subId);
10899 if (instance == null) {
10900 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10901 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10902 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10903 }
10904 return instance;
10905 }
Hui Wang761a6682020-10-31 05:12:53 +000010906
10907 /**
10908 * indicate whether the device and the carrier can support
10909 * RCS VoLTE single registration.
10910 */
10911 @Override
10912 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010913 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10914 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10915 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10916 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010917
10918 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10919 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10920 }
10921
10922 final long identity = Binder.clearCallingIdentity();
10923 try {
10924 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10925 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010926 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10927 if (isCapable != null) {
10928 return isCapable;
10929 }
Hui Wang761a6682020-10-31 05:12:53 +000010930 }
Hui Wang67af90e2021-06-04 16:57:15 -070010931 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10932 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010933 } finally {
10934 Binder.restoreCallingIdentity(identity);
10935 }
10936 }
10937
10938 /**
10939 * Register RCS provisioning callback.
10940 */
10941 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010942 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010943 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010944 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010945 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010946 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10947 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010948
10949 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10950 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10951 }
10952 if (!isImsAvailableOnDevice()) {
10953 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10954 "IMS not available on device.");
10955 }
10956
10957 final long identity = Binder.clearCallingIdentity();
10958 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010959 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010960 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010961 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10962 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010963 }
Hui Wang761a6682020-10-31 05:12:53 +000010964 } finally {
10965 Binder.restoreCallingIdentity(identity);
10966 }
10967 }
10968
10969 /**
10970 * Unregister RCS provisioning callback.
10971 */
10972 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010973 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010974 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010975 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010976 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010977 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10978 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010979
10980 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10981 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10982 }
10983 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010984 // operation failed silently
10985 Rlog.w(LOG_TAG, "IMS not available on device.");
10986 return;
Hui Wang761a6682020-10-31 05:12:53 +000010987 }
10988
10989 final long identity = Binder.clearCallingIdentity();
10990 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010991 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010992 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010993 } finally {
10994 Binder.restoreCallingIdentity(identity);
10995 }
10996 }
10997
10998 /**
10999 * trigger RCS reconfiguration.
11000 */
11001 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011002 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11003 "triggerRcsReconfiguration",
11004 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011005
11006 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11007 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11008 }
11009 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011010 // ProvisioningManager can not handle ServiceSpecificException.
11011 // Throw the IllegalStateException and annotate ProvisioningManager.
11012 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000011013 }
11014
11015 final long identity = Binder.clearCallingIdentity();
11016 try {
11017 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11018 } finally {
11019 Binder.restoreCallingIdentity(identity);
11020 }
11021 }
11022
11023 /**
11024 * Provide the client configuration parameters of the RCS application.
11025 */
11026 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011027 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11028 "setRcsClientConfiguration",
11029 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011030
11031 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11032 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11033 }
11034 if (!isImsAvailableOnDevice()) {
11035 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11036 "IMS not available on device.");
11037 }
11038
11039 final long identity = Binder.clearCallingIdentity();
11040
11041 try {
11042 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11043 if (configBinder == null) {
11044 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011045 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11046 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011047 } else {
11048 configBinder.setRcsClientConfiguration(rcc);
11049 }
joonhunshin3e154242021-09-17 06:33:39 +000011050
11051 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11052 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011053 } catch (RemoteException e) {
11054 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011055 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11056 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011057 } finally {
11058 Binder.restoreCallingIdentity(identity);
11059 }
11060 }
11061
11062 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011063 * Enables or disables the test mode for RCS VoLTE single registration.
11064 */
11065 @Override
11066 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11067 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11068 "setRcsSingleRegistrationTestModeEnabled");
11069
11070 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11071 }
11072
11073 /**
11074 * Gets the test mode for RCS VoLTE single registration.
11075 */
11076 @Override
11077 public boolean getRcsSingleRegistrationTestModeEnabled() {
11078 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11079 "getRcsSingleRegistrationTestModeEnabled");
11080
11081 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11082 }
11083
11084 /**
Hui Wang761a6682020-10-31 05:12:53 +000011085 * Overrides the config of RCS VoLTE single registration enabled for the device.
11086 */
11087 @Override
11088 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11089 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11090 "setDeviceSingleRegistrationEnabledOverride");
11091 enforceModifyPermission();
11092
11093 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11094 : Boolean.parseBoolean(enabledStr);
11095 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011096 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011097 }
11098
11099 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011100 * Sends a device to device communication message. Only usable via shell.
11101 * @param message message to send.
11102 * @param value message value.
11103 */
11104 @Override
11105 public void sendDeviceToDeviceMessage(int message, int value) {
11106 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011107 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011108 enforceModifyPermission();
11109
11110 final long identity = Binder.clearCallingIdentity();
11111 try {
11112 TelephonyConnectionService service =
11113 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11114 if (service == null) {
11115 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11116 return;
11117 }
11118 service.sendTestDeviceToDeviceMessage(message, value);
11119 } finally {
11120 Binder.restoreCallingIdentity(identity);
11121 }
11122 }
11123
Tyler Gunnbabbda02021-02-10 11:05:02 -080011124 /**
11125 * Sets the specified device to device transport active.
11126 * @param transport The transport to set active.
11127 */
11128 @Override
11129 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11130 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11131 "setActiveDeviceToDeviceTransport");
11132 enforceModifyPermission();
11133
11134 final long identity = Binder.clearCallingIdentity();
11135 try {
11136 TelephonyConnectionService service =
11137 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11138 if (service == null) {
11139 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11140 return;
11141 }
11142 service.setActiveDeviceToDeviceTransport(transport);
11143 } finally {
11144 Binder.restoreCallingIdentity(identity);
11145 }
11146 }
Tyler Gunn92479152021-01-20 16:30:10 -080011147
Tyler Gunnd4339262021-05-03 14:46:49 -070011148 @Override
11149 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11150 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11151 "setDeviceToDeviceForceEnabled");
11152
11153 final long identity = Binder.clearCallingIdentity();
11154 try {
11155 Arrays.stream(PhoneFactory.getPhones()).forEach(
11156 p -> {
11157 Phone thePhone = p.getImsPhone();
11158 if (thePhone != null && thePhone instanceof ImsPhone) {
11159 ImsPhone imsPhone = (ImsPhone) thePhone;
11160 CallTracker tracker = imsPhone.getCallTracker();
11161 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11162 ImsPhoneCallTracker imsPhoneCallTracker =
11163 (ImsPhoneCallTracker) tracker;
11164 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11165 }
11166 }
11167 }
11168 );
11169 } finally {
11170 Binder.restoreCallingIdentity(identity);
11171 }
11172 }
11173
Tyler Gunn92479152021-01-20 16:30:10 -080011174 /**
Hui Wang761a6682020-10-31 05:12:53 +000011175 * Gets the config of RCS VoLTE single registration enabled for the device.
11176 */
11177 @Override
11178 public boolean getDeviceSingleRegistrationEnabled() {
11179 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11180 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11181 }
11182
11183 /**
11184 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11185 */
11186 @Override
11187 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11188 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11189 "setCarrierSingleRegistrationEnabledOverride");
11190 enforceModifyPermission();
11191
11192 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11193 : Boolean.parseBoolean(enabledStr);
11194 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11195 subId, enabled);
11196 }
11197
11198 /**
11199 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11200 */
11201 @Override
11202 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11203 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11204 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11205 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011206
11207 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011208 * Overrides the ims feature validation result
11209 */
11210 @Override
11211 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11212 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11213 "setImsFeatureValidationOverride");
11214
11215 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11216 : Boolean.parseBoolean(enabledStr);
11217 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11218 subId, enabled);
11219 }
11220
11221 /**
11222 * Gets the ims feature validation override value
11223 */
11224 @Override
11225 public boolean getImsFeatureValidationOverride(int subId) {
11226 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11227 "getImsFeatureValidationOverride");
11228 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11229 }
11230
11231 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011232 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11233 * their mobile plan.
11234 */
11235 @Override
11236 public String getMobileProvisioningUrl() {
11237 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11238 final long identity = Binder.clearCallingIdentity();
11239 try {
11240 return getDefaultPhone().getMobileProvisioningUrl();
11241 } finally {
11242 Binder.restoreCallingIdentity(identity);
11243 }
11244 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011245
James.cf Linbcdf8b32021-01-14 16:44:13 +080011246 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011247 * Get the EAB contact from the EAB database.
11248 */
11249 @Override
11250 public String getContactFromEab(String contact) {
11251 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11252 enforceModifyPermission();
11253 final long identity = Binder.clearCallingIdentity();
11254 try {
11255 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11256 } finally {
11257 Binder.restoreCallingIdentity(identity);
11258 }
11259 }
11260
11261 /**
Calvin Pana1434322021-07-01 19:27:01 +080011262 * Get the EAB capability from the EAB database.
11263 */
11264 @Override
11265 public String getCapabilityFromEab(String contact) {
11266 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11267 enforceModifyPermission();
11268 final long identity = Binder.clearCallingIdentity();
11269 try {
11270 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11271 } finally {
11272 Binder.restoreCallingIdentity(identity);
11273 }
11274 }
11275
11276 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011277 * Remove the EAB contacts from the EAB database.
11278 */
11279 @Override
11280 public int removeContactFromEab(int subId, String contacts) {
11281 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11282 enforceModifyPermission();
11283 final long identity = Binder.clearCallingIdentity();
11284 try {
11285 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11286 } finally {
11287 Binder.restoreCallingIdentity(identity);
11288 }
11289 }
11290
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011291 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011292 public boolean getDeviceUceEnabled() {
11293 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11294 final long identity = Binder.clearCallingIdentity();
11295 try {
11296 return mApp.getDeviceUceEnabled();
11297 } finally {
11298 Binder.restoreCallingIdentity(identity);
11299 }
11300 }
11301
11302 @Override
11303 public void setDeviceUceEnabled(boolean isEnabled) {
11304 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11305 final long identity = Binder.clearCallingIdentity();
11306 try {
11307 mApp.setDeviceUceEnabled(isEnabled);
11308 } finally {
11309 Binder.restoreCallingIdentity(identity);
11310 }
11311 }
11312
Brad Ebinger14d467f2021-02-12 06:18:28 +000011313 /**
11314 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11315 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11316 */
11317 // Used for SHELL command only right now.
11318 @Override
11319 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11320 List<String> featureTags) {
11321 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11322 "addUceRegistrationOverrideShell");
11323 final long identity = Binder.clearCallingIdentity();
11324 try {
11325 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11326 new ArraySet<>(featureTags));
11327 } catch (ImsException e) {
11328 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11329 } finally {
11330 Binder.restoreCallingIdentity(identity);
11331 }
11332 }
11333
11334 /**
11335 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11336 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11337 */
11338 // Used for SHELL command only right now.
11339 @Override
11340 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11341 List<String> featureTags) {
11342 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11343 "removeUceRegistrationOverrideShell");
11344 final long identity = Binder.clearCallingIdentity();
11345 try {
11346 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11347 new ArraySet<>(featureTags));
11348 } catch (ImsException e) {
11349 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11350 } finally {
11351 Binder.restoreCallingIdentity(identity);
11352 }
11353 }
11354
11355 /**
11356 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11357 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11358 */
11359 // Used for SHELL command only right now.
11360 @Override
11361 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11362 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11363 "clearUceRegistrationOverrideShell");
11364 final long identity = Binder.clearCallingIdentity();
11365 try {
11366 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11367 } catch (ImsException e) {
11368 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11369 } finally {
11370 Binder.restoreCallingIdentity(identity);
11371 }
11372 }
11373
11374 /**
11375 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11376 */
11377 // Used for SHELL command only right now.
11378 @Override
11379 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11380 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11381 "getLatestRcsContactUceCapabilityShell");
11382 final long identity = Binder.clearCallingIdentity();
11383 try {
11384 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11385 } catch (ImsException e) {
11386 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11387 } finally {
11388 Binder.restoreCallingIdentity(identity);
11389 }
11390 }
11391
11392 /**
11393 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11394 * device does not have an active PUBLISH.
11395 */
11396 // Used for SHELL command only right now.
11397 @Override
11398 public String getLastUcePidfXmlShell(int subId) {
11399 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11400 final long identity = Binder.clearCallingIdentity();
11401 try {
11402 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11403 } catch (ImsException e) {
11404 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11405 } finally {
11406 Binder.restoreCallingIdentity(identity);
11407 }
11408 }
11409
James.cf Line8713a42021-04-29 16:04:26 +080011410 /**
11411 * Remove UCE requests cannot be sent to the network status.
11412 */
11413 // Used for SHELL command only right now.
11414 @Override
11415 public boolean removeUceRequestDisallowedStatus(int subId) {
11416 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11417 final long identity = Binder.clearCallingIdentity();
11418 try {
11419 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11420 } catch (ImsException e) {
11421 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11422 } finally {
11423 Binder.restoreCallingIdentity(identity);
11424 }
11425 }
11426
James.cf Lin18bb9002021-05-25 01:37:38 +080011427 /**
11428 * Remove UCE requests cannot be sent to the network status.
11429 */
11430 // Used for SHELL command only.
11431 @Override
11432 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11433 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11434 final long identity = Binder.clearCallingIdentity();
11435 try {
11436 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11437 } catch (ImsException e) {
11438 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11439 } finally {
11440 Binder.restoreCallingIdentity(identity);
11441 }
11442 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011443
James.cf Lin4b784aa2021-01-31 03:25:15 +080011444 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011445 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11446 String callingPackage) {
11447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11448 mApp, subId, "setSignalStrengthUpdateRequest");
11449
11450 final int callingUid = Binder.getCallingUid();
11451 // Verify that tha callingPackage belongs to the calling UID
11452 mApp.getSystemService(AppOpsManager.class)
11453 .checkPackage(callingUid, callingPackage);
11454
Rambo Wang3607f502021-02-01 21:51:40 -080011455 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011456
11457 final long identity = Binder.clearCallingIdentity();
11458 try {
11459 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11460 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11461
11462 if (result instanceof IllegalStateException) {
11463 throw (IllegalStateException) result;
11464 }
11465 } finally {
11466 Binder.restoreCallingIdentity(identity);
11467 }
11468 }
11469
11470 @Override
11471 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11472 String callingPackage) {
11473 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11474 mApp, subId, "clearSignalStrengthUpdateRequest");
11475
11476 final int callingUid = Binder.getCallingUid();
11477 // Verify that tha callingPackage belongs to the calling UID
11478 mApp.getSystemService(AppOpsManager.class)
11479 .checkPackage(callingUid, callingPackage);
11480
11481 final long identity = Binder.clearCallingIdentity();
11482 try {
11483 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11484 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11485
11486 if (result instanceof IllegalStateException) {
11487 throw (IllegalStateException) result;
11488 }
11489 } finally {
11490 Binder.restoreCallingIdentity(identity);
11491 }
11492 }
11493
Rambo Wang3607f502021-02-01 21:51:40 -080011494 private static void validateSignalStrengthUpdateRequest(Context context,
11495 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011496 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11497 // phone/system process do not have further restriction on request
11498 return;
11499 }
11500
11501 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011502 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011503 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011504 context.enforceCallingOrSelfPermission(
11505 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11506 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011507 }
11508
11509 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011510 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011511 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011512 || info.isEnabled()) {
11513 throw new IllegalArgumentException(
11514 "Only system can set hide fields in SignalThresholdInfo");
11515 }
11516
11517 // Thresholds length for each RAN need in range. This has been validated in
11518 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11519 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11520 final int[] thresholds = info.getThresholds();
11521 Objects.requireNonNull(thresholds);
11522 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11523 || thresholds.length
11524 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11525 throw new IllegalArgumentException(
11526 "thresholds length is out of range: " + thresholds.length);
11527 }
11528 }
11529 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011530
11531 /**
11532 * Gets the current phone capability.
11533 *
11534 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11535 * @return the PhoneCapability which describes the data connection capability of modem.
11536 * It's used to evaluate possible phone config change, for example from single
11537 * SIM device to multi-SIM device.
11538 */
11539 @Override
11540 public PhoneCapability getPhoneCapability() {
11541 enforceReadPrivilegedPermission("getPhoneCapability");
11542 final long identity = Binder.clearCallingIdentity();
11543 try {
11544 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11545 } finally {
11546 Binder.restoreCallingIdentity(identity);
11547 }
11548 }
Michele Berionne5e411512020-11-13 02:36:59 +000011549
11550 /**
11551 * Prepare TelephonyManager for an unattended reboot. The reboot is
11552 * required to be done shortly after the API is invoked.
11553 */
11554 @Override
11555 @TelephonyManager.PrepareUnattendedRebootResult
11556 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011557 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011558 enforceRebootPermission();
11559
11560 final long identity = Binder.clearCallingIdentity();
11561 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011562 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011563 } finally {
11564 Binder.restoreCallingIdentity(identity);
11565 }
11566 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011567
11568 /**
11569 * Request to get the current slicing configuration including URSP rules and
11570 * NSSAIs (configured, allowed and rejected).
11571 *
11572 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11573 */
11574 @Override
11575 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011576 TelephonyPermissions
11577 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11578 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011579
11580 final long identity = Binder.clearCallingIdentity();
11581 try {
11582 Phone phone = getDefaultPhone();
11583 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11584 } finally {
11585 Binder.restoreCallingIdentity(identity);
11586 }
11587 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011588
11589 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011590 * Check whether the given premium capability is available for purchase from the carrier.
11591 *
11592 * @param capability The premium capability to check.
11593 * @param subId The subId to check the premium capability for.
11594 *
11595 * @return Whether the given premium capability is available to purchase.
11596 */
11597 @Override
11598 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11599 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11600 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11601 log("Premium capability "
11602 + TelephonyManager.convertPremiumCapabilityToString(capability)
11603 + " is not available for purchase due to missing permissions.");
11604 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11605 + "permission READ_BASIC_PHONE_STATE.");
11606 }
11607
11608 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011609 if (phone == null) {
11610 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11611 return false;
11612 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011613 final long identity = Binder.clearCallingIdentity();
11614 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011615 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011616 .isPremiumCapabilityAvailableForPurchase(capability);
11617 } finally {
11618 Binder.restoreCallingIdentity(identity);
11619 }
11620 }
11621
11622 /**
11623 * Purchase the given premium capability from the carrier.
11624 *
11625 * @param capability The premium capability to purchase.
11626 * @param callback The result of the purchase request.
11627 * @param subId The subId to purchase the premium capability for.
11628 */
11629 @Override
11630 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11631 log("purchasePremiumCapability: capability="
11632 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11633 + getCurrentPackageName());
11634
11635 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11636 mApp, "purchasePremiumCapability")) {
11637 log("purchasePremiumCapability "
11638 + TelephonyManager.convertPremiumCapabilityToString(capability)
11639 + " failed due to missing permissions.");
11640 throw new SecurityException("purchasePremiumCapability requires permission "
11641 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011642 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11643 mApp, "purchasePremiumCapability")) {
11644 log("purchasePremiumCapability "
11645 + TelephonyManager.convertPremiumCapabilityToString(capability)
11646 + " failed due to missing permissions.");
11647 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011648 }
11649
11650 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011651 if (phone == null) {
11652 try {
11653 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11654 callback.accept(result);
11655 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11656 } catch (RemoteException e) {
11657 String logStr = "Purchase premium capability "
11658 + TelephonyManager.convertPremiumCapabilityToString(capability)
11659 + " failed due to RemoteException handling null phone: " + e;
11660 if (DBG) log(logStr);
11661 AnomalyReporter.reportAnomaly(
11662 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11663 }
11664 return;
11665 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011666
11667 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011668 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011669 callingProcess = mApp.getPackageManager().getApplicationInfo(
11670 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011671 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011672 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011673 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011674
11675 boolean isVisible = false;
11676 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11677 if (am != null) {
11678 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11679 if (processes != null) {
11680 for (ActivityManager.RunningAppProcessInfo process : processes) {
11681 log("purchasePremiumCapability: process " + process.processName
11682 + "has importance " + process.importance);
11683 if (process.processName.equals(callingProcess) && process.importance
11684 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11685 isVisible = true;
11686 break;
11687 }
11688 }
11689 }
11690 }
11691
11692 if (!isVisible) {
11693 try {
11694 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11695 callback.accept(result);
11696 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11697 } catch (RemoteException e) {
11698 String logStr = "Purchase premium capability "
11699 + TelephonyManager.convertPremiumCapabilityToString(capability)
11700 + " failed due to RemoteException handling background application: " + e;
11701 if (DBG) log(logStr);
11702 AnomalyReporter.reportAnomaly(
11703 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11704 }
11705 return;
11706 }
11707
Sarah Chin71b3a852022-09-28 15:54:19 -070011708 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011709 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011710 }
11711
11712 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011713 * Register an IMS connection state callback
11714 */
11715 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011716 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11717 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011718 if (feature == ImsFeature.FEATURE_MMTEL) {
11719 // ImsMmTelManager
11720 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11721 TelephonyPermissions
11722 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11723 mApp, subId, "registerImsStateCallback");
11724 } else if (feature == ImsFeature.FEATURE_RCS) {
11725 // ImsRcsManager or SipDelegateManager
11726 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11727 Binder.getCallingUid(), "registerImsStateCallback",
11728 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11729 Manifest.permission.READ_PRECISE_PHONE_STATE,
11730 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11731 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11732 }
11733
11734 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11735 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11736 "IMS not available on device.");
11737 }
11738
11739 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11740 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11741 }
11742
11743 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11744 if (controller == null) {
11745 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11746 "IMS not available on device.");
11747 }
11748
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011749 if (callingPackage == null) {
11750 callingPackage = getCurrentPackageName();
11751 }
11752
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011753 final long token = Binder.clearCallingIdentity();
11754 try {
11755 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011756 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011757 } catch (ImsException e) {
11758 throw new ServiceSpecificException(e.getCode());
11759 } finally {
11760 Binder.restoreCallingIdentity(token);
11761 }
11762 }
11763
11764 /**
11765 * Unregister an IMS connection state callback
11766 */
11767 @Override
11768 public void unregisterImsStateCallback(IImsStateCallback cb) {
11769 final long token = Binder.clearCallingIdentity();
11770 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11771 if (controller == null) {
11772 return;
11773 }
11774 try {
11775 controller.unregisterImsStateCallback(cb);
11776 } finally {
11777 Binder.restoreCallingIdentity(token);
11778 }
11779 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011780
11781 /**
11782 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11783 *
11784 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11785 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11786 * SecurityException.
11787 * If there is current registered network this value will be same as the registered cell
11788 * identity. If the device goes out of service the previous cell identity is cached and
11789 * will be returned. If the cache age of the Cell identity is more than 24 hours
11790 * it will be cleared and null will be returned.
11791 *
11792 */
11793 @Override
11794 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11795 String callingFeatureId) {
11796 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11797 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11798 LocationAccessPolicy.checkLocationPermission(mApp,
11799 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11800 .setCallingPackage(callingPackage)
11801 .setCallingFeatureId(callingFeatureId)
11802 .setCallingPid(Binder.getCallingPid())
11803 .setCallingUid(Binder.getCallingUid())
11804 .setMethod("getLastKnownCellIdentity")
11805 .setLogAsInfo(true)
11806 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11807 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11808 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11809 .build());
11810
11811 boolean hasFinePermission =
11812 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11813 if (!hasFinePermission
11814 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11815 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011816 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011817 }
11818
11819 final long identity = Binder.clearCallingIdentity();
11820 try {
Ling Mac28f0212023-03-24 16:07:15 -070011821 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011822 if (sst == null) return null;
11823 return sst.getLastKnownCellIdentity();
11824 } finally {
11825 Binder.restoreCallingIdentity(identity);
11826 }
11827 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011828
jimsun3b9ccac2021-10-26 15:01:23 +080011829 /**
11830 * Sets the modem service class Name that Telephony will bind to.
11831 *
11832 * @param serviceName The class name of the modem service.
11833 * @return true if the operation is succeed, otherwise false.
11834 */
11835 public boolean setModemService(String serviceName) {
11836 Log.d(LOG_TAG, "setModemService - " + serviceName);
11837 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011839 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11840 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080011841 return mPhoneConfigurationManager.setModemService(serviceName);
11842 }
11843
11844 /**
11845 * Return the class name of the currently bounded modem service.
11846 *
11847 * @return the class name of the modem service.
11848 */
11849 public String getModemService() {
11850 String result;
11851 Log.d(LOG_TAG, "getModemService");
11852 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11853 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011854 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080011855 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11856 "getModemService");
11857 result = mPhoneConfigurationManager.getModemService();
11858 Log.d(LOG_TAG, "result = " + result);
11859 return result;
11860 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011861
11862 @Override
11863 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11864 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11865 mApp.enforceCallingOrSelfPermission(
11866 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11867 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11868
11869 final long identity = Binder.clearCallingIdentity();
11870 try {
11871 Phone phone = getPhone(subId);
11872 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080011873 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
11874 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011875 phone.setVoiceServiceStateOverride(hasService);
11876 } finally {
11877 Binder.restoreCallingIdentity(identity);
11878 }
11879 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011880
11881 /**
11882 * set removable eSIM as default eUICC.
11883 *
11884 * @hide
11885 */
11886 @Override
11887 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11888 enforceModifyPermission();
11889 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11890
11891 final long identity = Binder.clearCallingIdentity();
11892 try {
11893 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11894 } finally {
11895 Binder.restoreCallingIdentity(identity);
11896 }
11897 }
11898
11899 /**
11900 * Returns whether the removable eSIM is default eUICC or not.
11901 *
11902 * @hide
11903 */
11904 @Override
11905 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11906 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11907 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11908
11909 final long identity = Binder.clearCallingIdentity();
11910 try {
11911 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11912 } finally {
11913 Binder.restoreCallingIdentity(identity);
11914 }
11915 }
11916
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011917 /**
11918 * Get the component name of the default app to direct respond-via-message intent for the
11919 * user associated with this subscription, update the cache if there is no respond-via-message
11920 * application currently configured for this user.
11921 * @return component name of the app and class to direct Respond Via Message intent to, or
11922 * {@code null} if the functionality is not supported.
11923 * @hide
11924 */
11925 @Override
11926 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11927 boolean updateIfNeeded) {
11928 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011929
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000011930 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
11931
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011932 UserHandle userHandle = null;
11933 final long identity = Binder.clearCallingIdentity();
11934 try {
11935 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11936 } finally {
11937 Binder.restoreCallingIdentity(identity);
11938 }
11939 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11940 updateIfNeeded, userHandle);
11941 }
Jack Yuf5badd92022-12-08 00:50:53 -080011942
11943 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011944 * Set whether the device is able to connect with null ciphering or integrity
11945 * algorithms. This is a global setting and will apply to all active subscriptions
11946 * and all new subscriptions after this.
11947 *
11948 * @param enabled when true, null cipher and integrity algorithms are allowed.
11949 * @hide
11950 */
11951 @Override
11952 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11953 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11954 enforceModifyPermission();
11955 checkForNullCipherAndIntegritySupport();
11956
11957 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11958 // for listening to these preference changes and applying them immediately.
11959 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11960 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11961 editor.apply();
11962
11963 for (Phone phone: PhoneFactory.getPhones()) {
11964 phone.handleNullCipherEnabledChange();
11965 }
11966 }
11967
11968
11969 /**
11970 * Get whether the device is able to connect with null ciphering or integrity
11971 * algorithms. Note that this retrieves the phone-global preference and not
11972 * the state of the radio.
11973 *
11974 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11975 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11976 * version for this feature.
11977 * @hide
11978 */
11979 @Override
11980 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11981 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11982 enforceReadPermission();
11983 checkForNullCipherAndIntegritySupport();
11984 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11985 }
11986
11987 private void checkForNullCipherAndIntegritySupport() {
11988 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11989 throw new UnsupportedOperationException(
11990 "Null cipher and integrity operations require HAL 2.1 or above");
11991 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000011992 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
11993 throw new UnsupportedOperationException(
11994 "Null cipher and integrity operations unsupported by modem");
11995 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011996 }
11997
11998 /**
Jack Yuf5badd92022-12-08 00:50:53 -080011999 * Get the SIM state for the slot index.
12000 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12001 *
12002 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12003 */
12004 @Override
12005 @SimState
12006 public int getSimStateForSlotIndex(int slotIndex) {
12007 IccCardConstants.State simState;
12008 if (slotIndex < 0) {
12009 simState = IccCardConstants.State.UNKNOWN;
12010 } else {
12011 Phone phone = null;
12012 try {
12013 phone = PhoneFactory.getPhone(slotIndex);
12014 } catch (IllegalStateException e) {
12015 // ignore
12016 }
12017 if (phone == null) {
12018 simState = IccCardConstants.State.UNKNOWN;
12019 } else {
12020 IccCard icc = phone.getIccCard();
12021 if (icc == null) {
12022 simState = IccCardConstants.State.UNKNOWN;
12023 } else {
12024 simState = icc.getState();
12025 }
12026 }
12027 }
12028 return simState.ordinal();
12029 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012030
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012031 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12032 boolean enableLogcat,
12033 long logcatStartTimestampMillis, boolean enableTelecomDump,
12034 boolean enableTelephonyDump) {
12035 //TODO: next CL
12036 }
12037
12038 /**
12039 * Request telephony to persist state for debugging emergency call failures.
12040 *
12041 * @param dropBoxTag Tag to use when persisting data to dropbox service.
12042 * @param enableLogcat whether to collect logcat output
12043 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12044 * @param enableTelecomDump whether to collect telecom dumpsys
12045 * @param enableTelephonyDump whether to collect telephony dumpsys
12046 */
12047 @Override
12048 @RequiresPermission(android.Manifest.permission.DUMP)
12049 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12050 long logcatStartTimestampMillis, boolean enableTelecomDump,
12051 boolean enableTelephonyDump) {
12052 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12053 "persistEmergencyCallDiagnosticData");
12054 final long identity = Binder.clearCallingIdentity();
12055 try {
12056 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12057 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12058
12059 } finally {
12060 Binder.restoreCallingIdentity(identity);
12061 }
12062 }
12063
Hui Wang9b5793a2022-12-05 14:38:06 -060012064 /**
12065 * Get current cell broadcast ranges.
12066 */
12067 @Override
12068 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12069 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12070 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12071 "getCellBroadcastIdRanges");
12072 final long identity = Binder.clearCallingIdentity();
12073 try {
12074 return getPhone(subId).getCellBroadcastIdRanges();
12075 } finally {
12076 Binder.restoreCallingIdentity(identity);
12077 }
12078 }
12079
12080 /**
12081 * Set reception of cell broadcast messages with the list of the given ranges
12082 *
12083 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12084 */
12085 @Override
12086 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12087 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12088 @Nullable IIntegerConsumer callback) {
12089 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12090 "setCellBroadcastIdRanges");
12091 final long identity = Binder.clearCallingIdentity();
12092 try {
12093 Phone phone = getPhoneFromSubId(subId);
12094 if (DBG) {
12095 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12096 }
12097 phone.setCellBroadcastIdRanges(ranges, result -> {
12098 if (callback != null) {
12099 try {
12100 callback.accept(result);
12101 } catch (RemoteException e) {
12102 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12103 }
12104 }
12105 });
12106 } finally {
12107 Binder.restoreCallingIdentity(identity);
12108 }
12109 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012110
12111 /**
12112 * Returns whether the device supports the domain selection service.
12113 *
12114 * @return {@code true} if the device supports the domain selection service.
12115 */
12116 @Override
12117 public boolean isDomainSelectionSupported() {
12118 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12119 "isDomainSelectionSupported");
12120
12121 final long identity = Binder.clearCallingIdentity();
12122 try {
12123 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12124 } finally {
12125 Binder.restoreCallingIdentity(identity);
12126 }
12127 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012128
12129 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012130 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12131 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12132 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012133 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012134 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012135 * @param enableSatellite {@code true} to enable the satellite modem and
12136 * {@code false} to disable.
12137 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
12138 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012139 *
12140 * @throws SecurityException if the caller doesn't have the required permission.
12141 */
12142 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012143 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
12144 @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012145 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Sarah Chinabf081b2023-03-09 23:00:57 -080012146 mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode,
12147 callback);
Sarah Chin503828c2023-02-01 23:54:20 -080012148 }
12149
12150 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012151 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012152 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012153 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012154 * @param result The result receiver that returns whether the satellite modem is enabled
12155 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012156 *
12157 * @throws SecurityException if the caller doesn't have the required permission.
12158 */
12159 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012160 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12161 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012162 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012163 }
12164
12165 /**
Sarah Chin43457982023-02-15 17:50:38 -080012166 * Request to get whether the satellite service demo mode is enabled.
12167 *
12168 * @param subId The subId of the subscription to check whether the satellite demo mode
12169 * is enabled for.
12170 * @param result The result receiver that returns whether the satellite demo mode is enabled
12171 * if the request is successful or an error code if the request failed.
12172 *
12173 * @throws SecurityException if the caller doesn't have the required permission.
12174 */
12175 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012176 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
12177 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
12178 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080012179 }
12180
12181 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012182 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012183 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012184 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012185 * @param result The result receiver that returns whether the satellite service is supported on
12186 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012187 */
12188 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012189 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012190 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012191 }
12192
12193 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012194 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012195 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012196 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012197 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12198 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012199 *
12200 * @throws SecurityException if the caller doesn't have required permission.
12201 */
12202 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012203 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12204 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012205 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012206 }
12207
12208 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012209 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012210 * This can be called by the pointing UI when the user starts pointing to the satellite.
12211 * Modem should continue to report the pointing input as the device or satellite moves.
12212 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012213 * @param subId The subId of the subscription to start satellite transmission updates for.
12214 * @param resultCallback The callback to get the result of the request.
12215 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080012216 *
12217 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012218 */
12219 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012220 public void startSatelliteTransmissionUpdates(int subId,
12221 @NonNull IIntegerConsumer resultCallback,
12222 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12223 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
12224 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080012225 }
12226
12227 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012228 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012229 * This can be called by the pointing UI when the user stops pointing to the satellite.
12230 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012231 * @param subId The subId of the subscription to stop satellite transmission updates for.
12232 * @param resultCallback The callback to get the result of the request.
12233 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
12234 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080012235 *
12236 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012237 */
12238 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012239 public void stopSatelliteTransmissionUpdates(int subId,
12240 @NonNull IIntegerConsumer resultCallback,
12241 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12242 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
12243 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012244 }
12245
12246 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012247 * Register the subscription with a satellite provider.
12248 * This is needed to register the subscription if the provider allows dynamic registration.
12249 *
12250 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012251 * @param token The token to be used as a unique identifier for provisioning with satellite
12252 * gateway.
Sarah Chinabf081b2023-03-09 23:00:57 -080012253 * @param regionId The region ID for the device's current location.
12254 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012255 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012256 * @return The signal transport used by the caller to cancel the provision request,
12257 * or {@code null} if the request failed.
12258 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012259 * @throws SecurityException if the caller doesn't have the required permission.
12260 */
12261 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012262 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Sarah Chinabf081b2023-03-09 23:00:57 -080012263 @NonNull String token, @NonNull String regionId, @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012264 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Sarah Chinabf081b2023-03-09 23:00:57 -080012265 return mSatelliteController.provisionSatelliteService(subId, token, regionId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012266 }
12267
12268 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012269 * Unregister the device/subscription with the satellite provider.
12270 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012271 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012272 * should report as deprovisioned.
12273 *
12274 * @param subId The subId of the subscription to be deprovisioned.
12275 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080012276 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012277 *
12278 * @throws SecurityException if the caller doesn't have the required permission.
12279 */
12280 @Override
12281 public void deprovisionSatelliteService(int subId,
12282 @NonNull String token, @NonNull IIntegerConsumer callback) {
12283 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012284 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012285 }
12286
12287 /**
Sarah Chin43457982023-02-15 17:50:38 -080012288 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012289 *
Sarah Chin43457982023-02-15 17:50:38 -080012290 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012291 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012292 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012293 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12294 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012295 * @throws SecurityException if the caller doesn't have the required permission.
12296 */
12297 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080012298 @SatelliteManager.SatelliteError public int registerForSatelliteProvisionStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012299 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012300 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012301 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012302 }
12303
12304 /**
Sarah Chin43457982023-02-15 17:50:38 -080012305 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012306 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012307 *
Sarah Chin43457982023-02-15 17:50:38 -080012308 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012309 * @param callback The callback that was passed to
12310 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012311 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012312 * @throws SecurityException if the caller doesn't have the required permission.
12313 */
12314 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012315 public void unregisterForSatelliteProvisionStateChanged(
12316 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012317 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012318 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012319 }
12320
12321 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012322 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012323 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012324 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012325 * @param result The result receiver that returns whether the device is provisioned with a
12326 * satellite provider if the request is successful or an error code if the
12327 * request failed.
12328 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012329 * @throws SecurityException if the caller doesn't have the required permission.
12330 */
12331 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012332 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
12333 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012334 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012335 }
12336
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012337 /**
Sarah Chin43457982023-02-15 17:50:38 -080012338 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012339 *
Sarah Chin43457982023-02-15 17:50:38 -080012340 * @param subId The subId of the subscription to register for satellite modem state changed.
12341 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080012342 *
12343 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12344 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012345 * @throws SecurityException if the caller doesn't have the required permission.
12346 */
12347 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012348 @SatelliteManager.SatelliteError public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012349 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012350 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012351 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012352 }
12353
12354 /**
Sarah Chin43457982023-02-15 17:50:38 -080012355 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012356 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012357 *
Sarah Chin43457982023-02-15 17:50:38 -080012358 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080012359 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080012360 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012361 *
12362 * @throws SecurityException if the caller doesn't have the required permission.
12363 */
12364 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012365 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012366 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012367 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012368 mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012369 }
12370
12371 /**
12372 * Register to receive incoming datagrams over satellite.
12373 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012374 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080012375 * @param callback The callback to handle incoming datagrams over satellite.
12376 *
12377 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12378 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012379 * @throws SecurityException if the caller doesn't have the required permission.
12380 */
12381 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080012382 @SatelliteManager.SatelliteError public int registerForSatelliteDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012383 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012384 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Sarah Chinabf081b2023-03-09 23:00:57 -080012385 return mSatelliteController.registerForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012386 }
12387
12388 /**
12389 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012390 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012391 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012392 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
12393 * @param callback The callback that was passed to
Sarah Chinabf081b2023-03-09 23:00:57 -080012394 * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012395 *
12396 * @throws SecurityException if the caller doesn't have the required permission.
12397 */
12398 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012399 public void unregisterForSatelliteDatagram(int subId,
12400 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012401 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012402 mSatelliteController.unregisterForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012403 }
12404
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012405 /**
12406 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012407 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012408 * This method requests modem to check if there are any pending datagrams to be received over
12409 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012410 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012411 * ILongConsumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080012412 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012413 * @param subId The subId of the subscription used for receiving datagrams.
12414 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012415 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012416 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012417 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012418 @Override
12419 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012420 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012421 mSatelliteController.pollPendingSatelliteDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012422 }
12423
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012424 /**
12425 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012426 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012427 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
12428 * input to this method. Datagram received here will be passed down to modem without any
12429 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080012430 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012431 * @param subId The subId of the subscription to send satellite datagrams for.
12432 * @param datagramType datagram type indicating whether the datagram is of type
12433 * SOS_SMS or LOCATION_SHARING.
12434 * @param datagram encoded gateway datagram which is encrypted by the caller.
12435 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000012436 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
12437 * full screen mode.
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012438 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012439 *
12440 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012441 */
12442 @Override
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012443 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
12444 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
12445 @NonNull IIntegerConsumer callback) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012446 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012447 mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram,
12448 needFullScreenPointingUI, callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012449 }
12450
Sarah Chindf715ec2023-02-13 13:46:24 -080012451 /**
12452 * Request to get whether satellite communication is allowed for the current location.
12453 *
12454 * @param subId The subId of the subscription to check whether satellite communication is
12455 * allowed for the current location for.
12456 * @param result The result receiver that returns whether satellite communication is allowed
12457 * for the current location if the request is successful or an error code
12458 * if the request failed.
12459 *
12460 * @throws SecurityException if the caller doesn't have the required permission.
12461 */
12462 @Override
12463 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
12464 @NonNull ResultReceiver result) {
12465 enforceSatelliteCommunicationPermission(
12466 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012467 mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId,
12468 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080012469 }
12470
12471 /**
Sarah Chin5f57c582023-02-14 04:16:10 -080012472 * Request to get the time after which the satellite will be visible
Sarah Chindf715ec2023-02-13 13:46:24 -080012473 *
Sarah Chin5f57c582023-02-14 04:16:10 -080012474 * @param subId The subId to get the time after which the satellite will be visible for.
12475 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080012476 * be visible if the request is successful or an error code if the request failed.
12477 *
12478 * @throws SecurityException if the caller doesn't have the required permission.
12479 */
12480 @Override
12481 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
12482 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012483 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012484 }
12485
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012486 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000012487 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12488 *
12489 * <p>This method behaves in one of the following ways:
12490 * <ul>
12491 * <li>return true : if the calling package has the appop permission {@link
12492 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12493 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12494 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12495 * Owner device identifier access check, or the calling package has carrier privileges</>
12496 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12497 * </ul>
12498 */
12499 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12500 String callingPackage, @Nullable String callingFeatureId, String message) {
12501 for (Phone phone : PhoneFactory.getPhones()) {
12502 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12503 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12504 return true;
12505 }
12506 }
12507 return false;
12508 }
arunvoddud7401012022-12-15 16:08:12 +000012509
12510 /**
Jack Yufa8ed012023-02-11 15:42:28 -080012511 * @return The subscription manager service instance.
12512 */
12513 public SubscriptionManagerService getSubscriptionManagerService() {
12514 return SubscriptionManagerService.getInstance();
12515 }
12516
12517 /**
arunvoddud7401012022-12-15 16:08:12 +000012518 * Class binds the consumer[callback] and carrierId.
12519 */
12520 private static class CallerCallbackInfo {
12521 private final Consumer<Integer> mConsumer;
12522 private final int mCarrierId;
12523
12524 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12525 mConsumer = consumer;
12526 mCarrierId = carrierId;
12527 }
12528
12529 public Consumer<Integer> getConsumer() {
12530 return mConsumer;
12531 }
12532
12533 public int getCarrierId() {
12534 return mCarrierId;
12535 }
12536 }
Jack Yufa8ed012023-02-11 15:42:28 -080012537}