blob: c3c28b693ee85a29946c0e1a4b101b35e6e09fc7 [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;
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080054import android.os.DropBoxManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070056import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080057import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080058import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import android.os.Looper;
60import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070061import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080062import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070063import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070064import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080065import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080066import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070067import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070068import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080069import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070071import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070072import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070073import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070074import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080075import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070076import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000077import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090078import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080079import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080080import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070081import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080082import android.telephony.AccessNetworkConstants;
83import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070084import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070085import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080086import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070087import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080088import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070089import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080090import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060091import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -070092import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080093import android.telephony.CellIdentityCdma;
94import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070096import android.telephony.CellInfoGsm;
97import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070098import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080099import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700100import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700101import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700102import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800103import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700104import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800105import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700106import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800107import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800108import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700109import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800110import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800112import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800113import android.telephony.SignalStrengthUpdateRequest;
114import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800115import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800117import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700118import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700119import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800120import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800121import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800122import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800123import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000124import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000125import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000126import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700127import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700128import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800129import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800130import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700131import android.telephony.gba.GbaAuthRequest;
132import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700133import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800134import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000135import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000136import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700137import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000138import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700139import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800140import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700141import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800142import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700143import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000144import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700145import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800146import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800147import android.telephony.ims.stub.ImsRegistrationImplBase;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800148import android.telephony.satellite.ISatelliteDatagramCallback;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800149import android.telephony.satellite.ISatelliteProvisionStateCallback;
150import android.telephony.satellite.ISatelliteStateCallback;
Sarah Chinabf081b2023-03-09 23:00:57 -0800151import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
Sarah Chin503828c2023-02-01 23:54:20 -0800152import android.telephony.satellite.SatelliteCapabilities;
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +0000153import android.telephony.satellite.SatelliteDatagram;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800154import android.telephony.satellite.SatelliteDatagramCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800155import android.telephony.satellite.SatelliteManager;
Thomas Nguyen299d6cd2023-02-14 09:57:15 -0800156import android.telephony.satellite.SatelliteProvisionStateCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800158import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700159import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700160import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800161import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800162
Andrew Lee312e8172014-10-23 17:01:36 -0700163import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800164import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800165import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800166import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800167import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700168import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700169import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700170import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800171import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800172import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700173import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700174import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800175import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700176import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800177import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800178import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800179import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700180import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000181import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700182import com.android.internal.telephony.IIntegerConsumer;
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +0000183import com.android.internal.telephony.ILongConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800184import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800186import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800187import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800188import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700189import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700190import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700191import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700193import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800194import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700195import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700196import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700197import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700198import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800199import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800200import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700201import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000202import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700203import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700204import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800205import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800206import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800207import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700208import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000209import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800210import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700211import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800212import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700213import com.android.internal.telephony.imsphone.ImsPhone;
214import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000215import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800216import com.android.internal.telephony.metrics.TelephonyMetrics;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000217import com.android.internal.telephony.satellite.SatelliteController;
Jack Yu285100e2022-12-02 22:48:35 -0800218import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
219import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700220import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700221import com.android.internal.telephony.uicc.IccIoResult;
222import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800223import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700224import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800225import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700226import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000227import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800228import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000229import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800230import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000231import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700232import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700233import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800234import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800235import com.android.phone.callcomposer.CallComposerPictureManager;
236import com.android.phone.callcomposer.CallComposerPictureTransfer;
237import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700238import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700239import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000240import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700241import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800242import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700243import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700244import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800245import com.android.services.telephony.TelecomAccountRegistry;
246import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800247import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800248
Hall Liu82694d52020-12-11 18:22:04 -0800249import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700250import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800251import java.io.IOException;
252import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700253import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700254import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800255import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000256import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800257import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800258import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800259import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800260import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100261import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800262import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700263import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800264import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800265import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700266import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800267import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800268import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800269import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270
271/**
272 * Implementation of the ITelephony interface.
273 */
Santos Cordon117fee72014-05-16 17:56:12 -0700274public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275 private static final String LOG_TAG = "PhoneInterfaceManager";
276 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
277 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800278 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700279
280 // Message codes used with mMainThreadHandler
281 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700282 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
283 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700284 private static final int CMD_OPEN_CHANNEL = 9;
285 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
286 private static final int CMD_CLOSE_CHANNEL = 11;
287 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800288 private static final int CMD_NV_READ_ITEM = 13;
289 private static final int EVENT_NV_READ_ITEM_DONE = 14;
290 private static final int CMD_NV_WRITE_ITEM = 15;
291 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
292 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
293 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700294 private static final int CMD_RESET_MODEM_CONFIG = 19;
295 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800296 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
297 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800298 private static final int CMD_SEND_ENVELOPE = 25;
299 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000300 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
301 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700302 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
303 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
304 private static final int CMD_EXCHANGE_SIM_IO = 31;
305 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800306 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
307 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700308 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
309 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700310 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
311 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700312 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
313 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
314 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
315 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700316 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
317 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
318 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
319 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700320 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800321 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
322 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000323 private static final int CMD_SWITCH_SLOTS = 50;
324 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700325 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
326 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
327 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
328 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
329 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
330 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
331 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
332 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700333 private static final int CMD_GET_ALL_CELL_INFO = 60;
334 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
335 private static final int CMD_GET_CELL_LOCATION = 62;
336 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700337 private static final int CMD_MODEM_REBOOT = 64;
338 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700339 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
340 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800341 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
342 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700343 private static final int CMD_GET_MODEM_STATUS = 70;
344 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700345 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
346 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700347 private static final int CMD_ERASE_MODEM_CONFIG = 74;
348 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800349 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
350 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
351 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
352 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800353 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
354 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800355 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800356 private static final int CMD_GET_CALL_FORWARDING = 83;
357 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
358 private static final int CMD_SET_CALL_FORWARDING = 85;
359 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
360 private static final int CMD_GET_CALL_WAITING = 87;
361 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
362 private static final int CMD_SET_CALL_WAITING = 89;
363 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700364 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
365 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
366 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
367 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700368 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
369 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800370 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
371 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800372 private static final int CMD_SET_DATA_THROTTLING = 99;
373 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800374 private static final int CMD_SET_SIM_POWER = 101;
375 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800376 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
377 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
378 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
379 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800380 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
381 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000382 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800383 private static final int CMD_GET_SLICING_CONFIG = 110;
384 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800385 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700386 private static final int CMD_ENABLE_VONR = 113;
387 private static final int EVENT_ENABLE_VONR_DONE = 114;
388 private static final int CMD_IS_VONR_ENABLED = 115;
389 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700390 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
391 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000392
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800393 // Parameters of select command.
394 private static final int SELECT_COMMAND = 0xA4;
395 private static final int SELECT_P1 = 0x04;
396 private static final int SELECT_P2 = 0;
397 private static final int SELECT_P3 = 0x10;
398
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000399 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
400 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
401
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700402 /** The singleton instance. */
403 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800404 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405
Sarah Chin4beb2b72023-02-14 14:47:54 -0800406 private final PhoneGlobals mApp;
407 private final CallManager mCM;
408 private final ImsResolver mImsResolver;
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +0000409
410 private final SatelliteController mSatelliteController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800411 private final UserManager mUserManager;
412 private final AppOpsManager mAppOps;
413 private final MainThreadHandler mMainThreadHandler;
Jack Yue37dd262022-12-16 11:53:37 -0800414 private final SubscriptionController mSubscriptionController;
Sarah Chin4beb2b72023-02-14 14:47:54 -0800415 private final SharedPreferences mTelephonySharedPreferences;
416 private final PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800417 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700418
Peter Wangdafb9ac2020-01-15 14:13:38 -0800419 /** User Activity */
Sarah Chin4beb2b72023-02-14 14:47:54 -0800420 private final AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800421 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
422
Sarah Chin4beb2b72023-02-14 14:47:54 -0800423 private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800424
Derek Tan97ebb422014-09-05 16:55:38 -0700425 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
426 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800427 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800428 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700429
Michelecea4cf22018-12-21 15:00:11 -0800430 // String to store multi SIM allowed
431 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
432
Derek Tan740e1672017-06-27 14:56:27 -0700433 // The AID of ISD-R.
434 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
435
yinxub1bed742017-04-17 11:45:04 -0700436 private NetworkScanRequestTracker mNetworkScanRequestTracker;
437
David Kelly5e06a7f2018-03-12 14:10:59 +0000438 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
439 private static final int MANUFACTURER_CODE_LENGTH = 8;
440
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800441 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800442 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800443
Sarah Chin2ec39f62022-08-31 17:03:26 -0700444 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
445 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
446
Derek Tan89e89d42014-07-08 17:00:10 -0700447 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700448 * Experiment flag to enable erase modem config on reset network, default value is false
449 */
450 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
451 "reset_network_erase_modem_config_enabled";
452
Rambo Wang0f050d82021-02-12 11:43:36 -0800453 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800454
Gary Jian76280a42022-12-07 16:18:33 +0800455 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
456
sandeepjsb6c87872021-09-27 15:34:44 +0000457 /**
458 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
459 * one ICCID active at the same time.
460 * Apps should use below API signatures if targeting SDK is T and beyond.
461 *
462 * @hide
463 */
464 @ChangeId
465 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
466 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800467
Naina Nallurid63128d2019-09-17 14:10:30 -0700468 /**
Chen Xu540470b2021-12-14 17:15:47 -0800469 * Apps targeting on Android T and beyond will get exception whenever icc close channel
470 * operation fails.
471 */
472 @ChangeId
473 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
474 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
475
476 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 * A request object to use for transmitting data to an ICC.
478 */
479 private static final class IccAPDUArgument {
480 public int channel, cla, command, p1, p2, p3;
481 public String data;
482
483 public IccAPDUArgument(int channel, int cla, int command,
484 int p1, int p2, int p3, String data) {
485 this.channel = channel;
486 this.cla = cla;
487 this.command = command;
488 this.p1 = p1;
489 this.p2 = p2;
490 this.p3 = p3;
491 this.data = data;
492 }
493 }
494
495 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700496 * A request object to use for transmitting data to an ICC.
497 */
498 private static final class ManualNetworkSelectionArgument {
499 public OperatorInfo operatorInfo;
500 public boolean persistSelection;
501
502 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
503 this.operatorInfo = operatorInfo;
504 this.persistSelection = persistSelection;
505 }
506 }
507
Sarah Chin71b3a852022-09-28 15:54:19 -0700508 private static final class PurchasePremiumCapabilityArgument {
509 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700510 public @NonNull IIntegerConsumer callback;
511
512 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800513 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700514 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700515 this.callback = callback;
516 }
517 }
518
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700519 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700520 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
521 * request after sending. The main thread will notify the request when it is complete.
522 */
523 private static final class MainThreadRequest {
524 /** The argument to use for the request */
525 public Object argument;
526 /** The result of the request that is run on the main thread */
527 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800528 // The subscriber id that this request applies to. Defaults to
529 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
530 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700531
Nathan Harold92bed182018-10-12 18:16:49 -0700532 // In cases where subId is unavailable, the caller needs to specify the phone.
533 public Phone phone;
534
vagdeviaf9a5b92018-08-15 16:01:53 -0700535 public WorkSource workSource;
536
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700537 public MainThreadRequest(Object argument) {
538 this.argument = argument;
539 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800540
Nathan Harold92bed182018-10-12 18:16:49 -0700541 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
542 this.argument = argument;
543 if (phone != null) {
544 this.phone = phone;
545 }
546 this.workSource = workSource;
547 }
548
vagdeviaf9a5b92018-08-15 16:01:53 -0700549 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800550 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800551 if (subId != null) {
552 this.subId = subId;
553 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700554 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700556 }
557
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800558 private static final class IncomingThirdPartyCallArgs {
559 public final ComponentName component;
560 public final String callId;
561 public final String callerDisplayName;
562
563 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
564 String callerDisplayName) {
565 this.component = component;
566 this.callId = callId;
567 this.callerDisplayName = callerDisplayName;
568 }
569 }
570
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700571 /**
572 * A handler that processes messages on the main thread in the phone process. Since many
573 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
574 * inbound binder threads to the main thread in the phone process. The Binder thread
575 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
576 * on, which will be notified when the operation completes and will contain the result of the
577 * request.
578 *
579 * <p>If a MainThreadRequest object is provided in the msg.obj field,
580 * note that request.result must be set to something non-null for the calling thread to
581 * unblock.
582 */
583 private final class MainThreadHandler extends Handler {
584 @Override
585 public void handleMessage(Message msg) {
586 MainThreadRequest request;
587 Message onCompleted;
588 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000589 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800591 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700592
593 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 case CMD_HANDLE_USSD_REQUEST: {
595 request = (MainThreadRequest) msg.obj;
596 final Phone phone = getPhoneFromRequest(request);
597 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800598 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700599 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700600
Pengquan Menga1bb6272018-09-06 09:59:22 -0700601 if (!isUssdApiAllowed(request.subId)) {
602 // Carrier does not support use of this API, return failure.
603 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
604 UssdResponse response = new UssdResponse(ussdRequest, null);
605 Bundle returnData = new Bundle();
606 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
607 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700608
Pengquan Menga1bb6272018-09-06 09:59:22 -0700609 request.result = true;
610 notifyRequester(request);
611 return;
612 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700613
Pengquan Menga1bb6272018-09-06 09:59:22 -0700614 try {
615 request.result = phone != null
616 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
617 } catch (CallStateException cse) {
618 request.result = false;
619 }
620 // Wake up the requesting thread
621 notifyRequester(request);
622 break;
pkanwar32d516d2016-10-14 19:37:38 -0700623 }
624
Yorke Lee716f67e2015-06-17 15:39:16 -0700625 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700626 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700627 final Phone phone = getPhoneFromRequest(request);
628 request.result = phone != null ?
629 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
630 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700631 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700632 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700633 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700634 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700635
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700636 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700638 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000639 uiccPort = getUiccPortFromRequest(request);
640 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700641 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800642 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700643 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700644 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700645 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800646 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000647 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800648 iccArgument.channel, iccArgument.cla, iccArgument.command,
649 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
650 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700651 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 break;
653
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700654 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 ar = (AsyncResult) msg.obj;
656 request = (MainThreadRequest) ar.userObj;
657 if (ar.exception == null && ar.result != null) {
658 request.result = ar.result;
659 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800660 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 if (ar.result == null) {
662 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800663 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800665 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 } else {
667 loge("iccTransmitApduLogicalChannel: Unknown exception");
668 }
669 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700670 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 break;
672
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700673 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
674 request = (MainThreadRequest) msg.obj;
675 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000676 uiccPort = getUiccPortFromRequest(request);
677 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700678 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800679 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700680 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700681 } else {
682 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800683 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000684 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800685 iccArgument.cla, iccArgument.command, iccArgument.p1,
686 iccArgument.p2,
687 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700688 }
689 break;
690
691 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
692 ar = (AsyncResult) msg.obj;
693 request = (MainThreadRequest) ar.userObj;
694 if (ar.exception == null && ar.result != null) {
695 request.result = ar.result;
696 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800697 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700698 if (ar.result == null) {
699 loge("iccTransmitApduBasicChannel: Empty response");
700 } else if (ar.exception instanceof CommandException) {
701 loge("iccTransmitApduBasicChannel: CommandException: " +
702 ar.exception);
703 } else {
704 loge("iccTransmitApduBasicChannel: Unknown exception");
705 }
706 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700707 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 break;
709
710 case CMD_EXCHANGE_SIM_IO:
711 request = (MainThreadRequest) msg.obj;
712 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000713 uiccPort = getUiccPortFromRequest(request);
714 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700715 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800716 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700717 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700718 } else {
719 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
720 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000721 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700722 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
723 iccArgument.data, onCompleted);
724 }
725 break;
726
727 case EVENT_EXCHANGE_SIM_IO_DONE:
728 ar = (AsyncResult) msg.obj;
729 request = (MainThreadRequest) ar.userObj;
730 if (ar.exception == null && ar.result != null) {
731 request.result = ar.result;
732 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800733 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700734 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700735 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700736 break;
737
Derek Tan4d5e5c12014-02-04 11:54:58 -0800738 case CMD_SEND_ENVELOPE:
739 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000740 uiccPort = getUiccPortFromRequest(request);
741 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700742 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800743 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700744 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700745 } else {
746 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800747 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700748 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800749 break;
750
751 case EVENT_SEND_ENVELOPE_DONE:
752 ar = (AsyncResult) msg.obj;
753 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700754 if (ar.exception == null && ar.result != null) {
755 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800756 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800757 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700758 if (ar.result == null) {
759 loge("sendEnvelopeWithStatus: Empty response");
760 } else if (ar.exception instanceof CommandException) {
761 loge("sendEnvelopeWithStatus: CommandException: " +
762 ar.exception);
763 } else {
764 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
765 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800766 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700767 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800768 break;
769
Shishir Agrawal566b7612013-10-28 14:41:00 -0700770 case CMD_OPEN_CHANNEL:
771 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000772 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800773 IccLogicalChannelRequest openChannelRequest =
774 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000775 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700776 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800777 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800778 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700779 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700780 } else {
781 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800782 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
783 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700784 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700785 break;
786
787 case EVENT_OPEN_CHANNEL_DONE:
788 ar = (AsyncResult) msg.obj;
789 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700790 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700791 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700792 int[] result = (int[]) ar.result;
793 int channelId = result[0];
794 byte[] selectResponse = null;
795 if (result.length > 1) {
796 selectResponse = new byte[result.length - 1];
797 for (int i = 1; i < result.length; ++i) {
798 selectResponse[i - 1] = (byte) result[i];
799 }
800 }
801 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800802 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800803
804 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700805 if (uiccPort == null) {
806 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
807 } else {
808 IccLogicalChannelRequest channelRequest =
809 (IccLogicalChannelRequest) request.argument;
810 channelRequest.channel = channelId;
811 uiccPort.onLogicalChannelOpened(channelRequest);
812 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700813 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700814 if (ar.result == null) {
815 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700816 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700817 if (ar.exception != null) {
818 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
819 }
820
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700821 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700822 if (ar.exception instanceof CommandException) {
823 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800824 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700825 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700826 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700827 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700828 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700829 }
830 }
831 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800832 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700833 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700834 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700835 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700836 break;
837
838 case CMD_CLOSE_CHANNEL:
839 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000840 uiccPort = getUiccPortFromRequest(request);
841 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700842 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800843 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800844 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800845 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700846 } else {
847 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000848 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700849 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700850 break;
851
852 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800853 ar = (AsyncResult) msg.obj;
854 request = (MainThreadRequest) ar.userObj;
855 if (ar.exception == null) {
856 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800857 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700858 if (uiccPort == null) {
859 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
860 } else {
861 final int channelId = (Integer) request.argument;
862 uiccPort.onLogicalChannelClosed(channelId);
863 }
Chen Xu540470b2021-12-14 17:15:47 -0800864 } else {
865 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800866 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800867 if (ar.exception instanceof CommandException) {
868 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
869 CommandException.Error error =
870 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800871 if (error == CommandException.Error.INVALID_ARGUMENTS) {
872 // should only throw exceptions from the binder threads.
873 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800874 "iccCloseLogicalChannel: invalid argument ");
875 }
876 } else {
877 loge("iccCloseLogicalChannel: Unknown exception");
878 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800879 request.result = (exception != null) ? exception :
880 new IllegalStateException(
881 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800882 }
883 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800884 break;
885
886 case CMD_NV_READ_ITEM:
887 request = (MainThreadRequest) msg.obj;
888 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800889 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
890 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800891 break;
892
893 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700894 ar = (AsyncResult) msg.obj;
895 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800896 if (ar.exception == null && ar.result != null) {
897 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700898 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800899 request.result = "";
900 if (ar.result == null) {
901 loge("nvReadItem: Empty response");
902 } else if (ar.exception instanceof CommandException) {
903 loge("nvReadItem: CommandException: " +
904 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700905 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800906 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700907 }
908 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700909 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700910 break;
911
Jake Hambye994d462014-02-03 13:10:13 -0800912 case CMD_NV_WRITE_ITEM:
913 request = (MainThreadRequest) msg.obj;
914 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
915 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800916 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700917 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800918 break;
919
920 case EVENT_NV_WRITE_ITEM_DONE:
921 handleNullReturnEvent(msg, "nvWriteItem");
922 break;
923
924 case CMD_NV_WRITE_CDMA_PRL:
925 request = (MainThreadRequest) msg.obj;
926 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800927 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800928 break;
929
930 case EVENT_NV_WRITE_CDMA_PRL_DONE:
931 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
932 break;
933
chen xu6dac5ab2018-10-26 17:39:23 -0700934 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800935 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700936 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800937 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800938 break;
939
chen xu6dac5ab2018-10-26 17:39:23 -0700940 case EVENT_RESET_MODEM_CONFIG_DONE:
941 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800942 break;
943
Sooraj Sasindran37444802020-08-11 10:40:43 -0700944 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
945 request = (MainThreadRequest) msg.obj;
946 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
947 request);
948 Phone phone = getPhoneFromRequest(request);
949 if (phone != null) {
950 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
951 } else {
952 loge("isNRDualConnectivityEnabled: No phone object");
953 request.result = false;
954 notifyRequester(request);
955 }
956 break;
957 }
958
959 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
960 ar = (AsyncResult) msg.obj;
961 request = (MainThreadRequest) ar.userObj;
962 if (ar.exception == null && ar.result != null) {
963 request.result = ar.result;
964 } else {
965 // request.result must be set to something non-null
966 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700967 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700968 request.result = ar.result;
969 } else {
970 request.result = false;
971 }
972 if (ar.result == null) {
973 loge("isNRDualConnectivityEnabled: Empty response");
974 } else if (ar.exception instanceof CommandException) {
975 loge("isNRDualConnectivityEnabled: CommandException: "
976 + ar.exception);
977 } else {
978 loge("isNRDualConnectivityEnabled: Unknown exception");
979 }
980 }
981 notifyRequester(request);
982 break;
983
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700984 case CMD_IS_VONR_ENABLED: {
985 request = (MainThreadRequest) msg.obj;
986 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
987 request);
988 Phone phone = getPhoneFromRequest(request);
989 if (phone != null) {
990 phone.isVoNrEnabled(onCompleted, request.workSource);
991 } else {
992 loge("isVoNrEnabled: No phone object");
993 request.result = false;
994 notifyRequester(request);
995 }
996 break;
997 }
998
999 case EVENT_IS_VONR_ENABLED_DONE:
1000 ar = (AsyncResult) msg.obj;
1001 request = (MainThreadRequest) ar.userObj;
1002 if (ar.exception == null && ar.result != null) {
1003 request.result = ar.result;
1004 } else {
1005 // request.result must be set to something non-null
1006 // for the calling thread to unblock
1007 if (ar.result != null) {
1008 request.result = ar.result;
1009 } else {
1010 request.result = false;
1011 }
1012 if (ar.result == null) {
1013 loge("isVoNrEnabled: Empty response");
1014 } else if (ar.exception instanceof CommandException) {
1015 loge("isVoNrEnabled: CommandException: "
1016 + ar.exception);
1017 } else {
1018 loge("isVoNrEnabled: Unknown exception");
1019 }
1020 }
1021 notifyRequester(request);
1022 break;
1023
Sooraj Sasindran37444802020-08-11 10:40:43 -07001024 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1025 request = (MainThreadRequest) msg.obj;
1026 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1027 Phone phone = getPhoneFromRequest(request);
1028 if (phone != null) {
1029 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1030 request.workSource);
1031 } else {
1032 loge("enableNrDualConnectivity: No phone object");
1033 request.result =
1034 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1035 notifyRequester(request);
1036 }
1037 break;
1038 }
1039
1040 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
1043 if (ar.exception == null) {
1044 request.result =
1045 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1046 } else {
1047 request.result =
1048 TelephonyManager
1049 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1050 if (ar.exception instanceof CommandException) {
1051 CommandException.Error error =
1052 ((CommandException) (ar.exception)).getCommandError();
1053 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1054 request.result =
1055 TelephonyManager
1056 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001057 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1058 request.result =
1059 TelephonyManager
1060 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001061 }
1062 loge("enableNrDualConnectivity" + ": CommandException: "
1063 + ar.exception);
1064 } else {
1065 loge("enableNrDualConnectivity" + ": Unknown exception");
1066 }
1067 }
1068 notifyRequester(request);
1069 break;
1070 }
1071
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001072 case CMD_ENABLE_VONR: {
1073 request = (MainThreadRequest) msg.obj;
1074 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1075 Phone phone = getPhoneFromRequest(request);
1076 if (phone != null) {
1077 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1078 request.workSource);
1079 } else {
1080 loge("setVoNrEnabled: No phone object");
1081 request.result =
1082 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1083 notifyRequester(request);
1084 }
1085 break;
1086 }
1087
1088 case EVENT_ENABLE_VONR_DONE: {
1089 ar = (AsyncResult) msg.obj;
1090 request = (MainThreadRequest) ar.userObj;
1091 if (ar.exception == null) {
1092 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1093 } else {
1094 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1095 if (ar.exception instanceof CommandException) {
1096 CommandException.Error error =
1097 ((CommandException) (ar.exception)).getCommandError();
1098 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1099 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1100 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1101 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1102 } else {
1103 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1104 }
1105 loge("setVoNrEnabled" + ": CommandException: "
1106 + ar.exception);
1107 } else {
1108 loge("setVoNrEnabled" + ": Unknown exception");
1109 }
1110 }
1111 notifyRequester(request);
1112 break;
1113 }
1114
SongFerngWang3ef3e072020-12-21 16:41:52 +08001115 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001116 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001117 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1118 request);
1119 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001120 break;
1121
SongFerngWang3ef3e072020-12-21 16:41:52 +08001122 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001123 ar = (AsyncResult) msg.obj;
1124 request = (MainThreadRequest) ar.userObj;
1125 if (ar.exception == null && ar.result != null) {
1126 request.result = ar.result; // Integer
1127 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301128 // request.result must be set to something non-null
1129 // for the calling thread to unblock
1130 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001131 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001132 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001133 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001134 loge("getAllowedNetworkTypesBitmask: CommandException: "
1135 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001136 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001137 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001138 }
1139 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001140 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001141 break;
1142
SongFerngWang3ef3e072020-12-21 16:41:52 +08001143 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001144 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001145 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1146 request);
1147 Pair<Integer, Long> reasonWithNetworkTypes =
1148 (Pair<Integer, Long>) request.argument;
1149 getPhoneFromRequest(request).setAllowedNetworkTypes(
1150 reasonWithNetworkTypes.first,
1151 reasonWithNetworkTypes.second,
1152 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001153 break;
1154
SongFerngWang3ef3e072020-12-21 16:41:52 +08001155 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1156 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001157 break;
1158
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001159 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1160 request = (MainThreadRequest)msg.obj;
1161 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001162 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001163 break;
1164
1165 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1166 ar = (AsyncResult)msg.obj;
1167 request = (MainThreadRequest)ar.userObj;
1168 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001169 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001170 break;
1171
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001172 case CMD_SET_VOICEMAIL_NUMBER:
1173 request = (MainThreadRequest) msg.obj;
1174 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1175 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001176 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1177 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001178 break;
1179
1180 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1181 handleNullReturnEvent(msg, "setVoicemailNumber");
1182 break;
1183
Stuart Scott54788802015-03-30 13:18:01 -07001184 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1185 request = (MainThreadRequest) msg.obj;
1186 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1187 request);
1188 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1189 break;
1190
1191 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1192 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1193 break;
1194
Shishir Agrawal302c8692015-06-19 13:49:39 -07001195 case CMD_PERFORM_NETWORK_SCAN:
1196 request = (MainThreadRequest) msg.obj;
1197 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1198 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1199 break;
1200
Hall Liu27d24262020-09-18 19:04:59 -07001201 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001202 request = (MainThreadRequest) msg.obj;
1203 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001204 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1205 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1206 request.argument;
1207 int callForwardingReason = args.first;
1208 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001209 break;
Hall Liu27d24262020-09-18 19:04:59 -07001210 }
1211 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001212 ar = (AsyncResult) msg.obj;
1213 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001214 TelephonyManager.CallForwardingInfoCallback callback =
1215 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1216 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001217 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001218 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001219 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1220 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1221 // Service Class is a bit mask per 3gpp 27.007. Search for
1222 // any service for voice call.
1223 if ((callForwardInfo.serviceClass
1224 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001225 callForwardingInfo = new CallForwardingInfo(
1226 callForwardInfo.status
1227 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001228 callForwardInfo.reason,
1229 callForwardInfo.number,
1230 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001231 break;
1232 }
1233 }
1234 // Didn't find a call forward info for voice call.
1235 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001236 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1237 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001238 }
Hall Liu27d24262020-09-18 19:04:59 -07001239 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001240 } else {
1241 if (ar.result == null) {
1242 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1243 }
1244 if (ar.exception != null) {
1245 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1246 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001247 int errorCode = TelephonyManager
1248 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001249 if (ar.exception instanceof CommandException) {
1250 CommandException.Error error =
1251 ((CommandException) (ar.exception)).getCommandError();
1252 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001253 errorCode = TelephonyManager
1254 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001255 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001256 errorCode = TelephonyManager
1257 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001258 }
1259 }
Hall Liu27d24262020-09-18 19:04:59 -07001260 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001261 }
Shuo Qian4a594052020-01-23 11:59:30 -08001262 break;
Hall Liu27d24262020-09-18 19:04:59 -07001263 }
Shuo Qian4a594052020-01-23 11:59:30 -08001264
Hall Liu27d24262020-09-18 19:04:59 -07001265 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001266 request = (MainThreadRequest) msg.obj;
1267 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001268 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001269 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001270 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1271 request.argument).first;
1272 request.phone.setCallForwardingOption(
1273 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001274 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001275 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001276 callForwardingInfoToSet.getReason(),
1277 callForwardingInfoToSet.getNumber(),
1278 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1279 break;
Hall Liu27d24262020-09-18 19:04:59 -07001280 }
Shuo Qian4a594052020-01-23 11:59:30 -08001281
Hall Liu27d24262020-09-18 19:04:59 -07001282 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001283 ar = (AsyncResult) msg.obj;
1284 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001285 Consumer<Integer> callback =
1286 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1287 request.argument).second;
1288 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001289 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001290 int errorCode = TelephonyManager.CallForwardingInfoCallback
1291 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001292 if (ar.exception instanceof CommandException) {
1293 CommandException.Error error =
1294 ((CommandException) (ar.exception)).getCommandError();
1295 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001296 errorCode = TelephonyManager.CallForwardingInfoCallback
1297 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001298 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001299 errorCode = TelephonyManager.CallForwardingInfoCallback
1300 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001301 }
1302 }
1303 callback.accept(errorCode);
1304 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001305 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001306 }
Shuo Qian4a594052020-01-23 11:59:30 -08001307 break;
Hall Liu27d24262020-09-18 19:04:59 -07001308 }
Shuo Qian4a594052020-01-23 11:59:30 -08001309
Hall Liu27d24262020-09-18 19:04:59 -07001310 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001311 request = (MainThreadRequest) msg.obj;
1312 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1313 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1314 break;
Hall Liu27d24262020-09-18 19:04:59 -07001315 }
Shuo Qian4a594052020-01-23 11:59:30 -08001316
Hall Liu27d24262020-09-18 19:04:59 -07001317 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001318 ar = (AsyncResult) msg.obj;
1319 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001320 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001321 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001322 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001323 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001324 // Service Class is a bit mask per 3gpp 27.007.
1325 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001326 if (callForwardResults.length > 1
1327 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001328 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001329 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001330 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1331 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001332 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001333 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001334 }
1335 } else {
1336 if (ar.result == null) {
1337 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1338 }
1339 if (ar.exception != null) {
1340 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1341 }
1342 if (ar.exception instanceof CommandException) {
1343 CommandException.Error error =
1344 ((CommandException) (ar.exception)).getCommandError();
1345 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001346 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001347 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001348 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1349 callWaitingStatus =
1350 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001351 }
1352 }
1353 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001354 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001355 break;
Hall Liu27d24262020-09-18 19:04:59 -07001356 }
Shuo Qian4a594052020-01-23 11:59:30 -08001357
Hall Liu27d24262020-09-18 19:04:59 -07001358 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001359 request = (MainThreadRequest) msg.obj;
1360 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001361 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1362 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001363 break;
Hall Liu27d24262020-09-18 19:04:59 -07001364 }
Shuo Qian4a594052020-01-23 11:59:30 -08001365
Hall Liu27d24262020-09-18 19:04:59 -07001366 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001367 ar = (AsyncResult) msg.obj;
1368 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001369 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1370 Consumer<Integer> callback =
1371 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1372 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001373 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001374 if (ar.exception instanceof CommandException) {
1375 CommandException.Error error =
1376 ((CommandException) (ar.exception)).getCommandError();
1377 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1378 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001379 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1380 callback.accept(
1381 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001382 } else {
1383 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1384 }
1385 } else {
1386 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1387 }
1388 } else {
1389 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1390 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001391 }
Shuo Qian4a594052020-01-23 11:59:30 -08001392 break;
Hall Liu27d24262020-09-18 19:04:59 -07001393 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001394 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1395 ar = (AsyncResult) msg.obj;
1396 request = (MainThreadRequest) ar.userObj;
1397 CellNetworkScanResult cellScanResult;
1398 if (ar.exception == null && ar.result != null) {
1399 cellScanResult = new CellNetworkScanResult(
1400 CellNetworkScanResult.STATUS_SUCCESS,
1401 (List<OperatorInfo>) ar.result);
1402 } else {
1403 if (ar.result == null) {
1404 loge("getCellNetworkScanResults: Empty response");
1405 }
1406 if (ar.exception != null) {
1407 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1408 }
1409 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1410 if (ar.exception instanceof CommandException) {
1411 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001412 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001413 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1414 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1415 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1416 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1417 }
1418 }
1419 cellScanResult = new CellNetworkScanResult(errorCode, null);
1420 }
1421 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001422 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001423 break;
1424
1425 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1426 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001427 ManualNetworkSelectionArgument selArg =
1428 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001429 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1430 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001431 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1432 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001433 break;
1434
1435 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001436 ar = (AsyncResult) msg.obj;
1437 request = (MainThreadRequest) ar.userObj;
1438 if (ar.exception == null) {
1439 request.result = true;
1440 } else {
1441 request.result = false;
1442 loge("setNetworkSelectionModeManual " + ar.exception);
1443 }
1444 notifyRequester(request);
1445 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001446 break;
1447
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001448 case CMD_GET_MODEM_ACTIVITY_INFO:
1449 request = (MainThreadRequest) msg.obj;
1450 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001451 if (defaultPhone != null) {
1452 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001453 } else {
1454 ResultReceiver result = (ResultReceiver) request.argument;
1455 Bundle bundle = new Bundle();
1456 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001457 new ModemActivityInfo(0, 0, 0,
1458 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001459 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001460 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001461 break;
1462
Hall Liud0f208c2020-10-14 16:54:44 -07001463 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001464 ar = (AsyncResult) msg.obj;
1465 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001466 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001467 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001468 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001469 if (mLastModemActivityInfo == null) {
1470 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1471 mLastModemActivitySpecificInfo[0] =
1472 new ActivityStatsTechSpecificInfo(
1473 0,
1474 0,
1475 new int[ModemActivityInfo.getNumTxPowerLevels()],
1476 0);
1477 mLastModemActivityInfo =
1478 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1479 }
1480
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001481 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001482 // Update the last modem activity info and the result of the request.
1483 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1484 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001485 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001486 } else {
1487 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001488 }
Kai Shi917fdc62022-11-28 14:01:02 -08001489 // This is needed to decouple ret from mLastModemActivityInfo
1490 // We don't want to return mLastModemActivityInfo which is updated
1491 // inside mergeModemActivityInfo()
1492 ret = new ModemActivityInfo(
1493 mLastModemActivityInfo.getTimestampMillis(),
1494 mLastModemActivityInfo.getSleepTimeMillis(),
1495 mLastModemActivityInfo.getIdleTimeMillis(),
1496 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001497
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001498 } else {
1499 if (ar.result == null) {
1500 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001501 error = TelephonyManager.ModemActivityInfoException
1502 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001503 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001504 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001505 error = TelephonyManager.ModemActivityInfoException
1506 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001507 } else {
1508 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001509 error = TelephonyManager.ModemActivityInfoException
1510 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001511 }
1512 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001513 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001514 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001515 bundle.putParcelable(
1516 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001517 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001518 } else {
1519 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1520 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001521 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001522 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001523 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001524 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001525
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001526 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001527 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001528 CarrierRestrictionRules argument =
1529 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001530 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001531 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001532 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001533 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001534
1535 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1536 ar = (AsyncResult) msg.obj;
1537 request = (MainThreadRequest) ar.userObj;
1538 if (ar.exception == null && ar.result != null) {
1539 request.result = ar.result;
1540 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001541 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1542 if (ar.exception instanceof CommandException) {
1543 loge("setAllowedCarriers: CommandException: " + ar.exception);
1544 CommandException.Error error =
1545 ((CommandException) (ar.exception)).getCommandError();
1546 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1547 request.result =
1548 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1549 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001550 } else {
1551 loge("setAllowedCarriers: Unknown exception");
1552 }
1553 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001554 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001555 break;
1556
1557 case CMD_GET_ALLOWED_CARRIERS:
1558 request = (MainThreadRequest) msg.obj;
1559 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001560 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001561 break;
1562
1563 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1564 ar = (AsyncResult) msg.obj;
1565 request = (MainThreadRequest) ar.userObj;
1566 if (ar.exception == null && ar.result != null) {
1567 request.result = ar.result;
1568 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001569 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001570 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001571 if (ar.result == null) {
1572 loge("getAllowedCarriers: Empty response");
1573 } else if (ar.exception instanceof CommandException) {
1574 loge("getAllowedCarriers: CommandException: " +
1575 ar.exception);
1576 } else {
1577 loge("getAllowedCarriers: Unknown exception");
1578 }
1579 }
arunvoddud7401012022-12-15 16:08:12 +00001580 if (request.argument != null) {
1581 // This is for the implementation of carrierRestrictionStatus.
1582 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1583 Consumer<Integer> callback = callbackInfo.getConsumer();
1584 int callerCarrierId = callbackInfo.getCarrierId();
1585 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1586 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1587 CarrierRestrictionRules carrierRestrictionRules =
1588 (CarrierRestrictionRules) ar.result;
1589 int carrierId = -1;
1590 try {
1591 CarrierIdentifier carrierIdentifier =
1592 carrierRestrictionRules.getAllowedCarriers().get(0);
1593 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1594 carrierIdentifier);
1595 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1596 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1597 }
1598 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1599 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1600 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001601 lockStatus = TelephonyManager
1602 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001603 }
1604 } else {
1605 Rlog.e(LOG_TAG,
1606 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1607 }
1608 callback.accept(lockStatus);
1609 } else {
1610 // This is for the implementation of getAllowedCarriers.
1611 notifyRequester(request);
1612 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001613 break;
1614
Nathan Haroldb3014052017-01-25 15:57:32 -08001615 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1616 ar = (AsyncResult) msg.obj;
1617 request = (MainThreadRequest) ar.userObj;
1618 if (ar.exception == null && ar.result != null) {
1619 request.result = ar.result;
1620 } else {
1621 request.result = new IllegalArgumentException(
1622 "Failed to retrieve Forbidden Plmns");
1623 if (ar.result == null) {
1624 loge("getForbiddenPlmns: Empty response");
1625 } else {
1626 loge("getForbiddenPlmns: Unknown exception");
1627 }
1628 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001629 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001630 break;
1631
1632 case CMD_GET_FORBIDDEN_PLMNS:
1633 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001634 uiccPort = getUiccPortFromRequest(request);
1635 if (uiccPort == null) {
1636 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001637 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001638 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001639 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001640 break;
1641 }
1642 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001643 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001644 if (uiccApp == null) {
1645 loge("getForbiddenPlmns() no app with specified type -- "
1646 + appType);
1647 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001648 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001649 break;
1650 } else {
1651 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1652 + " specified type -- " + appType);
1653 }
1654 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1655 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001656 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001657 break;
1658
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001659 case CMD_SWITCH_SLOTS:
1660 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001661 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001662 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001663 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001664 break;
1665
1666 case EVENT_SWITCH_SLOTS_DONE:
1667 ar = (AsyncResult) msg.obj;
1668 request = (MainThreadRequest) ar.userObj;
1669 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001670 notifyRequester(request);
1671 break;
1672 case CMD_GET_NETWORK_SELECTION_MODE:
1673 request = (MainThreadRequest) msg.obj;
1674 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1675 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1676 break;
1677
1678 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1679 ar = (AsyncResult) msg.obj;
1680 request = (MainThreadRequest) ar.userObj;
1681 if (ar.exception != null) {
1682 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1683 } else {
1684 int mode = ((int[]) ar.result)[0];
1685 if (mode == 0) {
1686 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1687 } else {
1688 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1689 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001690 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001691 notifyRequester(request);
1692 break;
1693 case CMD_GET_CDMA_ROAMING_MODE:
1694 request = (MainThreadRequest) msg.obj;
1695 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1696 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1697 break;
1698 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1699 ar = (AsyncResult) msg.obj;
1700 request = (MainThreadRequest) ar.userObj;
1701 if (ar.exception != null) {
1702 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1703 } else {
1704 request.result = ((int[]) ar.result)[0];
1705 }
1706 notifyRequester(request);
1707 break;
1708 case CMD_SET_CDMA_ROAMING_MODE:
1709 request = (MainThreadRequest) msg.obj;
1710 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1711 int mode = (int) request.argument;
1712 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1713 break;
1714 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1715 ar = (AsyncResult) msg.obj;
1716 request = (MainThreadRequest) ar.userObj;
1717 request.result = ar.exception == null;
1718 notifyRequester(request);
1719 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001720 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1721 request = (MainThreadRequest) msg.obj;
1722 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1723 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1724 break;
1725 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1726 ar = (AsyncResult) msg.obj;
1727 request = (MainThreadRequest) ar.userObj;
1728 if (ar.exception != null) {
1729 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1730 } else {
1731 request.result = ((int[]) ar.result)[0];
1732 }
1733 notifyRequester(request);
1734 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001735 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1736 request = (MainThreadRequest) msg.obj;
1737 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1738 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001739 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1740 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001741 break;
1742 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1743 ar = (AsyncResult) msg.obj;
1744 request = (MainThreadRequest) ar.userObj;
1745 request.result = ar.exception == null;
1746 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001747 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001748 case CMD_GET_ALL_CELL_INFO:
1749 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001750 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001751 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001752 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001753 case EVENT_GET_ALL_CELL_INFO_DONE:
1754 ar = (AsyncResult) msg.obj;
1755 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001756 // If a timeout occurs, the response will be null
1757 request.result = (ar.exception == null && ar.result != null)
1758 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001759 synchronized (request) {
1760 request.notifyAll();
1761 }
1762 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001763 case CMD_REQUEST_CELL_INFO_UPDATE:
1764 request = (MainThreadRequest) msg.obj;
1765 request.phone.requestCellInfoUpdate(request.workSource,
1766 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1767 break;
1768 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1769 ar = (AsyncResult) msg.obj;
1770 request = (MainThreadRequest) ar.userObj;
1771 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1772 try {
1773 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001774 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001775 cb.onError(
1776 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1777 ar.exception.getClass().getName(),
1778 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001779 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001780 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001781 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001782 } else {
1783 // use the result as returned
1784 cb.onCellInfo((List<CellInfo>) ar.result);
1785 }
1786 } catch (RemoteException re) {
1787 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1788 }
1789 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001790 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001791 request = (MainThreadRequest) msg.obj;
1792 WorkSource ws = (WorkSource) request.argument;
1793 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001794 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001795 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001796 }
1797 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001798 ar = (AsyncResult) msg.obj;
1799 request = (MainThreadRequest) ar.userObj;
1800 if (ar.exception == null) {
1801 request.result = ar.result;
1802 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001803 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001804 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001805 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001806 }
1807
1808 synchronized (request) {
1809 request.notifyAll();
1810 }
1811 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001812 }
chen xu6dac5ab2018-10-26 17:39:23 -07001813 case CMD_MODEM_REBOOT:
1814 request = (MainThreadRequest) msg.obj;
1815 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001816 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001817 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001818 case EVENT_CMD_MODEM_REBOOT_DONE:
1819 handleNullReturnEvent(msg, "rebootModem");
1820 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001821 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001822 request = (MainThreadRequest) msg.obj;
1823 boolean enable = (boolean) request.argument;
1824 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001825 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001826 PhoneConfigurationManager.getInstance()
1827 .enablePhone(request.phone, enable, onCompleted);
1828 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001829 }
Michele Berionne5e411512020-11-13 02:36:59 +00001830 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001831 ar = (AsyncResult) msg.obj;
1832 request = (MainThreadRequest) ar.userObj;
1833 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001834 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001835 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001836 if ((boolean) request.result) {
1837 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1838 updateModemStateMetrics();
1839 } else {
1840 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1841 + ar.exception);
1842 }
1843 notifyRequester(request);
1844 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001845 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001846 case CMD_GET_MODEM_STATUS:
1847 request = (MainThreadRequest) msg.obj;
1848 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1849 PhoneConfigurationManager.getInstance()
1850 .getPhoneStatusFromModem(request.phone, onCompleted);
1851 break;
1852 case EVENT_GET_MODEM_STATUS_DONE:
1853 ar = (AsyncResult) msg.obj;
1854 request = (MainThreadRequest) ar.userObj;
1855 int id = request.phone.getPhoneId();
1856 if (ar.exception == null && ar.result != null) {
1857 request.result = ar.result;
1858 //update the cache as modem status has changed
1859 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1860 (boolean) request.result);
1861 } else {
1862 // Return true if modem status cannot be retrieved. For most cases,
1863 // modem status is on. And for older version modems, GET_MODEM_STATUS
1864 // and disable modem are not supported. Modem is always on.
1865 // TODO: this should be fixed in R to support a third
1866 // status UNKNOWN b/131631629
1867 request.result = true;
1868 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1869 + ar.exception);
1870 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001871 notifyRequester(request);
1872 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001873 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1874 request = (MainThreadRequest) msg.obj;
1875 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1876 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1877 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1878 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1879 break;
1880 }
1881 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1882 ar = (AsyncResult) msg.obj;
1883 request = (MainThreadRequest) ar.userObj;
1884 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1885 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1886 args.second.accept(ar.exception == null);
1887 notifyRequester(request);
1888 break;
1889 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001890 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1891 request = (MainThreadRequest) msg.obj;
1892 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1893 Phone phone = getPhoneFromRequest(request);
1894 if (phone != null) {
1895 phone.getSystemSelectionChannels(onCompleted);
1896 } else {
1897 loge("getSystemSelectionChannels: No phone object");
1898 request.result = new ArrayList<RadioAccessSpecifier>();
1899 notifyRequester(request);
1900 }
1901 break;
1902 }
1903 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1904 ar = (AsyncResult) msg.obj;
1905 request = (MainThreadRequest) ar.userObj;
1906 if (ar.exception == null && ar.result != null) {
1907 request.result = ar.result;
1908 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001909 request.result = new IllegalStateException(
1910 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001911 if (ar.result == null) {
1912 loge("getSystemSelectionChannels: Empty response");
1913 } else {
1914 loge("getSystemSelectionChannels: Unknown exception");
1915 }
1916 }
1917 notifyRequester(request);
1918 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001919 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1920 ar = (AsyncResult) msg.obj;
1921 request = (MainThreadRequest) ar.userObj;
1922 if (ar.exception == null && ar.result != null) {
1923 request.result = ar.result;
1924 } else {
1925 request.result = -1;
1926 loge("Failed to set Forbidden Plmns");
1927 if (ar.result == null) {
1928 loge("setForbidenPlmns: Empty response");
1929 } else if (ar.exception != null) {
1930 loge("setForbiddenPlmns: Exception: " + ar.exception);
1931 request.result = -1;
1932 } else {
1933 loge("setForbiddenPlmns: Unknown exception");
1934 }
1935 }
1936 notifyRequester(request);
1937 break;
1938 case CMD_SET_FORBIDDEN_PLMNS:
1939 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001940 uiccPort = getUiccPortFromRequest(request);
1941 if (uiccPort == null) {
1942 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001943 request.result = -1;
1944 notifyRequester(request);
1945 break;
1946 }
1947 Pair<Integer, List<String>> setFplmnsArgs =
1948 (Pair<Integer, List<String>>) request.argument;
1949 appType = setFplmnsArgs.first;
1950 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001951 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001952 if (uiccApp == null) {
1953 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1954 request.result = -1;
1955 loge("Failed to get UICC App");
1956 notifyRequester(request);
1957 } else {
1958 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1959 ((SIMRecords) uiccApp.getIccRecords())
1960 .setForbiddenPlmns(onCompleted, fplmns);
1961 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001962 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001963 case CMD_ERASE_MODEM_CONFIG:
1964 request = (MainThreadRequest) msg.obj;
1965 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1966 defaultPhone.eraseModemConfig(onCompleted);
1967 break;
1968 case EVENT_ERASE_MODEM_CONFIG_DONE:
1969 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001970 break;
zoey chene02881a2019-12-30 16:11:23 +08001971
Kai Shif70f46f2021-03-03 13:59:46 -08001972 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1973 request = (MainThreadRequest) msg.obj;
1974 request.result = defaultPhone.eraseDataInSharedPreferences();
1975 notifyRequester(request);
1976 break;
1977
zoey chene02881a2019-12-30 16:11:23 +08001978 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1979 request = (MainThreadRequest) msg.obj;
1980 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1981 Pair<String, String> changed = (Pair<String, String>) request.argument;
1982 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1983 changed.first, changed.second, onCompleted);
1984 break;
1985 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1986 ar = (AsyncResult) msg.obj;
1987 request = (MainThreadRequest) ar.userObj;
1988 if (ar.exception == null) {
1989 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001990 // If the operation is successful, update the PIN storage
1991 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1992 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001993 UiccController.getInstance().getPinStorage()
1994 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001995 } else {
1996 request.result = msg.arg1;
1997 }
1998 notifyRequester(request);
1999 break;
2000
Michele Berionne5e411512020-11-13 02:36:59 +00002001 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002002 request = (MainThreadRequest) msg.obj;
2003 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2004 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2005 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2006 enabled.first, enabled.second, onCompleted);
2007 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002008 }
zoey chene02881a2019-12-30 16:11:23 +08002009 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2010 ar = (AsyncResult) msg.obj;
2011 request = (MainThreadRequest) ar.userObj;
2012 if (ar.exception == null) {
2013 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002014 // If the operation is successful, update the PIN storage
2015 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2016 int phoneId = getPhoneFromRequest(request).getPhoneId();
2017 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002018 UiccController.getInstance().getPinStorage()
2019 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002020 } else {
2021 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2022 }
zoey chene02881a2019-12-30 16:11:23 +08002023 } else {
2024 request.result = msg.arg1;
2025 }
Michele Berionne5e411512020-11-13 02:36:59 +00002026
2027
zoey chene02881a2019-12-30 16:11:23 +08002028 notifyRequester(request);
2029 break;
2030
Peter Wangdafb9ac2020-01-15 14:13:38 -08002031 case MSG_NOTIFY_USER_ACTIVITY:
2032 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002033 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002034 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2035 getDefaultPhone().getContext().sendBroadcastAsUser(
2036 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2037 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002038
2039 case CMD_SET_DATA_THROTTLING: {
2040 request = (MainThreadRequest) msg.obj;
2041 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2042 DataThrottlingRequest dataThrottlingRequest =
2043 (DataThrottlingRequest) request.argument;
2044 Phone phone = getPhoneFromRequest(request);
2045 if (phone != null) {
2046 phone.setDataThrottling(onCompleted,
2047 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2048 dataThrottlingRequest.getCompletionDurationMillis());
2049 } else {
2050 loge("setDataThrottling: No phone object");
2051 request.result =
2052 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2053 notifyRequester(request);
2054 }
2055
2056 break;
2057 }
2058 case EVENT_SET_DATA_THROTTLING_DONE:
2059 ar = (AsyncResult) msg.obj;
2060 request = (MainThreadRequest) ar.userObj;
2061
2062 if (ar.exception == null) {
2063 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2064 } else if (ar.exception instanceof CommandException) {
2065 loge("setDataThrottling: CommandException: " + ar.exception);
2066 CommandException.Error error =
2067 ((CommandException) (ar.exception)).getCommandError();
2068
2069 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2070 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002071 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002072 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2073 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002074 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2075 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002076 } else {
2077 request.result =
2078 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2079 }
2080 } else {
2081 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2082 }
2083 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2084 notifyRequester(request);
2085 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002086
2087 case CMD_SET_SIM_POWER: {
2088 request = (MainThreadRequest) msg.obj;
2089 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2090 request = (MainThreadRequest) msg.obj;
2091 int stateToSet =
2092 ((Pair<Integer, IIntegerConsumer>)
2093 request.argument).first;
2094 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2095 break;
2096 }
2097 case EVENT_SET_SIM_POWER_DONE: {
2098 ar = (AsyncResult) msg.obj;
2099 request = (MainThreadRequest) ar.userObj;
2100 IIntegerConsumer callback =
2101 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2102 if (ar.exception != null) {
2103 loge("setSimPower exception: " + ar.exception);
2104 int errorCode = TelephonyManager.CallForwardingInfoCallback
2105 .RESULT_ERROR_UNKNOWN;
2106 if (ar.exception instanceof CommandException) {
2107 CommandException.Error error =
2108 ((CommandException) (ar.exception)).getCommandError();
2109 if (error == CommandException.Error.SIM_ERR) {
2110 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2111 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2112 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2113 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2114 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2115 } else {
2116 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2117 }
2118 }
2119 try {
2120 callback.accept(errorCode);
2121 } catch (RemoteException e) {
2122 // Ignore if the remote process is no longer available to call back.
2123 Log.w(LOG_TAG, "setSimPower: callback not available.");
2124 }
2125 } else {
2126 try {
2127 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2128 } catch (RemoteException e) {
2129 // Ignore if the remote process is no longer available to call back.
2130 Log.w(LOG_TAG, "setSimPower: callback not available.");
2131 }
2132 }
2133 break;
2134 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002135 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2136 request = (MainThreadRequest) msg.obj;
2137
2138 final Phone phone = getPhoneFromRequest(request);
2139 if (phone == null || phone.getServiceStateTracker() == null) {
2140 request.result = new IllegalStateException("Phone or SST is null");
2141 notifyRequester(request);
2142 break;
2143 }
2144
2145 Pair<Integer, SignalStrengthUpdateRequest> pair =
2146 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2147 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2148 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002149 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002150 request.subId, pair.first /*callingUid*/,
2151 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002152 break;
2153 }
2154 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2155 ar = (AsyncResult) msg.obj;
2156 request = (MainThreadRequest) ar.userObj;
2157 // request.result will be the exception of ar if present, true otherwise.
2158 // Be cautious not to leave result null which will wait() forever
2159 request.result = ar.exception != null ? ar.exception : true;
2160 notifyRequester(request);
2161 break;
2162 }
2163 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2164 request = (MainThreadRequest) msg.obj;
2165
2166 Phone phone = getPhoneFromRequest(request);
2167 if (phone == null || phone.getServiceStateTracker() == null) {
2168 request.result = new IllegalStateException("Phone or SST is null");
2169 notifyRequester(request);
2170 break;
2171 }
2172
2173 Pair<Integer, SignalStrengthUpdateRequest> pair =
2174 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2175 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2176 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002177 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002178 request.subId, pair.first /*callingUid*/,
2179 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002180 break;
2181 }
2182 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2183 ar = (AsyncResult) msg.obj;
2184 request = (MainThreadRequest) ar.userObj;
2185 request.result = ar.exception != null ? ar.exception : true;
2186 notifyRequester(request);
2187 break;
2188 }
Jordan Liu109698e2020-11-24 14:50:34 -08002189
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002190 case CMD_GET_SLICING_CONFIG: {
2191 request = (MainThreadRequest) msg.obj;
2192 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2193 request.phone.getSlicingConfig(onCompleted);
2194 break;
2195 }
2196 case EVENT_GET_SLICING_CONFIG_DONE: {
2197 ar = (AsyncResult) msg.obj;
2198 request = (MainThreadRequest) ar.userObj;
2199 ResultReceiver result = (ResultReceiver) request.argument;
2200
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002201 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002202 Bundle bundle = new Bundle();
2203 int resultCode = 0;
2204 if (ar.exception != null) {
2205 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2206 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002207 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002208 } else if (ar.result == null) {
2209 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002210 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002211 } else {
2212 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002213 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2214 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002215 }
2216
2217 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002218 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002219 }
2220 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2221 result.send(resultCode, bundle);
2222 notifyRequester(request);
2223 break;
2224 }
2225
Sarah Chin71b3a852022-09-28 15:54:19 -07002226 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002227 request = (MainThreadRequest) msg.obj;
2228 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002229 PurchasePremiumCapabilityArgument arg =
2230 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002231 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chinb8218c22023-01-04 13:35:29 -08002232 arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002233 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002234 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002235
Sarah Chin71b3a852022-09-28 15:54:19 -07002236 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002237 ar = (AsyncResult) msg.obj;
2238 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002239 PurchasePremiumCapabilityArgument arg =
2240 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002241 try {
2242 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002243 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002244 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002245 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002246 + ", result= "
2247 + TelephonyManager.convertPurchaseResultToString(result));
2248 } catch (RemoteException e) {
2249 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002250 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002251 + " failed: " + e;
2252 if (DBG) log(logStr);
2253 AnomalyReporter.reportAnomaly(
2254 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2255 }
2256 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002257 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002258
Michele Berionne5e411512020-11-13 02:36:59 +00002259 case CMD_PREPARE_UNATTENDED_REBOOT:
2260 request = (MainThreadRequest) msg.obj;
2261 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002262 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002263 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002264 notifyRequester(request);
2265 break;
2266
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 default:
2268 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2269 break;
2270 }
2271 }
Jake Hambye994d462014-02-03 13:10:13 -08002272
Pengquan Menga1bb6272018-09-06 09:59:22 -07002273 private void notifyRequester(MainThreadRequest request) {
2274 synchronized (request) {
2275 request.notifyAll();
2276 }
2277 }
2278
Jake Hambye994d462014-02-03 13:10:13 -08002279 private void handleNullReturnEvent(Message msg, String command) {
2280 AsyncResult ar = (AsyncResult) msg.obj;
2281 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2282 if (ar.exception == null) {
2283 request.result = true;
2284 } else {
2285 request.result = false;
2286 if (ar.exception instanceof CommandException) {
2287 loge(command + ": CommandException: " + ar.exception);
2288 } else {
2289 loge(command + ": Unknown exception");
2290 }
2291 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002292 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 }
2295
2296 /**
2297 * Posts the specified command to be executed on the main thread,
2298 * waits for the request to complete, and returns the result.
2299 * @see #sendRequestAsync
2300 */
2301 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002302 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2303 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002304 }
2305
2306 /**
2307 * Posts the specified command to be executed on the main thread,
2308 * waits for the request to complete, and returns the result.
2309 * @see #sendRequestAsync
2310 */
2311 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2312 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002313 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002314 }
2315
2316 /**
2317 * Posts the specified command to be executed on the main thread,
2318 * waits for the request to complete, and returns the result.
2319 * @see #sendRequestAsync
2320 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002321 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002322 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2323 }
2324
2325 /**
2326 * Posts the specified command to be executed on the main thread,
2327 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2328 * if not timeout or null otherwise.
2329 * @see #sendRequestAsync
2330 */
2331 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2332 long timeoutInMs) {
2333 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002334 }
2335
2336 /**
2337 * Posts the specified command to be executed on the main thread,
2338 * waits for the request to complete, and returns the result.
2339 * @see #sendRequestAsync
2340 */
Nathan Harold92bed182018-10-12 18:16:49 -07002341 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002342 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002343 }
2344
2345 /**
2346 * Posts the specified command to be executed on the main thread,
2347 * waits for the request to complete, and returns the result.
2348 * @see #sendRequestAsync
2349 */
2350 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002351 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2352 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002353 }
2354
2355 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002356 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2357 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2358 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002359 * @see #sendRequestAsync
2360 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002361 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2362 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2364 throw new RuntimeException("This method will deadlock if called from the main thread.");
2365 }
2366
Nathan Harold92bed182018-10-12 18:16:49 -07002367 MainThreadRequest request = null;
2368 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2369 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2370 } else if (phone != null) {
2371 request = new MainThreadRequest(argument, phone, workSource);
2372 } else {
2373 request = new MainThreadRequest(argument, subId, workSource);
2374 }
2375
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002376 Message msg = mMainThreadHandler.obtainMessage(command, request);
2377 msg.sendToTarget();
2378
Rambo Wang0f050d82021-02-12 11:43:36 -08002379
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002380 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002381 if (timeoutInMs >= 0) {
2382 // Wait for at least timeoutInMs before returning null request result
2383 long now = SystemClock.elapsedRealtime();
2384 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002385 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002386 try {
2387 request.wait(deadline - now);
2388 } catch (InterruptedException e) {
2389 // Do nothing, go back and check if request is completed or timeout
2390 } finally {
2391 now = SystemClock.elapsedRealtime();
2392 }
2393 }
2394 } else {
2395 // Wait for the request to complete
2396 while (request.result == null) {
2397 try {
2398 request.wait();
2399 } catch (InterruptedException e) {
2400 // Do nothing, go back and wait until the request is complete
2401 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002402 }
2403 }
2404 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002405 if (request.result == null) {
2406 Log.wtf(LOG_TAG,
2407 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002409 return request.result;
2410 }
2411
2412 /**
2413 * Asynchronous ("fire and forget") version of sendRequest():
2414 * Posts the specified command to be executed on the main thread, and
2415 * returns immediately.
2416 * @see #sendRequest
2417 */
2418 private void sendRequestAsync(int command) {
2419 mMainThreadHandler.sendEmptyMessage(command);
2420 }
2421
2422 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002423 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002424 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002425 */
2426 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002427 sendRequestAsync(command, argument, null, null);
2428 }
2429
2430 /**
2431 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2432 * @see {@link #sendRequest(int,Object)}
2433 */
2434 private void sendRequestAsync(
2435 int command, Object argument, Phone phone, WorkSource workSource) {
2436 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002437 Message msg = mMainThreadHandler.obtainMessage(command, request);
2438 msg.sendToTarget();
2439 }
2440
2441 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002442 * Initialize the singleton PhoneInterfaceManager instance.
2443 * This is only done once, at startup, from PhoneApp.onCreate().
2444 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002445 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002446 synchronized (PhoneInterfaceManager.class) {
2447 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002448 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 } else {
2450 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2451 }
2452 return sInstance;
2453 }
2454 }
2455
2456 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002457 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002460 mImsResolver = ImsResolver.getInstance();
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +00002461 mSatelliteController = SatelliteController.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002462 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2464 mMainThreadHandler = new MainThreadHandler();
Jack Yue37dd262022-12-16 11:53:37 -08002465 if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) {
2466 mSubscriptionController = SubscriptionController.getInstance();
2467 } else {
2468 mSubscriptionController = null;
2469 }
Sarah Chin4beb2b72023-02-14 14:47:54 -08002470 mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002471 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002472 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002473 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002474 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002475 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476 publish();
arunvoddud7401012022-12-15 16:08:12 +00002477 CarrierAllowListInfo.loadInstance(mApp);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 }
2479
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002480 @VisibleForTesting
2481 public SharedPreferences getSharedPreferences() {
2482 return mTelephonySharedPreferences;
2483 }
2484
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002485 /**
2486 * Get the default phone for this device.
2487 */
2488 @VisibleForTesting
2489 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002490 Phone thePhone = getPhone(getDefaultSubscription());
2491 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2492 }
2493
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002494 private void publish() {
2495 if (DBG) log("publish: " + this);
2496
Peter Wangc035ce42020-01-08 21:00:22 -08002497 TelephonyFrameworkInitializer
2498 .getTelephonyServiceManager()
2499 .getTelephonyServiceRegisterer()
2500 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 }
2502
Stuart Scott584921c2015-01-15 17:10:34 -08002503 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002504 if (request.phone != null) {
2505 return request.phone;
2506 } else {
2507 return getPhoneFromSubId(request.subId);
2508 }
2509 }
2510
2511 private Phone getPhoneFromSubId(int subId) {
2512 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2513 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002514 }
2515
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002516 /**
2517 * Get phone object associated with a subscription.
2518 * Return default phone if phone object associated with subscription is null
2519 * @param subId - subscriptionId
2520 * @return phone object associated with a subscription or default phone if null.
2521 */
Ling Mac28f0212023-03-24 16:07:15 -07002522 private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) {
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002523 Phone phone = getPhoneFromSubId(subId);
2524 if (phone == null) {
Ling Mac28f0212023-03-24 16:07:15 -07002525 loge("Called with invalid subId: " + subId + ". Retrying with default phone.");
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002526 phone = getDefaultPhone();
2527 }
2528 return phone;
2529 }
2530
Rambo Wange53e07d2022-05-10 13:01:13 -07002531 @Nullable
2532 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002533 Phone phone = getPhoneFromRequest(request);
2534 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002535 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002536 }
2537
Ling Mac28f0212023-03-24 16:07:15 -07002538 /**
2539 * @param subId The sub Id that associates the phone. If the device has no active SIM, passing
2540 * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <=
2541 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}.
2542 * @return The Phone associated the sub Id
2543 */
2544 private @Nullable Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002545 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002546 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002547
Kai Shif70f46f2021-03-03 13:59:46 -08002548 private void sendEraseModemConfig(@NonNull Phone phone) {
2549 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2550 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2551 }
2552
2553 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2554 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2555 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002556 }
2557
Peter Wang44b186e2020-01-13 23:33:09 -08002558 private boolean isImsAvailableOnDevice() {
2559 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2560 if (pm == null) {
2561 // For some reason package manger is not available.. This will fail internally anyway,
2562 // so do not throw error and allow.
2563 return true;
2564 }
2565 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2566 }
2567
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002569 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002570 }
2571
Wink Savilleb564aae2014-10-23 10:18:09 -07002572 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002573 if (DBG) log("dial: " + number);
2574 // No permission check needed here: This is just a wrapper around the
2575 // ACTION_DIAL intent, which is available to any app since it puts up
2576 // the UI before it does anything.
2577
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002578 final long identity = Binder.clearCallingIdentity();
2579 try {
2580 String url = createTelUrl(number);
2581 if (url == null) {
2582 return;
2583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002584
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002585 // PENDING: should we just silently fail if phone is offhook or ringing?
2586 PhoneConstants.State state = mCM.getState(subId);
2587 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2588 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2589 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2590 mApp.startActivity(intent);
2591 }
2592 } finally {
2593 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002594 }
2595 }
2596
2597 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002598 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002599 }
2600
Wink Savilleb564aae2014-10-23 10:18:09 -07002601 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002602 if (DBG) log("call: " + number);
2603
2604 // This is just a wrapper around the ACTION_CALL intent, but we still
2605 // need to do a permission check since we're calling startActivity()
2606 // from the context of the phone app.
2607 enforceCallPermission();
2608
Jordan Liu1617b712019-07-10 15:06:26 -07002609 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002610 != AppOpsManager.MODE_ALLOWED) {
2611 return;
2612 }
2613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614 final long identity = Binder.clearCallingIdentity();
2615 try {
2616 String url = createTelUrl(number);
2617 if (url == null) {
2618 return;
2619 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621 boolean isValid = false;
2622 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2623 if (slist != null) {
2624 for (SubscriptionInfo subInfoRecord : slist) {
2625 if (subInfoRecord.getSubscriptionId() == subId) {
2626 isValid = true;
2627 break;
2628 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002629 }
Wink Saville08874612014-08-31 19:19:58 -07002630 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002631 if (!isValid) {
2632 return;
2633 }
Wink Saville08874612014-08-31 19:19:58 -07002634
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002635 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2636 intent.putExtra(SUBSCRIPTION_KEY, subId);
2637 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2638 mApp.startActivity(intent);
2639 } finally {
2640 Binder.restoreCallingIdentity(identity);
2641 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002642 }
2643
Wink Savilleb564aae2014-10-23 10:18:09 -07002644 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002645 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002646 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2647 }
2648
Wink Savilleb564aae2014-10-23 10:18:09 -07002649 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002650 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002651 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2652 }
2653
Wink Savilleb564aae2014-10-23 10:18:09 -07002654 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002655 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002656
2657 final long identity = Binder.clearCallingIdentity();
2658 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002659 Phone phone = getPhone(subId);
2660 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002661 checkSimPin.start();
2662 return checkSimPin.unlockSim(null, pin);
2663 } finally {
2664 Binder.restoreCallingIdentity(identity);
2665 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 }
2667
Wink Savilleb564aae2014-10-23 10:18:09 -07002668 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002669 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002670
2671 final long identity = Binder.clearCallingIdentity();
2672 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002673 Phone phone = getPhone(subId);
2674 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002675 checkSimPuk.start();
2676 return checkSimPuk.unlockSim(puk, pin);
2677 } finally {
2678 Binder.restoreCallingIdentity(identity);
2679 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002680 }
2681
2682 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002683 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002684 * a synchronous one.
2685 */
2686 private static class UnlockSim extends Thread {
2687
2688 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002689 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002690
2691 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002692 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2693 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002694
2695 // For replies from SimCard interface
2696 private Handler mHandler;
2697
2698 // For async handler to identify request type
2699 private static final int SUPPLY_PIN_COMPLETE = 100;
2700
Michele Berionne5e411512020-11-13 02:36:59 +00002701 UnlockSim(int phoneId, IccCard simCard) {
2702 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002703 mSimCard = simCard;
2704 }
2705
2706 @Override
2707 public void run() {
2708 Looper.prepare();
2709 synchronized (UnlockSim.this) {
2710 mHandler = new Handler() {
2711 @Override
2712 public void handleMessage(Message msg) {
2713 AsyncResult ar = (AsyncResult) msg.obj;
2714 switch (msg.what) {
2715 case SUPPLY_PIN_COMPLETE:
2716 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2717 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002718 mRetryCount = msg.arg1;
2719 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002720 CommandException.Error error = null;
2721 if (ar.exception instanceof CommandException) {
2722 error = ((CommandException) (ar.exception))
2723 .getCommandError();
2724 }
2725 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07002726 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002727 } else if (error == CommandException.Error.ABORTED) {
2728 /* When UiccCardApp dispose, handle message and return
2729 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08002730 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002731 } else {
2732 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2733 }
2734 } else {
2735 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2736 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002737 mDone = true;
2738 UnlockSim.this.notifyAll();
2739 }
2740 break;
2741 }
2742 }
2743 };
2744 UnlockSim.this.notifyAll();
2745 }
2746 Looper.loop();
2747 }
2748
2749 /*
2750 * Use PIN or PUK to unlock SIM card
2751 *
2752 * If PUK is null, unlock SIM card with PIN
2753 *
2754 * If PUK is not null, unlock SIM card with PUK and set PIN code
2755 */
Wink Saville9de0f752013-10-22 19:04:03 -07002756 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002757
2758 while (mHandler == null) {
2759 try {
2760 wait();
2761 } catch (InterruptedException e) {
2762 Thread.currentThread().interrupt();
2763 }
2764 }
2765 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2766
2767 if (puk == null) {
2768 mSimCard.supplyPin(pin, callback);
2769 } else {
2770 mSimCard.supplyPuk(puk, pin, callback);
2771 }
2772
2773 while (!mDone) {
2774 try {
2775 Log.d(LOG_TAG, "wait for done");
2776 wait();
2777 } catch (InterruptedException e) {
2778 // Restore the interrupted status
2779 Thread.currentThread().interrupt();
2780 }
2781 }
2782 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002783 int[] resultArray = new int[2];
2784 resultArray[0] = mResult;
2785 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002786
2787 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002788 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002789 }
2790
Wink Saville9de0f752013-10-22 19:04:03 -07002791 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 }
2793 }
2794
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002795 /**
2796 * This method has been removed due to privacy and stability concerns.
2797 */
2798 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002799 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002800 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2801 return;
Wink Saville36469e72014-06-11 15:17:00 -07002802 }
2803
Nathan Harold1f889d82020-06-04 17:05:26 -07002804 @Override
2805 public void updateServiceLocationWithPackageName(String callingPackage) {
2806 mApp.getSystemService(AppOpsManager.class)
2807 .checkPackage(Binder.getCallingUid(), callingPackage);
2808
Nathan Haroldf096d982020-11-18 17:18:06 -08002809 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002810 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2811 // Callers targeting S have no business invoking this method.
2812 return;
2813 }
2814
2815 LocationAccessPolicy.LocationPermissionResult locationResult =
2816 LocationAccessPolicy.checkLocationPermission(mApp,
2817 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2818 .setCallingPackage(callingPackage)
2819 .setCallingFeatureId(null)
2820 .setCallingPid(Binder.getCallingPid())
2821 .setCallingUid(Binder.getCallingUid())
2822 .setMethod("updateServiceLocation")
2823 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2824 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2825 .build());
2826 // Apps that lack location permission have no business calling this method;
2827 // however, because no permission was declared in the public API, denials must
2828 // all be "soft".
2829 switch (locationResult) {
2830 case DENIED_HARD: /* fall through */
2831 case DENIED_SOFT:
2832 return;
2833 }
2834
2835 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002836 final long identity = Binder.clearCallingIdentity();
2837 try {
Ling Mac28f0212023-03-24 16:07:15 -07002838 getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002839 } finally {
2840 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002841 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002842 }
2843
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002844 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002845 @Override
2846 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002847 return isRadioOnWithFeature(callingPackage, null);
2848 }
2849
2850
2851 @Override
2852 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2853 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2854 callingFeatureId);
2855 }
2856
2857 @Deprecated
2858 @Override
2859 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2860 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002861 }
2862
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002863 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002864 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2865 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002866 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002867 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002868 return false;
2869 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002870
2871 final long identity = Binder.clearCallingIdentity();
2872 try {
2873 return isRadioOnForSubscriber(subId);
2874 } finally {
2875 Binder.restoreCallingIdentity(identity);
2876 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002877 }
2878
2879 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880 final long identity = Binder.clearCallingIdentity();
2881 try {
2882 final Phone phone = getPhone(subId);
2883 if (phone != null) {
2884 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2885 } else {
2886 return false;
2887 }
2888 } finally {
2889 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002890 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002891 }
2892
2893 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002894 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002895 }
Wink Saville36469e72014-06-11 15:17:00 -07002896
Wink Savilleb564aae2014-10-23 10:18:09 -07002897 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002898 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002899
2900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 final Phone phone = getPhone(subId);
2903 if (phone != null) {
2904 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2905 }
2906 } finally {
2907 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002908 }
Wink Saville36469e72014-06-11 15:17:00 -07002909 }
2910
2911 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002912 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002913 }
2914
Wink Savilleb564aae2014-10-23 10:18:09 -07002915 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002916 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002917
2918 final long identity = Binder.clearCallingIdentity();
2919 try {
2920 final Phone phone = getPhone(subId);
2921 if (phone == null) {
2922 return false;
2923 }
2924 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2925 toggleRadioOnOffForSubscriber(subId);
2926 }
2927 return true;
2928 } finally {
2929 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002930 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002931 }
Wink Saville36469e72014-06-11 15:17:00 -07002932
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002933 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002934 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002935 /*
2936 * If any of the Radios are available, it will need to be
2937 * shutdown. So return true if any Radio is available.
2938 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002939 final long identity = Binder.clearCallingIdentity();
2940 try {
2941 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2942 Phone phone = PhoneFactory.getPhone(i);
2943 if (phone != null && phone.isRadioAvailable()) return true;
2944 }
2945 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2946 return false;
2947 } finally {
2948 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002949 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002950 }
2951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002952 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002953 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002954 enforceModifyPermission();
2955
2956 final long identity = Binder.clearCallingIdentity();
2957 try {
2958 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2959 logv("Shutting down Phone " + i);
2960 shutdownRadioUsingPhoneId(i);
2961 }
2962 } finally {
2963 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002964 }
2965 }
2966
2967 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002968 Phone phone = PhoneFactory.getPhone(phoneId);
2969 if (phone != null && phone.isRadioAvailable()) {
2970 phone.shutdownRadio();
2971 }
2972 }
2973
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002974 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002975 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002976
Ling Ma83dc5ea2023-01-12 15:06:04 -08002977 if (!turnOn) {
2978 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
2979 }
2980
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002981 final long identity = Binder.clearCallingIdentity();
2982 try {
2983 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2984 if (defaultPhone != null) {
2985 defaultPhone.setRadioPower(turnOn);
2986 return true;
2987 } else {
2988 loge("There's no default phone.");
2989 return false;
2990 }
2991 } finally {
2992 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002993 }
Wink Saville36469e72014-06-11 15:17:00 -07002994 }
2995
Wink Savilleb564aae2014-10-23 10:18:09 -07002996 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002997 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002998
Ling Ma83dc5ea2023-01-12 15:06:04 -08002999 if (!turnOn) {
3000 log("setRadioPowerForSubscriber off: subId=" + subId
3001 + ",callingPackage=" + getCurrentPackageName());
3002 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003 final long identity = Binder.clearCallingIdentity();
3004 try {
3005 final Phone phone = getPhone(subId);
3006 if (phone != null) {
3007 phone.setRadioPower(turnOn);
3008 return true;
3009 } else {
3010 return false;
3011 }
3012 } finally {
3013 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003014 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003015 }
3016
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003017 /**
3018 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3019 * no reason to power it off. When any of the voters want to power it off, it will be turned
3020 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3021 * powering it off, and these radio off votes will be cleared.
3022 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3023 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3024 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3025 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3026 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3027 * check its vote.
3028 *
3029 * @param subId The subscription ID.
3030 * @param reason The reason for powering off radio.
3031 * @return true on success and false on failure.
3032 */
3033 public boolean requestRadioPowerOffForReason(int subId,
3034 @TelephonyManager.RadioPowerReason int reason) {
3035 enforceModifyPermission();
3036
Ling Ma83dc5ea2023-01-12 15:06:04 -08003037 log("requestRadioPowerOffForReason: subId=" + subId
3038 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003039 final long identity = Binder.clearCallingIdentity();
3040 try {
3041 final Phone phone = getPhone(subId);
3042 if (phone != null) {
3043 phone.setRadioPowerForReason(false, reason);
3044 return true;
3045 } else {
3046 return false;
3047 }
3048 } finally {
3049 Binder.restoreCallingIdentity(identity);
3050 }
3051 }
3052
3053 /**
3054 * Remove the vote on powering off the radio for a reason, as requested by
3055 * {@link requestRadioPowerOffForReason}.
3056 *
3057 * @param subId The subscription ID.
3058 * @param reason The reason for powering off radio.
3059 * @return true on success and false on failure.
3060 */
3061 public boolean clearRadioPowerOffForReason(int subId,
3062 @TelephonyManager.RadioPowerReason int reason) {
3063 enforceModifyPermission();
3064
3065 final long identity = Binder.clearCallingIdentity();
3066 try {
3067 final Phone phone = getPhone(subId);
3068 if (phone != null) {
3069 phone.setRadioPowerForReason(true, reason);
3070 return true;
3071 } else {
3072 return false;
3073 }
3074 } finally {
3075 Binder.restoreCallingIdentity(identity);
3076 }
3077 }
3078
3079 /**
3080 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3081 *
3082 * @param subId The subscription ID.
3083 * @param callingPackage The package making the call.
3084 * @param callingFeatureId The feature in the package.
3085 * @return List of reasons for powering off radio.
3086 */
3087 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3088 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3089
3090 final long identity = Binder.clearCallingIdentity();
3091 List result = new ArrayList();
3092 try {
3093 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3094 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3095 return result;
3096 }
3097
3098 final Phone phone = getPhone(subId);
3099 if (phone != null) {
3100 result.addAll(phone.getRadioPowerOffReasons());
3101 }
3102 } finally {
3103 Binder.restoreCallingIdentity(identity);
3104 }
3105 return result;
3106 }
3107
Wink Saville36469e72014-06-11 15:17:00 -07003108 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003109 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003110 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003111 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003112
3113 final long identity = Binder.clearCallingIdentity();
3114 try {
Jack Yu285100e2022-12-02 22:48:35 -08003115 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003116 final Phone phone = getPhone(subId);
3117 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003118 phone.getDataSettingsManager().setDataEnabled(
3119 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003120 return true;
3121 } else {
3122 return false;
3123 }
3124 } finally {
3125 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003126 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003127 }
3128
Wink Saville36469e72014-06-11 15:17:00 -07003129 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003130 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003131 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003132 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003133
3134 final long identity = Binder.clearCallingIdentity();
3135 try {
Jack Yu285100e2022-12-02 22:48:35 -08003136 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003137 final Phone phone = getPhone(subId);
3138 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003139 phone.getDataSettingsManager().setDataEnabled(
3140 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003141 return true;
3142 } else {
3143 return false;
3144 }
3145 } finally {
3146 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003147 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003148 }
3149
Sanket Padawe356d7632015-06-22 14:03:32 -07003150 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003151 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003152 final long identity = Binder.clearCallingIdentity();
3153 try {
3154 final Phone phone = getPhone(subId);
3155 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003156 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003157 } else {
3158 return false;
3159 }
3160 } finally {
3161 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003162 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003163 }
3164
3165 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003166 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003167 }
3168
pkanwarae03a6b2016-11-06 20:37:09 -08003169 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003170 enforceCallPermission();
3171
3172 final long identity = Binder.clearCallingIdentity();
3173 try {
3174 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3175 return;
3176 }
3177 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3178 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3179 } finally {
3180 Binder.restoreCallingIdentity(identity);
3181 }
pkanwar32d516d2016-10-14 19:37:38 -07003182 };
3183
Wink Savilleb564aae2014-10-23 10:18:09 -07003184 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003185 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003186
3187 final long identity = Binder.clearCallingIdentity();
3188 try {
3189 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3190 return false;
3191 }
3192 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3193 } finally {
3194 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003195 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003196 }
3197
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003198 /**
3199 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3200 * tag on getCallState Binder call.
3201 */
3202 @Deprecated
3203 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003204 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003205 if (CompatChanges.isChangeEnabled(
3206 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3207 Binder.getCallingUid())) {
3208 // Do not allow this API to be called on API version 31+, it should only be
3209 // called on old apps using this Binder call directly.
3210 throw new SecurityException("This method can only be used for applications "
3211 + "targeting API version 30 or less.");
3212 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003213 final long identity = Binder.clearCallingIdentity();
3214 try {
Ling Mac28f0212023-03-24 16:07:15 -07003215 Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription());
3216 return PhoneConstantConversions.convertCallState(phone.getState());
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003217 } finally {
3218 Binder.restoreCallingIdentity(identity);
3219 }
3220 }
3221
3222 @Override
3223 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3224 if (CompatChanges.isChangeEnabled(
3225 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3226 Binder.getCallingUid())) {
3227 // Check READ_PHONE_STATE for API version 31+
3228 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3229 featureId, "getCallStateForSubscription")) {
3230 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3231 + "targeting API level 31+.");
3232 }
3233 }
3234 final long identity = Binder.clearCallingIdentity();
3235 try {
3236 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003237 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3238 PhoneConstantConversions.convertCallState(phone.getState());
3239 } finally {
3240 Binder.restoreCallingIdentity(identity);
3241 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003242 }
3243
Sanket Padawe356d7632015-06-22 14:03:32 -07003244 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003245 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003246 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003247 }
3248
3249 @Override
3250 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003251 final long identity = Binder.clearCallingIdentity();
3252 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003253 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003254 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003255 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003256 } else {
3257 return PhoneConstantConversions.convertDataState(
3258 PhoneConstants.DataState.DISCONNECTED);
3259 }
3260 } finally {
3261 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003262 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003263 }
3264
Sanket Padawe356d7632015-06-22 14:03:32 -07003265 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003266 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003267 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003268 }
3269
3270 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003271 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003272 final long identity = Binder.clearCallingIdentity();
3273 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003274 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003275 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003276 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003277 } else {
3278 return TelephonyManager.DATA_ACTIVITY_NONE;
3279 }
3280 } finally {
3281 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003282 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003283 }
3284
3285 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003286 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003287 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003288 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003289
3290 LocationAccessPolicy.LocationPermissionResult locationResult =
3291 LocationAccessPolicy.checkLocationPermission(mApp,
3292 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3293 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003294 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003295 .setCallingPid(Binder.getCallingPid())
3296 .setCallingUid(Binder.getCallingUid())
3297 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003298 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003299 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3300 .build());
3301 switch (locationResult) {
3302 case DENIED_HARD:
3303 throw new SecurityException("Not allowed to access cell location");
3304 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003305 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3306 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003307 }
3308
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003309 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003310 final long identity = Binder.clearCallingIdentity();
3311 try {
3312 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003313 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003314 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003315 } finally {
3316 Binder.restoreCallingIdentity(identity);
3317 }
Svetoslav64fad262015-04-14 14:35:21 -07003318 }
3319
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003320 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003321 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003322 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3323 // registered cell info, so return a NULL country instead.
3324 final long identity = Binder.clearCallingIdentity();
3325 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003326 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3327 // Get default phone in this case.
3328 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3329 }
Jack Yu285100e2022-12-02 22:48:35 -08003330 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003331 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003332 if (phone == null) return "";
3333 ServiceStateTracker sst = phone.getServiceStateTracker();
3334 if (sst == null) return "";
3335 LocaleTracker lt = sst.getLocaleTracker();
3336 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003337 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003338 } finally {
3339 Binder.restoreCallingIdentity(identity);
3340 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003341 }
3342
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003343 /**
3344 * This method was removed due to potential issues caused by performing partial
3345 * updates of service state, and lack of a credible use case.
3346 *
3347 * This has the ability to break the telephony implementation by disabling notification of
3348 * changes in device connectivity. DO NOT USE THIS!
3349 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003350 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003351 public void enableLocationUpdates() {
3352 mApp.enforceCallingOrSelfPermission(
3353 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003354 }
3355
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003356 /**
3357 * This method was removed due to potential issues caused by performing partial
3358 * updates of service state, and lack of a credible use case.
3359 *
3360 * This has the ability to break the telephony implementation by disabling notification of
3361 * changes in device connectivity. DO NOT USE THIS!
3362 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003363 @Override
3364 public void disableLocationUpdates() {
3365 mApp.enforceCallingOrSelfPermission(
3366 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003367 }
3368
3369 @Override
3370 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003371 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3372 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003373 try {
3374 mApp.getSystemService(AppOpsManager.class)
3375 .checkPackage(Binder.getCallingUid(), callingPackage);
3376 } catch (SecurityException e) {
3377 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3378 throw e;
3379 }
3380
Nathan Haroldf096d982020-11-18 17:18:06 -08003381 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003382 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3383 throw new SecurityException(
3384 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3385 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003386
Jordan Liu1617b712019-07-10 15:06:26 -07003387 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003388 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3389 return null;
3390 }
Svetoslav64fad262015-04-14 14:35:21 -07003391
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003392 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003393
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003394 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003395 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003396
Nathan Haroldf180aac2018-06-01 18:43:55 -07003397 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3398 for (CellInfo ci : info) {
3399 if (ci instanceof CellInfoGsm) {
3400 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3401 } else if (ci instanceof CellInfoWcdma) {
3402 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003404 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003405 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003406 }
3407
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003408 private List<CellInfo> getCachedCellInfo() {
3409 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3410 for (Phone phone : PhoneFactory.getPhones()) {
3411 List<CellInfo> info = phone.getAllCellInfo();
3412 if (info != null) cellInfos.addAll(info);
3413 }
3414 return cellInfos;
3415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003416
3417 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003418 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003419 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003420 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003421
3422 LocationAccessPolicy.LocationPermissionResult locationResult =
3423 LocationAccessPolicy.checkLocationPermission(mApp,
3424 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3425 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003426 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003427 .setCallingPid(Binder.getCallingPid())
3428 .setCallingUid(Binder.getCallingUid())
3429 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003430 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003431 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3432 .build());
3433 switch (locationResult) {
3434 case DENIED_HARD:
3435 throw new SecurityException("Not allowed to access cell info");
3436 case DENIED_SOFT:
3437 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003438 }
3439
Nathan Haroldf096d982020-11-18 17:18:06 -08003440 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003441 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3442 return getCachedCellInfo();
3443 }
3444
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003445 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003446 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003447 final long identity = Binder.clearCallingIdentity();
3448 try {
3449 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3450 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003451 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003452 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003453 if (info != null) cellInfos.addAll(info);
3454 }
3455 return cellInfos;
3456 } finally {
3457 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003458 }
3459 }
3460
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003461 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003462 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3463 String callingFeatureId) {
3464 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3465 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003466 }
3467
3468 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003469 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3470 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003471 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003472 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003473 }
3474
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003475 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3476 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003477 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003478 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003479
3480 LocationAccessPolicy.LocationPermissionResult locationResult =
3481 LocationAccessPolicy.checkLocationPermission(mApp,
3482 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3483 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003484 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003485 .setCallingPid(Binder.getCallingPid())
3486 .setCallingUid(Binder.getCallingUid())
3487 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003488 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3489 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003490 .build());
3491 switch (locationResult) {
3492 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003493 if (TelephonyPermissions
3494 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003495 // Safetynet logging for b/154934934
3496 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3497 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003498 throw new SecurityException("Not allowed to access cell info");
3499 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003500 if (TelephonyPermissions
3501 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003502 // Safetynet logging for b/154934934
3503 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3504 }
Nathan Harold5320c422019-05-09 10:26:08 -07003505 try {
3506 cb.onCellInfo(new ArrayList<CellInfo>());
3507 } catch (RemoteException re) {
3508 // Drop without consequences
3509 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003510 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003511 }
3512
Nathan Harolda939a962019-05-09 10:13:47 -07003513
3514 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003515 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3516
3517 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3518 }
3519
3520 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003521 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003522 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003523 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003524
3525 final long identity = Binder.clearCallingIdentity();
3526 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003527 Phone phone = getPhone(subId);
3528 if (phone == null) {
3529 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3530 } else {
3531 phone.setCellInfoListRate(rateInMillis, workSource);
3532 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003533 } finally {
3534 Binder.restoreCallingIdentity(identity);
3535 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003536 }
3537
Shishir Agrawala9f32182016-04-12 12:00:16 -07003538 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003539 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003540 Phone phone = PhoneFactory.getPhone(slotIndex);
3541 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003542 return null;
3543 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003544 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003545 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003546 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003547 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003548 return null;
3549 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003550
3551 final long identity = Binder.clearCallingIdentity();
3552 try {
3553 return phone.getImei();
3554 } finally {
3555 Binder.restoreCallingIdentity(identity);
3556 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003557 }
3558
3559 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003560 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3561 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3562 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3563 callingFeatureId, "getPrimaryImei")) {
3564 throw new SecurityException("Caller does not have permission");
3565 }
3566 final long identity = Binder.clearCallingIdentity();
3567 try {
3568 for (Phone phone : PhoneFactory.getPhones()) {
3569 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3570 return phone.getImei();
3571 }
3572 }
3573 throw new UnsupportedOperationException("Operation not supported");
3574 } finally {
3575 Binder.restoreCallingIdentity(identity);
3576 }
3577 }
3578
3579 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003580 public String getTypeAllocationCodeForSlot(int slotIndex) {
3581 Phone phone = PhoneFactory.getPhone(slotIndex);
3582 String tac = null;
3583 if (phone != null) {
3584 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003585 try {
3586 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3587 } catch (IndexOutOfBoundsException e) {
3588 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3589 return null;
3590 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003591 }
3592 return tac;
3593 }
3594
3595 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003596 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003597 try {
3598 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3599 } catch (SecurityException se) {
3600 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3601 throw new SecurityException("Package " + callingPackage + " does not belong to "
3602 + Binder.getCallingUid());
3603 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003604 Phone phone = PhoneFactory.getPhone(slotIndex);
3605 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003606 return null;
3607 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003608
Jeff Davidson913390f2018-02-23 17:11:49 -08003609 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003610 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003611 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003612 return null;
3613 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003614
3615 final long identity = Binder.clearCallingIdentity();
3616 try {
3617 return phone.getMeid();
3618 } finally {
3619 Binder.restoreCallingIdentity(identity);
3620 }
Jack Yu2af8d712017-03-15 17:14:14 -07003621 }
3622
3623 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003624 public String getManufacturerCodeForSlot(int slotIndex) {
3625 Phone phone = PhoneFactory.getPhone(slotIndex);
3626 String manufacturerCode = null;
3627 if (phone != null) {
3628 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003629 try {
3630 manufacturerCode =
3631 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3632 } catch (IndexOutOfBoundsException e) {
3633 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3634 return null;
3635 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003636 }
3637 return manufacturerCode;
3638 }
3639
3640 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003641 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3642 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003643 Phone phone = PhoneFactory.getPhone(slotIndex);
3644 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003645 return null;
3646 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003647 int subId = phone.getSubId();
3648 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003649 mApp, subId, callingPackage, callingFeatureId,
3650 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003651 return null;
3652 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003653
3654 final long identity = Binder.clearCallingIdentity();
3655 try {
3656 return phone.getDeviceSvn();
3657 } finally {
3658 Binder.restoreCallingIdentity(identity);
3659 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003660 }
3661
fionaxu43304da2017-11-27 22:51:16 -08003662 @Override
3663 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003664 final long identity = Binder.clearCallingIdentity();
3665 try {
3666 final Phone phone = getPhone(subId);
3667 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3668 } finally {
3669 Binder.restoreCallingIdentity(identity);
3670 }
fionaxu43304da2017-11-27 22:51:16 -08003671 }
3672
3673 @Override
3674 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003675 final long identity = Binder.clearCallingIdentity();
3676 try {
3677 final Phone phone = getPhone(subId);
3678 return phone == null ? null : phone.getCarrierName();
3679 } finally {
3680 Binder.restoreCallingIdentity(identity);
3681 }
fionaxu43304da2017-11-27 22:51:16 -08003682 }
3683
calvinpanffe225e2018-11-01 19:43:06 +08003684 @Override
chen xu0026ca62019-03-06 15:28:50 -08003685 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003686 final long identity = Binder.clearCallingIdentity();
3687 try {
3688 final Phone phone = getPhone(subId);
3689 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003690 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003691 } finally {
3692 Binder.restoreCallingIdentity(identity);
3693 }
3694 }
3695
3696 @Override
chen xu0026ca62019-03-06 15:28:50 -08003697 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003698 final long identity = Binder.clearCallingIdentity();
3699 try {
3700 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003701 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003702 } finally {
3703 Binder.restoreCallingIdentity(identity);
3704 }
3705 }
3706
chen xu651eec72018-11-11 19:03:44 -08003707 @Override
chen xu864e11c2018-12-06 22:10:03 -08003708 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3709 if (!isSubscriptionMccMnc) {
3710 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3711 }
chen xu651eec72018-11-11 19:03:44 -08003712 final Phone phone = PhoneFactory.getPhone(slotIndex);
3713 if (phone == null) {
3714 return TelephonyManager.UNKNOWN_CARRIER_ID;
3715 }
3716 final long identity = Binder.clearCallingIdentity();
3717 try {
3718 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3719 } finally {
3720 Binder.restoreCallingIdentity(identity);
3721 }
3722 }
3723
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003724 //
3725 // Internal helper methods.
3726 //
3727
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003728 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003729 * Make sure the caller is the calling package itself
3730 *
3731 * @throws SecurityException if the caller is not the calling package
3732 */
3733 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3734 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003735 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3736 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003737 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003738 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003739 } catch (PackageManager.NameNotFoundException e) {
3740 // packageUid is -1
3741 }
3742 if (packageUid != callingUid) {
3743 throw new SecurityException(message + ": Package " + callingPackage
3744 + " does not belong to " + callingUid);
3745 }
3746 }
3747
3748 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003749 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3750 *
3751 * @throws SecurityException if the caller does not have the required permission
3752 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003753 @VisibleForTesting
3754 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003755 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3756 }
3757
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003758 /**
arunvoddud7401012022-12-15 16:08:12 +00003759 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003760 *
3761 * @throws SecurityException if the caller does not have the required permission
3762 */
3763 @VisibleForTesting
3764 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00003765 enforceReadPermission(null);
3766 }
3767
3768 /**
3769 * Make sure the caller has the READ_PHONE_STATE permissions.
3770 *
3771 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
3772 */
3773 @VisibleForTesting
3774 public void enforceReadPermission(String msg) {
3775 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00003776 }
3777
Shuo Qian3b6ee772019-11-13 17:43:31 -08003778 private void enforceActiveEmergencySessionPermission() {
3779 mApp.enforceCallingOrSelfPermission(
3780 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3781 }
3782
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003783 /**
3784 * Make sure the caller has the CALL_PHONE permission.
3785 *
3786 * @throws SecurityException if the caller does not have the required permission
3787 */
3788 private void enforceCallPermission() {
3789 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3790 }
3791
paulhu5a773602019-08-23 19:17:33 +08003792 private void enforceSettingsPermission() {
3793 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003794 }
3795
Michele Berionne5e411512020-11-13 02:36:59 +00003796 private void enforceRebootPermission() {
3797 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3798 }
3799
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00003800 /**
3801 * Make sure the caller has SATELLITE_COMMUNICATION permission.
3802 * @param message - log message to print.
3803 * @throws SecurityException if the caller does not have the required permission
3804 */
3805 private void enforceSatelliteCommunicationPermission(String message) {
3806 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
3807 }
3808
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003809 private String createTelUrl(String number) {
3810 if (TextUtils.isEmpty(number)) {
3811 return null;
3812 }
3813
Jake Hambye994d462014-02-03 13:10:13 -08003814 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003815 }
3816
Ihab Awadf9e92732013-12-05 18:02:52 -08003817 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08003818 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003819 }
3820
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003821 private static void logv(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003822 Log.v(LOG_TAG, msg);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003823 }
3824
Ihab Awadf9e92732013-12-05 18:02:52 -08003825 private static void loge(String msg) {
Sarah Chin4beb2b72023-02-14 14:47:54 -08003826 Log.e(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003827 }
3828
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003829 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003830 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003831 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003832 }
3833
Sanket Padawe356d7632015-06-22 14:03:32 -07003834 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003835 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003836 final long identity = Binder.clearCallingIdentity();
3837 try {
3838 final Phone phone = PhoneFactory.getPhone(slotIndex);
3839 if (phone == null) {
3840 return PhoneConstants.PHONE_TYPE_NONE;
3841 } else {
3842 return phone.getPhoneType();
3843 }
3844 } finally {
3845 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003846 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003847 }
3848
3849 /**
3850 * Returns the CDMA ERI icon index to display
3851 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003852 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003853 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3854 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3855 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003856 }
3857
Sanket Padawe356d7632015-06-22 14:03:32 -07003858 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003859 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3860 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003861 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003862 mApp, subId, callingPackage, callingFeatureId,
3863 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003864 return -1;
3865 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003866
3867 final long identity = Binder.clearCallingIdentity();
3868 try {
3869 final Phone phone = getPhone(subId);
3870 if (phone != null) {
3871 return phone.getCdmaEriIconIndex();
3872 } else {
3873 return -1;
3874 }
3875 } finally {
3876 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003877 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003878 }
3879
3880 /**
3881 * Returns the CDMA ERI icon mode,
3882 * 0 - ON
3883 * 1 - FLASHING
3884 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003885 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003886 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3887 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3888 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003889 }
3890
Sanket Padawe356d7632015-06-22 14:03:32 -07003891 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003892 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3893 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003894 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003895 mApp, subId, callingPackage, callingFeatureId,
3896 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003897 return -1;
3898 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003899
3900 final long identity = Binder.clearCallingIdentity();
3901 try {
3902 final Phone phone = getPhone(subId);
3903 if (phone != null) {
3904 return phone.getCdmaEriIconMode();
3905 } else {
3906 return -1;
3907 }
3908 } finally {
3909 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003910 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003911 }
3912
3913 /**
3914 * Returns the CDMA ERI text,
3915 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003916 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003917 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3918 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3919 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003920 }
3921
Sanket Padawe356d7632015-06-22 14:03:32 -07003922 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003923 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3924 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003925 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003926 mApp, subId, callingPackage, callingFeatureId,
3927 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003928 return null;
3929 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003930
3931 final long identity = Binder.clearCallingIdentity();
3932 try {
3933 final Phone phone = getPhone(subId);
3934 if (phone != null) {
3935 return phone.getCdmaEriText();
3936 } else {
3937 return null;
3938 }
3939 } finally {
3940 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003942 }
3943
3944 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003945 * Returns the CDMA MDN.
3946 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003947 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003948 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003949 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3950 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003951
3952 final long identity = Binder.clearCallingIdentity();
3953 try {
3954 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003955 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003956 return phone.getLine1Number();
3957 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003958 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003959 return null;
3960 }
3961 } finally {
3962 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003963 }
3964 }
3965
3966 /**
3967 * Returns the CDMA MIN.
3968 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003969 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003970 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3972 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003973
3974 final long identity = Binder.clearCallingIdentity();
3975 try {
3976 final Phone phone = getPhone(subId);
3977 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3978 return phone.getCdmaMin();
3979 } else {
3980 return null;
3981 }
3982 } finally {
3983 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003984 }
3985 }
3986
Hall Liud892bec2018-11-30 14:51:45 -08003987 @Override
3988 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3989 INumberVerificationCallback callback, String callingPackage) {
3990 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3991 != PERMISSION_GRANTED) {
3992 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3993 }
3994 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3995
3996 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3997 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003998 throw new SecurityException("Calling package must be configured in the device config: "
3999 + "calling package: " + callingPackage
4000 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004001 }
4002
4003 if (range == null) {
4004 throw new NullPointerException("Range must be non-null");
4005 }
4006
4007 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004008 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004009
4010 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4011 }
4012
Junda Liuca05d5d2014-08-14 22:36:34 -07004013 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004014 * Returns true if CDMA provisioning needs to run.
4015 */
4016 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004017 final long identity = Binder.clearCallingIdentity();
4018 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004019 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004020 } finally {
4021 Binder.restoreCallingIdentity(identity);
4022 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004023 }
4024
4025 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004026 * Sets the voice mail number of a given subId.
4027 */
4028 @Override
4029 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004030 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4031 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004032
4033 final long identity = Binder.clearCallingIdentity();
4034 try {
4035 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4036 new Pair<String, String>(alphaTag, number), new Integer(subId));
4037 return success;
4038 } finally {
4039 Binder.restoreCallingIdentity(identity);
4040 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004041 }
4042
Ta-wei Yen87c49842016-05-13 21:19:52 -07004043 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004044 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4045 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004046 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4047 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004048 if (!TextUtils.equals(callingPackage, systemDialer)) {
4049 throw new SecurityException("caller must be system dialer");
4050 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004051
4052 final long identity = Binder.clearCallingIdentity();
4053 try {
4054 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4055 if (phoneAccountHandle == null) {
4056 return null;
4057 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004058 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004059 } finally {
4060 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004061 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004062 }
4063
4064 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004065 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4066 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004067 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004068 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004069 mApp, subId, callingPackage, callingFeatureId,
4070 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004071 return null;
4072 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004073
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004074 final long identity = Binder.clearCallingIdentity();
4075 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004076 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004077 } finally {
4078 Binder.restoreCallingIdentity(identity);
4079 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004080 }
4081
4082 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004083 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4084 VisualVoicemailSmsFilterSettings settings) {
4085 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004086
4087 final long identity = Binder.clearCallingIdentity();
4088 try {
4089 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004090 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004091 } finally {
4092 Binder.restoreCallingIdentity(identity);
4093 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004094 }
4095
4096 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004097 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4098 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004099
4100 final long identity = Binder.clearCallingIdentity();
4101 try {
4102 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004103 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004104 } finally {
4105 Binder.restoreCallingIdentity(identity);
4106 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004107 }
4108
4109 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004110 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4111 String callingPackage, int subId) {
4112 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004113
4114 final long identity = Binder.clearCallingIdentity();
4115 try {
4116 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004117 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004118 } finally {
4119 Binder.restoreCallingIdentity(identity);
4120 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004121 }
4122
4123 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004124 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004125 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004126
4127 final long identity = Binder.clearCallingIdentity();
4128 try {
4129 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004130 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004131 } finally {
4132 Binder.restoreCallingIdentity(identity);
4133 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004134 }
4135
4136 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004137 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4138 String callingAttributionTag, int subId, String number, int port, String text,
4139 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004140 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004141 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004142 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004143 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004144 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4145 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004146 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004147
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004148 /**
fionaxu0152e512016-11-14 13:36:14 -08004149 * Sets the voice activation state of a given subId.
4150 */
4151 @Override
4152 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004153 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4154 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004155
4156 final long identity = Binder.clearCallingIdentity();
4157 try {
4158 final Phone phone = getPhone(subId);
4159 if (phone != null) {
4160 phone.setVoiceActivationState(activationState);
4161 } else {
4162 loge("setVoiceActivationState fails with invalid subId: " + subId);
4163 }
4164 } finally {
4165 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004166 }
4167 }
4168
4169 /**
4170 * Sets the data activation state of a given subId.
4171 */
4172 @Override
4173 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004174 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4175 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004176
4177 final long identity = Binder.clearCallingIdentity();
4178 try {
4179 final Phone phone = getPhone(subId);
4180 if (phone != null) {
4181 phone.setDataActivationState(activationState);
4182 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004183 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004184 }
4185 } finally {
4186 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004187 }
4188 }
4189
4190 /**
4191 * Returns the voice activation state of a given subId.
4192 */
4193 @Override
4194 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004195 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004196
fionaxu0152e512016-11-14 13:36:14 -08004197 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004198 final long identity = Binder.clearCallingIdentity();
4199 try {
4200 if (phone != null) {
4201 return phone.getVoiceActivationState();
4202 } else {
4203 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4204 }
4205 } finally {
4206 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004207 }
4208 }
4209
4210 /**
4211 * Returns the data activation state of a given subId.
4212 */
4213 @Override
4214 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004215 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004216
fionaxu0152e512016-11-14 13:36:14 -08004217 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004218 final long identity = Binder.clearCallingIdentity();
4219 try {
4220 if (phone != null) {
4221 return phone.getDataActivationState();
4222 } else {
4223 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4224 }
4225 } finally {
4226 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004227 }
4228 }
4229
4230 /**
Wink Saville36469e72014-06-11 15:17:00 -07004231 * Returns the unread count of voicemails for a subId
4232 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004233 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004234 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4235 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004236 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004237 mApp, subId, callingPackage, callingFeatureId,
4238 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004239 return 0;
4240 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004241 final long identity = Binder.clearCallingIdentity();
4242 try {
4243 final Phone phone = getPhone(subId);
4244 if (phone != null) {
4245 return phone.getVoiceMessageCount();
4246 } else {
4247 return 0;
4248 }
4249 } finally {
4250 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004251 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004252 }
4253
4254 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004255 * returns true, if the device is in a state where both voice and data
4256 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004257 */
4258 @Override
4259 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004260 final long identity = Binder.clearCallingIdentity();
4261 try {
Ling Mac28f0212023-03-24 16:07:15 -07004262 return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004263 } finally {
4264 Binder.restoreCallingIdentity(identity);
4265 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004266 }
4267
4268 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004269 * Send the dialer code if called from the current default dialer or the caller has
4270 * carrier privilege.
4271 * @param inputCode The dialer code to send
4272 */
4273 @Override
4274 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004275 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004276 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004277 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4278 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004279 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004280 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004281 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004282 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004283
4284 final long identity = Binder.clearCallingIdentity();
4285 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004286 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004287 } finally {
4288 Binder.restoreCallingIdentity(identity);
4289 }
fionaxu235cc5e2017-03-06 22:25:57 -08004290 }
4291
Pengquan Menga1bb6272018-09-06 09:59:22 -07004292 @Override
4293 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004294 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004295 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4296 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004297 final long identity = Binder.clearCallingIdentity();
4298 try {
4299 if (!isActiveSubscription(subId)) {
4300 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4301 }
4302 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4303 } finally {
4304 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004305 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004306 }
4307
Brad Ebinger35c841c2018-10-01 10:40:55 -07004308 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004309 public boolean isInEmergencySmsMode() {
4310 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4311 final long identity = Binder.clearCallingIdentity();
4312 try {
4313 for (Phone phone : PhoneFactory.getPhones()) {
4314 if (phone.isInEmergencySmsMode()) {
4315 return true;
4316 }
4317 }
4318 } finally {
4319 Binder.restoreCallingIdentity(identity);
4320 }
4321 return false;
4322 }
4323
shilu366312e2019-12-17 09:28:10 -08004324 /**
4325 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4326 * @param subId The subscription to use to check the configuration.
4327 * @param c The callback that will be used to send the result.
4328 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004329 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004330 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4331 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004332 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004333 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004334
4335 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4336 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4337 "IMS not available on device.");
4338 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004339 final long token = Binder.clearCallingIdentity();
4340 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004341 int slotId = getSlotIndexOrException(subId);
4342 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004343
4344 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4345 if (controller != null) {
4346 ImsManager imsManager = controller.getImsManager(subId);
4347 if (imsManager != null) {
4348 imsManager.addRegistrationCallbackForSubscription(c, subId);
4349 } else {
4350 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4351 }
4352 } else {
4353 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4354 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004355 } catch (ImsException e) {
4356 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004357 } finally {
4358 Binder.restoreCallingIdentity(token);
4359 }
4360 }
4361
shilu366312e2019-12-17 09:28:10 -08004362 /**
4363 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4364 * @param subId The subscription to use to check the configuration.
4365 * @param c The callback that will be used to send the result.
4366 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004367 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004368 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004369 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004370 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004371 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4372 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4373 }
Meng Wangafbc5852019-09-19 17:37:13 -07004374 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004375
Meng Wangafbc5852019-09-19 17:37:13 -07004376 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004377 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4378 if (controller != null) {
4379 ImsManager imsManager = controller.getImsManager(subId);
4380 if (imsManager != null) {
4381 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4382 } else {
4383 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4384 + "is inactive, ignoring unregister.");
4385 // If the ImsManager is not valid, just return, since the callback
4386 // will already have been removed internally.
4387 }
4388 }
Meng Wangafbc5852019-09-19 17:37:13 -07004389 } finally {
4390 Binder.restoreCallingIdentity(token);
4391 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004392 }
4393
Brad Ebingera34a6c22019-10-22 17:36:18 -07004394 /**
4395 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4396 */
4397 @Override
4398 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4399 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4400 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4401 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4402 "IMS not available on device.");
4403 }
4404 final long token = Binder.clearCallingIdentity();
4405 try {
4406 Phone phone = getPhone(subId);
4407 if (phone == null) {
4408 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4409 + subId + "'");
4410 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4411 }
4412 phone.getImsRegistrationState(regState -> {
4413 try {
4414 consumer.accept((regState == null)
4415 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4416 } catch (RemoteException e) {
4417 // Ignore if the remote process is no longer available to call back.
4418 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4419 }
4420 });
4421 } finally {
4422 Binder.restoreCallingIdentity(token);
4423 }
4424 }
4425
4426 /**
4427 * Get the transport type for the IMS service registration state.
4428 */
4429 @Override
4430 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004431 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004432 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004433 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4434 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4435 "IMS not available on device.");
4436 }
4437 final long token = Binder.clearCallingIdentity();
4438 try {
4439 Phone phone = getPhone(subId);
4440 if (phone == null) {
4441 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4442 + subId + "'");
4443 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4444 }
4445 phone.getImsRegistrationTech(regTech -> {
4446 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4447 int regTechConverted = (regTech == null)
4448 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4449 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4450 regTechConverted);
4451 try {
4452 consumer.accept(regTechConverted);
4453 } catch (RemoteException e) {
4454 // Ignore if the remote process is no longer available to call back.
4455 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4456 }
4457 });
4458 } finally {
4459 Binder.restoreCallingIdentity(token);
4460 }
4461 }
4462
shilu366312e2019-12-17 09:28:10 -08004463 /**
4464 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4465 * @param subId The subscription to use to check the configuration.
4466 * @param c The callback that will be used to send the result.
4467 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004468 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004469 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4470 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004471 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004472 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004473 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4474 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4475 "IMS not available on device.");
4476 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004477 final long token = Binder.clearCallingIdentity();
4478 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004479 int slotId = getSlotIndexOrException(subId);
4480 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004481
4482 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4483 if (controller != null) {
4484 ImsManager imsManager = controller.getImsManager(subId);
4485 if (imsManager != null) {
4486 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4487 } else {
4488 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4489 }
4490 } else {
4491 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4492 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004493 } catch (ImsException e) {
4494 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004495 } finally {
4496 Binder.restoreCallingIdentity(token);
4497 }
4498 }
4499
shilu366312e2019-12-17 09:28:10 -08004500 /**
4501 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4502 * @param subId The subscription to use to check the configuration.
4503 * @param c The callback that will be used to send the result.
4504 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004505 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004506 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004507 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004508 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004509 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4510 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4511 }
Meng Wangafbc5852019-09-19 17:37:13 -07004512
4513 final long token = Binder.clearCallingIdentity();
4514 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004515 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4516 if (controller != null) {
4517 ImsManager imsManager = controller.getImsManager(subId);
4518 if (imsManager != null) {
4519 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4520 } else {
4521 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4522 + " is inactive, ignoring unregister.");
4523 // If the ImsManager is not valid, just return, since the callback
4524 // will already have been removed internally.
4525 }
4526 }
Meng Wangafbc5852019-09-19 17:37:13 -07004527 } finally {
4528 Binder.restoreCallingIdentity(token);
4529 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004530 }
4531
4532 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004533 public boolean isCapable(int subId, int capability, int regTech) {
4534 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004535 final long token = Binder.clearCallingIdentity();
4536 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004537 int slotId = getSlotIndexOrException(subId);
4538 verifyImsMmTelConfiguredOrThrow(slotId);
4539 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4540 } catch (com.android.ims.ImsException e) {
4541 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4542 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004543 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004544 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4545 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004546 } finally {
4547 Binder.restoreCallingIdentity(token);
4548 }
4549 }
4550
4551 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004552 public boolean isAvailable(int subId, int capability, int regTech) {
4553 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004554 final long token = Binder.clearCallingIdentity();
4555 try {
4556 Phone phone = getPhone(subId);
4557 if (phone == null) return false;
4558 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004559 } catch (com.android.ims.ImsException e) {
4560 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4561 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004562 } finally {
4563 Binder.restoreCallingIdentity(token);
4564 }
4565 }
4566
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004567 /**
4568 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4569 * subscription.
4570 * @param subId The subscription to use to check the configuration.
4571 * @param callback The callback that will be used to send the result.
4572 * @param capability The MmTelFeature capability that will be used to send the result.
4573 * @param transportType The transport type of the MmTelFeature capability.
4574 */
4575 @Override
4576 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4577 int transportType) {
4578 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004579 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4580 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4581 "IMS not available on device.");
4582 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004583 final long token = Binder.clearCallingIdentity();
4584 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004585 int slotId = getSlotIndex(subId);
4586 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4587 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4588 + subId + "'");
4589 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4590 }
4591 verifyImsMmTelConfiguredOrThrow(slotId);
4592 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4593 transportType, aBoolean -> {
4594 try {
4595 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4596 } catch (RemoteException e) {
4597 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4598 + "running. Ignore");
4599 }
4600 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004601 } catch (ImsException e) {
4602 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004603 } finally {
4604 Binder.restoreCallingIdentity(token);
4605 }
4606 }
4607
shilu366312e2019-12-17 09:28:10 -08004608 /**
4609 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4610 * @param subId The subscription to use to check the configuration.
4611 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004612 @Override
4613 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004614 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004615 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004616
Brad Ebinger35c841c2018-10-01 10:40:55 -07004617 final long token = Binder.clearCallingIdentity();
4618 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004619 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004620 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004621 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004622 } catch (ImsException e) {
4623 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004624 } finally {
4625 Binder.restoreCallingIdentity(token);
4626 }
4627 }
4628
4629 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004630 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004632 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004633 final long identity = Binder.clearCallingIdentity();
4634 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004635 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004636 // This setting doesn't require an active ImsService connection, so do not verify. The
4637 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004638 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004639 } catch (ImsException e) {
4640 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004641 } finally {
4642 Binder.restoreCallingIdentity(identity);
4643 }
4644 }
4645
shilu366312e2019-12-17 09:28:10 -08004646 /**
4647 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4648 * @param subId The subscription to use to check the configuration.
4649 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004650 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004651 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004652 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004653 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004654 final long identity = Binder.clearCallingIdentity();
4655 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004656 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004657 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004658 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004659 } catch (ImsException e) {
4660 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004661 } finally {
4662 Binder.restoreCallingIdentity(identity);
4663 }
4664 }
4665
4666 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004667 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004668 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004669 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004670 final long identity = Binder.clearCallingIdentity();
4671 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004672 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004673 // This setting doesn't require an active ImsService connection, so do not verify. The
4674 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004675 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004676 } catch (ImsException e) {
4677 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004678 } finally {
4679 Binder.restoreCallingIdentity(identity);
4680 }
4681 }
4682
shilu366312e2019-12-17 09:28:10 -08004683 /**
4684 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4685 * @param subId The subscription to use to check the configuration.
4686 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004687 @Override
4688 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004689 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004690 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004691 final long identity = Binder.clearCallingIdentity();
4692 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004693 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004694 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004695 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004696 } catch (ImsException e) {
4697 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004698 } finally {
4699 Binder.restoreCallingIdentity(identity);
4700 }
4701 }
4702
4703 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004704 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004705 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004706 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004707 final long identity = Binder.clearCallingIdentity();
4708 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004709 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004710 // This setting doesn't require an active ImsService connection, so do not verify. The
4711 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004712 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004713 } catch (ImsException e) {
4714 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004715 } finally {
4716 Binder.restoreCallingIdentity(identity);
4717 }
4718 }
4719
shilu366312e2019-12-17 09:28:10 -08004720 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004721 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4722 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4723 * @param subId The subscription to use to check the configuration.
4724 */
4725 @Override
4726 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004727 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004728 mApp, subId, "isCrossSimCallingEnabledByUser");
4729 final long identity = Binder.clearCallingIdentity();
4730 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004731 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004732 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004733 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004734 } catch (ImsException e) {
4735 throw new ServiceSpecificException(e.getCode());
4736 } finally {
4737 Binder.restoreCallingIdentity(identity);
4738 }
4739 }
4740
4741 /**
4742 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4743 * Requires MODIFY_PHONE_STATE permission.
4744 * @param subId The subscription to use to check the configuration.
4745 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4746 * false otherwise
4747 */
4748 @Override
4749 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4750 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4751 "setCrossSimCallingEnabled");
4752 final long identity = Binder.clearCallingIdentity();
4753 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004754 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004755 // This setting doesn't require an active ImsService connection, so do not verify. The
4756 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004757 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004758 } catch (ImsException e) {
4759 throw new ServiceSpecificException(e.getCode());
4760 } finally {
4761 Binder.restoreCallingIdentity(identity);
4762 }
4763 }
4764
4765 /**
shilu366312e2019-12-17 09:28:10 -08004766 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4767 * @param subId The subscription to use to check the configuration.
4768 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004769 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004770
Brad Ebinger35c841c2018-10-01 10:40:55 -07004771 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004772 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004773 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004774 final long identity = Binder.clearCallingIdentity();
4775 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004776 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004777 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004778 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004779 } catch (ImsException e) {
4780 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004781 } finally {
4782 Binder.restoreCallingIdentity(identity);
4783 }
4784 }
4785
4786 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004787 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004789 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004790 final long identity = Binder.clearCallingIdentity();
4791 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004792 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004793 // This setting doesn't require an active ImsService connection, so do not verify. The
4794 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004795 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004796 } catch (ImsException e) {
4797 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004798 } finally {
4799 Binder.restoreCallingIdentity(identity);
4800 }
4801 }
4802
4803 @Override
4804 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4805 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4806 "setVoWiFiNonPersistent");
4807 final long identity = Binder.clearCallingIdentity();
4808 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004809 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004810 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004811 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004812 } catch (ImsException e) {
4813 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004814 } finally {
4815 Binder.restoreCallingIdentity(identity);
4816 }
4817 }
4818
shilu366312e2019-12-17 09:28:10 -08004819 /**
4820 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4821 * @param subId The subscription to use to check the configuration.
4822 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004823 @Override
4824 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004825 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004826 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004827 final long identity = Binder.clearCallingIdentity();
4828 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004829 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004830 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004831 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004832 } catch (ImsException e) {
4833 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004834 } finally {
4835 Binder.restoreCallingIdentity(identity);
4836 }
4837 }
4838
4839 @Override
4840 public void setVoWiFiModeSetting(int subId, int mode) {
4841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4842 "setVoWiFiModeSetting");
4843 final long identity = Binder.clearCallingIdentity();
4844 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004845 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004846 // This setting doesn't require an active ImsService connection, so do not verify. The
4847 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004848 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004849 } catch (ImsException e) {
4850 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004851 } finally {
4852 Binder.restoreCallingIdentity(identity);
4853 }
4854 }
4855
4856 @Override
4857 public int getVoWiFiRoamingModeSetting(int subId) {
4858 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4859 final long identity = Binder.clearCallingIdentity();
4860 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004861 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004862 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004863 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004864 } catch (ImsException e) {
4865 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004866 } finally {
4867 Binder.restoreCallingIdentity(identity);
4868 }
4869 }
4870
4871 @Override
4872 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4874 "setVoWiFiRoamingModeSetting");
4875 final long identity = Binder.clearCallingIdentity();
4876 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004877 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004878 // This setting doesn't require an active ImsService connection, so do not verify. The
4879 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004880 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004881 } catch (ImsException e) {
4882 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004883 } finally {
4884 Binder.restoreCallingIdentity(identity);
4885 }
4886 }
4887
4888 @Override
4889 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4890 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4891 "setRttCapabilityEnabled");
4892 final long identity = Binder.clearCallingIdentity();
4893 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004894 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004895 // This setting doesn't require an active ImsService connection, so do not verify. The
4896 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004897 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004898 } catch (ImsException e) {
4899 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004900 } finally {
4901 Binder.restoreCallingIdentity(identity);
4902 }
4903 }
4904
shilu366312e2019-12-17 09:28:10 -08004905 /**
4906 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4907 * @param subId The subscription to use to check the configuration.
4908 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004909 @Override
4910 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004911 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004912 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004913 final long identity = Binder.clearCallingIdentity();
4914 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004915 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004916 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004917 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004918 } catch (ImsException e) {
4919 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004920 } finally {
4921 Binder.restoreCallingIdentity(identity);
4922 }
4923 }
4924
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004925 @Override
4926 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4927 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004928
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004929 final long identity = Binder.clearCallingIdentity();
4930 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004931 if (!isImsAvailableOnDevice()) {
4932 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4933 "IMS not available on device.");
4934 }
4935 int slotId = getSlotIndexOrException(subId);
4936 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004937
4938 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4939 if (controller != null) {
4940 ImsManager imsManager = controller.getImsManager(subId);
4941 if (imsManager != null) {
4942 imsManager.addProvisioningCallbackForSubscription(callback, subId);
4943 } else {
4944 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4945 }
4946 } else {
4947 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4948 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004949 } catch (ImsException e) {
4950 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004951 } finally {
4952 Binder.restoreCallingIdentity(identity);
4953 }
4954 }
4955
4956 @Override
4957 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4958 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004959
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004960 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004961 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4962 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4963 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004964 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004965 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4966 if (controller != null) {
4967 ImsManager imsManager = controller.getImsManager(subId);
4968 if (imsManager != null) {
4969 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
4970 } else {
4971 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4972 + " is inactive, ignoring unregister.");
4973 // If the ImsManager is not valid, just return, since the callback will already
4974 // have been removed internally.
4975 }
4976 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004977 } finally {
4978 Binder.restoreCallingIdentity(identity);
4979 }
4980 }
4981
joonhunshincffb7fc2021-11-28 07:32:01 +00004982 @Override
4983 public void registerFeatureProvisioningChangedCallback(int subId,
4984 IFeatureProvisioningCallback callback) {
4985 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4986 mApp, subId, "registerFeatureProvisioningChangedCallback");
4987
4988 final long identity = Binder.clearCallingIdentity();
4989 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4990 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4991 }
4992
joonhunshin91bc1952022-04-29 08:47:15 +00004993 try {
4994 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4995 if (controller == null) {
4996 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4997 "Device does not support IMS");
4998 }
4999 controller.addFeatureProvisioningChangedCallback(subId, callback);
5000 } finally {
5001 Binder.restoreCallingIdentity(identity);
5002 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005003 }
5004
5005 @Override
5006 public void unregisterFeatureProvisioningChangedCallback(int subId,
5007 IFeatureProvisioningCallback callback) {
5008 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5009 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5010
5011 final long identity = Binder.clearCallingIdentity();
5012 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5013 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5014 }
5015
joonhunshin91bc1952022-04-29 08:47:15 +00005016 try {
5017 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5018 if (controller == null) {
5019 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5020 return;
5021 }
5022 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5023 } finally {
5024 Binder.restoreCallingIdentity(identity);
5025 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005026 }
allenwtsu99c623b2020-01-03 18:24:23 +08005027
5028 private void checkModifyPhoneStatePermission(int subId, String message) {
5029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5030 message);
5031 }
5032
allenwtsu99c623b2020-01-03 18:24:23 +08005033 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005034 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005035 boolean isProvisioned) {
5036 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5037
5038 final long identity = Binder.clearCallingIdentity();
5039 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005040 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5041 if (controller == null) {
5042 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5043 return;
5044 }
5045 controller.setRcsProvisioningStatusForCapability(
5046 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005047 } finally {
5048 Binder.restoreCallingIdentity(identity);
5049 }
allenwtsu99c623b2020-01-03 18:24:23 +08005050 }
5051
5052
5053 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005054 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5055 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5056 mApp, subId, "getRcsProvisioningStatusForCapability");
5057
allenwtsu99c623b2020-01-03 18:24:23 +08005058 final long identity = Binder.clearCallingIdentity();
5059 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005060 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5061 if (controller == null) {
5062 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5063
5064 // device does not support IMS, this method will return true always.
5065 return true;
5066 }
5067 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005068 } finally {
5069 Binder.restoreCallingIdentity(identity);
5070 }
5071 }
5072
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005073 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005074 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5075 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005076 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005077
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005078 final long identity = Binder.clearCallingIdentity();
5079 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005080 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5081 if (controller == null) {
5082 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5083 return;
5084 }
5085 controller.setImsProvisioningStatusForCapability(
5086 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005087 } finally {
5088 Binder.restoreCallingIdentity(identity);
5089 }
5090 }
5091
5092 @Override
5093 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005094 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5095 mApp, subId, "getProvisioningStatusForCapability");
5096
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005097 final long identity = Binder.clearCallingIdentity();
5098 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005099 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5100 if (controller == null) {
5101 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005102
joonhunshin91bc1952022-04-29 08:47:15 +00005103 // device does not support IMS, this method will return true always.
5104 return true;
5105 }
5106 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005107 } finally {
5108 Binder.restoreCallingIdentity(identity);
5109 }
5110 }
5111
5112 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005113 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5114 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5115 mApp, subId, "isProvisioningRequiredForCapability");
5116
5117 final long identity = Binder.clearCallingIdentity();
5118 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005119 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5120 if (controller == null) {
5121 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5122
5123 // device does not support IMS, this method will return false
5124 return false;
5125 }
5126 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005127 } finally {
5128 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005129 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005130 }
5131
5132 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005133 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5134 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5135 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005136
joonhunshincffb7fc2021-11-28 07:32:01 +00005137 final long identity = Binder.clearCallingIdentity();
5138 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005139 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5140 if (controller == null) {
5141 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5142
5143 // device does not support IMS, this method will return false
5144 return false;
5145 }
5146 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005147 } finally {
5148 Binder.restoreCallingIdentity(identity);
5149 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005150 }
5151
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005152 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005153 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005154 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5155 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5156 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005157 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5158 mApp, subId, "getImsProvisioningInt");
5159
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005160 final long identity = Binder.clearCallingIdentity();
5161 try {
5162 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005163 int slotId = getSlotIndex(subId);
5164 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5165 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5166 + subId + "' for key:" + key);
5167 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5168 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005169
joonhunshin91bc1952022-04-29 08:47:15 +00005170 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5171 if (controller == null) {
5172 loge("getImsProvisioningInt: Device does not support IMS");
5173
5174 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5175 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5176 }
5177 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005178 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5179 return retVal;
5180 }
5181
calvinpanb5a34062021-02-08 19:59:36 +08005182 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005183 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005184 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5185 + subId + "' for key:" + key);
5186 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005187 } finally {
5188 Binder.restoreCallingIdentity(identity);
5189 }
5190 }
5191
5192 @Override
5193 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005194 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5195 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5196 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005197 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5198 mApp, subId, "getImsProvisioningString");
5199
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005200 final long identity = Binder.clearCallingIdentity();
5201 try {
5202 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005203 int slotId = getSlotIndex(subId);
5204 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5205 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5206 + subId + "' for key:" + key);
5207 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5208 }
calvinpanb5a34062021-02-08 19:59:36 +08005209 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005210 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005211 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5212 + subId + "' for key:" + key);
5213 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005214 } finally {
5215 Binder.restoreCallingIdentity(identity);
5216 }
5217 }
5218
5219 @Override
5220 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005221 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5222 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5223 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005224 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5225 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005226
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005227 final long identity = Binder.clearCallingIdentity();
5228 try {
5229 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005230 int slotId = getSlotIndex(subId);
5231 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5232 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5233 + subId + "' for key:" + key);
5234 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5235 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005236
joonhunshin91bc1952022-04-29 08:47:15 +00005237 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5238 if (controller == null) {
5239 loge("setImsProvisioningInt: Device does not support IMS");
5240
5241 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5242 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5243 }
5244 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005245 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5246 return retVal;
5247 }
5248
calvinpanb5a34062021-02-08 19:59:36 +08005249 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5250 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005251 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005252 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005253 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005254 } finally {
5255 Binder.restoreCallingIdentity(identity);
5256 }
5257 }
5258
5259 @Override
5260 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005261 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5262 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5263 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005264 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5265 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005266 final long identity = Binder.clearCallingIdentity();
5267 try {
5268 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005269 int slotId = getSlotIndex(subId);
5270 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5271 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5272 + subId + "' for key:" + key);
5273 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5274 }
calvinpanb5a34062021-02-08 19:59:36 +08005275 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5276 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005277 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005278 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005279 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005280 } finally {
5281 Binder.restoreCallingIdentity(identity);
5282 }
5283 }
5284
Brad Ebinger919631e2021-06-02 17:46:35 -07005285 /**
5286 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5287 * for the given slot ID or no ImsResolver instance has been created.
5288 * @param slotId The slot ID that the IMS service is created for.
5289 * @throws ImsException If there is no ImsService configured for this slot.
5290 */
5291 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5292 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5293 ImsFeature.FEATURE_MMTEL)) {
5294 throw new ImsException("This subscription does not support MMTEL over IMS",
5295 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5296 }
5297 }
5298
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005299 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005300 int slotId = SubscriptionManager.getSlotIndex(subId);
5301 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005302 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5303 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005304 }
5305 return slotId;
5306 }
5307
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005308 private int getSlotIndex(int subId) {
5309 int slotId = SubscriptionManager.getSlotIndex(subId);
5310 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5311 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5312 }
5313 return slotId;
5314 }
5315
Wink Saville36469e72014-06-11 15:17:00 -07005316 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005317 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005318 */
5319 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005320 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5321 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005322 try {
5323 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5324 } catch (SecurityException se) {
5325 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5326 throw new SecurityException("Package " + callingPackage + " does not belong to "
5327 + Binder.getCallingUid());
5328 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005329 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005330 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005331 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005332 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005333 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005334 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005335 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005336 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5337 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005338
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005339 final long identity = Binder.clearCallingIdentity();
5340 try {
5341 final Phone phone = getPhone(subId);
5342 if (phone != null) {
5343 return phone.getServiceState().getDataNetworkType();
5344 } else {
5345 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5346 }
5347 } finally {
5348 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005349 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005350 }
5351
5352 /**
5353 * Returns the data network type
5354 */
5355 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005356 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005357 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005358 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005359 }
5360
5361 /**
5362 * Returns the data network type for a subId
5363 */
5364 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005365 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5366 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005367 String functionName = "getDataNetworkTypeForSubscriber";
5368 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5369 mApp, functionName)) {
5370 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5371 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5372 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5373 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005374 }
5375
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005376 final long identity = Binder.clearCallingIdentity();
5377 try {
5378 final Phone phone = getPhone(subId);
5379 if (phone != null) {
5380 return phone.getServiceState().getDataNetworkType();
5381 } else {
5382 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5383 }
5384 } finally {
5385 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005386 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005387 }
5388
5389 /**
Wink Saville36469e72014-06-11 15:17:00 -07005390 * Returns the Voice network type for a subId
5391 */
5392 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005393 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5394 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005395 String functionName = "getVoiceNetworkTypeForSubscriber";
5396 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5397 mApp, functionName)) {
5398 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5399 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5400 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5401 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005402 }
5403
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005404 final long identity = Binder.clearCallingIdentity();
5405 try {
5406 final Phone phone = getPhone(subId);
5407 if (phone != null) {
5408 return phone.getServiceState().getVoiceNetworkType();
5409 } else {
5410 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5411 }
5412 } finally {
5413 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005414 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005415 }
5416
5417 /**
5418 * @return true if a ICC card is present
5419 */
5420 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005421 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005422 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005423 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005424 }
5425
5426 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005427 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005428 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005429 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005430 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005431 final long identity = Binder.clearCallingIdentity();
5432 try {
5433 final Phone phone = PhoneFactory.getPhone(slotIndex);
5434 if (phone != null) {
5435 return phone.getIccCard().hasIccCard();
5436 } else {
5437 return false;
5438 }
5439 } finally {
5440 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005442 }
5443
5444 /**
5445 * Return if the current radio is LTE on CDMA. This
5446 * is a tri-state return value as for a period of time
5447 * the mode may be unknown.
5448 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005449 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005450 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005451 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005452 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005453 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005454 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5455 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5456 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005457 }
5458
Sanket Padawe356d7632015-06-22 14:03:32 -07005459 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005460 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5461 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005462 try {
5463 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5464 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005465 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5466 }
5467
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005468 final long identity = Binder.clearCallingIdentity();
5469 try {
5470 final Phone phone = getPhone(subId);
5471 if (phone == null) {
5472 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5473 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005474 return TelephonyProperties.lte_on_cdma_device()
5475 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005476 }
5477 } finally {
5478 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005479 }
Wink Saville36469e72014-06-11 15:17:00 -07005480 }
5481
Wink Saville36469e72014-06-11 15:17:00 -07005482 /**
5483 * {@hide}
5484 * Returns Default subId, 0 in the case of single standby.
5485 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005486 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005487 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005488 }
5489
Shishir Agrawala9f32182016-04-12 12:00:16 -07005490 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005491 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005492 }
5493
Wink Savilleb564aae2014-10-23 10:18:09 -07005494 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005495 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005496 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005497
Pengquan Menge92a50d2018-09-21 15:54:48 -07005498 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08005499 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08005500 return getSubscriptionManagerService().isActiveSubId(subId,
Jack Yu285100e2022-12-02 22:48:35 -08005501 mApp.getOpPackageName(), mApp.getFeatureId());
5502 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005503 return mSubscriptionController.isActiveSubId(subId);
5504 }
5505
Ihab Awadf2177b72013-11-25 13:33:23 -08005506 /**
5507 * @see android.telephony.TelephonyManager.WifiCallingChoices
5508 */
5509 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005510 final long identity = Binder.clearCallingIdentity();
5511 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005512 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005513 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5514 getWhenToMakeWifiCallsDefaultPreference());
5515 } finally {
5516 Binder.restoreCallingIdentity(identity);
5517 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005518 }
5519
5520 /**
5521 * @see android.telephony.TelephonyManager.WifiCallingChoices
5522 */
5523 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005524 final long identity = Binder.clearCallingIdentity();
5525 try {
5526 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005527 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005528 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5529 } finally {
5530 Binder.restoreCallingIdentity(identity);
5531 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005532 }
5533
Sailesh Nepald1e68152013-12-12 19:08:02 -08005534 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005535 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005536 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005537 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005538
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005539 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5540 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5541 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005542 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005543 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005544 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005545 }
5546 return PhoneFactory.getPhone(phoneId);
5547 }
5548
Shishir Agrawal566b7612013-10-28 14:41:00 -07005549 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005550 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005551 @NonNull IccLogicalChannelRequest request) {
5552 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5553 /*message=*/ "iccOpenLogicalChannel");
5554
5555 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5556 // Verify that the callingPackage in the request belongs to the calling UID
5557 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5558
5559 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005560 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005561
Rambo Wanga1782702021-11-10 20:15:19 -08005562 private Phone getPhoneFromValidIccLogicalChannelRequest(
5563 @NonNull IccLogicalChannelRequest request, String message) {
5564 Phone phone;
5565 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5566 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5567 mApp, request.subId, message);
5568 phone = getPhoneFromSubId(request.subId);
5569 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5570 enforceModifyPermission();
5571 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5572 } else {
5573 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005574 }
Rambo Wanga1782702021-11-10 20:15:19 -08005575 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005576 }
5577
5578 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005579 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005580 final long identity = Binder.clearCallingIdentity();
5581 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005582 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005584 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5585 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005586 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5587 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005588 loge("The calling package is not allowed to access ISD-R.");
5589 throw new SecurityException(
5590 "The calling package is not allowed to access ISD-R.");
5591 }
Derek Tan740e1672017-06-27 14:56:27 -07005592 }
Derek Tan740e1672017-06-27 14:56:27 -07005593
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005594 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005595 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5596 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005597 return response;
5598 } finally {
5599 Binder.restoreCallingIdentity(identity);
5600 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005601 }
5602
5603 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005604 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5605 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5606 /*message=*/"iccCloseLogicalChannel");
5607
5608 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5609
5610 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005611 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005612
Rambo Wanga1782702021-11-10 20:15:19 -08005613 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5614 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005615 // before this feature is enabled, this API should only return false if
5616 // the operation fails instead of throwing runtime exception for
5617 // backward-compatibility.
5618 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5619 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005620 final long identity = Binder.clearCallingIdentity();
5621 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005622 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005623 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005624 }
Chen Xue9d737e2022-01-01 23:41:31 -08005625 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005626 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005627 Boolean success = false;
5628 if (result instanceof RuntimeException) {
5629 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005630 if (shouldThrowExceptionOnFailure) {
5631 throw (RuntimeException) result;
5632 } else {
5633 return false;
5634 }
Chen Xue9d737e2022-01-01 23:41:31 -08005635 } else if (result instanceof Boolean) {
5636 success = (Boolean) result;
5637 } else {
5638 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5639 }
Rambo Wanga1782702021-11-10 20:15:19 -08005640 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 return success;
5642 } finally {
5643 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005644 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005645 }
5646
5647 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005648 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005649 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5651 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005652 if (DBG) {
5653 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5654 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5655 + p3 + " data=" + data);
5656 }
5657 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5658 command, p1, p2, p3, data);
5659 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005660
Jordan Liu4c733742019-02-28 12:03:40 -08005661 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005662 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005663 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005664 enforceModifyPermission();
5665 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005666 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005667 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5668 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005669 }
5670 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005671 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5672 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005673 }
5674
5675 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5676 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677 final long identity = Binder.clearCallingIdentity();
5678 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005679 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005680 return "";
5681 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005682
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005683 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005684 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5685 null /* workSource */);
5686 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005687
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005688 // Append the returned status code to the end of the response payload.
5689 String s = Integer.toHexString(
5690 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5691 if (response.payload != null) {
5692 s = IccUtils.bytesToHexString(response.payload) + s;
5693 }
5694 return s;
5695 } finally {
5696 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005697 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005698 }
Jake Hambye994d462014-02-03 13:10:13 -08005699
Evan Charltonc66da362014-05-16 14:06:40 -07005700 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005701 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5702 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5704 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005705 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005706 if (DBG) {
5707 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5708 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5709 }
5710 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5711 cla, command, p1, p2, p3, data);
5712 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005713
Jordan Liu4c733742019-02-28 12:03:40 -08005714 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005715 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005716 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005717 enforceModifyPermission();
5718 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5719 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005720 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005721 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5722 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005723 }
5724
5725 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005726 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5727 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005728 }
5729
5730 // open APDU basic channel assuming the caller has sufficient permissions
5731 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5732 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005733 final long identity = Binder.clearCallingIdentity();
5734 try {
5735 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5736 && TextUtils.equals(ISDR_AID, data)) {
5737 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005738 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5739 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005740 if (bestComponent == null
5741 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5742 loge("The calling package is not allowed to select ISD-R.");
5743 throw new SecurityException(
5744 "The calling package is not allowed to select ISD-R.");
5745 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005746 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005747
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005748 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005749 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5750 null /* workSource */);
5751 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005752
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005753 // Append the returned status code to the end of the response payload.
5754 String s = Integer.toHexString(
5755 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5756 if (response.payload != null) {
5757 s = IccUtils.bytesToHexString(response.payload) + s;
5758 }
5759 return s;
5760 } finally {
5761 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005762 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005763 }
5764
5765 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005766 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005767 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5769 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005770
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005771 final long identity = Binder.clearCallingIdentity();
5772 try {
5773 if (DBG) {
5774 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5775 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5776 }
5777
5778 IccIoResult response =
5779 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5780 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5781 subId);
5782
5783 if (DBG) {
5784 log("Exchange SIM_IO [R]" + response);
5785 }
5786
5787 byte[] result = null;
5788 int length = 2;
5789 if (response.payload != null) {
5790 length = 2 + response.payload.length;
5791 result = new byte[length];
5792 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5793 } else {
5794 result = new byte[length];
5795 }
5796
5797 result[length - 1] = (byte) response.sw2;
5798 result[length - 2] = (byte) response.sw1;
5799 return result;
5800 } finally {
5801 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005802 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005803 }
5804
Nathan Haroldb3014052017-01-25 15:57:32 -08005805 /**
5806 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5807 * on a particular subscription
5808 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005809 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5810 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005811 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005812 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005813 return null;
5814 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005815
5816 final long identity = Binder.clearCallingIdentity();
5817 try {
5818 if (appType != TelephonyManager.APPTYPE_USIM
5819 && appType != TelephonyManager.APPTYPE_SIM) {
5820 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5821 return null;
5822 }
5823 Object response = sendRequest(
5824 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5825 if (response instanceof String[]) {
5826 return (String[]) response;
5827 }
yincheng zhao2737e882019-09-06 17:06:54 -07005828 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005829 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005830 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005831 } finally {
5832 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005833 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005834 }
5835
yincheng zhao2737e882019-09-06 17:06:54 -07005836 /**
5837 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5838 * subscription.
5839 *
5840 * @param subId the id of the subscription.
5841 * @param appType the uicc app type, must be USIM or SIM.
5842 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5843 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005844 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005845 * @return number of fplmns that is successfully written to the SIM.
5846 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005847 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5848 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5850 mApp, subId, "setForbiddenPlmns");
5851
yincheng zhao2737e882019-09-06 17:06:54 -07005852 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5853 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5854 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5855 }
5856 if (fplmns == null) {
5857 throw new IllegalArgumentException("Fplmn List provided is null");
5858 }
5859 for (String fplmn : fplmns) {
5860 if (!CellIdentity.isValidPlmn(fplmn)) {
5861 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5862 }
5863 }
5864 final long identity = Binder.clearCallingIdentity();
5865 try {
5866 Object response = sendRequest(
5867 CMD_SET_FORBIDDEN_PLMNS,
5868 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5869 subId);
5870 return (int) response;
5871 } finally {
5872 Binder.restoreCallingIdentity(identity);
5873 }
5874 }
5875
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005876 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005877 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5879 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005880
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005881 final long identity = Binder.clearCallingIdentity();
5882 try {
5883 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5884 if (response.payload == null) {
5885 return "";
5886 }
Evan Charltonc66da362014-05-16 14:06:40 -07005887
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005888 // Append the returned status code to the end of the response payload.
5889 String s = Integer.toHexString(
5890 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5891 s = IccUtils.bytesToHexString(response.payload) + s;
5892 return s;
5893 } finally {
5894 Binder.restoreCallingIdentity(identity);
5895 }
Evan Charltonc66da362014-05-16 14:06:40 -07005896 }
5897
Jake Hambye994d462014-02-03 13:10:13 -08005898 /**
5899 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5900 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5901 *
5902 * @param itemID the ID of the item to read
5903 * @return the NV item as a String, or null on error.
5904 */
5905 @Override
5906 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005907 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005908 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5909 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005910
5911 final long identity = Binder.clearCallingIdentity();
5912 try {
5913 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005914 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005915 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5916 return value;
5917 } finally {
5918 Binder.restoreCallingIdentity(identity);
5919 }
Jake Hambye994d462014-02-03 13:10:13 -08005920 }
5921
5922 /**
5923 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5924 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5925 *
5926 * @param itemID the ID of the item to read
5927 * @param itemValue the value to write, as a String
5928 * @return true on success; false on any failure
5929 */
5930 @Override
5931 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005932 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005933 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5934 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005935
5936 final long identity = Binder.clearCallingIdentity();
5937 try {
5938 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5939 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005940 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005941 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5942 return success;
5943 } finally {
5944 Binder.restoreCallingIdentity(identity);
5945 }
Jake Hambye994d462014-02-03 13:10:13 -08005946 }
5947
5948 /**
5949 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5950 * Used for device configuration by some CDMA operators.
5951 *
5952 * @param preferredRoamingList byte array containing the new PRL
5953 * @return true on success; false on any failure
5954 */
5955 @Override
5956 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005957 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5958 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005959
5960 final long identity = Binder.clearCallingIdentity();
5961 try {
5962 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5963 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5964 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5965 return success;
5966 } finally {
5967 Binder.restoreCallingIdentity(identity);
5968 }
Jake Hambye994d462014-02-03 13:10:13 -08005969 }
5970
5971 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005972 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005973 * Used for device configuration by some CDMA operators.
5974 *
chen xu6dac5ab2018-10-26 17:39:23 -07005975 * @param slotIndex - device slot.
5976 *
Jake Hambye994d462014-02-03 13:10:13 -08005977 * @return true on success; false on any failure
5978 */
5979 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005980 public boolean resetModemConfig(int slotIndex) {
5981 Phone phone = PhoneFactory.getPhone(slotIndex);
5982 if (phone != null) {
5983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5984 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985
chen xu6dac5ab2018-10-26 17:39:23 -07005986 final long identity = Binder.clearCallingIdentity();
5987 try {
5988 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5989 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5990 return success;
5991 } finally {
5992 Binder.restoreCallingIdentity(identity);
5993 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994 }
chen xu6dac5ab2018-10-26 17:39:23 -07005995 return false;
5996 }
5997
5998 /**
5999 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6000 *
6001 * @param slotIndex - device slot.
6002 *
6003 * @return true on success; false on any failure
6004 */
6005 @Override
6006 public boolean rebootModem(int slotIndex) {
6007 Phone phone = PhoneFactory.getPhone(slotIndex);
6008 if (phone != null) {
6009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6010 mApp, phone.getSubId(), "rebootModem");
6011
6012 final long identity = Binder.clearCallingIdentity();
6013 try {
6014 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6015 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6016 return success;
6017 } finally {
6018 Binder.restoreCallingIdentity(identity);
6019 }
6020 }
6021 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006022 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006023
Brad Ebinger51f743a2017-01-23 13:50:20 -08006024 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006025 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6026 * {@link #disableIms(int)}.
6027 * @param slotIndex device slot.
6028 */
6029 public void resetIms(int slotIndex) {
6030 enforceModifyPermission();
6031
6032 final long identity = Binder.clearCallingIdentity();
6033 try {
6034 if (mImsResolver == null) {
6035 // may happen if the does not support IMS.
6036 return;
6037 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006038 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006039 } finally {
6040 Binder.restoreCallingIdentity(identity);
6041 }
6042 }
6043
6044 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006045 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6046 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006047 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006048 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006049 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006050
6051 final long identity = Binder.clearCallingIdentity();
6052 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006053 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006054 // may happen if the device does not support IMS.
6055 return;
6056 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006057 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006058 } finally {
6059 Binder.restoreCallingIdentity(identity);
6060 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006061 }
6062
6063 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006064 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6065 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006066 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006067 public void disableIms(int slotId) {
6068 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006069
6070 final long identity = Binder.clearCallingIdentity();
6071 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006072 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006073 // may happen if the device does not support IMS.
6074 return;
6075 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006076 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006077 } finally {
6078 Binder.restoreCallingIdentity(identity);
6079 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006080 }
6081
6082 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006083 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6084 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006085 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006086 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006087 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006088 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006089
6090 final long identity = Binder.clearCallingIdentity();
6091 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006092 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006093 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6094 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006095 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006096 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006097 } finally {
6098 Binder.restoreCallingIdentity(identity);
6099 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006100 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006101 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006102 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6103 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006104 @Override
6105 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006106 enforceModifyPermission();
6107
6108 final long identity = Binder.clearCallingIdentity();
6109 try {
6110 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006111 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006112 } finally {
6113 Binder.restoreCallingIdentity(identity);
6114 }
6115 }
6116
6117 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006118 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006119 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006120 */
6121 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6122 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006123
6124 final long identity = Binder.clearCallingIdentity();
6125 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006126 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006127 // may happen if the device does not support IMS.
6128 return null;
6129 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006130 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006131 } finally {
6132 Binder.restoreCallingIdentity(identity);
6133 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006134 }
6135
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006136 /**
6137 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006138 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006139 */
6140 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6141 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006142
6143 final long identity = Binder.clearCallingIdentity();
6144 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006145 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006146 // may happen if the device does not support IMS.
6147 return null;
6148 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006149 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006150 } finally {
6151 Binder.restoreCallingIdentity(identity);
6152 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006153 }
6154
Brad Ebinger884c07b2018-02-15 16:17:40 -08006155 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006156 * Sets the ImsService Package Name that Telephony will bind to.
6157 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006158 * @param slotIndex the slot ID that the ImsService should bind for.
6159 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006160 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006161 * @param featureTypes An integer array of feature types associated with a packageName.
6162 * @param packageName The name of the package that the current configuration will be replaced
6163 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006164 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006165 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006166 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6167 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006168 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006169 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006170 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006171
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006172 final long identity = Binder.clearCallingIdentity();
6173 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006174 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006175 // may happen if the device does not support IMS.
6176 return false;
6177 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006178 Map<Integer, String> featureConfig = new HashMap<>();
6179 for (int featureType : featureTypes) {
6180 featureConfig.put(featureType, packageName);
6181 }
6182 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6183 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006184 } finally {
6185 Binder.restoreCallingIdentity(identity);
6186 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006187 }
6188
6189 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006190 * Clears any carrier ImsService overrides for the slot index specified that were previously
6191 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6192 *
6193 * This should only be used for testing.
6194 *
6195 * @param slotIndex the slot ID that the ImsService should bind for.
6196 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6197 */
6198 @Override
6199 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006200 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6201 "clearCarrierImsServiceOverride");
6202 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006203 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006204
6205 final long identity = Binder.clearCallingIdentity();
6206 try {
6207 if (mImsResolver == null) {
6208 // may happen if the device does not support IMS.
6209 return false;
6210 }
6211 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6212 } finally {
6213 Binder.restoreCallingIdentity(identity);
6214 }
6215 }
6216
6217 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006218 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006219 *
6220 * @param slotId The slot that the ImsService is associated with.
6221 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6222 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006223 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006224 * @return the package name of the ImsService configuration.
6225 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006226 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6227 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006228 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006229 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6230 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006231
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006232 final long identity = Binder.clearCallingIdentity();
6233 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006234 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006235 // may happen if the device does not support IMS.
6236 return "";
6237 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006238 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006239 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6240 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006241 } finally {
6242 Binder.restoreCallingIdentity(identity);
6243 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006244 }
6245
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006246 /**
6247 * Get the MmTelFeature state associated with the requested subscription id.
6248 * @param subId The subscription that the MmTelFeature is associated with.
6249 * @param callback A callback with an integer containing the
6250 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6251 */
6252 @Override
6253 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6254 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006255 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6256 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6257 "IMS not available on device.");
6258 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006259 final long token = Binder.clearCallingIdentity();
6260 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006261 int slotId = getSlotIndex(subId);
6262 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6263 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6264 + subId + "'");
6265 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6266 }
6267 verifyImsMmTelConfiguredOrThrow(slotId);
6268 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6269 try {
6270 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6271 } catch (RemoteException e) {
6272 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6273 + "Ignore");
6274 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006275 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006276 } catch (ImsException e) {
6277 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006278 } finally {
6279 Binder.restoreCallingIdentity(token);
6280 }
6281 }
6282
Daniel Brightbb5840b2021-01-12 15:48:18 -08006283 /**
6284 * Sets the ims registration state on all valid {@link Phone}s.
6285 */
6286 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006287 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006288
6289 final long identity = Binder.clearCallingIdentity();
6290 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006291 // NOTE: Before S, this method only set the default phone.
6292 for (final Phone phone : PhoneFactory.getPhones()) {
6293 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6294 phone.setImsRegistrationState(registered);
6295 }
6296 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006297 } finally {
6298 Binder.restoreCallingIdentity(identity);
6299 }
Wink Saville36469e72014-06-11 15:17:00 -07006300 }
6301
6302 /**
Stuart Scott54788802015-03-30 13:18:01 -07006303 * Set the network selection mode to automatic.
6304 *
6305 */
6306 @Override
6307 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6309 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006310
6311 final long identity = Binder.clearCallingIdentity();
6312 try {
shilufc958392020-01-20 11:36:01 -08006313 if (!isActiveSubscription(subId)) {
6314 return;
6315 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006316 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006317 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6318 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006319 } finally {
6320 Binder.restoreCallingIdentity(identity);
6321 }
Stuart Scott54788802015-03-30 13:18:01 -07006322 }
6323
Jack Yud10cdd42020-09-28 20:28:01 -07006324 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006325 * Ask the radio to connect to the input network and change selection mode to manual.
6326 *
6327 * @param subId the id of the subscription.
6328 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6329 * the operator to attach to.
6330 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6331 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6332 * normal network selection next time.
6333 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006334 */
6335 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006336 public boolean setNetworkSelectionModeManual(
6337 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006338 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6339 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006340
Jack Yu285100e2022-12-02 22:48:35 -08006341 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006342 if (!isActiveSubscription(subId)) {
6343 return false;
6344 }
6345
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006346 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006347 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006348 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006349 if (DBG) {
6350 log("setNetworkSelectionModeManual: subId: " + subId
6351 + " operator: " + operatorInfo);
6352 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6354 } finally {
6355 Binder.restoreCallingIdentity(identity);
6356 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006357 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006358 /**
shilu84f6e8b2019-12-19 13:58:01 -08006359 * Get the manual network selection
6360 *
6361 * @param subId the id of the subscription.
6362 *
6363 * @return the previously saved user selected PLMN
6364 */
6365 @Override
6366 public String getManualNetworkSelectionPlmn(int subId) {
6367 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006368 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6369 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006370
6371 final long identity = Binder.clearCallingIdentity();
6372 try {
6373 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006374 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006375 }
6376
6377 final Phone phone = getPhone(subId);
6378 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006379 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006380 }
6381 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6382 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006383 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006384 } finally {
6385 Binder.restoreCallingIdentity(identity);
6386 }
6387 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006388
6389 /**
6390 * Scans for available networks.
6391 */
6392 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006393 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6394 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6396 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006397 LocationAccessPolicy.LocationPermissionResult locationResult =
6398 LocationAccessPolicy.checkLocationPermission(mApp,
6399 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6400 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006401 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006402 .setCallingPid(Binder.getCallingPid())
6403 .setCallingUid(Binder.getCallingUid())
6404 .setMethod("getCellNetworkScanResults")
6405 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006406 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6407 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006408 .build());
6409 switch (locationResult) {
6410 case DENIED_HARD:
6411 throw new SecurityException("Not allowed to access scan results -- location");
6412 case DENIED_SOFT:
6413 return null;
6414 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006415
Pengquan Menga1bb6272018-09-06 09:59:22 -07006416 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417 try {
6418 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006419 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006420 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006421 } finally {
6422 Binder.restoreCallingIdentity(identity);
6423 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006424 }
6425
6426 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006427 * Get the call forwarding info, given the call forwarding reason.
6428 */
6429 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006430 public void getCallForwarding(int subId, int callForwardingReason,
6431 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006432 enforceReadPrivilegedPermission("getCallForwarding");
6433 long identity = Binder.clearCallingIdentity();
6434 try {
6435 if (DBG) {
6436 log("getCallForwarding: subId " + subId
6437 + " callForwardingReason" + callForwardingReason);
6438 }
Hall Liu27d24262020-09-18 19:04:59 -07006439
6440 Phone phone = getPhone(subId);
6441 if (phone == null) {
6442 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006443 callback.onError(
6444 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006445 } catch (RemoteException e) {
6446 // ignore
6447 }
6448 return;
6449 }
6450
6451 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6452 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6453 @Override
6454 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6455 try {
6456 callback.onCallForwardingInfoAvailable(info);
6457 } catch (RemoteException e) {
6458 // ignore
6459 }
6460 }
6461
6462 @Override
6463 public void onError(int error) {
6464 try {
6465 callback.onError(error);
6466 } catch (RemoteException e) {
6467 // ignore
6468 }
6469 }
6470 });
6471 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006472 } finally {
6473 Binder.restoreCallingIdentity(identity);
6474 }
6475 }
6476
6477 /**
6478 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6479 * reason, the number to forward, and the timeout before the forwarding is attempted.
6480 */
6481 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006482 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6483 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006484 enforceModifyPermission();
6485 long identity = Binder.clearCallingIdentity();
6486 try {
6487 if (DBG) {
6488 log("setCallForwarding: subId " + subId
6489 + " callForwardingInfo" + callForwardingInfo);
6490 }
Hall Liu27d24262020-09-18 19:04:59 -07006491
6492 Phone phone = getPhone(subId);
6493 if (phone == null) {
6494 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006495 callback.accept(
6496 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006497 } catch (RemoteException e) {
6498 // ignore
6499 }
6500 return;
6501 }
6502
6503 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6504 FunctionalUtils.ignoreRemoteException(callback::accept));
6505
6506 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006507 } finally {
6508 Binder.restoreCallingIdentity(identity);
6509 }
6510 }
6511
6512 /**
Hall Liu27d24262020-09-18 19:04:59 -07006513 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006514 */
6515 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006516 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006517 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006518 long identity = Binder.clearCallingIdentity();
6519 try {
Hall Liu27d24262020-09-18 19:04:59 -07006520 Phone phone = getPhone(subId);
6521 if (phone == null) {
6522 try {
6523 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6524 } catch (RemoteException e) {
6525 // ignore
6526 }
6527 return;
6528 }
SongFerngWang0e767992021-03-31 22:08:45 +08006529 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6530 PersistableBundle c = configManager.getConfigForSubId(subId);
6531 boolean requireUssd = c.getBoolean(
6532 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006533
Shuo Qian4a594052020-01-23 11:59:30 -08006534 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006535 if (requireUssd) {
6536 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6537 getSubscriptionCarrierId(subId));
6538 String newUssdCommand = "";
6539 try {
6540 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006541 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006542 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6543 } catch (NullPointerException e) {
6544 loge("Failed to generate USSD number" + e);
6545 }
6546 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6547 mMainThreadHandler, callback, carrierXmlParser,
6548 CarrierXmlParser.SsEntry.SSAction.QUERY);
6549 final String ussdCommand = newUssdCommand;
6550 Executors.newSingleThreadExecutor().execute(() -> {
6551 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6552 });
6553 } else {
6554 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6555 callback::accept);
6556 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6557 }
Shuo Qian4a594052020-01-23 11:59:30 -08006558 } finally {
6559 Binder.restoreCallingIdentity(identity);
6560 }
6561 }
6562
6563 /**
Hall Liu27d24262020-09-18 19:04:59 -07006564 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006565 */
6566 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006567 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006568 enforceModifyPermission();
6569 long identity = Binder.clearCallingIdentity();
6570 try {
Hall Liu27d24262020-09-18 19:04:59 -07006571 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6572
6573 Phone phone = getPhone(subId);
6574 if (phone == null) {
6575 try {
6576 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6577 } catch (RemoteException e) {
6578 // ignore
6579 }
6580 return;
6581 }
6582
SongFerngWang0e767992021-03-31 22:08:45 +08006583 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6584 PersistableBundle c = configManager.getConfigForSubId(subId);
6585 boolean requireUssd = c.getBoolean(
6586 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006587
SongFerngWang0e767992021-03-31 22:08:45 +08006588 if (DBG) log("getCallWaitingStatus: subId " + subId);
6589 if (requireUssd) {
6590 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6591 getSubscriptionCarrierId(subId));
6592 CarrierXmlParser.SsEntry.SSAction ssAction =
6593 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6594 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6595 String newUssdCommand = "";
6596 try {
6597 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006598 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006599 .makeCommand(ssAction, null);
6600 } catch (NullPointerException e) {
6601 loge("Failed to generate USSD number" + e);
6602 }
6603 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6604 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6605 final String ussdCommand = newUssdCommand;
6606 Executors.newSingleThreadExecutor().execute(() -> {
6607 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6608 });
6609 } else {
6610 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6611 FunctionalUtils.ignoreRemoteException(callback::accept));
6612
6613 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6614 }
Shuo Qian4a594052020-01-23 11:59:30 -08006615 } finally {
6616 Binder.restoreCallingIdentity(identity);
6617 }
6618 }
6619
6620 /**
yinxub1bed742017-04-17 11:45:04 -07006621 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006622 *
yinxub1bed742017-04-17 11:45:04 -07006623 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006624 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6625 * location related information which will be sent if the caller already possess
6626 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006627 * @param request contains the radio access networks with bands/channels to scan
6628 * @param messenger callback messenger for scan results or errors
6629 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006630 * @return the id of the requested scan which can be used to stop the scan.
6631 */
6632 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006633 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6634 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006635 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6637 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006638 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006639 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6640 if (!renounceFineLocationAccess) {
6641 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006642 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6643 .setCallingPackage(callingPackage)
6644 .setCallingFeatureId(callingFeatureId)
6645 .setCallingPid(Binder.getCallingPid())
6646 .setCallingUid(Binder.getCallingUid())
6647 .setMethod("requestNetworkScan")
6648 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6649 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6650 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6651 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006652 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006653 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006654 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6655 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006656 if (e != null) {
6657 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6658 throw e;
6659 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006660 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006661 return TelephonyScanManager.INVALID_SCAN_ID;
6662 }
6663 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006664 }
Hall Liu912dfd32019-04-25 14:02:26 -07006665 int callingUid = Binder.getCallingUid();
6666 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006667 final long identity = Binder.clearCallingIdentity();
6668 try {
6669 return mNetworkScanRequestTracker.startNetworkScan(
Ling Mac28f0212023-03-24 16:07:15 -07006670 renounceFineLocationAccess, request, messenger, binder,
6671 getPhoneFromSubIdOrDefault(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006672 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006673 } finally {
6674 Binder.restoreCallingIdentity(identity);
6675 }
yinxu504e1392017-04-12 16:03:22 -07006676 }
6677
Hall Liub2ac8ef2019-02-28 15:56:23 -08006678 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006679 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006680 boolean hasCarrierPriv;
6681 final long identity = Binder.clearCallingIdentity();
6682 try {
6683 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6684 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6685 } finally {
6686 Binder.restoreCallingIdentity(identity);
6687 }
Hall Liu558027f2019-05-15 19:14:05 -07006688 boolean hasNetworkScanPermission =
6689 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006690 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07006691
6692 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6693 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6694 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006695 }
6696
6697 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6698 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006699 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6700 return new SecurityException("Specific channels must not be"
6701 + " scanned without location access.");
6702 }
6703 }
6704 }
6705
Hall Liub2ac8ef2019-02-28 15:56:23 -08006706 return null;
6707 }
6708
yinxu504e1392017-04-12 16:03:22 -07006709 /**
6710 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006711 *
6712 * @param subId id of the subscription
6713 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006714 */
6715 @Override
6716 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006717 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6718 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006719
Hall Liu912dfd32019-04-25 14:02:26 -07006720 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006721 final long identity = Binder.clearCallingIdentity();
6722 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006723 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006724 } finally {
6725 Binder.restoreCallingIdentity(identity);
6726 }
yinxu504e1392017-04-12 16:03:22 -07006727 }
6728
6729 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006730 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006731 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006732 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006733 */
6734 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006735 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006736 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006737 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006738 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006739
6740 final long identity = Binder.clearCallingIdentity();
6741 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006742 if (DBG) log("getAllowedNetworkTypesBitmask");
6743 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6744 int networkTypesBitmask = (result != null ? result[0] : -1);
6745 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6746 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006747 } finally {
6748 Binder.restoreCallingIdentity(identity);
6749 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006750 }
6751
6752 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006753 * Get the allowed network types for certain reason.
6754 *
6755 * @param subId the id of the subscription.
6756 * @param reason the reason the allowed network type change is taking place
6757 * @return the allowed network types.
6758 */
6759 @Override
6760 public long getAllowedNetworkTypesForReason(int subId,
6761 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006762 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006763 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006764 final long identity = Binder.clearCallingIdentity();
6765 try {
Jack Yu7247ac82023-03-02 23:52:10 -08006766 return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason);
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006767 } finally {
6768 Binder.restoreCallingIdentity(identity);
6769 }
6770 }
6771
6772 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006773 * Enable/Disable E-UTRA-NR Dual Connectivity
6774 * @param subId subscription id of the sim card
6775 * @param nrDualConnectivityState expected NR dual connectivity state
6776 * This can be passed following states
6777 * <ol>
6778 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6779 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6780 * <li>Disable NR dual connectivity and force secondary cell to be released
6781 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6782 * </ol>
6783 * @return operation result.
6784 */
6785 @Override
6786 public int setNrDualConnectivityState(int subId,
6787 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6789 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006790 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006791 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6792 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6793 }
6794
Sooraj Sasindran37444802020-08-11 10:40:43 -07006795 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6796 final long identity = Binder.clearCallingIdentity();
6797 try {
6798 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6799 nrDualConnectivityState, subId,
6800 workSource);
6801 if (DBG) log("enableNRDualConnectivity result: " + result);
6802 return result;
6803 } finally {
6804 Binder.restoreCallingIdentity(identity);
6805 }
6806 }
6807
6808 /**
6809 * Is E-UTRA-NR Dual Connectivity enabled
6810 * @return true if dual connectivity is enabled else false
6811 */
6812 @Override
6813 public boolean isNrDualConnectivityEnabled(int subId) {
6814 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006815 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006816 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006817 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006818 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6819 return false;
6820 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006821 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6822 final long identity = Binder.clearCallingIdentity();
6823 try {
6824 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6825 null, subId, workSource);
6826 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6827 return isEnabled;
6828 } finally {
6829 Binder.restoreCallingIdentity(identity);
6830 }
6831 }
6832
6833 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006834 * Set the allowed network types of the device and
6835 * provide the reason triggering the allowed network change.
6836 *
6837 * @param subId the id of the subscription.
6838 * @param reason the reason the allowed network type change is taking place
6839 * @param allowedNetworkTypes the allowed network types.
6840 * @return true on success; false on any failure.
6841 */
6842 @Override
6843 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006844 @TelephonyManager.AllowedNetworkTypesReason int reason,
6845 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6847 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006848 // If the caller only has carrier privileges, then they should not be able to override
6849 // any network types which were set for security reasons.
6850 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6851 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006852 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006853 throw new SecurityException(
6854 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00006855 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006856 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006857 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006858 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08006859 return false;
6860 }
6861 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6862 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006863 return false;
6864 }
6865
Jack Yu5b494332023-01-23 18:18:04 +00006866 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
6867 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006868
Jack Yue37dd262022-12-16 11:53:37 -08006869 Phone phone = getPhone(subId);
6870 if (phone == null) {
6871 return false;
6872 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006873
Jack Yue37dd262022-12-16 11:53:37 -08006874 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00006875 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006876 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006877 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006878
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006879 final long identity = Binder.clearCallingIdentity();
6880 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006881 Boolean success = (Boolean) sendRequest(
6882 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6883 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6884
6885 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6886 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006887 } finally {
6888 Binder.restoreCallingIdentity(identity);
6889 }
6890 }
6891
6892 /**
Miaoa84611c2019-03-15 09:21:10 +08006893 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006894 *
Miaoa84611c2019-03-15 09:21:10 +08006895 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006896 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006897 * @hide
6898 */
6899 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006900 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006901 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006902 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006903 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006904 try {
Miaoa84611c2019-03-15 09:21:10 +08006905 if (phone != null) {
6906 return phone.hasMatchedTetherApnSetting();
6907 } else {
6908 return false;
6909 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006910 } finally {
6911 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006912 }
Junda Liu475951f2014-11-07 16:45:03 -08006913 }
6914
6915 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006916 * Get the user enabled state of Mobile Data.
6917 *
6918 * TODO: remove and use isUserDataEnabled.
6919 * This can't be removed now because some vendor codes
6920 * calls through ITelephony directly while they should
6921 * use TelephonyManager.
6922 *
6923 * @return true on enabled
6924 */
6925 @Override
6926 public boolean getDataEnabled(int subId) {
6927 return isUserDataEnabled(subId);
6928 }
6929
6930 /**
6931 * Get whether mobile data is enabled per user setting.
6932 *
6933 * There are other factors deciding whether mobile data is actually enabled, but they are
6934 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006935 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006936 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6937 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006938 *
6939 * @return {@code true} if data is enabled else {@code false}
6940 */
6941 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006942 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006943 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006944 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006945 try {
6946 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6947 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006948 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006949 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6950 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006951 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006953 mApp, subId, functionName);
6954
Robert Greenwalt646120a2014-05-23 11:54:03 -07006955 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006956
6957 final long identity = Binder.clearCallingIdentity();
6958 try {
Jack Yu285100e2022-12-02 22:48:35 -08006959 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006960 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6961 Phone phone = PhoneFactory.getPhone(phoneId);
6962 if (phone != null) {
6963 boolean retVal = phone.isUserDataEnabled();
6964 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6965 return retVal;
6966 } else {
6967 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6968 return false;
6969 }
6970 } finally {
6971 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006972 }
6973 }
6974
6975 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006976 * Checks if the device is capable of mobile data by considering whether whether the
6977 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6978 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006979 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006980 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006981 */
6982 @Override
6983 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006984 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006985 try {
6986 try {
6987 mApp.enforceCallingOrSelfPermission(
6988 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006989 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006990 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006991 try {
6992 mApp.enforceCallingOrSelfPermission(
6993 android.Manifest.permission.READ_PHONE_STATE,
6994 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006995 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006996 mApp.enforceCallingOrSelfPermission(
6997 permission.READ_BASIC_PHONE_STATE, functionName);
6998 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006999 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007000 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007001 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007002 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007003
7004 final long identity = Binder.clearCallingIdentity();
7005 try {
Jack Yu285100e2022-12-02 22:48:35 -08007006 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007007 Phone phone = PhoneFactory.getPhone(phoneId);
7008 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007009 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007010 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007011 return retVal;
7012 } else {
7013 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7014 return false;
7015 }
7016 } finally {
7017 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007018 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007019 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007020
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007021 /**
7022 * Check if data is enabled for a specific reason
7023 * @param subId Subscription index
7024 * @param reason the reason the data enable change is taking place
7025 * @return {@code true} if the overall data is enabled; {@code false} if not.
7026 */
7027 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007028 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007029 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007030 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007031 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007032 try {
7033 mApp.enforceCallingOrSelfPermission(
7034 android.Manifest.permission.ACCESS_NETWORK_STATE,
7035 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007036 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007037 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7038 functionName);
7039 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007040 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007041 try {
7042 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007043 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007044 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007045 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007046 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007047 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007048 }
7049
7050
7051 final long identity = Binder.clearCallingIdentity();
7052 try {
Jack Yu285100e2022-12-02 22:48:35 -08007053 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007054 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007055 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007056 + " reason=" + reason);
7057 }
7058 Phone phone = PhoneFactory.getPhone(phoneId);
7059 if (phone != null) {
7060 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007061 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007062 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007063 return retVal;
7064 } else {
7065 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007066 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007067 + subId + " retVal=false");
7068 }
7069 return false;
7070 }
7071 } finally {
7072 Binder.restoreCallingIdentity(identity);
7073 }
7074 }
7075
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007076 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007077 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007078 // No permission needed; this only lets the caller inspect their own status.
7079 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007080 }
Junda Liu29340342014-07-10 15:23:27 -07007081
7082 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007083 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007084 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007085 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7086 }
7087
7088 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7089 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007090 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007091 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007092 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7093 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007094 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7095 if (cpt == null) {
7096 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007097 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7098 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007099 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007100 }
7101
7102 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007103 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007104 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007105 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007106 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007107 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007108 Phone phone = getPhone(subId);
7109 if (phone == null) {
7110 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7111 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7112 }
7113 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7114 if (cpt == null) {
7115 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007116 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7117 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007118 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007119 }
7120
7121 @Override
7122 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007123 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007124 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7125 }
7126
7127 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007128 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007129 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007130 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007131 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007132 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7133 Phone phone = PhoneFactory.getPhone(phoneId);
7134 if (phone == null) {
7135 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007136 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007137 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7138 if (cpt == null) {
7139 continue;
7140 }
7141 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007142 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7143 break;
7144 }
7145 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007146 return result;
Junda Liu29340342014-07-10 15:23:27 -07007147 }
Derek Tan89e89d42014-07-08 17:00:10 -07007148
7149 @Override
Junda Liue64de782015-04-16 17:19:16 -07007150 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007151 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007152 Phone phone = PhoneFactory.getPhone(phoneId);
7153 if (phone == null) {
7154 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007155 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007156 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7157 if (cpt == null) {
7158 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007159 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007160 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007161 }
7162
Amith Yamasani6e118872016-02-19 12:53:51 -08007163 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007164 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007165 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007166 Phone phone = PhoneFactory.getPhone(phoneId);
7167 if (phone == null) {
7168 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007169 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007170 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7171 if (cpt == null) {
7172 return Collections.emptyList();
7173 }
7174 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007175 }
7176
chen xuf7e9fe82019-05-09 19:31:02 -07007177 @Override
7178 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007179 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007180 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007181 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007182 try {
7183 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7184 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7185 }
7186 } finally {
7187 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007188 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007189 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007190 }
7191
Rambo Wang6812ffb2022-03-15 16:54:17 -07007192 @Override
7193 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7194 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7195
7196 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7197 if (phone == null) {
7198 return null;
7199 }
7200 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7201 if (cpt == null) {
7202 return null;
7203 }
7204 return cpt.getCarrierServicePackageName();
7205 }
7206
Wink Savilleb564aae2014-10-23 10:18:09 -07007207 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007208 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007209 UiccPort port = phone == null ? null : phone.getUiccPort();
7210 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007211 return null;
7212 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007213 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007214 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007215 return null;
7216 }
7217 return iccId;
7218 }
7219
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007220 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007221 public void setCallComposerStatus(int subId, int status) {
7222 enforceModifyPermission();
7223
7224 final long identity = Binder.clearCallingIdentity();
7225 try {
7226 Phone phone = getPhone(subId);
7227 if (phone != null) {
7228 Phone defaultPhone = phone.getImsPhone();
7229 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7230 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7231 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007232 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7233 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007234 }
7235 }
Shuo Qian284ae752020-12-22 19:10:14 -08007236 } catch (ImsException e) {
7237 throw new ServiceSpecificException(e.getCode());
7238 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007239 Binder.restoreCallingIdentity(identity);
7240 }
7241 }
7242
7243 @Override
7244 public int getCallComposerStatus(int subId) {
7245 enforceReadPrivilegedPermission("getCallComposerStatus");
7246
7247 final long identity = Binder.clearCallingIdentity();
7248 try {
7249 Phone phone = getPhone(subId);
7250 if (phone != null) {
7251 Phone defaultPhone = phone.getImsPhone();
7252 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7253 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7254 return imsPhone.getCallComposerStatus();
7255 }
7256 }
7257 } finally {
7258 Binder.restoreCallingIdentity(identity);
7259 }
7260 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7261 }
7262
7263 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007264 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7265 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007266 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007267 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007268
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007269 final long identity = Binder.clearCallingIdentity();
7270 try {
7271 final String iccId = getIccId(subId);
7272 final Phone phone = getPhone(subId);
7273 if (phone == null) {
7274 return false;
7275 }
7276 final String subscriberId = phone.getSubscriberId();
7277
7278 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007279 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007280 + subscriberId + " to " + number);
7281 }
7282
7283 if (TextUtils.isEmpty(iccId)) {
7284 return false;
7285 }
7286
7287 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7288
7289 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7290 if (alphaTag == null) {
7291 editor.remove(alphaTagPrefKey);
7292 } else {
7293 editor.putString(alphaTagPrefKey, alphaTag);
7294 }
7295
7296 // Record both the line number and IMSI for this ICCID, since we need to
7297 // track all merged IMSIs based on line number
7298 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7299 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7300 if (number == null) {
7301 editor.remove(numberPrefKey);
7302 editor.remove(subscriberPrefKey);
7303 } else {
7304 editor.putString(numberPrefKey, number);
7305 editor.putString(subscriberPrefKey, subscriberId);
7306 }
7307
7308 editor.commit();
7309 return true;
7310 } finally {
7311 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007312 }
Derek Tan7226c842014-07-02 17:42:23 -07007313 }
7314
7315 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007316 public String getLine1NumberForDisplay(int subId, String callingPackage,
7317 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007318 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007319 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007320 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007321 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007322 return null;
7323 }
Derek Tan97ebb422014-09-05 16:55:38 -07007324
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007325 final long identity = Binder.clearCallingIdentity();
7326 try {
7327 String iccId = getIccId(subId);
7328 if (iccId != null) {
7329 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7330 if (DBG_MERGE) {
7331 log("getLine1NumberForDisplay returning "
7332 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7333 }
7334 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007335 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007336 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7337 return null;
7338 } finally {
7339 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007340 }
Derek Tan7226c842014-07-02 17:42:23 -07007341 }
7342
7343 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007344 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7345 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007346 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007347 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007348 return null;
7349 }
Derek Tan97ebb422014-09-05 16:55:38 -07007350
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007351 final long identity = Binder.clearCallingIdentity();
7352 try {
7353 String iccId = getIccId(subId);
7354 if (iccId != null) {
7355 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7356 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7357 }
7358 return null;
7359 } finally {
7360 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007361 }
Derek Tan7226c842014-07-02 17:42:23 -07007362 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007363
7364 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007365 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7366 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007367 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7368 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007369 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007370 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007371 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007372 return null;
7373 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007374
Jordan Liub49b04b2019-05-06 14:45:15 -07007375 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7376 // the process, where TelephonyManager was instantiated.
7377 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007378 final long identity = Binder.clearCallingIdentity();
7379 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007380 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007381 final TelephonyManager tele = TelephonyManager.from(context);
7382 final SubscriptionManager sub = SubscriptionManager.from(context);
7383
7384 // Figure out what subscribers are currently active
7385 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007386
Jordan Liub49b04b2019-05-06 14:45:15 -07007387 // Only consider subs which match the current subId
7388 // This logic can be simplified. See b/131189269 for progress.
7389 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007390 activeSubscriberIds.add(tele.getSubscriberId(subId));
7391 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007392
7393 // First pass, find a number override for an active subscriber
7394 String mergeNumber = null;
7395 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7396 for (String key : prefs.keySet()) {
7397 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7398 final String subscriberId = (String) prefs.get(key);
7399 if (activeSubscriberIds.contains(subscriberId)) {
7400 final String iccId = key.substring(
7401 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7402 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7403 mergeNumber = (String) prefs.get(numberKey);
7404 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007405 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007406 + " for active subscriber " + subscriberId);
7407 }
7408 if (!TextUtils.isEmpty(mergeNumber)) {
7409 break;
7410 }
7411 }
7412 }
7413 }
7414
7415 // Shortcut when no active merged subscribers
7416 if (TextUtils.isEmpty(mergeNumber)) {
7417 return null;
7418 }
7419
7420 // Second pass, find all subscribers under that line override
7421 final ArraySet<String> result = new ArraySet<>();
7422 for (String key : prefs.keySet()) {
7423 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7424 final String number = (String) prefs.get(key);
7425 if (mergeNumber.equals(number)) {
7426 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7427 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7428 final String subscriberId = (String) prefs.get(subscriberKey);
7429 if (!TextUtils.isEmpty(subscriberId)) {
7430 result.add(subscriberId);
7431 }
7432 }
7433 }
7434 }
7435
7436 final String[] resultArray = result.toArray(new String[result.size()]);
7437 Arrays.sort(resultArray);
7438 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007439 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007440 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7441 }
7442 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007443 } finally {
7444 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007445 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007446 }
7447
7448 @Override
zoey chen38003472019-12-13 17:16:31 +08007449 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7450 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007451
7452 final long identity = Binder.clearCallingIdentity();
7453 try {
7454 final TelephonyManager telephonyManager = mApp.getSystemService(
7455 TelephonyManager.class);
7456 String subscriberId = telephonyManager.getSubscriberId(subId);
7457 if (subscriberId == null) {
7458 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007459 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007460 + subId);
7461 }
7462 return null;
7463 }
7464
Jack Yu285100e2022-12-02 22:48:35 -08007465 ParcelUuid groupUuid;
7466 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08007467 final SubscriptionInfo info = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08007468 .getSubscriptionInfo(subId);
7469 groupUuid = info.getGroupUuid();
7470 } else {
7471 final SubscriptionInfo info = mSubscriptionController
7472 .getSubscriptionInfo(subId);
7473 groupUuid = info.getGroupUuid();
7474 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007475 // If it doesn't belong to any group, return just subscriberId of itself.
7476 if (groupUuid == null) {
7477 return new String[]{subscriberId};
7478 }
7479
7480 // Get all subscriberIds from the group.
7481 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007482 List<SubscriptionInfo> groupInfos;
7483 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08007484 groupInfos = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08007485 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7486 mApp.getAttributionTag());
7487 } else {
7488 groupInfos = mSubscriptionController
7489 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7490 mApp.getAttributionTag());
7491 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007492 for (SubscriptionInfo subInfo : groupInfos) {
7493 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7494 if (subscriberId != null) {
7495 mergedSubscriberIds.add(subscriberId);
7496 }
7497 }
7498
7499 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7500 } finally {
7501 Binder.restoreCallingIdentity(identity);
7502
7503 }
7504 }
7505
7506 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007507 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007508 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007509 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007510
7511 final long identity = Binder.clearCallingIdentity();
7512 try {
7513 final Phone phone = getPhone(subId);
7514 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7515 } finally {
7516 Binder.restoreCallingIdentity(identity);
7517 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007518 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007519
7520 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007521 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007522 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7523 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007524 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7525 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007526
7527 final long identity = Binder.clearCallingIdentity();
7528 try {
7529 final Phone phone = getPhone(subId);
7530 if (phone == null) {
7531 return false;
7532 }
7533 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7534 cdmaNonRoamingList);
7535 } finally {
7536 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007537 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007538 }
7539
7540 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007541 @Deprecated
7542 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7543 enforceModifyPermission();
7544
7545 int returnValue = 0;
7546 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007547 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007548 if(result.exception == null) {
7549 if (result.result != null) {
7550 byte[] responseData = (byte[])(result.result);
7551 if(responseData.length > oemResp.length) {
7552 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7553 responseData.length + "bytes. Buffer Size is " +
7554 oemResp.length + "bytes.");
7555 }
7556 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7557 returnValue = responseData.length;
7558 }
7559 } else {
7560 CommandException ex = (CommandException) result.exception;
7561 returnValue = ex.getCommandError().ordinal();
7562 if(returnValue > 0) returnValue *= -1;
7563 }
7564 } catch (RuntimeException e) {
7565 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7566 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7567 if(returnValue > 0) returnValue *= -1;
7568 }
7569
7570 return returnValue;
7571 }
7572
7573 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007574 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007575 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007576 Phone phone = PhoneFactory.getPhone(phoneId);
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007577 if (phone == null) {
7578 return raf;
7579 }
7580
Shuo Qiandee53402020-05-29 14:08:15 -07007581 try {
7582 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007583 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007584 mApp, phone.getSubId(), "getRadioAccessFamily");
7585 } catch (SecurityException e) {
7586 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7587 throw e;
7588 }
Aishwarya Mallampati11e82872023-03-13 21:04:00 +00007589
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007590 final long identity = Binder.clearCallingIdentity();
7591 try {
chen xub97461a2018-10-26 14:17:57 -07007592 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007593 } finally {
7594 Binder.restoreCallingIdentity(identity);
7595 }
chen xub97461a2018-10-26 14:17:57 -07007596 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007597 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007598
7599 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007600 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007601 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007602 try {
7603 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7604 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007605 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007606 }
7607 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007608 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007609 }
7610 RoleManager rm = mApp.getSystemService(RoleManager.class);
7611 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7612 if (!dialerRoleHolders.contains(callingPackage)) {
7613 throw new SecurityException("App must be the dialer role holder to"
7614 + " upload a call composer pic");
7615 }
7616
7617 Executors.newSingleThreadExecutor().execute(() -> {
7618 ByteArrayOutputStream output = new ByteArrayOutputStream(
7619 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7620 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7621 boolean readUntilEnd = false;
7622 int totalBytesRead = 0;
7623 byte[] buffer = new byte[16 * 1024];
7624 while (true) {
7625 int numRead;
7626 try {
7627 numRead = input.read(buffer);
7628 } catch (IOException e) {
7629 try {
7630 fd.checkError();
7631 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7632 null);
7633 } catch (IOException e1) {
7634 // This means that the other side closed explicitly with an error. If this
7635 // happens, log and ignore.
7636 loge("Remote end of call composer picture pipe closed: " + e1);
7637 }
7638 break;
7639 }
7640 if (numRead == -1) {
7641 readUntilEnd = true;
7642 break;
7643 }
7644 totalBytesRead += numRead;
7645 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7646 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7647 try {
7648 input.close();
7649 } catch (IOException e) {
7650 // ignore
7651 }
7652 break;
7653 }
7654 output.write(buffer, 0, numRead);
7655 }
7656 // Generally, the remote end will close the file descriptors. The only case where we
7657 // close is above, where the picture size is too big.
7658
7659 try {
7660 fd.checkError();
7661 } catch (IOException e) {
7662 loge("Remote end for call composer closed with an error: " + e);
7663 return;
7664 }
7665
Hall Liuaa4211e2021-01-20 15:43:39 -08007666 if (!readUntilEnd) {
7667 loge("Did not finish reading entire image; aborting");
7668 return;
7669 }
Hall Liu82694d52020-12-11 18:22:04 -08007670
Hall Liuaa4211e2021-01-20 15:43:39 -08007671 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7672 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7673 new CallComposerPictureTransfer.Factory() {},
7674 imageData,
7675 (result) -> {
7676 if (result.first != null) {
7677 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7678 Bundle outputResult = new Bundle();
7679 outputResult.putParcelable(
7680 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7681 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7682 outputResult);
7683 } else {
7684 callback.send(result.second, null);
7685 }
7686 }
7687 );
Hall Liu82694d52020-12-11 18:22:04 -08007688 });
7689 }
7690
7691 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007692 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007693 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007694 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007695
7696 final long identity = Binder.clearCallingIdentity();
7697 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007698 ImsManager.getInstance(defaultPhone.getContext(),
7699 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007700 } finally {
7701 Binder.restoreCallingIdentity(identity);
7702 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007703 }
7704
7705 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007706 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007707 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007708 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7709 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007710 return false;
7711 }
Svet Ganovb320e182015-04-16 12:30:10 -07007712
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007713 final long identity = Binder.clearCallingIdentity();
7714 try {
7715 // Check the user preference and the system-level IMS setting. Even if the user has
7716 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7717 // In the long run, we may instead need to check if there exists a connection service
7718 // which can support video calling.
7719 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007720 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007721 return imsManager.isVtEnabledByPlatform()
7722 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7723 && imsManager.isVtEnabledByUser();
7724 } finally {
7725 Binder.restoreCallingIdentity(identity);
7726 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007727 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007728
Andrew Leea1239f22015-03-02 17:44:07 -08007729 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007730 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7731 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007732 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007733 mApp, subId, callingPackage, callingFeatureId,
7734 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007735 return false;
7736 }
7737
7738 final long identity = Binder.clearCallingIdentity();
7739 try {
7740 CarrierConfigManager configManager =
7741 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007742 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007743 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7744 } finally {
7745 Binder.restoreCallingIdentity(identity);
7746 }
Andrew Leea1239f22015-03-02 17:44:07 -08007747 }
7748
7749 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007750 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007751 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007752 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007753 return false;
7754 }
7755
7756 final long identity = Binder.clearCallingIdentity();
7757 try {
7758 CarrierConfigManager configManager =
7759 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007760 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007761 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7762 } finally {
7763 Binder.restoreCallingIdentity(identity);
7764 }
Andrew Leea1239f22015-03-02 17:44:07 -08007765 }
7766
Andrew Lee9431b832015-03-09 18:46:45 -07007767 @Override
7768 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007769 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007770 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007771 }
7772
7773 @Override
7774 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007775 final long identity = Binder.clearCallingIdentity();
7776 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007777 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007778 } finally {
7779 Binder.restoreCallingIdentity(identity);
7780 }
Andrew Lee9431b832015-03-09 18:46:45 -07007781 }
7782
Hall Liuf6668912018-10-31 17:05:23 -07007783 /**
7784 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7785 * support for the feature and device firmware support.
7786 *
7787 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7788 */
7789 @Override
7790 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007791 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007792 final Phone phone = getPhone(subscriptionId);
7793 if (phone == null) {
7794 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7795 return false;
7796 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007797 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007798 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007799 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7800 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007801 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007802 return isCarrierSupported && isDeviceSupported;
7803 } finally {
7804 Binder.restoreCallingIdentity(identity);
7805 }
Hall Liu98187582018-01-22 19:15:32 -08007806 }
7807
Hall Liuf6668912018-10-31 17:05:23 -07007808 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007809 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7810 * RTT setting, will return true if the device and carrier both support RTT.
7811 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007812 */
7813 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007814 final long identity = Binder.clearCallingIdentity();
7815 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007816 boolean isRttSupported = isRttSupported(subscriptionId);
7817 boolean isUserRttSettingOn = Settings.Secure.getInt(
7818 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7819 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7820 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7821 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007822 } finally {
7823 Binder.restoreCallingIdentity(identity);
7824 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007825 }
7826
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007827 @Deprecated
7828 @Override
7829 public String getDeviceId(String callingPackage) {
7830 return getDeviceIdWithFeature(callingPackage, null);
7831 }
7832
Sanket Padawe7310cc72015-01-14 09:53:20 -08007833 /**
7834 * Returns the unique device ID of phone, for example, the IMEI for
7835 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7836 *
7837 * <p>Requires Permission:
7838 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7839 */
7840 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007841 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007842 try {
7843 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7844 } catch (SecurityException se) {
7845 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7846 throw new SecurityException("Package " + callingPackage + " does not belong to "
7847 + Binder.getCallingUid());
7848 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007849 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007850 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007851 return null;
7852 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007853 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007854 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007855 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007856 return null;
7857 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007858
7859 final long identity = Binder.clearCallingIdentity();
7860 try {
7861 return phone.getDeviceId();
7862 } finally {
7863 Binder.restoreCallingIdentity(identity);
7864 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007865 }
7866
Ping Sunc67b7c22016-03-02 19:16:45 +08007867 /**
7868 * {@hide}
7869 * Returns the IMS Registration Status on a particular subid
7870 *
7871 * @param subId
7872 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007873 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007874 Phone phone = getPhone(subId);
7875 if (phone != null) {
7876 return phone.isImsRegistered();
7877 } else {
7878 return false;
7879 }
7880 }
7881
Santos Cordon7a1885b2015-02-03 11:15:19 -08007882 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007883 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007884 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007885 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007886 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007887 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7888 }
7889 final long identity = Binder.clearCallingIdentity();
7890 try {
7891 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7892 } finally {
7893 Binder.restoreCallingIdentity(identity);
7894 }
7895 }
7896
7897 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007898 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007899 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007900 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007901 mApp,
7902 subscriptionId,
7903 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
7904 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007905 final long identity = Binder.clearCallingIdentity();
7906 try {
7907 Phone phone = getPhone(subscriptionId);
7908 if (phone == null) {
7909 return null;
7910 }
7911 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7912 } finally {
7913 Binder.restoreCallingIdentity(identity);
7914 }
7915 }
7916
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007917 /**
7918 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007919 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007920 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007921 final long identity = Binder.clearCallingIdentity();
7922 try {
7923 Phone phone = getPhone(subId);
7924 if (phone != null) {
7925 return phone.isWifiCallingEnabled();
7926 } else {
7927 return false;
7928 }
7929 } finally {
7930 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007931 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007932 }
7933
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007934 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007935 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007936 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007937 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007938 final long identity = Binder.clearCallingIdentity();
7939 try {
7940 Phone phone = getPhone(subId);
7941 if (phone != null) {
7942 return phone.isVideoEnabled();
7943 } else {
7944 return false;
7945 }
7946 } finally {
7947 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007948 }
7949 }
7950
7951 /**
7952 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7953 * defined in {@link ImsRegistrationImplBase}.
7954 */
7955 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007956 final long identity = Binder.clearCallingIdentity();
7957 try {
7958 Phone phone = getPhone(subId);
7959 if (phone != null) {
7960 return phone.getImsRegistrationTech();
7961 } else {
7962 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7963 }
7964 } finally {
7965 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007966 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007967 }
7968
Stuart Scott8eef64f2015-04-08 15:13:54 -07007969 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007970 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007971 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007972 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7973 return;
7974 }
Kai Shif70f46f2021-03-03 13:59:46 -08007975 Phone defaultPhone = getDefaultPhone();
7976 if (defaultPhone != null) {
7977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7978 mApp, getDefaultPhone().getSubId(), "factoryReset");
7979 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007980 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007981
Svet Ganovcc087f82015-05-12 20:35:54 -07007982 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007983 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7984 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007985 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007986 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007987 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007988 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007989 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007990 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007991 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007992 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007993 // There has been issues when Sms raw table somehow stores orphan
7994 // fragments. They lead to garbled message when new fragments come
7995 // in and combined with those stale ones. In case this happens again,
7996 // user can reset all network settings which will clean up this table.
7997 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007998 // Clean up IMS settings as well here.
7999 int slotId = getSlotIndex(subId);
8000 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8001 ImsManager.getInstance(mApp, slotId).factoryReset();
8002 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008003
Kai Shif70f46f2021-03-03 13:59:46 -08008004 if (defaultPhone == null) {
8005 return;
8006 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008007 // Erase modem config if erase modem on network setting is enabled.
8008 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8009 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8010 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008011 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008012 }
Kai Shif70f46f2021-03-03 13:59:46 -08008013
8014 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008015 } finally {
8016 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008017 }
8018 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008019
SongFerngWangfd89b102021-05-27 22:44:54 +08008020 @VisibleForTesting
8021 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8022 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8023 return;
8024 }
8025 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8026 RILConstants.PREFERRED_NETWORK_MODE);
8027 SubscriptionManager.setSubscriptionProperty(subId,
8028 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8029 "user=" + defaultNetworkType);
8030 phone.loadAllowedNetworksFromSubscriptionDatabase();
8031 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8032 defaultNetworkType, null);
8033 }
8034
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008035 private void cleanUpSmsRawTable(Context context) {
8036 ContentResolver resolver = context.getContentResolver();
8037 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8038 resolver.delete(uri, null, null);
8039 }
8040
Narayan Kamath1c496c22015-04-16 14:40:19 +01008041 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008042 public String getSimLocaleForSubscriber(int subId) {
8043 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8044 final Phone phone = getPhone(subId);
8045 if (phone == null) {
8046 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008047 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008048 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008049 final long identity = Binder.clearCallingIdentity();
8050 try {
Jack Yu285100e2022-12-02 22:48:35 -08008051 SubscriptionInfo info;
8052 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008053 info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
Jack Yu285100e2022-12-02 22:48:35 -08008054 phone.getContext().getOpPackageName(),
8055 phone.getContext().getAttributionTag());
8056 if (info == null) {
8057 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8058 return null;
8059 }
8060 } else {
8061 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
8062 phone.getContext().getOpPackageName(),
8063 phone.getContext().getAttributionTag());
8064 if (info == null) {
8065 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8066 return null;
8067 }
chen xu6291c472019-02-04 12:55:53 -08008068 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008069 // Try and fetch the locale from the carrier properties or from the SIM language
8070 // preferences (EF-PL and EF-LI)...
8071 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008072 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008073 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8074 if (localeFromDefaultSim != null) {
8075 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8076 if (DBG) log("Using locale from subId: " + subId + " locale: "
8077 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008078 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008079 } else {
8080 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008081 }
8082 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008083
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008084 // The SIM language preferences only store a language (e.g. fr = French), not an
8085 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8086 // the SIM and carrier preferences does not include a country we add the country
8087 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008088 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008089 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008090 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008091 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008092 }
8093
8094 if (DBG) log("No locale found - returning null");
8095 return null;
8096 } finally {
8097 Binder.restoreCallingIdentity(identity);
8098 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008099 }
8100
tom hsu0b59d292022-09-29 23:49:21 +08008101 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008102 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008103 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008104 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008105 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008106 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8107 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008108 Locale.forLanguageTag(localeTag).getCountry())) {
8109 return localeTag;
8110 }
8111 }
8112 return inputLocale.toLanguageTag();
8113 }
8114
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008115 /**
8116 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8117 */
8118 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08008119 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008120 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Jack Yu285100e2022-12-02 22:48:35 -08008121 mApp.getOpPackageName(), mApp.getAttributionTag());
8122 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008123 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08008124 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008125 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008126
Gary Jian3aa9a762022-01-24 16:41:19 +08008127 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8128 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008129
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008130 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008131 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8132 * representing the state of the modem.
8133 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008134 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8135 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008136 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008137 */
8138 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008139 public void requestModemActivityInfo(ResultReceiver result) {
8140 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008141 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008142
8143 final long identity = Binder.clearCallingIdentity();
8144 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008145 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008146 } finally {
8147 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008148 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008149 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008150
Gary Jian76280a42022-12-07 16:18:33 +08008151 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008152 // less than total activity duration.
8153 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8154 if (info == null) {
8155 return false;
8156 }
8157 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008158 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008159 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8160
Hall Liu49656c02020-10-09 19:00:11 -07008161 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8162
Siddharth Rayb8114062018-06-17 15:02:38 -07008163 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008164 && (info.getSleepTimeMillis() <= activityDurationMs)
8165 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008166 }
8167
Gary Jian3aa9a762022-01-24 16:41:19 +08008168 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8169 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8170 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8171 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8172
8173 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8174 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8175 }
8176
8177 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8178 mLastModemActivityInfo.setReceiveTimeMillis(
8179 rat,
8180 freq,
8181 info.getReceiveTimeMillis(rat, freq)
8182 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8183 }
8184
8185 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8186 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8187 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8188 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8189
8190 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8191 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8192 }
8193 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8194 mLastModemActivityInfo.setReceiveTimeMillis(
8195 rat,
8196 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8197 }
8198
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008199 /**
8200 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8201 * @param info recent ModemActivityInfo
8202 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008203 private void mergeModemActivityInfo(ModemActivityInfo info) {
8204 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008205 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008206 boolean matched;
8207 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8208 matched = false;
8209 int rat = info.getSpecificInfoRat(i);
8210 int freq = info.getSpecificInfoFrequencyRange(i);
8211 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8212 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8213 //if it already exists
8214 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8215 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8216 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8217 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8218 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8219 updateLastModemActivityInfo(info, rat, freq);
8220 matched = true;
8221 }
8222 } else {
8223 updateLastModemActivityInfo(info, rat);
8224 matched = true;
8225 }
8226 }
8227 }
8228
8229 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008230 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008231 new ActivityStatsTechSpecificInfo(
8232 rat,
8233 freq,
8234 info.getTransmitTimeMillis(rat, freq),
8235 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008236 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008237 }
8238 }
8239 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8240 mLastModemActivitySpecificInfo =
8241 new ActivityStatsTechSpecificInfo[merged.size()];
8242 merged.toArray(mLastModemActivitySpecificInfo);
8243
8244 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8245 mLastModemActivityInfo.setSleepTimeMillis(
8246 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008247 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008248 mLastModemActivityInfo.setIdleTimeMillis(
8249 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008250 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008251
8252 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008253 new ModemActivityInfo(
8254 mLastModemActivityInfo.getTimestampMillis(),
8255 mLastModemActivityInfo.getSleepTimeMillis(),
8256 mLastModemActivityInfo.getIdleTimeMillis(),
8257 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008258 }
8259
8260 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8261 ActivityStatsTechSpecificInfo[] info) {
8262 int infoSize = info.length;
8263 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8264 for (int i = 0; i < infoSize; i++) {
8265 ret[i] = new ActivityStatsTechSpecificInfo(
8266 info[i].getRat(), info[i].getFrequencyRange(),
8267 info[i].getTransmitTimeMillis(),
8268 (int) info[i].getReceiveTimeMillis());
8269 }
8270 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008271 }
8272
Jack Yu85bd38a2015-11-09 11:34:32 -08008273 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008274 * Returns the service state information on specified subscription.
8275 */
8276 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008277 public ServiceState getServiceStateForSubscriber(int subId,
8278 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8279 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008280 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008281 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008282 return null;
8283 }
8284
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008285 boolean hasFinePermission = false;
8286 boolean hasCoarsePermission = false;
8287 if (!renounceFineLocationAccess) {
8288 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8289 LocationAccessPolicy.checkLocationPermission(mApp,
8290 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8291 .setCallingPackage(callingPackage)
8292 .setCallingFeatureId(callingFeatureId)
8293 .setCallingPid(Binder.getCallingPid())
8294 .setCallingUid(Binder.getCallingUid())
8295 .setMethod("getServiceStateForSubscriber")
8296 .setLogAsInfo(true)
8297 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8298 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8299 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8300 .build());
8301 hasFinePermission =
8302 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8303 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008304
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008305 if (!renounceCoarseLocationAccess) {
8306 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8307 LocationAccessPolicy.checkLocationPermission(mApp,
8308 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8309 .setCallingPackage(callingPackage)
8310 .setCallingFeatureId(callingFeatureId)
8311 .setCallingPid(Binder.getCallingPid())
8312 .setCallingUid(Binder.getCallingUid())
8313 .setMethod("getServiceStateForSubscriber")
8314 .setLogAsInfo(true)
8315 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8316 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8317 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8318 .build());
8319 hasCoarsePermission =
8320 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8321 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008322
Jack Yu479f40e2020-10-27 21:29:25 -07008323 final Phone phone = getPhone(subId);
8324 if (phone == null) {
8325 return null;
8326 }
8327
Jordan Liu0f2bc442020-11-18 16:47:37 -08008328 final long identity = Binder.clearCallingIdentity();
8329
Jack Yu479f40e2020-10-27 21:29:25 -07008330 boolean isCallingPackageDataService = phone.getDataServicePackages()
8331 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008332 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008333 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008334 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008335 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008336 .getSubscriptionInfoInternal(subId);
8337 if (subInfo == null || !subInfo.isActive()) {
8338 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8339 + "subId=" + subId);
8340 return null;
8341 }
8342 } else {
8343 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8344 callingFeatureId)) {
8345 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8346 + "subId=" + subId);
8347 return null;
8348 }
Jordan Liuc437b192020-08-17 10:59:12 -07008349 }
8350
Hall Liuf19c44f2018-11-27 14:38:17 -08008351 ServiceState ss = phone.getServiceState();
8352
8353 // Scrub out the location info in ServiceState depending on what level of access
8354 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008355 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008356 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8357 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008358 } finally {
8359 Binder.restoreCallingIdentity(identity);
8360 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008361 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008362
8363 /**
8364 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8365 *
8366 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8367 * voicemail ringtone.
8368 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8369 * PhoneAccount.
8370 */
8371 @Override
8372 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008373 final long identity = Binder.clearCallingIdentity();
8374 try {
8375 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8376 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008377 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008378 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008379
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008380 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8381 } finally {
8382 Binder.restoreCallingIdentity(identity);
8383 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008384 }
8385
8386 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008387 * Sets the per-account voicemail ringtone.
8388 *
8389 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8390 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8391 *
8392 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8393 * voicemail ringtone.
8394 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8395 * PhoneAccount.
8396 */
8397 @Override
8398 public void setVoicemailRingtoneUri(String callingPackage,
8399 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008400 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008401 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008402 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8403 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008404 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8405 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8406 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008407 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008408
8409 final long identity = Binder.clearCallingIdentity();
8410 try {
8411 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8412 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008413 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008414 }
8415 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8416 } finally {
8417 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008418 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008419 }
8420
8421 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008422 * Returns whether vibration is set for voicemail notification in Phone settings.
8423 *
8424 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8425 * voicemail vibration setting.
8426 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8427 */
8428 @Override
8429 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008430 final long identity = Binder.clearCallingIdentity();
8431 try {
8432 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8433 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008434 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008435 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008436
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008437 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8438 } finally {
8439 Binder.restoreCallingIdentity(identity);
8440 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008441 }
8442
Youhan Wange64578a2016-05-02 15:32:42 -07008443 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008444 * Sets the per-account voicemail vibration.
8445 *
8446 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8447 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8448 *
8449 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8450 * voicemail vibration setting.
8451 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8452 * specific PhoneAccount.
8453 */
8454 @Override
8455 public void setVoicemailVibrationEnabled(String callingPackage,
8456 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008457 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008458 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008459 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8460 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8462 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8463 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008464 }
8465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008466 final long identity = Binder.clearCallingIdentity();
8467 try {
8468 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8469 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008470 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008471 }
8472 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8473 } finally {
8474 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008475 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008476 }
8477
8478 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008479 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8480 *
8481 * @throws SecurityException if the caller does not have the required permission
8482 */
arunvoddud7401012022-12-15 16:08:12 +00008483 @VisibleForTesting
8484 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008485 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008486 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008487 }
8488
8489 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008490 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8491 * permission.
8492 *
8493 * @throws SecurityException if the caller does not have the required permission
8494 */
8495 private void enforceSendSmsPermission() {
8496 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8497 }
8498
8499 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008500 * Make sure either called from same process as self (phone) or IPC caller has interact across
8501 * users permission.
8502 *
8503 * @throws SecurityException if the caller does not have the required permission
8504 */
8505 private void enforceInteractAcrossUsersPermission(String message) {
8506 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8507 }
8508
8509 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008510 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008511 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008512 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008513 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008514 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008515 final long identity = Binder.clearCallingIdentity();
8516 try {
8517 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008518 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008519 if (componentName == null) {
8520 throw new SecurityException(
8521 "Caller not current active visual voicemail package[null]");
8522 }
8523 String vvmPackage = componentName.getPackageName();
8524 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008525 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008526 }
8527 } finally {
8528 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008529 }
8530 }
8531
8532 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008533 * Return the application ID for the app type.
8534 *
8535 * @param subId the subscription ID that this request applies to.
8536 * @param appType the uicc app type.
8537 * @return Application ID for specificied app type, or null if no uicc.
8538 */
8539 @Override
8540 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008541 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008542 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008543
8544 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008545 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008546 if (phone == null) {
8547 return null;
8548 }
8549 String aid = null;
8550 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008551 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008552 .getApplicationByType(appType).getAid();
8553 } catch (Exception e) {
8554 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8555 }
8556 return aid;
8557 } finally {
8558 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008559 }
Youhan Wange64578a2016-05-02 15:32:42 -07008560 }
8561
Youhan Wang4001d252016-05-11 10:29:41 -07008562 /**
8563 * Return the Electronic Serial Number.
8564 *
8565 * @param subId the subscription ID that this request applies to.
8566 * @return ESN or null if error.
8567 */
8568 @Override
8569 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008570 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008571 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008572
8573 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008574 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008575 if (phone == null) {
8576 return null;
8577 }
8578 String esn = null;
8579 try {
8580 esn = phone.getEsn();
8581 } catch (Exception e) {
8582 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8583 }
8584 return esn;
8585 } finally {
8586 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008587 }
Youhan Wang4001d252016-05-11 10:29:41 -07008588 }
8589
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008590 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008591 * Return the Preferred Roaming List Version.
8592 *
8593 * @param subId the subscription ID that this request applies to.
8594 * @return PRLVersion or null if error.
8595 */
8596 @Override
8597 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008598 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008599 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008600
8601 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008602 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008603 if (phone == null) {
8604 return null;
8605 }
8606 String cdmaPrlVersion = null;
8607 try {
8608 cdmaPrlVersion = phone.getCdmaPrlVersion();
8609 } catch (Exception e) {
8610 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8611 }
8612 return cdmaPrlVersion;
8613 } finally {
8614 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008615 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008616 }
8617
8618 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008619 * Get snapshot of Telephony histograms
8620 * @return List of Telephony histograms
8621 * @hide
8622 */
8623 @Override
8624 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8626 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008627
8628 final long identity = Binder.clearCallingIdentity();
8629 try {
8630 return RIL.getTelephonyRILTimingHistograms();
8631 } finally {
8632 Binder.restoreCallingIdentity(identity);
8633 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008634 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008635
8636 /**
8637 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008638 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8639 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008640 * Require system privileges. In the future we may add this to carrier APIs.
8641 *
Michele Berionne482f8202018-11-27 18:57:59 -08008642 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008643 */
8644 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008645 @TelephonyManager.SetCarrierRestrictionResult
8646 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008647 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008648 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008649
Michele Berionne482f8202018-11-27 18:57:59 -08008650 if (carrierRestrictionRules == null) {
8651 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008652 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008653
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008654 final long identity = Binder.clearCallingIdentity();
8655 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008656 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008657 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008658 } finally {
8659 Binder.restoreCallingIdentity(identity);
8660 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008661 }
8662
8663 /**
8664 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008665 * Get the allowed carrier list and the excluded carrier list, including the priority between
8666 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008667 * Require system privileges. In the future we may add this to carrier APIs.
8668 *
Michele Berionne482f8202018-11-27 18:57:59 -08008669 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008670 */
8671 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008672 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008673 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008674 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008675
8676 final long identity = Binder.clearCallingIdentity();
8677 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008678 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8679 if (response instanceof CarrierRestrictionRules) {
8680 return (CarrierRestrictionRules) response;
8681 }
8682 // Response is an Exception of some kind,
8683 // which is signalled to the user as a NULL retval
8684 return null;
8685 } catch (Exception e) {
8686 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8687 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008688 } finally {
8689 Binder.restoreCallingIdentity(identity);
8690 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008691 }
8692
fionaxu59545b42016-05-25 15:53:37 -07008693 /**
arunvoddud7401012022-12-15 16:08:12 +00008694 * Fetches the carrier restriction status of the device and sends the status to the caller
8695 * through the callback.
8696 *
8697 * @param callback The callback that will be used to send the result.
8698 * @throws SecurityException if the caller does not have the required permission/privileges or
8699 * the caller is not allowlisted.
8700 */
8701 @Override
8702 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
8703 enforceReadPermission("getCarrierRestrictionStatus");
8704 int carrierId = validateCallerAndGetCarrierId(packageName);
8705 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
8706 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
8707 throw new SecurityException("Not an authorized caller");
8708 }
8709 final long identity = Binder.clearCallingIdentity();
8710 try {
8711 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
8712 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
8713 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
8714 } finally {
8715 Binder.restoreCallingIdentity(identity);
8716 }
8717 }
8718
8719 @VisibleForTesting
8720 public int validateCallerAndGetCarrierId(String packageName) {
8721 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
8722 return allowListInfo.validateCallerAndGetCarrierId(packageName);
8723 }
8724
8725 /**
fionaxu59545b42016-05-25 15:53:37 -07008726 * Action set from carrier signalling broadcast receivers to enable/disable radio
8727 * @param subId the subscription ID that this action applies to.
8728 * @param enabled control enable or disable radio.
8729 * {@hide}
8730 */
8731 @Override
8732 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8733 enforceModifyPermission();
8734 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008735
8736 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008737 if (phone == null) {
8738 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8739 return;
8740 }
8741 try {
8742 phone.carrierActionSetRadioEnabled(enabled);
8743 } catch (Exception e) {
8744 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008745 } finally {
8746 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008747 }
8748 }
8749
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008750 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008751 * Enable or disable Voice over NR (VoNR)
8752 * @param subId the subscription ID that this action applies to.
8753 * @param enabled enable or disable VoNR.
8754 * @return operation result.
8755 */
8756 @Override
8757 public int setVoNrEnabled(int subId, boolean enabled) {
8758 enforceModifyPermission();
8759 final Phone phone = getPhone(subId);
8760
8761 final long identity = Binder.clearCallingIdentity();
8762 if (phone == null) {
8763 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8764 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8765 }
8766
8767 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8768 try {
8769 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8770 workSource);
8771 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008772
8773 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8774 if (DBG) {
8775 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8776 }
8777 SubscriptionManager.setSubscriptionProperty(
8778 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8779 (enabled ? "1" : "0"));
8780 }
8781
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008782 return result;
8783 } finally {
8784 Binder.restoreCallingIdentity(identity);
8785 }
8786 }
8787
8788 /**
8789 * Is voice over NR enabled
8790 * @return true if VoNR is enabled else false
8791 */
8792 @Override
8793 public boolean isVoNrEnabled(int subId) {
8794 enforceReadPrivilegedPermission("isVoNrEnabled");
8795 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8796 final long identity = Binder.clearCallingIdentity();
8797 try {
8798 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8799 null, subId, workSource);
8800 if (DBG) log("isVoNrEnabled: " + isEnabled);
8801 return isEnabled;
8802 } finally {
8803 Binder.restoreCallingIdentity(identity);
8804 }
8805 }
8806
8807 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008808 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8809 * network status based on which carrier apps could apply actions accordingly,
8810 * enable/disable default url handler for example.
8811 *
8812 * @param subId the subscription ID that this action applies to.
8813 * @param report control start/stop reporting the default network status.
8814 * {@hide}
8815 */
8816 @Override
8817 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8818 enforceModifyPermission();
8819 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008820
8821 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008822 if (phone == null) {
8823 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8824 return;
8825 }
8826 try {
8827 phone.carrierActionReportDefaultNetworkStatus(report);
8828 } catch (Exception e) {
8829 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008830 } finally {
8831 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008832 }
8833 }
8834
8835 /**
fionaxud9622282017-07-17 17:51:30 -07008836 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8837 * @param subId the subscription ID that this action applies to.
8838 * {@hide}
8839 */
8840 @Override
8841 public void carrierActionResetAll(int subId) {
8842 enforceModifyPermission();
8843 final Phone phone = getPhone(subId);
8844 if (phone == null) {
8845 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8846 return;
8847 }
8848 try {
8849 phone.carrierActionResetAll();
8850 } catch (Exception e) {
8851 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8852 }
8853 }
8854
8855 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008856 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8857 * bug report is being generated.
8858 */
8859 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008860 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008861 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8862 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008863 writer.println("Permission Denial: can't dump Phone from pid="
8864 + Binder.getCallingPid()
8865 + ", uid=" + Binder.getCallingUid()
8866 + "without permission "
8867 + android.Manifest.permission.DUMP);
8868 return;
8869 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008870 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008871 }
Jack Yueb89b242016-06-22 13:27:47 -07008872
Brad Ebingerdac2f002018-04-03 15:17:52 -07008873 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008874 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8875 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8876 @NonNull String[] args) {
8877 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8878 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008879 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008880 }
8881
Jack Yueb89b242016-06-22 13:27:47 -07008882 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008883 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008884 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008885 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008886 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008887 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008888 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008889 */
8890 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008891 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008892 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008893 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8894 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8895 try {
8896 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008897 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008898 } catch (SecurityException se) {
8899 enforceModifyPermission();
8900 }
8901 } else {
8902 enforceModifyPermission();
8903 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008904
8905 final long identity = Binder.clearCallingIdentity();
8906 try {
8907 Phone phone = getPhone(subId);
8908 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008909 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8910 phone.carrierActionSetMeteredApnsEnabled(enabled);
8911 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008912 phone.getDataSettingsManager().setDataEnabled(
8913 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008914 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008915 }
8916 } finally {
8917 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008918 }
8919 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008920
8921 /**
8922 * Get Client request stats
8923 * @return List of Client Request Stats
8924 * @hide
8925 */
8926 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008927 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8928 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008929 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008930 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008931 return null;
8932 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008933 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008935 final long identity = Binder.clearCallingIdentity();
8936 try {
8937 if (phone != null) {
8938 return phone.getClientRequestStats();
8939 }
8940
8941 return null;
8942 } finally {
8943 Binder.restoreCallingIdentity(identity);
8944 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008945 }
8946
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008947 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008948 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008949 if (uid == Process.ROOT_UID && packageName == null) {
8950 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8951 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8952 // exception. ROOT_UID seems not to have a valid package name returned by
8953 // PackageManager, so just fake it here to avoid issues when running telephony shell
8954 // commands that plumb through the RIL as root, like so:
8955 // $ adb root
8956 // $ adb shell cmd phone ...
8957 packageName = "root";
8958 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008959 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008960 }
Jack Yueb4124c2017-02-16 15:32:43 -08008961
8962 /**
Grace Chen70990072017-03-24 17:21:30 -07008963 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008964 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008965 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008966 * @param state State of SIM (power down, power up, pass through)
8967 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8968 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8969 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008970 *
8971 **/
8972 @Override
Grace Chen70990072017-03-24 17:21:30 -07008973 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008974 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008975 Phone phone = PhoneFactory.getPhone(slotIndex);
8976
vagdeviaf9a5b92018-08-15 16:01:53 -07008977 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8978
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008979 final long identity = Binder.clearCallingIdentity();
8980 try {
8981 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008982 phone.setSimPowerState(state, null, workSource);
8983 }
8984 } finally {
8985 Binder.restoreCallingIdentity(identity);
8986 }
8987 }
8988
8989 /**
8990 * Set SIM card power state.
8991 *
8992 * @param slotIndex SIM slot id.
8993 * @param state State of SIM (power down, power up, pass through)
8994 * @param callback callback to trigger after success or failure
8995 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8996 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8997 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8998 *
8999 **/
9000 @Override
9001 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9002 IIntegerConsumer callback) {
9003 enforceModifyPermission();
9004 Phone phone = PhoneFactory.getPhone(slotIndex);
9005
9006 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9007
9008 final long identity = Binder.clearCallingIdentity();
9009 try {
9010 if (phone != null) {
9011 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9012 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009013 }
9014 } finally {
9015 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009016 }
9017 }
Shuo Qiandd210312017-04-12 22:11:33 +00009018
Tyler Gunn65d45c22017-06-05 11:22:26 -07009019 private boolean isUssdApiAllowed(int subId) {
9020 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009021 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009022 if (configManager == null) {
9023 return false;
9024 }
9025 PersistableBundle pb = configManager.getConfigForSubId(subId);
9026 if (pb == null) {
9027 return false;
9028 }
9029 return pb.getBoolean(
9030 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9031 }
9032
Shuo Qiandd210312017-04-12 22:11:33 +00009033 /**
Ling Mac28f0212023-03-24 16:07:15 -07009034 * Check if phone is in emergency callback mode.
Shuo Qiandd210312017-04-12 22:11:33 +00009035 * @return true if phone is in emergency callback mode
Ling Mac28f0212023-03-24 16:07:15 -07009036 * @param subId sub Id, but the check is in fact irrlevant to sub Id.
Shuo Qiandd210312017-04-12 22:11:33 +00009037 */
goneil9c5f4872017-12-05 14:07:56 -08009038 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009039 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009040 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009041 final long identity = Binder.clearCallingIdentity();
9042 try {
Ling Mac28f0212023-03-24 16:07:15 -07009043 return getPhoneFromSubIdOrDefault(subId).isInEcm();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009044 } finally {
9045 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009046 }
9047 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009048
9049 /**
9050 * Get the current signal strength information for the given subscription.
9051 * Because this information is not updated when the device is in a low power state
9052 * it should not be relied-upon to be current.
9053 * @param subId Subscription index
9054 * @return the most recent cached signal strength info from the modem
9055 */
9056 @Override
9057 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009058 final long identity = Binder.clearCallingIdentity();
9059 try {
9060 Phone p = getPhone(subId);
9061 if (p == null) {
9062 return null;
9063 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009064
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009065 return p.getSignalStrength();
9066 } finally {
9067 Binder.restoreCallingIdentity(identity);
9068 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009069 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009070
Pengquan Meng77b7f132018-08-22 14:49:57 -07009071 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009072 * Get the current modem radio state for the given slot.
9073 * @param slotIndex slot index.
9074 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009075 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009076 * @return the current radio power state from the modem
9077 */
9078 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009079 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009080 Phone phone = PhoneFactory.getPhone(slotIndex);
9081 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009082 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9083 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009084 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9085 }
9086
9087 final long identity = Binder.clearCallingIdentity();
9088 try {
9089 return phone.getRadioPowerState();
9090 } finally {
9091 Binder.restoreCallingIdentity(identity);
9092 }
9093 }
9094 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9095 }
9096
9097 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009098 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9099 *
9100 * <p>Requires one of the following permissions:
9101 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009102 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009103 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9104 * privileges.
9105 *
9106 * @param subId subscription id
9107 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9108 * {@code false}.
9109 */
9110 @Override
9111 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009112 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009113 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009114 try {
9115 mApp.enforceCallingOrSelfPermission(
9116 android.Manifest.permission.ACCESS_NETWORK_STATE,
9117 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009118 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009119 mApp.enforceCallingOrSelfPermission(
9120 permission.READ_BASIC_PHONE_STATE, functionName);
9121 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009122 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009123 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009124 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009125 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009126
Pengquan Menga1bb6272018-09-06 09:59:22 -07009127 boolean isEnabled = false;
9128 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009129 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009130 Phone phone = getPhone(subId);
9131 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009132 } finally {
9133 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009134 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009135 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009136 }
9137
9138
9139 /**
9140 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9141 *
9142 * <p> Requires permission:
9143 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9144 * privileges.
9145 *
9146 * @param subId subscription id
9147 * @param isEnabled {@code true} means enable, {@code false} means disable.
9148 */
9149 @Override
9150 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9152 mApp, subId, "setDataRoamingEnabled");
9153
Pengquan Menga1bb6272018-09-06 09:59:22 -07009154 final long identity = Binder.clearCallingIdentity();
9155 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009156 Phone phone = getPhone(subId);
9157 if (phone != null) {
9158 phone.setDataRoamingEnabled(isEnabled);
9159 }
9160 } finally {
9161 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009162 }
9163 }
9164
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009165 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009166 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009167 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009168 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009169 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009170
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009171 boolean isAllowed = true;
9172 final long identity = Binder.clearCallingIdentity();
9173 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009174 Phone phone = getPhone(subId);
9175 if (phone != null) {
9176 isAllowed = phone.isCspPlmnEnabled();
9177 }
9178 } finally {
9179 Binder.restoreCallingIdentity(identity);
9180 }
9181 return isAllowed;
9182 }
9183
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009184 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9185 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009186 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009187 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009188 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009189 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9190 if (phone == null) {
9191 return false;
9192 }
9193 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9194 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9195 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009196 }
9197
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009198 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009199 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009200 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009201 mApp.getSystemService(AppOpsManager.class)
9202 .checkPackage(Binder.getCallingUid(), callingPackage);
9203
Jordan Liu1e142fc2019-04-22 15:10:43 -07009204 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009205 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009206 try {
9207 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009208 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009209 } catch (SecurityException e) {
9210 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9211 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009212 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009213 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009214 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009215 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009216 }
sandeepjsb6c87872021-09-27 15:34:44 +00009217 // checking compatibility, if calling app's target SDK is T and beyond.
9218 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9219 Binder.getCallingUid())) {
9220 isIccIdAccessRestricted = true;
9221 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009222 final long identity = Binder.clearCallingIdentity();
9223 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009224 UiccController uiccController = UiccController.getInstance();
9225 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009226 if (hasReadPermission) {
9227 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009228 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009229
9230 // Remove private info if the caller doesn't have access
9231 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9232 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009233 //setting the value after compatibility check
9234 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009235 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9236 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009237 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009238 if (card == null) {
9239 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009240 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009241 continue;
9242 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009243 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9244 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009245 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009246 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009247 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009248 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9249 for (UiccPortInfo portInfo : portInfos) {
9250 UiccPort port = uiccController.getUiccPortForSlot(
9251 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9252 if (port == null) {
9253 // assume no access if port is null
9254 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9255 continue;
9256 }
9257 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9258 uiccPortInfos.add(portInfo);
9259 } else {
9260 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9261 }
9262 }
9263 filteredInfos.add(new UiccCardInfo(
9264 cardInfo.isEuicc(),
9265 cardInfo.getCardId(),
9266 null,
9267 cardInfo.getPhysicalSlotIndex(),
9268 cardInfo.isRemovable(),
9269 cardInfo.isMultipleEnabledProfilesSupported(),
9270 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009271 }
9272 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009273 } finally {
9274 Binder.restoreCallingIdentity(identity);
9275 }
9276 }
9277
sandeepjsb6c87872021-09-27 15:34:44 +00009278 /**
9279 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9280 * generally private and require carrier privileges to view.
9281 *
9282 * @hide
9283 */
9284 @NonNull
9285 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9286 List<UiccPortInfo> portinfo = new ArrayList<>();
9287 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9288 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9289 }
9290 return new UiccCardInfo(
9291 cardInfo.isEuicc(),
9292 cardInfo.getCardId(),
9293 null,
9294 cardInfo.getPhysicalSlotIndex(),
9295 cardInfo.isRemovable(),
9296 cardInfo.isMultipleEnabledProfilesSupported(),
9297 portinfo
9298 );
9299 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009300
sandeepjsb6c87872021-09-27 15:34:44 +00009301 /**
9302 * @hide
9303 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9304 * These values are generally private and require carrier privileges to view.
9305 */
9306 @NonNull
9307 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9308 return new UiccPortInfo(
9309 UiccPortInfo.ICCID_REDACTED,
9310 portInfo.getPortIndex(),
9311 portInfo.getLogicalSlotIndex(),
9312 portInfo.isActive()
9313 );
9314 }
9315 @Override
9316 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009317 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009318 mApp.getSystemService(AppOpsManager.class)
9319 .checkPackage(Binder.getCallingUid(), callingPackage);
9320
sandeepjsb6c87872021-09-27 15:34:44 +00009321 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009322
Aman Guptaf3c90b32022-03-17 04:54:16 +00009323 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9324 // we are reading iccId which is PII data.
9325 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009326
9327 // checking compatibility, if calling app's target SDK is T and beyond.
9328 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9329 Binder.getCallingUid())) {
9330 isLogicalSlotAccessRestricted = true;
9331 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009332 final long identity = Binder.clearCallingIdentity();
9333 try {
9334 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009335 if (slots == null || slots.length == 0) {
9336 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009337 return null;
9338 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009339 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9340 for (int i = 0; i < slots.length; i++) {
9341 UiccSlot slot = slots[i];
9342 if (slot == null) {
9343 continue;
9344 }
9345
Jordan Liu7be7e652019-05-06 18:55:02 +00009346 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009347 UiccCard card = slot.getUiccCard();
9348 if (card != null) {
9349 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009350 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009351 cardId = slot.getEid();
9352 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009353 // If cardId is null, use iccId of default port as cardId.
9354 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009355 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009356 }
9357
Jordan Liu857451f2019-05-09 16:35:35 -07009358 if (cardId != null) {
9359 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9360 // if cardId is an EID, it's all digits so this is fine
9361 cardId = IccUtils.stripTrailingFs(cardId);
9362 }
9363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009364 int cardState = 0;
9365 switch (slot.getCardState()) {
9366 case CARDSTATE_ABSENT:
9367 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9368 break;
9369 case CARDSTATE_PRESENT:
9370 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9371 break;
9372 case CARDSTATE_ERROR:
9373 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9374 break;
9375 case CARDSTATE_RESTRICTED:
9376 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9377 break;
9378 default:
9379 break;
9380
9381 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009382 List<UiccPortInfo> portInfos = new ArrayList<>();
9383 int[] portIndexes = slot.getPortList();
9384 for (int portIdx : portIndexes) {
9385 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009386 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009387 portInfos.add(new UiccPortInfo(iccId, portIdx,
9388 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009389 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009390 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009391 slot.isEuicc(),
9392 cardId,
9393 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009394 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009395 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009396 //setting the value after compatibility check
9397 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009398 }
9399 return infos;
9400 } finally {
9401 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009402 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009403 }
9404
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009405 /* Returns null if doesn't have read permission or carrier privilege access. */
9406 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9407 boolean hasReadPermission) {
9408 String iccId = slot.getIccId(portIndex);
9409 if (hasReadPermission) { // if has read permission
9410 return iccId;
9411 } else {
9412 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9413 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9414 // if no read permission, checking carrier privilege access
9415 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9416 return iccId;
9417 }
9418 }
9419 }
9420 // No read permission or carrier privilege access.
9421 return UiccPortInfo.ICCID_REDACTED;
9422 }
9423
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009424 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009425 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009426 public boolean switchSlots(int[] physicalSlots) {
9427 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009428
9429 final long identity = Binder.clearCallingIdentity();
9430 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009431 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9432 for (int i = 0; i < physicalSlots.length; i++) {
9433 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9434 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9435 physicalSlots[i], i));
9436 }
9437 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009438 } finally {
9439 Binder.restoreCallingIdentity(identity);
9440 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009441 }
Jack Yu4c988042018-02-27 15:30:01 -08009442
9443 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009444 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9445 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9446 enforceModifyPermission();
9447
9448 final long identity = Binder.clearCallingIdentity();
9449 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009450 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009451 } finally {
9452 Binder.restoreCallingIdentity(identity);
9453 }
9454 }
9455
9456 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009457 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009458 final long identity = Binder.clearCallingIdentity();
9459 try {
9460 return UiccController.getInstance().getCardIdForDefaultEuicc();
9461 } finally {
9462 Binder.restoreCallingIdentity(identity);
9463 }
9464 }
9465
Pengquan Meng85728fb2018-03-12 16:31:21 -07009466 /**
goneil47ffb6e2018-04-06 15:40:58 -07009467 * A test API to reload the UICC profile.
9468 *
9469 * <p>Requires that the calling app has permission
9470 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9471 * @hide
9472 */
9473 @Override
9474 public void refreshUiccProfile(int subId) {
9475 enforceModifyPermission();
9476
9477 final long identity = Binder.clearCallingIdentity();
9478 try {
9479 Phone phone = getPhone(subId);
9480 if (phone == null) {
9481 return;
9482 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009483 UiccPort uiccPort = phone.getUiccPort();
9484 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009485 return;
9486 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009487 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009488 if (uiccProfile == null) {
9489 return;
9490 }
9491 uiccProfile.refresh();
9492 } finally {
9493 Binder.restoreCallingIdentity(identity);
9494 }
9495 }
9496
9497 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009498 * Returns false if the mobile data is disabled by default, otherwise return true.
9499 */
9500 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009501 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009502 }
9503
9504 /**
9505 * Returns true if the data roaming is enabled by default, i.e the system property
9506 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9507 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9508 */
9509 private boolean getDefaultDataRoamingEnabled(int subId) {
9510 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009511 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009512 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009513 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9514 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9515 return isDataRoamingEnabled;
9516 }
9517
9518 /**
9519 * Returns the default network type for the given {@code subId}, if the default network type is
9520 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9521 */
9522 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009523 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009524 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009525 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9526 return list.get(phoneId);
9527 }
9528 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009529 }
fionaxua13278b2018-03-21 00:08:13 -07009530
9531 @Override
9532 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009533 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009534 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009535
9536 final long identity = Binder.clearCallingIdentity();
9537 try {
9538 final Phone phone = getPhone(subId);
9539 if (phone == null) {
9540 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9541 return;
9542 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009543 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9544 if (cpt != null) {
9545 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9546 }
9547 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009548 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9549 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009550 if (carrierPrivilegeRules == null) {
9551 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9552 } else {
9553 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9554 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009555 } finally {
9556 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009557 }
fionaxua13278b2018-03-21 00:08:13 -07009558 }
9559
9560 @Override
Benedict Wong66477622023-02-03 23:30:57 +00009561 public void setCarrierServicePackageOverride(
9562 int subId, String carrierServicePackage, String callingPackage) {
9563 TelephonyPermissions.enforceShellOnly(
9564 Binder.getCallingUid(), "setCarrierServicePackageOverride");
9565
9566 // Verify that the callingPackage belongs to the calling UID
9567 mApp.getSystemService(AppOpsManager.class)
9568 .checkPackage(Binder.getCallingUid(), callingPackage);
9569
9570 final long identity = Binder.clearCallingIdentity();
9571 try {
9572 final Phone phone = getPhone(subId);
9573 if (phone == null || phone.getSubId() != subId) {
9574 loge("setCarrierServicePackageOverride fails with invalid subId: " + subId);
9575 throw new IllegalArgumentException("No phone for subid");
9576 }
9577 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9578 if (cpt == null) {
9579 loge("setCarrierServicePackageOverride failed with no CPT for phone");
9580 throw new IllegalStateException("No CPT for phone");
9581 }
9582 cpt.setTestOverrideCarrierServicePackage(carrierServicePackage);
9583 } finally {
9584 Binder.restoreCallingIdentity(identity);
9585 }
9586 }
9587
9588 @Override
fionaxua13278b2018-03-21 00:08:13 -07009589 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009590 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009591
9592 final long identity = Binder.clearCallingIdentity();
9593 try {
9594 final Phone phone = getPhone(subId);
9595 if (phone == null) {
9596 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9597 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9598 }
9599 return phone.getCarrierIdListVersion();
9600 } finally {
9601 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009602 }
fionaxua13278b2018-03-21 00:08:13 -07009603 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009604
9605 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009606 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9607 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009608 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009609 mApp, subId, callingPackage, callingFeatureId,
9610 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009611 return -1;
9612 }
9613
9614 final long identity = Binder.clearCallingIdentity();
9615 try {
9616 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9617 } finally {
9618 Binder.restoreCallingIdentity(identity);
9619 }
9620 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009621
9622 @Override
9623 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009624 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009625 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009626 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -07009627
9628 final long identity = Binder.clearCallingIdentity();
9629 try {
9630 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9631 } finally {
9632 Binder.restoreCallingIdentity(identity);
9633 }
9634 }
9635
9636 @Override
9637 public boolean setCdmaRoamingMode(int subId, int mode) {
9638 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9639 mApp, subId, "setCdmaRoamingMode");
9640
9641 final long identity = Binder.clearCallingIdentity();
9642 try {
9643 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9644 } finally {
9645 Binder.restoreCallingIdentity(identity);
9646 }
9647 }
9648
9649 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009650 public int getCdmaSubscriptionMode(int subId) {
9651 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009652 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009653 mApp, subId, "getCdmaSubscriptionMode");
9654
9655 final long identity = Binder.clearCallingIdentity();
9656 try {
9657 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9658 } finally {
9659 Binder.restoreCallingIdentity(identity);
9660 }
9661 }
9662
9663 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009664 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9666 mApp, subId, "setCdmaSubscriptionMode");
9667
9668 final long identity = Binder.clearCallingIdentity();
9669 try {
9670 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9671 } finally {
9672 Binder.restoreCallingIdentity(identity);
9673 }
9674 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009675
sqianc5eccab2018-10-19 18:46:41 -07009676 @Override
sqian8c685422019-02-22 15:55:18 -08009677 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009678 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009679 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009680 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9681 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009682 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9683 }
9684 final long identity = Binder.clearCallingIdentity();
9685 try {
sqian854d44b2018-12-12 16:48:18 -08009686 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9687 for (Phone phone: PhoneFactory.getPhones()) {
9688 if (phone.getEmergencyNumberTracker() != null
9689 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9690 emergencyNumberListInternal.put(
9691 phone.getSubId(),
9692 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9693 }
sqian11b7a0e2018-12-05 18:48:28 -08009694 }
sqian854d44b2018-12-12 16:48:18 -08009695 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009696 } finally {
9697 Binder.restoreCallingIdentity(identity);
9698 }
sqianc5eccab2018-10-19 18:46:41 -07009699 }
9700
9701 @Override
sqian8c685422019-02-22 15:55:18 -08009702 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009703 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009704 if (!exactMatch) {
9705 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009706 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009707 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009708 }
9709 final long identity = Binder.clearCallingIdentity();
9710 try {
sqian854d44b2018-12-12 16:48:18 -08009711 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009712 //Note: we ignore passed in param exactMatch. We can remove it once
9713 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009714 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009715 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009716 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009717 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009718 }
sqian11b7a0e2018-12-05 18:48:28 -08009719 }
9720 return false;
9721 } finally {
9722 Binder.restoreCallingIdentity(identity);
9723 }
9724 }
9725
sqianf4ca7ed2019-01-15 18:32:07 -08009726 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009727 * Start emergency callback mode for GsmCdmaPhone for testing.
9728 */
9729 @Override
9730 public void startEmergencyCallbackMode() {
9731 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9732 "startEmergencyCallbackMode");
9733 enforceModifyPermission();
9734 final long identity = Binder.clearCallingIdentity();
9735 try {
9736 for (Phone phone : PhoneFactory.getPhones()) {
9737 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9738 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9739 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9740 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9741 gsmCdmaPhone.obtainMessage(
9742 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9743 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9744 }
9745 }
9746 } finally {
9747 Binder.restoreCallingIdentity(identity);
9748 }
9749 }
9750
9751 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009752 * Update emergency number list for test mode.
9753 */
9754 @Override
9755 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9756 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9757 "updateEmergencyNumberListTestMode");
9758
9759 final long identity = Binder.clearCallingIdentity();
9760 try {
9761 for (Phone phone: PhoneFactory.getPhones()) {
9762 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9763 if (tracker != null) {
9764 tracker.executeEmergencyNumberTestModeCommand(action, num);
9765 }
9766 }
9767 } finally {
9768 Binder.restoreCallingIdentity(identity);
9769 }
9770 }
9771
9772 /**
9773 * Get the full emergency number list for test mode.
9774 */
9775 @Override
9776 public List<String> getEmergencyNumberListTestMode() {
9777 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9778 "getEmergencyNumberListTestMode");
9779
9780 final long identity = Binder.clearCallingIdentity();
9781 try {
9782 Set<String> emergencyNumbers = new HashSet<>();
9783 for (Phone phone: PhoneFactory.getPhones()) {
9784 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9785 if (tracker != null) {
9786 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9787 emergencyNumbers.add(num.getNumber());
9788 }
9789 }
9790 }
9791 return new ArrayList<>(emergencyNumbers);
9792 } finally {
9793 Binder.restoreCallingIdentity(identity);
9794 }
9795 }
9796
chen xud6b45bd2018-10-30 22:27:10 -07009797 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009798 public int getEmergencyNumberDbVersion(int subId) {
9799 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9800
9801 final long identity = Binder.clearCallingIdentity();
9802 try {
9803 final Phone phone = getPhone(subId);
9804 if (phone == null) {
9805 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9806 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9807 }
9808 return phone.getEmergencyNumberDbVersion();
9809 } finally {
9810 Binder.restoreCallingIdentity(identity);
9811 }
9812 }
9813
9814 @Override
9815 public void notifyOtaEmergencyNumberDbInstalled() {
9816 enforceModifyPermission();
9817
9818 final long identity = Binder.clearCallingIdentity();
9819 try {
9820 for (Phone phone: PhoneFactory.getPhones()) {
9821 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9822 if (tracker != null) {
9823 tracker.updateOtaEmergencyNumberDatabase();
9824 }
9825 }
9826 } finally {
9827 Binder.restoreCallingIdentity(identity);
9828 }
9829 }
9830
9831 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009832 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009833 enforceActiveEmergencySessionPermission();
9834
9835 final long identity = Binder.clearCallingIdentity();
9836 try {
9837 for (Phone phone: PhoneFactory.getPhones()) {
9838 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9839 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009840 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9841 }
9842 }
9843 } finally {
9844 Binder.restoreCallingIdentity(identity);
9845 }
9846 }
9847
9848 @Override
9849 public void resetOtaEmergencyNumberDbFilePath() {
9850 enforceActiveEmergencySessionPermission();
9851
9852 final long identity = Binder.clearCallingIdentity();
9853 try {
9854 for (Phone phone: PhoneFactory.getPhones()) {
9855 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9856 if (tracker != null) {
9857 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009858 }
9859 }
9860 } finally {
9861 Binder.restoreCallingIdentity(identity);
9862 }
9863 }
9864
9865 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009866 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9867 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9868 Phone phone = getPhone(subId);
9869 if (phone == null) {
9870 return null;
9871 }
9872 final long identity = Binder.clearCallingIdentity();
9873 try {
9874 UiccProfile profile = UiccController.getInstance()
9875 .getUiccProfileForPhone(phone.getPhoneId());
9876 if (profile != null) {
9877 return profile.getCertsFromCarrierPrivilegeAccessRules();
9878 }
9879 } finally {
9880 Binder.restoreCallingIdentity(identity);
9881 }
9882 return null;
9883 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009884
9885 /**
9886 * Enable or disable a modem stack.
9887 */
9888 @Override
9889 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9890 enforceModifyPermission();
9891
9892 final long identity = Binder.clearCallingIdentity();
9893 try {
9894 Phone phone = PhoneFactory.getPhone(slotIndex);
9895 if (phone == null) {
9896 return false;
9897 } else {
9898 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9899 }
9900 } finally {
9901 Binder.restoreCallingIdentity(identity);
9902 }
9903 }
Michelecea4cf22018-12-21 15:00:11 -08009904
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009905 /**
9906 * Whether a modem stack is enabled or not.
9907 */
9908 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009909 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9910 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009911 Phone phone = PhoneFactory.getPhone(slotIndex);
9912 if (phone == null) return false;
9913
9914 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009915 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9916 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009917 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9918 }
9919
9920 final long identity = Binder.clearCallingIdentity();
9921 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009922 try {
9923 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9924 } catch (NoSuchElementException ex) {
9925 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9926 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009927 } finally {
9928 Binder.restoreCallingIdentity(identity);
9929 }
9930 }
9931
Michelecea4cf22018-12-21 15:00:11 -08009932 @Override
Michele0ea7d782019-03-19 14:58:42 -07009933 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009934 enforceModifyPermission();
9935
9936 final long identity = Binder.clearCallingIdentity();
9937 try {
9938 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009939 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009940 .commit();
9941 } finally {
9942 Binder.restoreCallingIdentity(identity);
9943 }
9944 }
9945
9946 @Override
Michele0ea7d782019-03-19 14:58:42 -07009947 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009948 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009949 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009950 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9951 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009952 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009953 }
Michelecea4cf22018-12-21 15:00:11 -08009954
9955 final long identity = Binder.clearCallingIdentity();
9956 try {
Michele0ea7d782019-03-19 14:58:42 -07009957 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009958 } finally {
9959 Binder.restoreCallingIdentity(identity);
9960 }
9961 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009962
Michele0ea7d782019-03-19 14:58:42 -07009963 @TelephonyManager.IsMultiSimSupportedResult
9964 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009965 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9966 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9967 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009968 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9969 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009970 }
9971 // Check if the hardware supports multisim functionality. If usage of multisim is not
9972 // supported by the modem, indicate that it is restricted.
9973 PhoneCapability staticCapability =
9974 mPhoneConfigurationManager.getStaticPhoneCapability();
9975 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009976 loge("isMultiSimSupportedInternal: no static configuration available");
9977 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009978 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009979 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009980 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9981 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009982 }
9983 // Check if support of multiple SIMs is restricted by carrier
9984 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009985 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009986 }
9987
Michele0ea7d782019-03-19 14:58:42 -07009988 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009989 }
9990
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009991 /**
9992 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009993 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9994 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9995 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009996 * @param numOfSims number of active sims we want to switch to
9997 */
9998 @Override
9999 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010000 if (numOfSims == 1) {
10001 enforceModifyPermission();
10002 } else {
10003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10004 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10005 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010006 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010007
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010008 try {
Michele30b57b22019-03-01 12:01:14 -080010009 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010010 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010011 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10012 return;
10013 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010014 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10015 } finally {
10016 Binder.restoreCallingIdentity(identity);
10017 }
10018 }
10019
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010020 @Override
10021 public boolean isApplicationOnUicc(int subId, int appType) {
10022 enforceReadPrivilegedPermission("isApplicationOnUicc");
10023 Phone phone = getPhone(subId);
10024 if (phone == null) {
10025 return false;
10026 }
10027 final long identity = Binder.clearCallingIdentity();
10028 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010029 UiccPort uiccPort = phone.getUiccPort();
10030 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010031 return false;
10032 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010033 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010034 if (uiccProfile == null) {
10035 return false;
10036 }
10037 if (TelephonyManager.APPTYPE_SIM <= appType
10038 && appType <= TelephonyManager.APPTYPE_ISIM) {
10039 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10040 }
10041 return false;
10042 } finally {
10043 Binder.restoreCallingIdentity(identity);
10044 }
10045 }
10046
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010047 /**
chen xub4baa772019-04-03 10:23:41 -070010048 * Get whether making changes to modem configurations will trigger reboot.
10049 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010050 */
10051 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010052 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10053 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010054 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010055 mApp, subId, callingPackage, callingFeatureId,
10056 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010057 return false;
10058 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010059 final long identity = Binder.clearCallingIdentity();
10060 try {
10061 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10062 } finally {
10063 Binder.restoreCallingIdentity(identity);
10064 }
10065 }
10066
Nathan Harold29f5f052019-02-15 13:41:57 -080010067 private void updateModemStateMetrics() {
10068 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10069 // TODO: check the state for each modem if the api is ready.
10070 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10071 }
10072
Pengquan Meng3889a572019-01-23 11:16:29 -080010073 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010074 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010075 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010076 // Verify that the callingPackage belongs to the calling UID
10077 mApp.getSystemService(AppOpsManager.class)
10078 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010079 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010080 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010081 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010082 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10083 if (slotInfos != null) {
10084 for (int i = 0; i < slotInfos.length; i++) {
10085 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10086 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10087 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10088 portInfo.getLogicalSlotIndex()));
10089 }
10090 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010091 }
10092 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010093 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010094 } finally {
10095 Binder.restoreCallingIdentity(identity);
10096 }
10097 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010098
10099 /**
10100 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010101 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010102 */
jimsunf9ec1622022-09-13 21:18:43 +080010103 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010104 @Override
10105 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010106 return getHalVersion(HAL_SERVICE_RADIO);
10107 }
10108
10109 /**
10110 * Get the HAL Version of a specific service
10111 */
10112 @Override
10113 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010114 Phone phone = getDefaultPhone();
10115 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010116 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010117 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10118 return hv.major * 100 + hv.minor;
10119 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010120
10121 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010122 * Get the current calling package name.
10123 * @return the current calling package name
10124 */
10125 @Override
10126 public String getCurrentPackageName() {
10127 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10128 }
10129
10130 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010131 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10132 * corresponding network requests on a subId.
10133 *
10134 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010135 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010136 * 2) APN is un-metered for this subscription, or
10137 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010138 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010139 *
10140 * @return whether data is allowed for a apn type.
10141 *
10142 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010143 */
10144 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010145 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010146 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10147 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010148
10149 // Now that all security checks passes, perform the operation as ourselves.
10150 final long identity = Binder.clearCallingIdentity();
10151 try {
10152 Phone phone = getPhone(subId);
10153 if (phone == null) return false;
10154
Jack Yu27422a52022-03-21 10:38:05 -070010155 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010156 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010157 isMetered = phone.getDataNetworkController().getDataConfigManager()
10158 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10159 phone.getServiceState().getDataRoaming());
10160 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010161 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010162 } finally {
10163 Binder.restoreCallingIdentity(identity);
10164 }
10165 }
10166
10167 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010168 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010169 enforceReadPrivilegedPermission("isApnMetered");
10170
10171 // Now that all security checks passes, perform the operation as ourselves.
10172 final long identity = Binder.clearCallingIdentity();
10173 try {
10174 Phone phone = getPhone(subId);
10175 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010176 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10177 DataUtils.apnTypeToNetworkCapability(apnType),
10178 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010179 } finally {
10180 Binder.restoreCallingIdentity(identity);
10181 }
10182 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010183
10184 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010185 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10186 int subscriptionId, IBooleanConsumer resultCallback) {
10187 enforceModifyPermission();
10188 long token = Binder.clearCallingIdentity();
10189 try {
10190 Phone phone = getPhone(subscriptionId);
10191 if (phone == null) {
10192 try {
10193 if (resultCallback != null) {
10194 resultCallback.accept(false);
10195 }
10196 } catch (RemoteException e) {
10197 // ignore
10198 }
10199 return;
10200 }
10201 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10202 Pair.create(specifiers, (x) -> {
10203 try {
10204 if (resultCallback != null) {
10205 resultCallback.accept(x);
10206 }
10207 } catch (RemoteException e) {
10208 // ignore
10209 }
10210 });
10211 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10212 } finally {
10213 Binder.restoreCallingIdentity(token);
10214 }
10215 }
10216
10217 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010218 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10219 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010220 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010221 mApp, subId, "getSystemSelectionChannels");
10222 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10223 final long identity = Binder.clearCallingIdentity();
10224 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010225 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10226 if (result instanceof IllegalStateException) {
10227 throw (IllegalStateException) result;
10228 }
10229 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010230 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10231 return specifiers;
10232 } finally {
10233 Binder.restoreCallingIdentity(identity);
10234 }
10235 }
10236
10237 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010238 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010239 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010240 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010241 }
10242
10243 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010244 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10245 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010246 if (callingPackage == null) {
10247 callingPackage = getCurrentPackageName();
10248 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010249 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10250 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010251 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10252 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010253 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10254 }
10255 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10256 Intent intent = new Intent();
10257 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10258 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10259 // Bring up choose default SMS subscription dialog right now
10260 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10261 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10262 mApp.startActivity(intent);
10263 }
chen xud5ca2d52019-05-28 15:20:57 -070010264
10265 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010266 public void showSwitchToManagedProfileDialog() {
10267 enforceModifyPermission();
10268
10269 Intent intent = new Intent();
10270 intent.setClass(mApp, ErrorDialogActivity.class);
10271 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10272 mApp.startActivity(intent);
10273 }
10274
10275 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010276 public String getMmsUAProfUrl(int subId) {
10277 //TODO investigate if this API should require proper permission check in R b/133791609
10278 final long identity = Binder.clearCallingIdentity();
10279 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010280 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10281 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10282 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10283 return carrierUAProfUrl;
10284 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010285 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10286 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010287 } finally {
10288 Binder.restoreCallingIdentity(identity);
10289 }
10290 }
10291
10292 @Override
10293 public String getMmsUserAgent(int subId) {
10294 //TODO investigate if this API should require proper permission check in R b/133791609
10295 final long identity = Binder.clearCallingIdentity();
10296 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010297 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10298 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10299 if (!TextUtils.isEmpty(carrierUserAgent)) {
10300 return carrierUserAgent;
10301 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010302 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10303 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010304 } finally {
10305 Binder.restoreCallingIdentity(identity);
10306 }
10307 }
Jack Yub07d4972019-05-28 16:12:25 -070010308
10309 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010310 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10311 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010312
Jack Yub07d4972019-05-28 16:12:25 -070010313 final long identity = Binder.clearCallingIdentity();
10314 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010315 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010316 if (phone == null) return false;
10317
Ling Maf188d502022-09-16 15:22:36 -070010318 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010319 } finally {
10320 Binder.restoreCallingIdentity(identity);
10321 }
10322 }
10323
10324 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010325 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010326 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010327 enforceModifyPermission();
10328
changbettyd5c246e2019-12-24 15:40:37 +080010329 final long identity = Binder.clearCallingIdentity();
10330 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010331 Phone phone = getPhone(subscriptionId);
10332 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010333
Ling Maf188d502022-09-16 15:22:36 -070010334 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010335 } finally {
10336 Binder.restoreCallingIdentity(identity);
10337 }
10338 }
10339
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010340 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010341 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010342 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10343 * otherwise.
10344 */
10345 @Override
10346 public void setCepEnabled(boolean isCepEnabled) {
10347 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10348
10349 final long identity = Binder.clearCallingIdentity();
10350 try {
10351 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10352 for (Phone phone : PhoneFactory.getPhones()) {
10353 Phone defaultPhone = phone.getImsPhone();
10354 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10355 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10356 ImsPhoneCallTracker imsPhoneCallTracker =
10357 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10358 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10359 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10360 + imsPhone.getMsisdn());
10361 }
10362 }
10363 } finally {
10364 Binder.restoreCallingIdentity(identity);
10365 }
10366 }
allenwtsu46dcc572020-01-08 18:24:03 +080010367
10368 /**
10369 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10370 *
10371 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10372 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10373 * before being read.
10374 */
10375 @Override
10376 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10377 isCompressed) {
10378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10379 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010380 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10381 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10382 }
10383 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010384 // ProvisioningManager can not handle ServiceSpecificException.
10385 // Throw the IllegalStateException and annotate ProvisioningManager.
10386 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010387 }
10388
10389 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010390 try {
Hui Wang761a6682020-10-31 05:12:53 +000010391 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10392 } finally {
10393 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010394 }
10395 }
zoey chene02881a2019-12-30 16:11:23 +080010396
10397 @Override
10398 public boolean isIccLockEnabled(int subId) {
10399 enforceReadPrivilegedPermission("isIccLockEnabled");
10400
10401 // Now that all security checks passes, perform the operation as ourselves.
10402 final long identity = Binder.clearCallingIdentity();
10403 try {
10404 Phone phone = getPhone(subId);
10405 if (phone != null && phone.getIccCard() != null) {
10406 return phone.getIccCard().getIccLockEnabled();
10407 } else {
10408 return false;
10409 }
10410 } finally {
10411 Binder.restoreCallingIdentity(identity);
10412 }
10413 }
10414
10415 /**
10416 * Set the ICC pin lock enabled or disabled.
10417 *
10418 * @return an integer representing the status of IccLock enabled or disabled in the following
10419 * three cases:
10420 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10421 * successfully.
10422 * - Positive number and zero for remaining password attempts.
10423 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10424 *
10425 */
10426 @Override
10427 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10428 enforceModifyPermission();
10429
10430 Phone phone = getPhone(subId);
10431 if (phone == null) {
10432 return 0;
10433 }
10434 // Now that all security checks passes, perform the operation as ourselves.
10435 final long identity = Binder.clearCallingIdentity();
10436 try {
10437 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10438 new Pair<Boolean, String>(enabled, password), phone, null);
10439 return attemptsRemaining;
10440
10441 } catch (Exception e) {
10442 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10443 } finally {
10444 Binder.restoreCallingIdentity(identity);
10445 }
10446 return 0;
10447 }
10448
10449 /**
10450 * Change the ICC password used in ICC pin lock.
10451 *
10452 * @return an integer representing the status of IccLock changed in the following three cases:
10453 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10454 * - Positive number and zero for remaining password attempts.
10455 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10456 *
10457 */
10458 @Override
10459 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10460 enforceModifyPermission();
10461
10462 Phone phone = getPhone(subId);
10463 if (phone == null) {
10464 return 0;
10465 }
10466 // Now that all security checks passes, perform the operation as ourselves.
10467 final long identity = Binder.clearCallingIdentity();
10468 try {
10469 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10470 new Pair<String, String>(oldPassword, newPassword), phone, null);
10471 return attemptsRemaining;
10472
10473 } catch (Exception e) {
10474 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10475 } finally {
10476 Binder.restoreCallingIdentity(identity);
10477 }
10478 return 0;
10479 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010480
10481 /**
10482 * Request for receiving user activity notification
10483 */
10484 @Override
10485 public void requestUserActivityNotification() {
10486 if (!mNotifyUserActivity.get()
10487 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10488 mNotifyUserActivity.set(true);
10489 }
10490 }
10491
10492 /**
10493 * Called when userActivity is signalled in the power manager.
10494 * This is safe to call from any thread, with any window manager locks held or not.
10495 */
10496 @Override
10497 public void userActivity() {
10498 // ***************************************
10499 // * Inherited from PhoneWindowManager *
10500 // ***************************************
10501 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10502 // WITH ITS LOCKS HELD.
10503 //
10504 // This code must be VERY careful about the locks
10505 // it acquires.
10506 // In fact, the current code acquires way too many,
10507 // and probably has lurking deadlocks.
10508
10509 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10510 throw new SecurityException("Only the OS may call notifyUserActivity()");
10511 }
10512
10513 if (mNotifyUserActivity.getAndSet(false)) {
10514 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10515 USER_ACTIVITY_NOTIFICATION_DELAY);
10516 }
10517 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010518
10519 @Override
10520 public boolean canConnectTo5GInDsdsMode() {
10521 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10522 }
Jack Yud10cdd42020-09-28 20:28:01 -070010523
10524 @Override
10525 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10526 String callingFeatureId) {
10527 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10528 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10529 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10530 }
10531
10532 Phone phone = getPhone(subId);
10533 if (phone == null) {
10534 throw new RuntimeException("phone is not available");
10535 }
10536 // Now that all security checks passes, perform the operation as ourselves.
10537 final long identity = Binder.clearCallingIdentity();
10538 try {
10539 return phone.getEquivalentHomePlmns();
10540 } finally {
10541 Binder.restoreCallingIdentity(identity);
10542 }
10543 }
Daniel Bright59e67312020-11-13 11:49:37 -080010544
10545 @Override
10546 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010547 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10548 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010549 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010550 if (radioInterfaceCapabilities == null) {
10551 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010552 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010553 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010554 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010555
Hui Wang641e81c2020-10-12 12:14:23 -070010556 @Override
10557 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10558 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010559 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10560 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10561 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10562 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10563 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010564 if (DBG) {
10565 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10566 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10567 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10568 }
10569
10570 if (!SubscriptionManager.isValidSubscriptionId(subId)
10571 || appType < TelephonyManager.APPTYPE_UNKNOWN
10572 || appType > TelephonyManager.APPTYPE_ISIM
10573 || nafUrl == null || securityProtocol == null || callback == null) {
10574 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10575 if (callback != null) {
10576 try {
10577 callback.onAuthenticationFailure(
10578 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10579 } catch (RemoteException exception) {
10580 log("Fail to notify onAuthenticationFailure due to " + exception);
10581 }
10582 return;
10583 }
10584 }
10585
10586 final long token = Binder.clearCallingIdentity();
10587 try {
10588 getGbaManager(subId).bootstrapAuthenticationRequest(
10589 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010590 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070010591 } finally {
10592 Binder.restoreCallingIdentity(token);
10593 }
10594 }
10595
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010596 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010597 * Attempts to set the radio power state for all phones for thermal reason.
10598 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010599 * requested radio power state will actually be set. See {@link
10600 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10601 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010602 * @param enable {@code true} if trying to turn radio on.
10603 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10604 * false}.
10605 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010606 private boolean setRadioPowerForThermal(boolean enable) {
10607 boolean isPhoneAvailable = false;
10608 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10609 Phone phone = PhoneFactory.getPhone(i);
10610 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010611 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010612 isPhoneAvailable = true;
10613 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010614 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010615
10616 // return true if successfully informed the phone object about the thermal radio power
10617 // request.
10618 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010619 }
10620
10621 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010622 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010623 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10624 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10625 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10626 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10627 throw new IllegalArgumentException("modem does not support data throttling");
10628 }
10629
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010630 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10631 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010632 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010633 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10634 }
10635
Sarah Chinecc78c42022-03-31 21:16:48 -070010636 setDataEnabledForReason(
10637 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010638
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010639 if (isDataThrottlingSupported) {
10640 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010641 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010642 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10643 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10644 } else if (thermalMitigationResult
10645 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010646 log("Modem likely does not support data throttling on secondary carrier. Data " +
10647 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10648 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010649 }
10650 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010651 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010652
10653 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010654 }
10655
Jack Nudelman644b91a2021-03-12 14:09:48 -080010656 private static List<String> getThermalMitigationAllowlist(Context context) {
10657 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10658 for (String pckg : context.getResources()
10659 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10660 sThermalMitigationAllowlistedPackages.add(pckg);
10661 }
10662 }
10663
10664 return sThermalMitigationAllowlistedPackages;
10665 }
10666
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010667 private boolean isAnyPhoneInEmergencyState() {
10668 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10669 if (tm.isInEmergencyCall()) {
10670 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10671 return true;
10672 }
10673 for (Phone phone : PhoneFactory.getPhones()) {
10674 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10675 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010676 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10677 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010678 return true;
10679 }
10680 }
10681
10682 return false;
10683 }
10684
Jack Nudelman644b91a2021-03-12 14:09:48 -080010685 /**
10686 * Used by shell commands to add an authorized package name for thermal mitigation.
10687 * @param packageName name of package to be allowlisted
10688 * @param context
10689 */
10690 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10691 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10692 sThermalMitigationAllowlistedPackages.add(packageName);
10693 }
10694
10695 /**
10696 * Used by shell commands to remove an authorized package name for thermal mitigation.
10697 * @param packageName name of package to remove from allowlist
10698 * @param context
10699 */
10700 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10701 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10702 sThermalMitigationAllowlistedPackages.remove(packageName);
10703 }
10704
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010705 /**
10706 * Thermal mitigation request to control functionalities at modem.
10707 *
10708 * @param subId the id of the subscription.
10709 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010710 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010711 *
10712 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10713 */
10714 @Override
10715 @ThermalMitigationResult
10716 public int sendThermalMitigationRequest(
10717 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010718 ThermalMitigationRequest thermalMitigationRequest,
10719 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010720 enforceModifyPermission();
10721
Jack Nudelman644b91a2021-03-12 14:09:48 -080010722 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10723 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10724 .contains(callingPackage)) {
10725 throw new SecurityException("Calling package must be configured in the device config. "
10726 + "calling package: " + callingPackage);
10727 }
10728
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010729 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10730 final long identity = Binder.clearCallingIdentity();
10731
10732 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10733 try {
10734 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10735 switch (thermalMitigationAction) {
10736 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10737 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010738 handleDataThrottlingRequest(subId,
10739 thermalMitigationRequest.getDataThrottlingRequest(),
10740 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010741 break;
10742 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10743 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10744 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10745 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10746 }
10747
10748 // Ensure that radio is on. If not able to power on due to phone being
10749 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010750 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010751 thermalMitigationResult =
10752 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10753 break;
10754 }
10755
10756 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010757 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010758 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10759 break;
10760 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10761 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10762 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10763 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10764 }
10765
10766 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10767 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010768 Phone phone = getPhone(subId);
10769 if (phone == null) {
10770 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010771 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010772 break;
10773 }
10774
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010775 TelephonyConnectionService service =
10776 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010777 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010778 Log.e(LOG_TAG, "An emergency call is pending");
10779 thermalMitigationResult =
10780 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10781 break;
10782 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010783 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010784 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010785 break;
10786 }
10787 } else {
10788 thermalMitigationResult =
10789 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10790 break;
10791 }
10792
10793 // Turn radio off. If not able to power off due to phone being unavailable,
10794 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010795 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010796 thermalMitigationResult =
10797 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10798 break;
10799 }
10800 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010801 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010802 break;
10803 default:
10804 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10805 + "not exist. Requested action: " + thermalMitigationAction);
10806 }
10807 } catch (IllegalArgumentException e) {
10808 throw e;
10809 } catch (Exception e) {
10810 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10811 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10812 } finally {
10813 Binder.restoreCallingIdentity(identity);
10814 }
10815
10816 if (DBG) {
10817 log("thermalMitigationRequest returning with thermalMitigationResult: "
10818 + thermalMitigationResult);
10819 }
10820
10821 return thermalMitigationResult;
10822 }
Hui Wang641e81c2020-10-12 12:14:23 -070010823
10824 /**
10825 * Set the GbaService Package Name that Telephony will bind to.
10826 *
10827 * @param subId The sim that the GbaService is associated with.
10828 * @param packageName The name of the package to be replaced with.
10829 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10830 */
10831 @Override
10832 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10833 enforceModifyPermission();
10834
10835 final long identity = Binder.clearCallingIdentity();
10836 try {
10837 return getGbaManager(subId).overrideServicePackage(packageName);
10838 } finally {
10839 Binder.restoreCallingIdentity(identity);
10840 }
10841 }
10842
10843 /**
10844 * Return the package name of the currently bound GbaService.
10845 *
10846 * @param subId The sim that the GbaService is associated with.
10847 * @return the package name of the GbaService configuration, null if GBA is not supported.
10848 */
10849 @Override
10850 public String getBoundGbaService(int subId) {
10851 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10852
10853 final long identity = Binder.clearCallingIdentity();
10854 try {
10855 return getGbaManager(subId).getServicePackage();
10856 } finally {
10857 Binder.restoreCallingIdentity(identity);
10858 }
10859 }
10860
10861 /**
10862 * Set the release time for telephony to unbind GbaService.
10863 *
10864 * @param subId The sim that the GbaService is associated with.
10865 * @param interval The release time to unbind GbaService by millisecond.
10866 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10867 */
10868 @Override
10869 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10870 enforceModifyPermission();
10871
10872 final long identity = Binder.clearCallingIdentity();
10873 try {
10874 return getGbaManager(subId).overrideReleaseTime(interval);
10875 } finally {
10876 Binder.restoreCallingIdentity(identity);
10877 }
10878 }
10879
10880 /**
10881 * Return the release time for telephony to unbind GbaService.
10882 *
10883 * @param subId The sim that the GbaService is associated with.
10884 * @return The release time to unbind GbaService by millisecond.
10885 */
10886 @Override
10887 public int getGbaReleaseTime(int subId) {
10888 enforceReadPrivilegedPermission("getGbaReleaseTime");
10889
10890 final long identity = Binder.clearCallingIdentity();
10891 try {
10892 return getGbaManager(subId).getReleaseTime();
10893 } finally {
10894 Binder.restoreCallingIdentity(identity);
10895 }
10896 }
10897
10898 private GbaManager getGbaManager(int subId) {
10899 GbaManager instance = GbaManager.getInstance(subId);
10900 if (instance == null) {
10901 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10902 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10903 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10904 }
10905 return instance;
10906 }
Hui Wang761a6682020-10-31 05:12:53 +000010907
10908 /**
10909 * indicate whether the device and the carrier can support
10910 * RCS VoLTE single registration.
10911 */
10912 @Override
10913 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010914 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10915 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10916 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10917 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010918
10919 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10920 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10921 }
10922
10923 final long identity = Binder.clearCallingIdentity();
10924 try {
10925 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10926 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010927 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10928 if (isCapable != null) {
10929 return isCapable;
10930 }
Hui Wang761a6682020-10-31 05:12:53 +000010931 }
Hui Wang67af90e2021-06-04 16:57:15 -070010932 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10933 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010934 } finally {
10935 Binder.restoreCallingIdentity(identity);
10936 }
10937 }
10938
10939 /**
10940 * Register RCS provisioning callback.
10941 */
10942 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010943 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010944 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010945 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010946 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010947 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10948 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010949
10950 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10951 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10952 }
10953 if (!isImsAvailableOnDevice()) {
10954 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10955 "IMS not available on device.");
10956 }
10957
10958 final long identity = Binder.clearCallingIdentity();
10959 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010960 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010961 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010962 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10963 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010964 }
Hui Wang761a6682020-10-31 05:12:53 +000010965 } finally {
10966 Binder.restoreCallingIdentity(identity);
10967 }
10968 }
10969
10970 /**
10971 * Unregister RCS provisioning callback.
10972 */
10973 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010974 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010975 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010976 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010977 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010978 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10979 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010980
10981 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10982 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10983 }
10984 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010985 // operation failed silently
10986 Rlog.w(LOG_TAG, "IMS not available on device.");
10987 return;
Hui Wang761a6682020-10-31 05:12:53 +000010988 }
10989
10990 final long identity = Binder.clearCallingIdentity();
10991 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010992 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010993 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010994 } finally {
10995 Binder.restoreCallingIdentity(identity);
10996 }
10997 }
10998
10999 /**
11000 * trigger RCS reconfiguration.
11001 */
11002 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011003 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11004 "triggerRcsReconfiguration",
11005 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011006
11007 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11008 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11009 }
11010 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011011 // ProvisioningManager can not handle ServiceSpecificException.
11012 // Throw the IllegalStateException and annotate ProvisioningManager.
11013 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000011014 }
11015
11016 final long identity = Binder.clearCallingIdentity();
11017 try {
11018 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11019 } finally {
11020 Binder.restoreCallingIdentity(identity);
11021 }
11022 }
11023
11024 /**
11025 * Provide the client configuration parameters of the RCS application.
11026 */
11027 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011028 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11029 "setRcsClientConfiguration",
11030 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011031
11032 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11033 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11034 }
11035 if (!isImsAvailableOnDevice()) {
11036 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11037 "IMS not available on device.");
11038 }
11039
11040 final long identity = Binder.clearCallingIdentity();
11041
11042 try {
11043 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11044 if (configBinder == null) {
11045 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011046 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11047 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011048 } else {
11049 configBinder.setRcsClientConfiguration(rcc);
11050 }
joonhunshin3e154242021-09-17 06:33:39 +000011051
11052 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11053 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011054 } catch (RemoteException e) {
11055 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011056 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11057 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011058 } finally {
11059 Binder.restoreCallingIdentity(identity);
11060 }
11061 }
11062
11063 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011064 * Enables or disables the test mode for RCS VoLTE single registration.
11065 */
11066 @Override
11067 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11068 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11069 "setRcsSingleRegistrationTestModeEnabled");
11070
11071 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11072 }
11073
11074 /**
11075 * Gets the test mode for RCS VoLTE single registration.
11076 */
11077 @Override
11078 public boolean getRcsSingleRegistrationTestModeEnabled() {
11079 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11080 "getRcsSingleRegistrationTestModeEnabled");
11081
11082 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11083 }
11084
11085 /**
Hui Wang761a6682020-10-31 05:12:53 +000011086 * Overrides the config of RCS VoLTE single registration enabled for the device.
11087 */
11088 @Override
11089 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11090 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11091 "setDeviceSingleRegistrationEnabledOverride");
11092 enforceModifyPermission();
11093
11094 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11095 : Boolean.parseBoolean(enabledStr);
11096 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011097 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011098 }
11099
11100 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011101 * Sends a device to device communication message. Only usable via shell.
11102 * @param message message to send.
11103 * @param value message value.
11104 */
11105 @Override
11106 public void sendDeviceToDeviceMessage(int message, int value) {
11107 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011108 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011109 enforceModifyPermission();
11110
11111 final long identity = Binder.clearCallingIdentity();
11112 try {
11113 TelephonyConnectionService service =
11114 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11115 if (service == null) {
11116 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11117 return;
11118 }
11119 service.sendTestDeviceToDeviceMessage(message, value);
11120 } finally {
11121 Binder.restoreCallingIdentity(identity);
11122 }
11123 }
11124
Tyler Gunnbabbda02021-02-10 11:05:02 -080011125 /**
11126 * Sets the specified device to device transport active.
11127 * @param transport The transport to set active.
11128 */
11129 @Override
11130 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11131 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11132 "setActiveDeviceToDeviceTransport");
11133 enforceModifyPermission();
11134
11135 final long identity = Binder.clearCallingIdentity();
11136 try {
11137 TelephonyConnectionService service =
11138 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11139 if (service == null) {
11140 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11141 return;
11142 }
11143 service.setActiveDeviceToDeviceTransport(transport);
11144 } finally {
11145 Binder.restoreCallingIdentity(identity);
11146 }
11147 }
Tyler Gunn92479152021-01-20 16:30:10 -080011148
Tyler Gunnd4339262021-05-03 14:46:49 -070011149 @Override
11150 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11151 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11152 "setDeviceToDeviceForceEnabled");
11153
11154 final long identity = Binder.clearCallingIdentity();
11155 try {
11156 Arrays.stream(PhoneFactory.getPhones()).forEach(
11157 p -> {
11158 Phone thePhone = p.getImsPhone();
11159 if (thePhone != null && thePhone instanceof ImsPhone) {
11160 ImsPhone imsPhone = (ImsPhone) thePhone;
11161 CallTracker tracker = imsPhone.getCallTracker();
11162 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11163 ImsPhoneCallTracker imsPhoneCallTracker =
11164 (ImsPhoneCallTracker) tracker;
11165 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11166 }
11167 }
11168 }
11169 );
11170 } finally {
11171 Binder.restoreCallingIdentity(identity);
11172 }
11173 }
11174
Tyler Gunn92479152021-01-20 16:30:10 -080011175 /**
Hui Wang761a6682020-10-31 05:12:53 +000011176 * Gets the config of RCS VoLTE single registration enabled for the device.
11177 */
11178 @Override
11179 public boolean getDeviceSingleRegistrationEnabled() {
11180 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11181 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11182 }
11183
11184 /**
11185 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11186 */
11187 @Override
11188 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11189 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11190 "setCarrierSingleRegistrationEnabledOverride");
11191 enforceModifyPermission();
11192
11193 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11194 : Boolean.parseBoolean(enabledStr);
11195 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11196 subId, enabled);
11197 }
11198
11199 /**
11200 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11201 */
11202 @Override
11203 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11204 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11205 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11206 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011207
11208 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011209 * Overrides the ims feature validation result
11210 */
11211 @Override
11212 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11213 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11214 "setImsFeatureValidationOverride");
11215
11216 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11217 : Boolean.parseBoolean(enabledStr);
11218 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11219 subId, enabled);
11220 }
11221
11222 /**
11223 * Gets the ims feature validation override value
11224 */
11225 @Override
11226 public boolean getImsFeatureValidationOverride(int subId) {
11227 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11228 "getImsFeatureValidationOverride");
11229 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11230 }
11231
11232 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011233 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11234 * their mobile plan.
11235 */
11236 @Override
11237 public String getMobileProvisioningUrl() {
11238 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11239 final long identity = Binder.clearCallingIdentity();
11240 try {
11241 return getDefaultPhone().getMobileProvisioningUrl();
11242 } finally {
11243 Binder.restoreCallingIdentity(identity);
11244 }
11245 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011246
James.cf Linbcdf8b32021-01-14 16:44:13 +080011247 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011248 * Get the EAB contact from the EAB database.
11249 */
11250 @Override
11251 public String getContactFromEab(String contact) {
11252 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11253 enforceModifyPermission();
11254 final long identity = Binder.clearCallingIdentity();
11255 try {
11256 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11257 } finally {
11258 Binder.restoreCallingIdentity(identity);
11259 }
11260 }
11261
11262 /**
Calvin Pana1434322021-07-01 19:27:01 +080011263 * Get the EAB capability from the EAB database.
11264 */
11265 @Override
11266 public String getCapabilityFromEab(String contact) {
11267 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11268 enforceModifyPermission();
11269 final long identity = Binder.clearCallingIdentity();
11270 try {
11271 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11272 } finally {
11273 Binder.restoreCallingIdentity(identity);
11274 }
11275 }
11276
11277 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011278 * Remove the EAB contacts from the EAB database.
11279 */
11280 @Override
11281 public int removeContactFromEab(int subId, String contacts) {
11282 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11283 enforceModifyPermission();
11284 final long identity = Binder.clearCallingIdentity();
11285 try {
11286 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11287 } finally {
11288 Binder.restoreCallingIdentity(identity);
11289 }
11290 }
11291
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011292 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011293 public boolean getDeviceUceEnabled() {
11294 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11295 final long identity = Binder.clearCallingIdentity();
11296 try {
11297 return mApp.getDeviceUceEnabled();
11298 } finally {
11299 Binder.restoreCallingIdentity(identity);
11300 }
11301 }
11302
11303 @Override
11304 public void setDeviceUceEnabled(boolean isEnabled) {
11305 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11306 final long identity = Binder.clearCallingIdentity();
11307 try {
11308 mApp.setDeviceUceEnabled(isEnabled);
11309 } finally {
11310 Binder.restoreCallingIdentity(identity);
11311 }
11312 }
11313
Brad Ebinger14d467f2021-02-12 06:18:28 +000011314 /**
11315 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11316 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11317 */
11318 // Used for SHELL command only right now.
11319 @Override
11320 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11321 List<String> featureTags) {
11322 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11323 "addUceRegistrationOverrideShell");
11324 final long identity = Binder.clearCallingIdentity();
11325 try {
11326 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11327 new ArraySet<>(featureTags));
11328 } catch (ImsException e) {
11329 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11330 } finally {
11331 Binder.restoreCallingIdentity(identity);
11332 }
11333 }
11334
11335 /**
11336 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11337 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11338 */
11339 // Used for SHELL command only right now.
11340 @Override
11341 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11342 List<String> featureTags) {
11343 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11344 "removeUceRegistrationOverrideShell");
11345 final long identity = Binder.clearCallingIdentity();
11346 try {
11347 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11348 new ArraySet<>(featureTags));
11349 } catch (ImsException e) {
11350 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11351 } finally {
11352 Binder.restoreCallingIdentity(identity);
11353 }
11354 }
11355
11356 /**
11357 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11358 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11359 */
11360 // Used for SHELL command only right now.
11361 @Override
11362 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11363 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11364 "clearUceRegistrationOverrideShell");
11365 final long identity = Binder.clearCallingIdentity();
11366 try {
11367 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11368 } catch (ImsException e) {
11369 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11370 } finally {
11371 Binder.restoreCallingIdentity(identity);
11372 }
11373 }
11374
11375 /**
11376 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11377 */
11378 // Used for SHELL command only right now.
11379 @Override
11380 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11381 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11382 "getLatestRcsContactUceCapabilityShell");
11383 final long identity = Binder.clearCallingIdentity();
11384 try {
11385 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11386 } catch (ImsException e) {
11387 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11388 } finally {
11389 Binder.restoreCallingIdentity(identity);
11390 }
11391 }
11392
11393 /**
11394 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11395 * device does not have an active PUBLISH.
11396 */
11397 // Used for SHELL command only right now.
11398 @Override
11399 public String getLastUcePidfXmlShell(int subId) {
11400 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11401 final long identity = Binder.clearCallingIdentity();
11402 try {
11403 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11404 } catch (ImsException e) {
11405 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11406 } finally {
11407 Binder.restoreCallingIdentity(identity);
11408 }
11409 }
11410
James.cf Line8713a42021-04-29 16:04:26 +080011411 /**
11412 * Remove UCE requests cannot be sent to the network status.
11413 */
11414 // Used for SHELL command only right now.
11415 @Override
11416 public boolean removeUceRequestDisallowedStatus(int subId) {
11417 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11418 final long identity = Binder.clearCallingIdentity();
11419 try {
11420 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11421 } catch (ImsException e) {
11422 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11423 } finally {
11424 Binder.restoreCallingIdentity(identity);
11425 }
11426 }
11427
James.cf Lin18bb9002021-05-25 01:37:38 +080011428 /**
11429 * Remove UCE requests cannot be sent to the network status.
11430 */
11431 // Used for SHELL command only.
11432 @Override
11433 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11434 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11435 final long identity = Binder.clearCallingIdentity();
11436 try {
11437 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11438 } catch (ImsException e) {
11439 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11440 } finally {
11441 Binder.restoreCallingIdentity(identity);
11442 }
11443 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011444
James.cf Lin4b784aa2021-01-31 03:25:15 +080011445 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011446 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11447 String callingPackage) {
11448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11449 mApp, subId, "setSignalStrengthUpdateRequest");
11450
11451 final int callingUid = Binder.getCallingUid();
11452 // Verify that tha callingPackage belongs to the calling UID
11453 mApp.getSystemService(AppOpsManager.class)
11454 .checkPackage(callingUid, callingPackage);
11455
Rambo Wang3607f502021-02-01 21:51:40 -080011456 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011457
11458 final long identity = Binder.clearCallingIdentity();
11459 try {
11460 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11461 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11462
11463 if (result instanceof IllegalStateException) {
11464 throw (IllegalStateException) result;
11465 }
11466 } finally {
11467 Binder.restoreCallingIdentity(identity);
11468 }
11469 }
11470
11471 @Override
11472 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11473 String callingPackage) {
11474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11475 mApp, subId, "clearSignalStrengthUpdateRequest");
11476
11477 final int callingUid = Binder.getCallingUid();
11478 // Verify that tha callingPackage belongs to the calling UID
11479 mApp.getSystemService(AppOpsManager.class)
11480 .checkPackage(callingUid, callingPackage);
11481
11482 final long identity = Binder.clearCallingIdentity();
11483 try {
11484 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11485 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11486
11487 if (result instanceof IllegalStateException) {
11488 throw (IllegalStateException) result;
11489 }
11490 } finally {
11491 Binder.restoreCallingIdentity(identity);
11492 }
11493 }
11494
Rambo Wang3607f502021-02-01 21:51:40 -080011495 private static void validateSignalStrengthUpdateRequest(Context context,
11496 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011497 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11498 // phone/system process do not have further restriction on request
11499 return;
11500 }
11501
11502 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011503 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011504 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011505 context.enforceCallingOrSelfPermission(
11506 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11507 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011508 }
11509
11510 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011511 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011512 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011513 || info.isEnabled()) {
11514 throw new IllegalArgumentException(
11515 "Only system can set hide fields in SignalThresholdInfo");
11516 }
11517
11518 // Thresholds length for each RAN need in range. This has been validated in
11519 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11520 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11521 final int[] thresholds = info.getThresholds();
11522 Objects.requireNonNull(thresholds);
11523 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11524 || thresholds.length
11525 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11526 throw new IllegalArgumentException(
11527 "thresholds length is out of range: " + thresholds.length);
11528 }
11529 }
11530 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011531
11532 /**
11533 * Gets the current phone capability.
11534 *
11535 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11536 * @return the PhoneCapability which describes the data connection capability of modem.
11537 * It's used to evaluate possible phone config change, for example from single
11538 * SIM device to multi-SIM device.
11539 */
11540 @Override
11541 public PhoneCapability getPhoneCapability() {
11542 enforceReadPrivilegedPermission("getPhoneCapability");
11543 final long identity = Binder.clearCallingIdentity();
11544 try {
11545 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11546 } finally {
11547 Binder.restoreCallingIdentity(identity);
11548 }
11549 }
Michele Berionne5e411512020-11-13 02:36:59 +000011550
11551 /**
11552 * Prepare TelephonyManager for an unattended reboot. The reboot is
11553 * required to be done shortly after the API is invoked.
11554 */
11555 @Override
11556 @TelephonyManager.PrepareUnattendedRebootResult
11557 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011558 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011559 enforceRebootPermission();
11560
11561 final long identity = Binder.clearCallingIdentity();
11562 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011563 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011564 } finally {
11565 Binder.restoreCallingIdentity(identity);
11566 }
11567 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011568
11569 /**
11570 * Request to get the current slicing configuration including URSP rules and
11571 * NSSAIs (configured, allowed and rejected).
11572 *
11573 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11574 */
11575 @Override
11576 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011577 TelephonyPermissions
11578 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11579 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011580
11581 final long identity = Binder.clearCallingIdentity();
11582 try {
11583 Phone phone = getDefaultPhone();
11584 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11585 } finally {
11586 Binder.restoreCallingIdentity(identity);
11587 }
11588 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011589
11590 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011591 * Check whether the given premium capability is available for purchase from the carrier.
11592 *
11593 * @param capability The premium capability to check.
11594 * @param subId The subId to check the premium capability for.
11595 *
11596 * @return Whether the given premium capability is available to purchase.
11597 */
11598 @Override
11599 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11600 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11601 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11602 log("Premium capability "
11603 + TelephonyManager.convertPremiumCapabilityToString(capability)
11604 + " is not available for purchase due to missing permissions.");
11605 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11606 + "permission READ_BASIC_PHONE_STATE.");
11607 }
11608
11609 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011610 if (phone == null) {
11611 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
11612 return false;
11613 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070011614 final long identity = Binder.clearCallingIdentity();
11615 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011616 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011617 .isPremiumCapabilityAvailableForPurchase(capability);
11618 } finally {
11619 Binder.restoreCallingIdentity(identity);
11620 }
11621 }
11622
11623 /**
11624 * Purchase the given premium capability from the carrier.
11625 *
11626 * @param capability The premium capability to purchase.
11627 * @param callback The result of the purchase request.
11628 * @param subId The subId to purchase the premium capability for.
11629 */
11630 @Override
11631 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11632 log("purchasePremiumCapability: capability="
11633 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11634 + getCurrentPackageName());
11635
11636 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11637 mApp, "purchasePremiumCapability")) {
11638 log("purchasePremiumCapability "
11639 + TelephonyManager.convertPremiumCapabilityToString(capability)
11640 + " failed due to missing permissions.");
11641 throw new SecurityException("purchasePremiumCapability requires permission "
11642 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080011643 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
11644 mApp, "purchasePremiumCapability")) {
11645 log("purchasePremiumCapability "
11646 + TelephonyManager.convertPremiumCapabilityToString(capability)
11647 + " failed due to missing permissions.");
11648 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070011649 }
11650
11651 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080011652 if (phone == null) {
11653 try {
11654 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
11655 callback.accept(result);
11656 loge("purchasePremiumCapability: phone is null, subId=" + subId);
11657 } catch (RemoteException e) {
11658 String logStr = "Purchase premium capability "
11659 + TelephonyManager.convertPremiumCapabilityToString(capability)
11660 + " failed due to RemoteException handling null phone: " + e;
11661 if (DBG) log(logStr);
11662 AnomalyReporter.reportAnomaly(
11663 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11664 }
11665 return;
11666 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011667
11668 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070011669 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011670 callingProcess = mApp.getPackageManager().getApplicationInfo(
11671 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070011672 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080011673 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070011674 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080011675
11676 boolean isVisible = false;
11677 ActivityManager am = mApp.getSystemService(ActivityManager.class);
11678 if (am != null) {
11679 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
11680 if (processes != null) {
11681 for (ActivityManager.RunningAppProcessInfo process : processes) {
11682 log("purchasePremiumCapability: process " + process.processName
11683 + "has importance " + process.importance);
11684 if (process.processName.equals(callingProcess) && process.importance
11685 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
11686 isVisible = true;
11687 break;
11688 }
11689 }
11690 }
11691 }
11692
11693 if (!isVisible) {
11694 try {
11695 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
11696 callback.accept(result);
11697 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
11698 } catch (RemoteException e) {
11699 String logStr = "Purchase premium capability "
11700 + TelephonyManager.convertPremiumCapabilityToString(capability)
11701 + " failed due to RemoteException handling background application: " + e;
11702 if (DBG) log(logStr);
11703 AnomalyReporter.reportAnomaly(
11704 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
11705 }
11706 return;
11707 }
11708
Sarah Chin71b3a852022-09-28 15:54:19 -070011709 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080011710 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011711 }
11712
11713 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011714 * Register an IMS connection state callback
11715 */
11716 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011717 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11718 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011719 if (feature == ImsFeature.FEATURE_MMTEL) {
11720 // ImsMmTelManager
11721 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11722 TelephonyPermissions
11723 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11724 mApp, subId, "registerImsStateCallback");
11725 } else if (feature == ImsFeature.FEATURE_RCS) {
11726 // ImsRcsManager or SipDelegateManager
11727 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11728 Binder.getCallingUid(), "registerImsStateCallback",
11729 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11730 Manifest.permission.READ_PRECISE_PHONE_STATE,
11731 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11732 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11733 }
11734
11735 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11736 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11737 "IMS not available on device.");
11738 }
11739
11740 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11741 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11742 }
11743
11744 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11745 if (controller == null) {
11746 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11747 "IMS not available on device.");
11748 }
11749
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011750 if (callingPackage == null) {
11751 callingPackage = getCurrentPackageName();
11752 }
11753
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011754 final long token = Binder.clearCallingIdentity();
11755 try {
11756 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011757 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011758 } catch (ImsException e) {
11759 throw new ServiceSpecificException(e.getCode());
11760 } finally {
11761 Binder.restoreCallingIdentity(token);
11762 }
11763 }
11764
11765 /**
11766 * Unregister an IMS connection state callback
11767 */
11768 @Override
11769 public void unregisterImsStateCallback(IImsStateCallback cb) {
11770 final long token = Binder.clearCallingIdentity();
11771 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11772 if (controller == null) {
11773 return;
11774 }
11775 try {
11776 controller.unregisterImsStateCallback(cb);
11777 } finally {
11778 Binder.restoreCallingIdentity(token);
11779 }
11780 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011781
11782 /**
11783 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11784 *
11785 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11786 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11787 * SecurityException.
11788 * If there is current registered network this value will be same as the registered cell
11789 * identity. If the device goes out of service the previous cell identity is cached and
11790 * will be returned. If the cache age of the Cell identity is more than 24 hours
11791 * it will be cleared and null will be returned.
11792 *
11793 */
11794 @Override
11795 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11796 String callingFeatureId) {
11797 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11798 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11799 LocationAccessPolicy.checkLocationPermission(mApp,
11800 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11801 .setCallingPackage(callingPackage)
11802 .setCallingFeatureId(callingFeatureId)
11803 .setCallingPid(Binder.getCallingPid())
11804 .setCallingUid(Binder.getCallingUid())
11805 .setMethod("getLastKnownCellIdentity")
11806 .setLogAsInfo(true)
11807 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11808 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11809 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11810 .build());
11811
11812 boolean hasFinePermission =
11813 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11814 if (!hasFinePermission
11815 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11816 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011817 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011818 }
11819
11820 final long identity = Binder.clearCallingIdentity();
11821 try {
Ling Mac28f0212023-03-24 16:07:15 -070011822 ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker();
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011823 if (sst == null) return null;
11824 return sst.getLastKnownCellIdentity();
11825 } finally {
11826 Binder.restoreCallingIdentity(identity);
11827 }
11828 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011829
jimsun3b9ccac2021-10-26 15:01:23 +080011830 /**
11831 * Sets the modem service class Name that Telephony will bind to.
11832 *
11833 * @param serviceName The class name of the modem service.
11834 * @return true if the operation is succeed, otherwise false.
11835 */
11836 public boolean setModemService(String serviceName) {
11837 Log.d(LOG_TAG, "setModemService - " + serviceName);
11838 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011840 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11841 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080011842 return mPhoneConfigurationManager.setModemService(serviceName);
11843 }
11844
11845 /**
11846 * Return the class name of the currently bounded modem service.
11847 *
11848 * @return the class name of the modem service.
11849 */
11850 public String getModemService() {
11851 String result;
11852 Log.d(LOG_TAG, "getModemService");
11853 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11854 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011855 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080011856 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11857 "getModemService");
11858 result = mPhoneConfigurationManager.getModemService();
11859 Log.d(LOG_TAG, "result = " + result);
11860 return result;
11861 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011862
11863 @Override
11864 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11865 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11866 mApp.enforceCallingOrSelfPermission(
11867 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11868 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11869
11870 final long identity = Binder.clearCallingIdentity();
11871 try {
11872 Phone phone = getPhone(subId);
11873 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080011874 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
11875 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011876 phone.setVoiceServiceStateOverride(hasService);
11877 } finally {
11878 Binder.restoreCallingIdentity(identity);
11879 }
11880 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011881
11882 /**
11883 * set removable eSIM as default eUICC.
11884 *
11885 * @hide
11886 */
11887 @Override
11888 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11889 enforceModifyPermission();
11890 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11891
11892 final long identity = Binder.clearCallingIdentity();
11893 try {
11894 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11895 } finally {
11896 Binder.restoreCallingIdentity(identity);
11897 }
11898 }
11899
11900 /**
11901 * Returns whether the removable eSIM is default eUICC or not.
11902 *
11903 * @hide
11904 */
11905 @Override
11906 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11907 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11908 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11909
11910 final long identity = Binder.clearCallingIdentity();
11911 try {
11912 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11913 } finally {
11914 Binder.restoreCallingIdentity(identity);
11915 }
11916 }
11917
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011918 /**
11919 * Get the component name of the default app to direct respond-via-message intent for the
11920 * user associated with this subscription, update the cache if there is no respond-via-message
11921 * application currently configured for this user.
11922 * @return component name of the app and class to direct Respond Via Message intent to, or
11923 * {@code null} if the functionality is not supported.
11924 * @hide
11925 */
11926 @Override
11927 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
11928 boolean updateIfNeeded) {
11929 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011930
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000011931 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
11932
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000011933 UserHandle userHandle = null;
11934 final long identity = Binder.clearCallingIdentity();
11935 try {
11936 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
11937 } finally {
11938 Binder.restoreCallingIdentity(identity);
11939 }
11940 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
11941 updateIfNeeded, userHandle);
11942 }
Jack Yuf5badd92022-12-08 00:50:53 -080011943
11944 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011945 * Set whether the device is able to connect with null ciphering or integrity
11946 * algorithms. This is a global setting and will apply to all active subscriptions
11947 * and all new subscriptions after this.
11948 *
11949 * @param enabled when true, null cipher and integrity algorithms are allowed.
11950 * @hide
11951 */
11952 @Override
11953 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
11954 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
11955 enforceModifyPermission();
11956 checkForNullCipherAndIntegritySupport();
11957
11958 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
11959 // for listening to these preference changes and applying them immediately.
11960 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
11961 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
11962 editor.apply();
11963
11964 for (Phone phone: PhoneFactory.getPhones()) {
11965 phone.handleNullCipherEnabledChange();
11966 }
11967 }
11968
11969
11970 /**
11971 * Get whether the device is able to connect with null ciphering or integrity
11972 * algorithms. Note that this retrieves the phone-global preference and not
11973 * the state of the radio.
11974 *
11975 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
11976 * @throws UnsupportedOperationException if the device does not support the minimum HAL
11977 * version for this feature.
11978 * @hide
11979 */
11980 @Override
11981 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
11982 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
11983 enforceReadPermission();
11984 checkForNullCipherAndIntegritySupport();
11985 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
11986 }
11987
11988 private void checkForNullCipherAndIntegritySupport() {
11989 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
11990 throw new UnsupportedOperationException(
11991 "Null cipher and integrity operations require HAL 2.1 or above");
11992 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000011993 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
11994 throw new UnsupportedOperationException(
11995 "Null cipher and integrity operations unsupported by modem");
11996 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000011997 }
11998
11999 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012000 * Get the SIM state for the slot index.
12001 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12002 *
12003 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12004 */
12005 @Override
12006 @SimState
12007 public int getSimStateForSlotIndex(int slotIndex) {
12008 IccCardConstants.State simState;
12009 if (slotIndex < 0) {
12010 simState = IccCardConstants.State.UNKNOWN;
12011 } else {
12012 Phone phone = null;
12013 try {
12014 phone = PhoneFactory.getPhone(slotIndex);
12015 } catch (IllegalStateException e) {
12016 // ignore
12017 }
12018 if (phone == null) {
12019 simState = IccCardConstants.State.UNKNOWN;
12020 } else {
12021 IccCard icc = phone.getIccCard();
12022 if (icc == null) {
12023 simState = IccCardConstants.State.UNKNOWN;
12024 } else {
12025 simState = icc.getState();
12026 }
12027 }
12028 }
12029 return simState.ordinal();
12030 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012031
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012032 private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag,
12033 boolean enableLogcat,
12034 long logcatStartTimestampMillis, boolean enableTelecomDump,
12035 boolean enableTelephonyDump) {
Chinmay Dhodapkar66262c42023-03-10 15:47:41 -080012036 DropBoxManager db = mApp.getSystemService(DropBoxManager.class);
12037 TelephonyManager.EmergencyCallDiagnosticParams edp =
12038 new TelephonyManager.EmergencyCallDiagnosticParams();
12039 edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis);
12040 edp.setTelephonyDumpSysCollection(enableTelephonyDump);
12041 edp.setTelecomDumpSysCollection(enableTelecomDump);
12042 Log.d(LOG_TAG, "persisting with Params " + edp.toString());
12043 DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(),
12044 Executors.newCachedThreadPool(), db,
12045 mApp.getSystemService(ActivityManager.class).isLowRamDevice());
12046 ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag);
Chinmay Dhodapkar3e11ced2023-03-03 19:44:00 -080012047 }
12048
12049 /**
12050 * Request telephony to persist state for debugging emergency call failures.
12051 *
12052 * @param dropBoxTag Tag to use when persisting data to dropbox service.
12053 * @param enableLogcat whether to collect logcat output
12054 * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted
12055 * @param enableTelecomDump whether to collect telecom dumpsys
12056 * @param enableTelephonyDump whether to collect telephony dumpsys
12057 */
12058 @Override
12059 @RequiresPermission(android.Manifest.permission.DUMP)
12060 public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat,
12061 long logcatStartTimestampMillis, boolean enableTelecomDump,
12062 boolean enableTelephonyDump) {
12063 mApp.enforceCallingPermission(android.Manifest.permission.DUMP,
12064 "persistEmergencyCallDiagnosticData");
12065 final long identity = Binder.clearCallingIdentity();
12066 try {
12067 persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat,
12068 logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump);
12069
12070 } finally {
12071 Binder.restoreCallingIdentity(identity);
12072 }
12073 }
12074
Hui Wang9b5793a2022-12-05 14:38:06 -060012075 /**
12076 * Get current cell broadcast ranges.
12077 */
12078 @Override
12079 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12080 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12081 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12082 "getCellBroadcastIdRanges");
12083 final long identity = Binder.clearCallingIdentity();
12084 try {
12085 return getPhone(subId).getCellBroadcastIdRanges();
12086 } finally {
12087 Binder.restoreCallingIdentity(identity);
12088 }
12089 }
12090
12091 /**
12092 * Set reception of cell broadcast messages with the list of the given ranges
12093 *
12094 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12095 */
12096 @Override
12097 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12098 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12099 @Nullable IIntegerConsumer callback) {
12100 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12101 "setCellBroadcastIdRanges");
12102 final long identity = Binder.clearCallingIdentity();
12103 try {
12104 Phone phone = getPhoneFromSubId(subId);
12105 if (DBG) {
12106 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12107 }
12108 phone.setCellBroadcastIdRanges(ranges, result -> {
12109 if (callback != null) {
12110 try {
12111 callback.accept(result);
12112 } catch (RemoteException e) {
12113 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12114 }
12115 }
12116 });
12117 } finally {
12118 Binder.restoreCallingIdentity(identity);
12119 }
12120 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012121
12122 /**
12123 * Returns whether the device supports the domain selection service.
12124 *
12125 * @return {@code true} if the device supports the domain selection service.
12126 */
12127 @Override
12128 public boolean isDomainSelectionSupported() {
12129 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12130 "isDomainSelectionSupported");
12131
12132 final long identity = Binder.clearCallingIdentity();
12133 try {
12134 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12135 } finally {
12136 Binder.restoreCallingIdentity(identity);
12137 }
12138 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012139
12140 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012141 * Request to enable or disable the satellite modem and demo mode. If the satellite modem is
12142 * enabled, this may also disable the cellular modem, and if the satellite modem is disabled,
12143 * this may also re-enable the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012144 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012145 * @param subId The subId of the subscription to set satellite enabled for.
Sarah Chinabf081b2023-03-09 23:00:57 -080012146 * @param enableSatellite {@code true} to enable the satellite modem and
12147 * {@code false} to disable.
12148 * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable.
12149 * @param callback The callback to get the result of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012150 *
12151 * @throws SecurityException if the caller doesn't have the required permission.
12152 */
12153 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012154 public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode,
12155 @NonNull IIntegerConsumer callback) {
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012156 enforceSatelliteCommunicationPermission("requestSatelliteEnabled");
Sarah Chinabf081b2023-03-09 23:00:57 -080012157 mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode,
12158 callback);
Sarah Chin503828c2023-02-01 23:54:20 -080012159 }
12160
12161 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012162 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012163 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012164 * @param subId The subId of the subscription to check whether satellite is enabled for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012165 * @param result The result receiver that returns whether the satellite modem is enabled
12166 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012167 *
12168 * @throws SecurityException if the caller doesn't have the required permission.
12169 */
12170 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012171 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12172 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012173 mSatelliteController.requestIsSatelliteEnabled(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012174 }
12175
12176 /**
Sarah Chin43457982023-02-15 17:50:38 -080012177 * Request to get whether the satellite service demo mode is enabled.
12178 *
12179 * @param subId The subId of the subscription to check whether the satellite demo mode
12180 * is enabled for.
12181 * @param result The result receiver that returns whether the satellite demo mode is enabled
12182 * if the request is successful or an error code if the request failed.
12183 *
12184 * @throws SecurityException if the caller doesn't have the required permission.
12185 */
12186 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012187 public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) {
12188 enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled");
12189 mSatelliteController.requestIsDemoModeEnabled(subId, result);
Sarah Chin43457982023-02-15 17:50:38 -080012190 }
12191
12192 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012193 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012194 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012195 * @param subId The subId of the subscription to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012196 * @param result The result receiver that returns whether the satellite service is supported on
12197 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012198 */
12199 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012200 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012201 mSatelliteController.requestIsSatelliteSupported(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012202 }
12203
12204 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012205 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012206 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012207 * @param subId The subId of the subscription to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012208 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12209 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012210 *
12211 * @throws SecurityException if the caller doesn't have required permission.
12212 */
12213 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012214 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12215 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012216 mSatelliteController.requestSatelliteCapabilities(subId, result);
Sarah Chin503828c2023-02-01 23:54:20 -080012217 }
12218
12219 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012220 * Start receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012221 * This can be called by the pointing UI when the user starts pointing to the satellite.
12222 * Modem should continue to report the pointing input as the device or satellite moves.
12223 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012224 * @param subId The subId of the subscription to start satellite transmission updates for.
12225 * @param resultCallback The callback to get the result of the request.
12226 * @param callback The callback to notify of satellite transmission updates.
Sarah Chin503828c2023-02-01 23:54:20 -080012227 *
12228 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012229 */
12230 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012231 public void startSatelliteTransmissionUpdates(int subId,
12232 @NonNull IIntegerConsumer resultCallback,
12233 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12234 enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates");
12235 mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback);
Sarah Chineccfbd12023-01-20 19:00:35 -080012236 }
12237
12238 /**
Sarah Chinabf081b2023-03-09 23:00:57 -080012239 * Stop receiving satellite transmission updates.
Sarah Chineccfbd12023-01-20 19:00:35 -080012240 * This can be called by the pointing UI when the user stops pointing to the satellite.
12241 *
Sarah Chinabf081b2023-03-09 23:00:57 -080012242 * @param subId The subId of the subscription to stop satellite transmission updates for.
12243 * @param resultCallback The callback to get the result of the request.
12244 * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates(
12245 * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}.
Sarah Chin503828c2023-02-01 23:54:20 -080012246 *
12247 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012248 */
12249 @Override
Sarah Chinabf081b2023-03-09 23:00:57 -080012250 public void stopSatelliteTransmissionUpdates(int subId,
12251 @NonNull IIntegerConsumer resultCallback,
12252 @NonNull ISatelliteTransmissionUpdateCallback callback) {
12253 enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates");
12254 mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012255 }
12256
12257 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012258 * Register the subscription with a satellite provider.
12259 * This is needed to register the subscription if the provider allows dynamic registration.
12260 *
12261 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012262 * @param token The token to be used as a unique identifier for provisioning with satellite
12263 * gateway.
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012264 * @param provisionData Data from the provisioning app that can be used by provisioning server
Sarah Chinabf081b2023-03-09 23:00:57 -080012265 * @param callback The callback to get the result of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012266 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012267 * @return The signal transport used by the caller to cancel the provision request,
12268 * or {@code null} if the request failed.
12269 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012270 * @throws SecurityException if the caller doesn't have the required permission.
12271 */
12272 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012273 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012274 @NonNull String token, @NonNull byte[] provisionData,
12275 @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012276 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Aishwarya Mallampati8b2310c2023-03-28 22:01:43 +000012277 return mSatelliteController.provisionSatelliteService(subId, token, provisionData,
12278 callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012279 }
12280
12281 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012282 * Unregister the device/subscription with the satellite provider.
12283 * This is needed if the provider allows dynamic registration. Once deprovisioned,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012284 * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)}
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012285 * should report as deprovisioned.
12286 *
12287 * @param subId The subId of the subscription to be deprovisioned.
12288 * @param token The token of the device/subscription to be deprovisioned.
Sarah Chinabf081b2023-03-09 23:00:57 -080012289 * @param callback The callback to get the result of the request.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012290 *
12291 * @throws SecurityException if the caller doesn't have the required permission.
12292 */
12293 @Override
12294 public void deprovisionSatelliteService(int subId,
12295 @NonNull String token, @NonNull IIntegerConsumer callback) {
12296 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012297 mSatelliteController.deprovisionSatelliteService(subId, token, callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012298 }
12299
12300 /**
Sarah Chin43457982023-02-15 17:50:38 -080012301 * Registers for the satellite provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012302 *
Sarah Chin43457982023-02-15 17:50:38 -080012303 * @param subId The subId of the subscription to register for provision state changed.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012304 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012305 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012306 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12307 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012308 * @throws SecurityException if the caller doesn't have the required permission.
12309 */
12310 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080012311 @SatelliteManager.SatelliteError public int registerForSatelliteProvisionStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012312 @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012313 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012314 return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012315 }
12316
12317 /**
Sarah Chin43457982023-02-15 17:50:38 -080012318 * Unregisters for the satellite provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012319 * If callback was not registered before, the request will be ignored.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012320 *
Sarah Chin43457982023-02-15 17:50:38 -080012321 * @param subId The subId of the subscription to unregister for provision state changed.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012322 * @param callback The callback that was passed to
12323 * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012324 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012325 * @throws SecurityException if the caller doesn't have the required permission.
12326 */
12327 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012328 public void unregisterForSatelliteProvisionStateChanged(
12329 int subId, @NonNull ISatelliteProvisionStateCallback callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012330 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012331 mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012332 }
12333
12334 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012335 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012336 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012337 * @param subId The subId of the subscription to get whether the device is provisioned for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012338 * @param result The result receiver that returns whether the device is provisioned with a
12339 * satellite provider if the request is successful or an error code if the
12340 * request failed.
12341 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012342 * @throws SecurityException if the caller doesn't have the required permission.
12343 */
12344 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012345 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
12346 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012347 mSatelliteController.requestIsSatelliteProvisioned(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012348 }
12349
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012350 /**
Sarah Chin43457982023-02-15 17:50:38 -080012351 * Registers for modem state changed from satellite modem.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012352 *
Sarah Chin43457982023-02-15 17:50:38 -080012353 * @param subId The subId of the subscription to register for satellite modem state changed.
12354 * @param callback The callback to handle the satellite modem state changed event.
Sarah Chindf715ec2023-02-13 13:46:24 -080012355 *
12356 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12357 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012358 * @throws SecurityException if the caller doesn't have the required permission.
12359 */
12360 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012361 @SatelliteManager.SatelliteError public int registerForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012362 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012363 enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012364 return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012365 }
12366
12367 /**
Sarah Chin43457982023-02-15 17:50:38 -080012368 * Unregisters for modem state changed from satellite modem.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012369 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012370 *
Sarah Chin43457982023-02-15 17:50:38 -080012371 * @param subId The subId of the subscription to unregister for satellite modem state changed.
Sarah Chindf715ec2023-02-13 13:46:24 -080012372 * @param callback The callback that was passed to
Sarah Chin43457982023-02-15 17:50:38 -080012373 * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012374 *
12375 * @throws SecurityException if the caller doesn't have the required permission.
12376 */
12377 @Override
Sarah Chin43457982023-02-15 17:50:38 -080012378 public void unregisterForSatelliteModemStateChanged(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012379 @NonNull ISatelliteStateCallback callback) {
Sarah Chin43457982023-02-15 17:50:38 -080012380 enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012381 mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012382 }
12383
12384 /**
12385 * Register to receive incoming datagrams over satellite.
12386 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012387 * @param subId The subId of the subscription to register for incoming satellite datagrams.
Sarah Chindf715ec2023-02-13 13:46:24 -080012388 * @param callback The callback to handle incoming datagrams over satellite.
12389 *
12390 * @return The {@link SatelliteManager.SatelliteError} result of the operation.
12391 *
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012392 * @throws SecurityException if the caller doesn't have the required permission.
12393 */
12394 @Override
Sarah Chindf715ec2023-02-13 13:46:24 -080012395 @SatelliteManager.SatelliteError public int registerForSatelliteDatagram(int subId,
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012396 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012397 enforceSatelliteCommunicationPermission("registerForSatelliteDatagram");
Sarah Chinabf081b2023-03-09 23:00:57 -080012398 return mSatelliteController.registerForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012399 }
12400
12401 /**
12402 * Unregister to stop receiving incoming datagrams over satellite.
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012403 * If callback was not registered before, the request will be ignored.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012404 *
Sarah Chindf715ec2023-02-13 13:46:24 -080012405 * @param subId The subId of the subscription to unregister for incoming satellite datagrams.
12406 * @param callback The callback that was passed to
Sarah Chinabf081b2023-03-09 23:00:57 -080012407 * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012408 *
12409 * @throws SecurityException if the caller doesn't have the required permission.
12410 */
12411 @Override
Thomas Nguyen299d6cd2023-02-14 09:57:15 -080012412 public void unregisterForSatelliteDatagram(int subId,
12413 @NonNull ISatelliteDatagramCallback callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012414 enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012415 mSatelliteController.unregisterForSatelliteDatagram(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012416 }
12417
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012418 /**
12419 * Poll pending satellite datagrams over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012420 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012421 * This method requests modem to check if there are any pending datagrams to be received over
12422 * satellite. If there are any incoming datagrams, they will be received via
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012423 * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int,
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012424 * ILongConsumer)})}
Sarah Chindf715ec2023-02-13 13:46:24 -080012425 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012426 * @param subId The subId of the subscription used for receiving datagrams.
12427 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
Sarah Chindf715ec2023-02-13 13:46:24 -080012428 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012429 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012430 */
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012431 @Override
12432 public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) {
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012433 enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012434 mSatelliteController.pollPendingSatelliteDatagrams(subId, callback);
Aishwarya Mallampati740d9ab2023-02-08 23:07:05 +000012435 }
12436
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012437 /**
12438 * Send datagram over satellite.
Sarah Chindf715ec2023-02-13 13:46:24 -080012439 *
Aishwarya Mallampati4d9a0942023-02-16 18:01:53 +000012440 * Gateway encodes SOS message or location sharing message into a datagram and passes it as
12441 * input to this method. Datagram received here will be passed down to modem without any
12442 * encoding or encryption.
Sarah Chindf715ec2023-02-13 13:46:24 -080012443 *
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012444 * @param subId The subId of the subscription to send satellite datagrams for.
12445 * @param datagramType datagram type indicating whether the datagram is of type
12446 * SOS_SMS or LOCATION_SHARING.
12447 * @param datagram encoded gateway datagram which is encrypted by the caller.
12448 * Datagram will be passed down to modem without any encoding or encryption.
Aishwarya Mallampatia46437b2023-02-21 18:52:58 +000012449 * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in
12450 * full screen mode.
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012451 * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request.
Aishwarya Mallampati224317a2023-02-13 22:09:30 +000012452 *
12453 * @throws SecurityException if the caller doesn't have required permission.
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012454 */
12455 @Override
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012456 public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType,
12457 @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI,
12458 @NonNull IIntegerConsumer callback) {
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012459 enforceSatelliteCommunicationPermission("sendSatelliteDatagram");
Aishwarya Mallampati14e0de02023-03-03 00:34:32 +000012460 mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram,
12461 needFullScreenPointingUI, callback);
Aishwarya Mallampatie8ac6862023-02-09 22:13:02 +000012462 }
12463
Sarah Chindf715ec2023-02-13 13:46:24 -080012464 /**
12465 * Request to get whether satellite communication is allowed for the current location.
12466 *
12467 * @param subId The subId of the subscription to check whether satellite communication is
12468 * allowed for the current location for.
12469 * @param result The result receiver that returns whether satellite communication is allowed
12470 * for the current location if the request is successful or an error code
12471 * if the request failed.
12472 *
12473 * @throws SecurityException if the caller doesn't have the required permission.
12474 */
12475 @Override
12476 public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId,
12477 @NonNull ResultReceiver result) {
12478 enforceSatelliteCommunicationPermission(
12479 "requestIsSatelliteCommunicationAllowedForCurrentLocation");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012480 mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId,
12481 result);
Sarah Chindf715ec2023-02-13 13:46:24 -080012482 }
12483
12484 /**
Sarah Chin5f57c582023-02-14 04:16:10 -080012485 * Request to get the time after which the satellite will be visible
Sarah Chindf715ec2023-02-13 13:46:24 -080012486 *
Sarah Chin5f57c582023-02-14 04:16:10 -080012487 * @param subId The subId to get the time after which the satellite will be visible for.
12488 * @param result The result receiver that returns the time after which the satellite will
Sarah Chindf715ec2023-02-13 13:46:24 -080012489 * be visible if the request is successful or an error code if the request failed.
12490 *
12491 * @throws SecurityException if the caller doesn't have the required permission.
12492 */
12493 @Override
12494 public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) {
12495 enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility");
Aishwarya Mallampati481aeee2023-02-17 21:32:22 +000012496 mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012497 }
12498
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012499 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000012500 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
12501 *
12502 * <p>This method behaves in one of the following ways:
12503 * <ul>
12504 * <li>return true : if the calling package has the appop permission {@link
12505 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
12506 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
12507 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
12508 * Owner device identifier access check, or the calling package has carrier privileges</>
12509 * <li>throw SecurityException: if the caller does not meet any of the requirements.
12510 * </ul>
12511 */
12512 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
12513 String callingPackage, @Nullable String callingFeatureId, String message) {
12514 for (Phone phone : PhoneFactory.getPhones()) {
12515 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
12516 phone.getSubId(), callingPackage, callingFeatureId, message)) {
12517 return true;
12518 }
12519 }
12520 return false;
12521 }
arunvoddud7401012022-12-15 16:08:12 +000012522
12523 /**
Jack Yufa8ed012023-02-11 15:42:28 -080012524 * @return The subscription manager service instance.
12525 */
12526 public SubscriptionManagerService getSubscriptionManagerService() {
12527 return SubscriptionManagerService.getInstance();
12528 }
12529
12530 /**
arunvoddud7401012022-12-15 16:08:12 +000012531 * Class binds the consumer[callback] and carrierId.
12532 */
12533 private static class CallerCallbackInfo {
12534 private final Consumer<Integer> mConsumer;
12535 private final int mCarrierId;
12536
12537 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
12538 mConsumer = consumer;
12539 mCarrierId = carrierId;
12540 }
12541
12542 public Consumer<Integer> getConsumer() {
12543 return mConsumer;
12544 }
12545
12546 public int getCarrierId() {
12547 return mCarrierId;
12548 }
12549 }
Jack Yufa8ed012023-02-11 15:42:28 -080012550}