blob: c55015358adfe4e931bff90d69aa03b130c8c9d1 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
Gil Cukierman1c0eb932022-12-06 22:28:24 +000020import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK;
jimsunf9ec1622022-09-13 21:18:43 +080021import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO;
Hall Liud892bec2018-11-30 14:51:45 -080022
Shuo Qianccbaf742021-02-22 18:32:21 -080023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
24import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070025import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000027import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070028
Brad Ebinger34c09a52021-02-17 23:23:21 +000029import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080030import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080031import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070032import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000033import android.annotation.RequiresPermission;
Sarah Chin532d6bb2022-12-28 22:50:43 -080034import android.app.ActivityManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080036import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070037import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000038import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080039import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000040import android.compat.annotation.ChangeId;
41import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070042import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070043import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.content.Context;
45import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070046import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070047import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070048import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.net.Uri;
50import android.os.AsyncResult;
51import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080052import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Bundle;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080054import android.os.CancellationSignal;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070056import android.os.IBinder;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080057import android.os.ICancellationSignal;
tom hsu0b59d292022-09-29 23:49:21 +080058import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import android.os.Looper;
60import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070061import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080062import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070063import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070064import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080065import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080066import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070067import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070068import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080069import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070071import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070072import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070073import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070074import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080075import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070076import android.provider.Telephony;
arunvoddud7401012022-12-15 16:08:12 +000077import android.service.carrier.CarrierIdentifier;
Inseob Kim14bb3d02018-12-13 17:11:34 +090078import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080079import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080080import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070081import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080082import android.telephony.AccessNetworkConstants;
83import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070084import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070085import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080086import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070087import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080088import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070089import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080090import android.telephony.CarrierRestrictionRules;
Hui Wang9b5793a2022-12-05 14:38:06 -060091import android.telephony.CellBroadcastIdRange;
yincheng zhao2737e882019-09-06 17:06:54 -070092import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080093import android.telephony.CellIdentityCdma;
94import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070096import android.telephony.CellInfoGsm;
97import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070098import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080099import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -0700100import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700101import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700102import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -0800103import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700104import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -0800105import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -0700106import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800107import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800108import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700109import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800110import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800112import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800113import android.telephony.SignalStrengthUpdateRequest;
114import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800115import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800117import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700118import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700119import android.telephony.TelephonyManager;
Jack Yuf5badd92022-12-08 00:50:53 -0800120import android.telephony.TelephonyManager.SimState;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800121import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800122import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800123import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000124import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000125import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000126import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700127import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700128import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800129import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800130import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700131import android.telephony.gba.GbaAuthRequest;
132import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700133import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800134import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000135import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000136import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700137import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000138import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700139import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800140import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700141import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800142import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700143import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000144import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700145import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800146import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800147import android.telephony.ims.stub.ImsRegistrationImplBase;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800148import android.telephony.satellite.ISatelliteStateListener;
Sarah Chineccfbd12023-01-20 19:00:35 -0800149import android.telephony.satellite.PointingInfo;
Sarah Chin503828c2023-02-01 23:54:20 -0800150import android.telephony.satellite.SatelliteCapabilities;
Sarah Chineccfbd12023-01-20 19:00:35 -0800151import android.telephony.satellite.SatelliteManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700152import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800153import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700154import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800156import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800157
Andrew Lee312e8172014-10-23 17:01:36 -0700158import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800159import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800160import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800161import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800162import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700164import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700165import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800166import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800167import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700168import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700169import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800170import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700171import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800172import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800173import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800174import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700175import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000176import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700177import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800178import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700179import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800180import com.android.internal.telephony.IccCard;
Jack Yuf5badd92022-12-08 00:50:53 -0800181import com.android.internal.telephony.IccCardConstants;
Rambo Wanga1782702021-11-10 20:15:19 -0800182import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700183import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700184import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700185import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700187import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800188import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700189import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700190import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700191import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700192import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800193import com.android.internal.telephony.RILConstants;
Sarah Chineccfbd12023-01-20 19:00:35 -0800194import com.android.internal.telephony.RILUtils;
Daniel Bright94f43662021-03-01 14:43:40 -0800195import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700196import com.android.internal.telephony.ServiceStateTracker;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000197import com.android.internal.telephony.SmsApplication;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700198import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700199import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800200import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800201import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800202import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700203import com.android.internal.telephony.data.DataUtils;
Hunsuk Choi42cc62a2022-10-16 06:03:40 +0000204import com.android.internal.telephony.domainselection.DomainSelectionResolver;
sqianf4ca7ed2019-01-15 18:32:07 -0800205import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700206import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800207import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700208import com.android.internal.telephony.imsphone.ImsPhone;
209import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000210import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800211import com.android.internal.telephony.metrics.TelephonyMetrics;
Jack Yu285100e2022-12-02 22:48:35 -0800212import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
213import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700214import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700215import com.android.internal.telephony.uicc.IccIoResult;
216import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800217import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700218import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800219import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700220import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000221import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800222import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000223import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800224import com.android.internal.telephony.util.LocaleUtils;
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +0000225import com.android.internal.telephony.util.TelephonyUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700226import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700227import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800228import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800229import com.android.phone.callcomposer.CallComposerPictureManager;
230import com.android.phone.callcomposer.CallComposerPictureTransfer;
231import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700232import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin46355ba2022-11-01 23:51:16 -0700233import com.android.phone.slice.SlicePurchaseController;
arunvoddud7401012022-12-15 16:08:12 +0000234import com.android.phone.utils.CarrierAllowListInfo;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700235import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800236import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700237import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700238import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800239import com.android.services.telephony.TelecomAccountRegistry;
240import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800241import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800242
Hall Liu82694d52020-12-11 18:22:04 -0800243import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700244import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800245import java.io.IOException;
246import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700247import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800249import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000250import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800251import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800252import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800253import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800254import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100255import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800256import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700257import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800258import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800259import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700260import java.util.UUID;
Sarah Chineccfbd12023-01-20 19:00:35 -0800261import java.util.concurrent.ConcurrentHashMap;
Hall Liu82694d52020-12-11 18:22:04 -0800262import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800263import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800264import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700265
266/**
267 * Implementation of the ITelephony interface.
268 */
Santos Cordon117fee72014-05-16 17:56:12 -0700269public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270 private static final String LOG_TAG = "PhoneInterfaceManager";
271 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
272 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800273 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274
275 // Message codes used with mMainThreadHandler
276 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700277 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
278 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700279 private static final int CMD_OPEN_CHANNEL = 9;
280 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
281 private static final int CMD_CLOSE_CHANNEL = 11;
282 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800283 private static final int CMD_NV_READ_ITEM = 13;
284 private static final int EVENT_NV_READ_ITEM_DONE = 14;
285 private static final int CMD_NV_WRITE_ITEM = 15;
286 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
287 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
288 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700289 private static final int CMD_RESET_MODEM_CONFIG = 19;
290 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800291 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
292 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800293 private static final int CMD_SEND_ENVELOPE = 25;
294 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000295 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
296 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700297 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
298 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
299 private static final int CMD_EXCHANGE_SIM_IO = 31;
300 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800301 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
302 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700303 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
304 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700305 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
306 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700307 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
308 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
309 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
310 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700311 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
312 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
313 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
314 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700315 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800316 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
317 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000318 private static final int CMD_SWITCH_SLOTS = 50;
319 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700320 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
321 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
322 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
323 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
324 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
325 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
326 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
327 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700328 private static final int CMD_GET_ALL_CELL_INFO = 60;
329 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
330 private static final int CMD_GET_CELL_LOCATION = 62;
331 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700332 private static final int CMD_MODEM_REBOOT = 64;
333 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700334 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
335 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800336 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
337 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700338 private static final int CMD_GET_MODEM_STATUS = 70;
339 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700340 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
341 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700342 private static final int CMD_ERASE_MODEM_CONFIG = 74;
343 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800344 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
345 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
346 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
347 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800348 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
349 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800350 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800351 private static final int CMD_GET_CALL_FORWARDING = 83;
352 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
353 private static final int CMD_SET_CALL_FORWARDING = 85;
354 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
355 private static final int CMD_GET_CALL_WAITING = 87;
356 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
357 private static final int CMD_SET_CALL_WAITING = 89;
358 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700359 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
360 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
361 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
362 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700363 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
364 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800365 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
366 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800367 private static final int CMD_SET_DATA_THROTTLING = 99;
368 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800369 private static final int CMD_SET_SIM_POWER = 101;
370 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800371 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
372 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
373 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
374 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800375 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
376 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000377 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800378 private static final int CMD_GET_SLICING_CONFIG = 110;
379 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800380 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700381 private static final int CMD_ENABLE_VONR = 113;
382 private static final int EVENT_ENABLE_VONR_DONE = 114;
383 private static final int CMD_IS_VONR_ENABLED = 115;
384 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700385 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
386 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Sarah Chineccfbd12023-01-20 19:00:35 -0800387 private static final int CMD_START_SATELLITE_POSITION_UPDATES = 119;
388 private static final int EVENT_START_SATELLITE_POSITION_UPDATES_DONE = 120;
389 private static final int CMD_STOP_SATELLITE_POSITION_UPDATES = 121;
390 private static final int EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE = 122;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +0000391 private static final int CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG = 123;
392 private static final int EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE = 124;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800393 private static final int CMD_PROVISION_SATELLITE_SERVICE = 125;
394 private static final int EVENT_PROVISION_SATELLITE_SERVICE_DONE = 126;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -0800395 private static final int CMD_DEPROVISION_SATELLITE_SERVICE = 127;
396 private static final int EVENT_DEPROVISION_SATELLITE_SERVICE_DONE = 128;
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800397 private static final int CMD_SET_SATELLITE_ENABLED = 129;
398 private static final int EVENT_SET_SATELLITE_ENABLED_DONE = 130;
399 private static final int CMD_IS_SATELLITE_ENABLED = 131;
400 private static final int EVENT_IS_SATELLITE_ENABLED_DONE = 132;
401 private static final int CMD_IS_SATELLITE_SUPPORTED = 133;
402 private static final int EVENT_IS_SATELLITE_SUPPORTED_DONE = 134;
403 private static final int CMD_GET_SATELLITE_CAPABILITIES = 135;
404 private static final int EVENT_GET_SATELLITE_CAPABILITIES_DONE = 136;
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800405 // Parameters of select command.
406 private static final int SELECT_COMMAND = 0xA4;
407 private static final int SELECT_P1 = 0x04;
408 private static final int SELECT_P2 = 0;
409 private static final int SELECT_P3 = 0x10;
410
Gil Cukierman1c0eb932022-12-06 22:28:24 +0000411 // Toggling null cipher and integrity support was added in IRadioNetwork 2.1
412 private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201;
413
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414 /** The singleton instance. */
415 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800416 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417
Wink Saville3ab207e2014-11-20 13:07:20 -0800418 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800419 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800420 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700421 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800422 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700423 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800424 private MainThreadHandler mMainThreadHandler;
Jack Yue37dd262022-12-16 11:53:37 -0800425 private final SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800426 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700427 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800428 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429
Peter Wangdafb9ac2020-01-15 14:13:38 -0800430 /** User Activity */
431 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800432 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
433
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700434 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800435
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800436 /**
437 * Map key: subId, value: callback to get error code of the provision request.
438 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800439 private final ConcurrentHashMap<Integer, Consumer<Integer>> mSatelliteProvisionCallbacks =
Sarah Chineccfbd12023-01-20 19:00:35 -0800440 new ConcurrentHashMap<>();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800441 /**
442 * Map key: subId, value: SatellitePositionUpdateHandler to notify registrants.
443 */
444 private final ConcurrentHashMap<IBinder, SatellitePositionUpdateHandler>
445 mSatellitePositionUpdateHandlers = new ConcurrentHashMap<>();
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800446 /**
447 * Map key: subId, value: SatelliteProvisionStateChangedHandler to notify registrants.
448 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800449 private final ConcurrentHashMap<Integer, SatelliteProvisionStateChangedHandler>
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800450 mSatelliteProvisionStateChangedHandlers = new ConcurrentHashMap<>();
451
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800452 private Boolean mIsSatelliteSupported = null;
453 private final Object mIsSatelliteSupportedLock = new Object();
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800454 private final ResultReceiver mSatelliteSupportedReceiver;
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800455
Derek Tan97ebb422014-09-05 16:55:38 -0700456 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
457 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800458 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800459 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700460
Michelecea4cf22018-12-21 15:00:11 -0800461 // String to store multi SIM allowed
462 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
463
Derek Tan740e1672017-06-27 14:56:27 -0700464 // The AID of ISD-R.
465 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
466
yinxub1bed742017-04-17 11:45:04 -0700467 private NetworkScanRequestTracker mNetworkScanRequestTracker;
468
David Kelly5e06a7f2018-03-12 14:10:59 +0000469 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
470 private static final int MANUFACTURER_CODE_LENGTH = 8;
471
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800472 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800473 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800474
Sarah Chin2ec39f62022-08-31 17:03:26 -0700475 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
476 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
477
Derek Tan89e89d42014-07-08 17:00:10 -0700478 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700479 * Experiment flag to enable erase modem config on reset network, default value is false
480 */
481 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
482 "reset_network_erase_modem_config_enabled";
483
Rambo Wang0f050d82021-02-12 11:43:36 -0800484 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800485
Gary Jian76280a42022-12-07 16:18:33 +0800486 private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50;
487
sandeepjsb6c87872021-09-27 15:34:44 +0000488 /**
489 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
490 * one ICCID active at the same time.
491 * Apps should use below API signatures if targeting SDK is T and beyond.
492 *
493 * @hide
494 */
495 @ChangeId
496 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
497 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800498
Naina Nallurid63128d2019-09-17 14:10:30 -0700499 /**
Chen Xu540470b2021-12-14 17:15:47 -0800500 * Apps targeting on Android T and beyond will get exception whenever icc close channel
501 * operation fails.
502 */
503 @ChangeId
504 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
505 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
506
507 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700508 * A request object to use for transmitting data to an ICC.
509 */
510 private static final class IccAPDUArgument {
511 public int channel, cla, command, p1, p2, p3;
512 public String data;
513
514 public IccAPDUArgument(int channel, int cla, int command,
515 int p1, int p2, int p3, String data) {
516 this.channel = channel;
517 this.cla = cla;
518 this.command = command;
519 this.p1 = p1;
520 this.p2 = p2;
521 this.p3 = p3;
522 this.data = data;
523 }
524 }
525
526 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700527 * A request object to use for transmitting data to an ICC.
528 */
529 private static final class ManualNetworkSelectionArgument {
530 public OperatorInfo operatorInfo;
531 public boolean persistSelection;
532
533 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
534 this.operatorInfo = operatorInfo;
535 this.persistSelection = persistSelection;
536 }
537 }
538
Sarah Chin71b3a852022-09-28 15:54:19 -0700539 private static final class PurchasePremiumCapabilityArgument {
540 public @TelephonyManager.PremiumCapability int capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700541 public @NonNull IIntegerConsumer callback;
542
543 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
Sarah Chinb8218c22023-01-04 13:35:29 -0800544 @NonNull IIntegerConsumer callback) {
Sarah Chin71b3a852022-09-28 15:54:19 -0700545 this.capability = capability;
Sarah Chin71b3a852022-09-28 15:54:19 -0700546 this.callback = callback;
547 }
548 }
549
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800550 private static final class ProvisionSatelliteServiceArgument {
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800551 public @NonNull String token;
552 public @NonNull Consumer<Integer> callback;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800553 public int subId;
554
Sarah Chin4a9e8b82023-02-10 21:10:57 -0800555 ProvisionSatelliteServiceArgument(String token, Consumer<Integer> callback, int subId) {
556 this.token = token;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800557 this.callback = callback;
558 this.subId = subId;
559 }
560 }
561
Sarah Chineccfbd12023-01-20 19:00:35 -0800562 private static final class SatellitePositionUpdateHandler extends Handler {
563 public static final int EVENT_POSITION_UPDATE = 1;
564 public static final int EVENT_MESSAGE_TRANSFER_STATE_UPDATE = 2;
565
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800566 private final ISatelliteStateListener mCallback;
Sarah Chineccfbd12023-01-20 19:00:35 -0800567
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800568 SatellitePositionUpdateHandler(ISatelliteStateListener callback, Looper looper) {
Sarah Chineccfbd12023-01-20 19:00:35 -0800569 super(looper);
570 mCallback = callback;
571 }
572
573 @Override
574 public void handleMessage(@NonNull Message msg) {
575 switch (msg.what) {
576 case EVENT_POSITION_UPDATE: {
577 AsyncResult ar = (AsyncResult) msg.obj;
578 PointingInfo pointingInfo = (PointingInfo) ar.result;
579 try {
580 mCallback.onSatellitePositionUpdate(pointingInfo);
581 } catch (RemoteException e) {
582 loge("EVENT_POSITION_UPDATE RemoteException: " + e);
583 }
584 break;
585 }
586 case EVENT_MESSAGE_TRANSFER_STATE_UPDATE: {
587 AsyncResult ar = (AsyncResult) msg.obj;
588 int state = (int) ar.result;
589 try {
590 mCallback.onMessageTransferStateUpdate(state);
591 } catch (RemoteException e) {
592 loge("EVENT_MESSAGE_TRANSFER_STATE_UPDATE RemoteException: " + e);
593 }
594 break;
595 }
596 default:
597 loge("SatellitePositionUpdateHandler unknown event: " + msg.what);
598 }
599 }
600 }
601
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800602 private static final class SatelliteProvisionStateChangedHandler extends Handler {
603 public static final int EVENT_PROVISION_STATE_CHANGED = 1;
604
605 private ConcurrentHashMap<IBinder, ISatelliteStateListener> mListeners;
606 private final int mSubId;
607
608 SatelliteProvisionStateChangedHandler(Looper looper, int subId) {
609 super(looper);
610 mListeners = new ConcurrentHashMap<>();
611 mSubId = subId;
612 }
613
614 public void addListener(ISatelliteStateListener listener) {
615 mListeners.put(listener.asBinder(), listener);
616 }
617
618 public boolean removeListener(ISatelliteStateListener listener) {
619 return (mListeners.remove(listener.asBinder()) != null);
620 }
621
622 @Override
623 public void handleMessage(@NonNull Message msg) {
624 switch (msg.what) {
625 case EVENT_PROVISION_STATE_CHANGED: {
626 AsyncResult ar = (AsyncResult) msg.obj;
627 boolean provisioned = (boolean) ar.userObj;
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800628 log("Received EVENT_PROVISION_STATE_CHANGED for subId=" + mSubId
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800629 + ", provisioned=" + provisioned);
630 mListeners.values().forEach(listener -> {
631 try {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -0800632 listener.onSatelliteProvisionStateChanged(provisioned);
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800633 } catch (RemoteException e) {
634 log("EVENT_PROVISION_STATE_CHANGED RemoteException: " + e);
635 }
636 });
637
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800638 setSatelliteProvisioned(provisioned);
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800639 /**
640 * TODO: Take bugreport if provisioned is true and user did not initiate the
641 * provision procedure for the corresponding subscription.
642 */
643 break;
644 }
645 default:
646 loge("SatelliteProvisionStateChangedHandler unknown event: " + msg.what);
647 }
648 }
649
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800650 private void setSatelliteProvisioned(boolean isProvisioned) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800651 if (mSubId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
652 SubscriptionManager.setSubscriptionProperty(
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800653 mSubId, SubscriptionManager.SATELLITE_ENABLED, isProvisioned ? "1" : "0");
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800654 } else {
Thomas Nguyene77de6d2023-02-10 17:42:43 -0800655 //TODO (b/267826133): set via SatelliteController.
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800656 }
657 }
658 }
659
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700660 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700661 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
662 * request after sending. The main thread will notify the request when it is complete.
663 */
664 private static final class MainThreadRequest {
665 /** The argument to use for the request */
666 public Object argument;
667 /** The result of the request that is run on the main thread */
668 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800669 // The subscriber id that this request applies to. Defaults to
670 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
671 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700672
Nathan Harold92bed182018-10-12 18:16:49 -0700673 // In cases where subId is unavailable, the caller needs to specify the phone.
674 public Phone phone;
675
vagdeviaf9a5b92018-08-15 16:01:53 -0700676 public WorkSource workSource;
677
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700678 public MainThreadRequest(Object argument) {
679 this.argument = argument;
680 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800681
Nathan Harold92bed182018-10-12 18:16:49 -0700682 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
683 this.argument = argument;
684 if (phone != null) {
685 this.phone = phone;
686 }
687 this.workSource = workSource;
688 }
689
vagdeviaf9a5b92018-08-15 16:01:53 -0700690 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800691 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800692 if (subId != null) {
693 this.subId = subId;
694 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700695 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700697 }
698
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800699 private static final class IncomingThirdPartyCallArgs {
700 public final ComponentName component;
701 public final String callId;
702 public final String callerDisplayName;
703
704 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
705 String callerDisplayName) {
706 this.component = component;
707 this.callId = callId;
708 this.callerDisplayName = callerDisplayName;
709 }
710 }
711
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700712 /**
713 * A handler that processes messages on the main thread in the phone process. Since many
714 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
715 * inbound binder threads to the main thread in the phone process. The Binder thread
716 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
717 * on, which will be notified when the operation completes and will contain the result of the
718 * request.
719 *
720 * <p>If a MainThreadRequest object is provided in the msg.obj field,
721 * note that request.result must be set to something non-null for the calling thread to
722 * unblock.
723 */
724 private final class MainThreadHandler extends Handler {
725 @Override
726 public void handleMessage(Message msg) {
727 MainThreadRequest request;
728 Message onCompleted;
729 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000730 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700731 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800732 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700733
734 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700735 case CMD_HANDLE_USSD_REQUEST: {
736 request = (MainThreadRequest) msg.obj;
737 final Phone phone = getPhoneFromRequest(request);
738 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800739 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700740 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700741
Pengquan Menga1bb6272018-09-06 09:59:22 -0700742 if (!isUssdApiAllowed(request.subId)) {
743 // Carrier does not support use of this API, return failure.
744 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
745 UssdResponse response = new UssdResponse(ussdRequest, null);
746 Bundle returnData = new Bundle();
747 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
748 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700749
Pengquan Menga1bb6272018-09-06 09:59:22 -0700750 request.result = true;
751 notifyRequester(request);
752 return;
753 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700754
Pengquan Menga1bb6272018-09-06 09:59:22 -0700755 try {
756 request.result = phone != null
757 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
758 } catch (CallStateException cse) {
759 request.result = false;
760 }
761 // Wake up the requesting thread
762 notifyRequester(request);
763 break;
pkanwar32d516d2016-10-14 19:37:38 -0700764 }
765
Yorke Lee716f67e2015-06-17 15:39:16 -0700766 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700767 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700768 final Phone phone = getPhoneFromRequest(request);
769 request.result = phone != null ?
770 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
771 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700772 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700773 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700774 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700775 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700776
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700777 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700778 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700779 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000780 uiccPort = getUiccPortFromRequest(request);
781 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700782 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800783 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700784 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700785 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700786 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800787 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000788 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800789 iccArgument.channel, iccArgument.cla, iccArgument.command,
790 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
791 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700792 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700793 break;
794
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700795 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700796 ar = (AsyncResult) msg.obj;
797 request = (MainThreadRequest) ar.userObj;
798 if (ar.exception == null && ar.result != null) {
799 request.result = ar.result;
800 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800801 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700802 if (ar.result == null) {
803 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800804 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700805 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800806 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700807 } else {
808 loge("iccTransmitApduLogicalChannel: Unknown exception");
809 }
810 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700811 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700812 break;
813
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700814 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
815 request = (MainThreadRequest) msg.obj;
816 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000817 uiccPort = getUiccPortFromRequest(request);
818 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700819 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800820 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700821 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700822 } else {
823 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800824 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000825 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800826 iccArgument.cla, iccArgument.command, iccArgument.p1,
827 iccArgument.p2,
828 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700829 }
830 break;
831
832 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
833 ar = (AsyncResult) msg.obj;
834 request = (MainThreadRequest) ar.userObj;
835 if (ar.exception == null && ar.result != null) {
836 request.result = ar.result;
837 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800838 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700839 if (ar.result == null) {
840 loge("iccTransmitApduBasicChannel: Empty response");
841 } else if (ar.exception instanceof CommandException) {
842 loge("iccTransmitApduBasicChannel: CommandException: " +
843 ar.exception);
844 } else {
845 loge("iccTransmitApduBasicChannel: Unknown exception");
846 }
847 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700848 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700849 break;
850
851 case CMD_EXCHANGE_SIM_IO:
852 request = (MainThreadRequest) msg.obj;
853 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000854 uiccPort = getUiccPortFromRequest(request);
855 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700856 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800857 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700858 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700859 } else {
860 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
861 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000862 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700863 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
864 iccArgument.data, onCompleted);
865 }
866 break;
867
868 case EVENT_EXCHANGE_SIM_IO_DONE:
869 ar = (AsyncResult) msg.obj;
870 request = (MainThreadRequest) ar.userObj;
871 if (ar.exception == null && ar.result != null) {
872 request.result = ar.result;
873 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800874 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700875 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700876 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700877 break;
878
Derek Tan4d5e5c12014-02-04 11:54:58 -0800879 case CMD_SEND_ENVELOPE:
880 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000881 uiccPort = getUiccPortFromRequest(request);
882 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700883 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800884 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700885 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700886 } else {
887 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800888 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700889 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800890 break;
891
892 case EVENT_SEND_ENVELOPE_DONE:
893 ar = (AsyncResult) msg.obj;
894 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700895 if (ar.exception == null && ar.result != null) {
896 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800897 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800898 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700899 if (ar.result == null) {
900 loge("sendEnvelopeWithStatus: Empty response");
901 } else if (ar.exception instanceof CommandException) {
902 loge("sendEnvelopeWithStatus: CommandException: " +
903 ar.exception);
904 } else {
905 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
906 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800907 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700908 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800909 break;
910
Shishir Agrawal566b7612013-10-28 14:41:00 -0700911 case CMD_OPEN_CHANNEL:
912 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000913 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800914 IccLogicalChannelRequest openChannelRequest =
915 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000916 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700917 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800918 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800919 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700920 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700921 } else {
922 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800923 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
924 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700925 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700926 break;
927
928 case EVENT_OPEN_CHANNEL_DONE:
929 ar = (AsyncResult) msg.obj;
930 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700931 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700932 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700933 int[] result = (int[]) ar.result;
934 int channelId = result[0];
935 byte[] selectResponse = null;
936 if (result.length > 1) {
937 selectResponse = new byte[result.length - 1];
938 for (int i = 1; i < result.length; ++i) {
939 selectResponse[i - 1] = (byte) result[i];
940 }
941 }
942 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800943 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800944
945 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700946 if (uiccPort == null) {
947 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
948 } else {
949 IccLogicalChannelRequest channelRequest =
950 (IccLogicalChannelRequest) request.argument;
951 channelRequest.channel = channelId;
952 uiccPort.onLogicalChannelOpened(channelRequest);
953 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700954 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700955 if (ar.result == null) {
956 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700957 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700958 if (ar.exception != null) {
959 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
960 }
961
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700962 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700963 if (ar.exception instanceof CommandException) {
964 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800965 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700966 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700967 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700968 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700969 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700970 }
971 }
972 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800973 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700974 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700975 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700976 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700977 break;
978
979 case CMD_CLOSE_CHANNEL:
980 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000981 uiccPort = getUiccPortFromRequest(request);
982 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700983 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800984 request.result = new IllegalArgumentException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -0800985 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800986 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700987 } else {
988 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000989 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700990 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700991 break;
992
993 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800994 ar = (AsyncResult) msg.obj;
995 request = (MainThreadRequest) ar.userObj;
996 if (ar.exception == null) {
997 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800998 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700999 if (uiccPort == null) {
1000 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
1001 } else {
1002 final int channelId = (Integer) request.argument;
1003 uiccPort.onLogicalChannelClosed(channelId);
1004 }
Chen Xu540470b2021-12-14 17:15:47 -08001005 } else {
1006 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -08001007 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -08001008 if (ar.exception instanceof CommandException) {
1009 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
1010 CommandException.Error error =
1011 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -08001012 if (error == CommandException.Error.INVALID_ARGUMENTS) {
1013 // should only throw exceptions from the binder threads.
1014 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -08001015 "iccCloseLogicalChannel: invalid argument ");
1016 }
1017 } else {
1018 loge("iccCloseLogicalChannel: Unknown exception");
1019 }
Chen Xua8f0dff2022-02-12 00:34:15 -08001020 request.result = (exception != null) ? exception :
1021 new IllegalStateException(
1022 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -08001023 }
1024 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001025 break;
1026
1027 case CMD_NV_READ_ITEM:
1028 request = (MainThreadRequest) msg.obj;
1029 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001030 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
1031 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -08001032 break;
1033
1034 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -07001035 ar = (AsyncResult) msg.obj;
1036 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -08001037 if (ar.exception == null && ar.result != null) {
1038 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -07001039 } else {
Jake Hambye994d462014-02-03 13:10:13 -08001040 request.result = "";
1041 if (ar.result == null) {
1042 loge("nvReadItem: Empty response");
1043 } else if (ar.exception instanceof CommandException) {
1044 loge("nvReadItem: CommandException: " +
1045 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001046 } else {
Jake Hambye994d462014-02-03 13:10:13 -08001047 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -07001048 }
1049 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001050 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -07001051 break;
1052
Jake Hambye994d462014-02-03 13:10:13 -08001053 case CMD_NV_WRITE_ITEM:
1054 request = (MainThreadRequest) msg.obj;
1055 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
1056 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001057 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -07001058 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -08001059 break;
1060
1061 case EVENT_NV_WRITE_ITEM_DONE:
1062 handleNullReturnEvent(msg, "nvWriteItem");
1063 break;
1064
1065 case CMD_NV_WRITE_CDMA_PRL:
1066 request = (MainThreadRequest) msg.obj;
1067 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001068 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -08001069 break;
1070
1071 case EVENT_NV_WRITE_CDMA_PRL_DONE:
1072 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
1073 break;
1074
chen xu6dac5ab2018-10-26 17:39:23 -07001075 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -08001076 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -07001077 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001078 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -08001079 break;
1080
chen xu6dac5ab2018-10-26 17:39:23 -07001081 case EVENT_RESET_MODEM_CONFIG_DONE:
1082 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -08001083 break;
1084
Sooraj Sasindran37444802020-08-11 10:40:43 -07001085 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
1086 request = (MainThreadRequest) msg.obj;
1087 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
1088 request);
1089 Phone phone = getPhoneFromRequest(request);
1090 if (phone != null) {
1091 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
1092 } else {
1093 loge("isNRDualConnectivityEnabled: No phone object");
1094 request.result = false;
1095 notifyRequester(request);
1096 }
1097 break;
1098 }
1099
1100 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
1101 ar = (AsyncResult) msg.obj;
1102 request = (MainThreadRequest) ar.userObj;
1103 if (ar.exception == null && ar.result != null) {
1104 request.result = ar.result;
1105 } else {
1106 // request.result must be set to something non-null
1107 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001108 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -07001109 request.result = ar.result;
1110 } else {
1111 request.result = false;
1112 }
1113 if (ar.result == null) {
1114 loge("isNRDualConnectivityEnabled: Empty response");
1115 } else if (ar.exception instanceof CommandException) {
1116 loge("isNRDualConnectivityEnabled: CommandException: "
1117 + ar.exception);
1118 } else {
1119 loge("isNRDualConnectivityEnabled: Unknown exception");
1120 }
1121 }
1122 notifyRequester(request);
1123 break;
1124
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001125 case CMD_IS_VONR_ENABLED: {
1126 request = (MainThreadRequest) msg.obj;
1127 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
1128 request);
1129 Phone phone = getPhoneFromRequest(request);
1130 if (phone != null) {
1131 phone.isVoNrEnabled(onCompleted, request.workSource);
1132 } else {
1133 loge("isVoNrEnabled: No phone object");
1134 request.result = false;
1135 notifyRequester(request);
1136 }
1137 break;
1138 }
1139
1140 case EVENT_IS_VONR_ENABLED_DONE:
1141 ar = (AsyncResult) msg.obj;
1142 request = (MainThreadRequest) ar.userObj;
1143 if (ar.exception == null && ar.result != null) {
1144 request.result = ar.result;
1145 } else {
1146 // request.result must be set to something non-null
1147 // for the calling thread to unblock
1148 if (ar.result != null) {
1149 request.result = ar.result;
1150 } else {
1151 request.result = false;
1152 }
1153 if (ar.result == null) {
1154 loge("isVoNrEnabled: Empty response");
1155 } else if (ar.exception instanceof CommandException) {
1156 loge("isVoNrEnabled: CommandException: "
1157 + ar.exception);
1158 } else {
1159 loge("isVoNrEnabled: Unknown exception");
1160 }
1161 }
1162 notifyRequester(request);
1163 break;
1164
Sooraj Sasindran37444802020-08-11 10:40:43 -07001165 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
1166 request = (MainThreadRequest) msg.obj;
1167 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
1168 Phone phone = getPhoneFromRequest(request);
1169 if (phone != null) {
1170 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1171 request.workSource);
1172 } else {
1173 loge("enableNrDualConnectivity: No phone object");
1174 request.result =
1175 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1176 notifyRequester(request);
1177 }
1178 break;
1179 }
1180
1181 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1182 ar = (AsyncResult) msg.obj;
1183 request = (MainThreadRequest) ar.userObj;
1184 if (ar.exception == null) {
1185 request.result =
1186 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1187 } else {
1188 request.result =
1189 TelephonyManager
1190 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1191 if (ar.exception instanceof CommandException) {
1192 CommandException.Error error =
1193 ((CommandException) (ar.exception)).getCommandError();
1194 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1195 request.result =
1196 TelephonyManager
1197 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001198 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1199 request.result =
1200 TelephonyManager
1201 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001202 }
1203 loge("enableNrDualConnectivity" + ": CommandException: "
1204 + ar.exception);
1205 } else {
1206 loge("enableNrDualConnectivity" + ": Unknown exception");
1207 }
1208 }
1209 notifyRequester(request);
1210 break;
1211 }
1212
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001213 case CMD_ENABLE_VONR: {
1214 request = (MainThreadRequest) msg.obj;
1215 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1216 Phone phone = getPhoneFromRequest(request);
1217 if (phone != null) {
1218 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1219 request.workSource);
1220 } else {
1221 loge("setVoNrEnabled: No phone object");
1222 request.result =
1223 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1224 notifyRequester(request);
1225 }
1226 break;
1227 }
1228
1229 case EVENT_ENABLE_VONR_DONE: {
1230 ar = (AsyncResult) msg.obj;
1231 request = (MainThreadRequest) ar.userObj;
1232 if (ar.exception == null) {
1233 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1234 } else {
1235 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1236 if (ar.exception instanceof CommandException) {
1237 CommandException.Error error =
1238 ((CommandException) (ar.exception)).getCommandError();
1239 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1240 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1241 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1242 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1243 } else {
1244 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1245 }
1246 loge("setVoNrEnabled" + ": CommandException: "
1247 + ar.exception);
1248 } else {
1249 loge("setVoNrEnabled" + ": Unknown exception");
1250 }
1251 }
1252 notifyRequester(request);
1253 break;
1254 }
1255
SongFerngWang3ef3e072020-12-21 16:41:52 +08001256 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001257 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001258 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1259 request);
1260 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001261 break;
1262
SongFerngWang3ef3e072020-12-21 16:41:52 +08001263 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001264 ar = (AsyncResult) msg.obj;
1265 request = (MainThreadRequest) ar.userObj;
1266 if (ar.exception == null && ar.result != null) {
1267 request.result = ar.result; // Integer
1268 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301269 // request.result must be set to something non-null
1270 // for the calling thread to unblock
1271 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001272 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001273 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001274 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001275 loge("getAllowedNetworkTypesBitmask: CommandException: "
1276 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001277 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001278 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001279 }
1280 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001281 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001282 break;
1283
SongFerngWang3ef3e072020-12-21 16:41:52 +08001284 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001285 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001286 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1287 request);
1288 Pair<Integer, Long> reasonWithNetworkTypes =
1289 (Pair<Integer, Long>) request.argument;
1290 getPhoneFromRequest(request).setAllowedNetworkTypes(
1291 reasonWithNetworkTypes.first,
1292 reasonWithNetworkTypes.second,
1293 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001294 break;
1295
SongFerngWang3ef3e072020-12-21 16:41:52 +08001296 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1297 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001298 break;
1299
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001300 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1301 request = (MainThreadRequest)msg.obj;
1302 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001303 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001304 break;
1305
1306 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1307 ar = (AsyncResult)msg.obj;
1308 request = (MainThreadRequest)ar.userObj;
1309 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001310 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001311 break;
1312
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001313 case CMD_SET_VOICEMAIL_NUMBER:
1314 request = (MainThreadRequest) msg.obj;
1315 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1316 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001317 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1318 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001319 break;
1320
1321 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1322 handleNullReturnEvent(msg, "setVoicemailNumber");
1323 break;
1324
Stuart Scott54788802015-03-30 13:18:01 -07001325 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1326 request = (MainThreadRequest) msg.obj;
1327 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1328 request);
1329 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1330 break;
1331
1332 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1333 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1334 break;
1335
Shishir Agrawal302c8692015-06-19 13:49:39 -07001336 case CMD_PERFORM_NETWORK_SCAN:
1337 request = (MainThreadRequest) msg.obj;
1338 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1339 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1340 break;
1341
Hall Liu27d24262020-09-18 19:04:59 -07001342 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001343 request = (MainThreadRequest) msg.obj;
1344 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001345 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1346 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1347 request.argument;
1348 int callForwardingReason = args.first;
1349 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001350 break;
Hall Liu27d24262020-09-18 19:04:59 -07001351 }
1352 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001353 ar = (AsyncResult) msg.obj;
1354 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001355 TelephonyManager.CallForwardingInfoCallback callback =
1356 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1357 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001358 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001359 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001360 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1361 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1362 // Service Class is a bit mask per 3gpp 27.007. Search for
1363 // any service for voice call.
1364 if ((callForwardInfo.serviceClass
1365 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001366 callForwardingInfo = new CallForwardingInfo(
1367 callForwardInfo.status
1368 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001369 callForwardInfo.reason,
1370 callForwardInfo.number,
1371 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001372 break;
1373 }
1374 }
1375 // Didn't find a call forward info for voice call.
1376 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001377 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1378 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001379 }
Hall Liu27d24262020-09-18 19:04:59 -07001380 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001381 } else {
1382 if (ar.result == null) {
1383 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1384 }
1385 if (ar.exception != null) {
1386 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1387 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001388 int errorCode = TelephonyManager
1389 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001390 if (ar.exception instanceof CommandException) {
1391 CommandException.Error error =
1392 ((CommandException) (ar.exception)).getCommandError();
1393 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001394 errorCode = TelephonyManager
1395 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001396 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001397 errorCode = TelephonyManager
1398 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001399 }
1400 }
Hall Liu27d24262020-09-18 19:04:59 -07001401 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001402 }
Shuo Qian4a594052020-01-23 11:59:30 -08001403 break;
Hall Liu27d24262020-09-18 19:04:59 -07001404 }
Shuo Qian4a594052020-01-23 11:59:30 -08001405
Hall Liu27d24262020-09-18 19:04:59 -07001406 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001407 request = (MainThreadRequest) msg.obj;
1408 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001409 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001410 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001411 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1412 request.argument).first;
1413 request.phone.setCallForwardingOption(
1414 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001415 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001416 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001417 callForwardingInfoToSet.getReason(),
1418 callForwardingInfoToSet.getNumber(),
1419 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1420 break;
Hall Liu27d24262020-09-18 19:04:59 -07001421 }
Shuo Qian4a594052020-01-23 11:59:30 -08001422
Hall Liu27d24262020-09-18 19:04:59 -07001423 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001424 ar = (AsyncResult) msg.obj;
1425 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001426 Consumer<Integer> callback =
1427 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1428 request.argument).second;
1429 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001430 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001431 int errorCode = TelephonyManager.CallForwardingInfoCallback
1432 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001433 if (ar.exception instanceof CommandException) {
1434 CommandException.Error error =
1435 ((CommandException) (ar.exception)).getCommandError();
1436 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001437 errorCode = TelephonyManager.CallForwardingInfoCallback
1438 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001439 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001440 errorCode = TelephonyManager.CallForwardingInfoCallback
1441 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001442 }
1443 }
1444 callback.accept(errorCode);
1445 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001446 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001447 }
Shuo Qian4a594052020-01-23 11:59:30 -08001448 break;
Hall Liu27d24262020-09-18 19:04:59 -07001449 }
Shuo Qian4a594052020-01-23 11:59:30 -08001450
Hall Liu27d24262020-09-18 19:04:59 -07001451 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001452 request = (MainThreadRequest) msg.obj;
1453 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1454 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1455 break;
Hall Liu27d24262020-09-18 19:04:59 -07001456 }
Shuo Qian4a594052020-01-23 11:59:30 -08001457
Hall Liu27d24262020-09-18 19:04:59 -07001458 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001459 ar = (AsyncResult) msg.obj;
1460 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001461 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001462 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001463 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001464 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001465 // Service Class is a bit mask per 3gpp 27.007.
1466 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001467 if (callForwardResults.length > 1
1468 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001469 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001470 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001471 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1472 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001473 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001474 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001475 }
1476 } else {
1477 if (ar.result == null) {
1478 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1479 }
1480 if (ar.exception != null) {
1481 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1482 }
1483 if (ar.exception instanceof CommandException) {
1484 CommandException.Error error =
1485 ((CommandException) (ar.exception)).getCommandError();
1486 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001487 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001488 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001489 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1490 callWaitingStatus =
1491 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001492 }
1493 }
1494 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001495 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001496 break;
Hall Liu27d24262020-09-18 19:04:59 -07001497 }
Shuo Qian4a594052020-01-23 11:59:30 -08001498
Hall Liu27d24262020-09-18 19:04:59 -07001499 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001500 request = (MainThreadRequest) msg.obj;
1501 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001502 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1503 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001504 break;
Hall Liu27d24262020-09-18 19:04:59 -07001505 }
Shuo Qian4a594052020-01-23 11:59:30 -08001506
Hall Liu27d24262020-09-18 19:04:59 -07001507 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001508 ar = (AsyncResult) msg.obj;
1509 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001510 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1511 Consumer<Integer> callback =
1512 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1513 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001514 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001515 if (ar.exception instanceof CommandException) {
1516 CommandException.Error error =
1517 ((CommandException) (ar.exception)).getCommandError();
1518 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1519 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001520 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1521 callback.accept(
1522 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001523 } else {
1524 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1525 }
1526 } else {
1527 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1528 }
1529 } else {
1530 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1531 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001532 }
Shuo Qian4a594052020-01-23 11:59:30 -08001533 break;
Hall Liu27d24262020-09-18 19:04:59 -07001534 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001535 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1536 ar = (AsyncResult) msg.obj;
1537 request = (MainThreadRequest) ar.userObj;
1538 CellNetworkScanResult cellScanResult;
1539 if (ar.exception == null && ar.result != null) {
1540 cellScanResult = new CellNetworkScanResult(
1541 CellNetworkScanResult.STATUS_SUCCESS,
1542 (List<OperatorInfo>) ar.result);
1543 } else {
1544 if (ar.result == null) {
1545 loge("getCellNetworkScanResults: Empty response");
1546 }
1547 if (ar.exception != null) {
1548 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1549 }
1550 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1551 if (ar.exception instanceof CommandException) {
1552 CommandException.Error error =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001553 ((CommandException) (ar.exception)).getCommandError();
Shishir Agrawal302c8692015-06-19 13:49:39 -07001554 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1555 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1556 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1557 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1558 }
1559 }
1560 cellScanResult = new CellNetworkScanResult(errorCode, null);
1561 }
1562 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001563 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001564 break;
1565
1566 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1567 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001568 ManualNetworkSelectionArgument selArg =
1569 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001570 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1571 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001572 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1573 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001574 break;
1575
1576 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001577 ar = (AsyncResult) msg.obj;
1578 request = (MainThreadRequest) ar.userObj;
1579 if (ar.exception == null) {
1580 request.result = true;
1581 } else {
1582 request.result = false;
1583 loge("setNetworkSelectionModeManual " + ar.exception);
1584 }
1585 notifyRequester(request);
1586 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001587 break;
1588
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001589 case CMD_GET_MODEM_ACTIVITY_INFO:
1590 request = (MainThreadRequest) msg.obj;
1591 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001592 if (defaultPhone != null) {
1593 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001594 } else {
1595 ResultReceiver result = (ResultReceiver) request.argument;
1596 Bundle bundle = new Bundle();
1597 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001598 new ModemActivityInfo(0, 0, 0,
1599 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001600 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001601 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001602 break;
1603
Hall Liud0f208c2020-10-14 16:54:44 -07001604 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001605 ar = (AsyncResult) msg.obj;
1606 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001607 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001608 int error = 0;
Kai Shi917fdc62022-11-28 14:01:02 -08001609 ModemActivityInfo ret = null;
Gary Jian3aa9a762022-01-24 16:41:19 +08001610 if (mLastModemActivityInfo == null) {
1611 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1612 mLastModemActivitySpecificInfo[0] =
1613 new ActivityStatsTechSpecificInfo(
1614 0,
1615 0,
1616 new int[ModemActivityInfo.getNumTxPowerLevels()],
1617 0);
1618 mLastModemActivityInfo =
1619 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1620 }
1621
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001622 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001623 // Update the last modem activity info and the result of the request.
1624 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1625 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001626 mergeModemActivityInfo(info);
Gary Jian76280a42022-12-07 16:18:33 +08001627 } else {
1628 loge("queryModemActivityInfo: invalid response");
Shuo Qian8f4750a2020-02-20 17:12:10 -08001629 }
Kai Shi917fdc62022-11-28 14:01:02 -08001630 // This is needed to decouple ret from mLastModemActivityInfo
1631 // We don't want to return mLastModemActivityInfo which is updated
1632 // inside mergeModemActivityInfo()
1633 ret = new ModemActivityInfo(
1634 mLastModemActivityInfo.getTimestampMillis(),
1635 mLastModemActivityInfo.getSleepTimeMillis(),
1636 mLastModemActivityInfo.getIdleTimeMillis(),
1637 deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08001638
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001639 } else {
1640 if (ar.result == null) {
1641 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001642 error = TelephonyManager.ModemActivityInfoException
1643 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001644 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001645 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001646 error = TelephonyManager.ModemActivityInfoException
1647 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001648 } else {
1649 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001650 error = TelephonyManager.ModemActivityInfoException
1651 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001652 }
1653 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001654 Bundle bundle = new Bundle();
Kai Shi917fdc62022-11-28 14:01:02 -08001655 if (ret != null) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001656 bundle.putParcelable(
1657 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Kai Shi917fdc62022-11-28 14:01:02 -08001658 ret);
Hall Liud0f208c2020-10-14 16:54:44 -07001659 } else {
1660 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1661 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001662 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001663 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001664 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001665 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001666
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001667 case CMD_SET_ALLOWED_CARRIERS: {
Meng Wang1a7c35a2016-05-05 20:56:15 -07001668 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001669 CarrierRestrictionRules argument =
1670 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001671 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001672 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001673 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001674 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001675
1676 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1677 ar = (AsyncResult) msg.obj;
1678 request = (MainThreadRequest) ar.userObj;
1679 if (ar.exception == null && ar.result != null) {
1680 request.result = ar.result;
1681 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001682 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1683 if (ar.exception instanceof CommandException) {
1684 loge("setAllowedCarriers: CommandException: " + ar.exception);
1685 CommandException.Error error =
1686 ((CommandException) (ar.exception)).getCommandError();
1687 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1688 request.result =
1689 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1690 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001691 } else {
1692 loge("setAllowedCarriers: Unknown exception");
1693 }
1694 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001695 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001696 break;
1697
1698 case CMD_GET_ALLOWED_CARRIERS:
1699 request = (MainThreadRequest) msg.obj;
1700 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001701 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001702 break;
1703
1704 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1705 ar = (AsyncResult) msg.obj;
1706 request = (MainThreadRequest) ar.userObj;
1707 if (ar.exception == null && ar.result != null) {
1708 request.result = ar.result;
1709 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001710 request.result = new IllegalStateException(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001711 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001712 if (ar.result == null) {
1713 loge("getAllowedCarriers: Empty response");
1714 } else if (ar.exception instanceof CommandException) {
1715 loge("getAllowedCarriers: CommandException: " +
1716 ar.exception);
1717 } else {
1718 loge("getAllowedCarriers: Unknown exception");
1719 }
1720 }
arunvoddud7401012022-12-15 16:08:12 +00001721 if (request.argument != null) {
1722 // This is for the implementation of carrierRestrictionStatus.
1723 CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument;
1724 Consumer<Integer> callback = callbackInfo.getConsumer();
1725 int callerCarrierId = callbackInfo.getCarrierId();
1726 int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN;
1727 if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) {
1728 CarrierRestrictionRules carrierRestrictionRules =
1729 (CarrierRestrictionRules) ar.result;
1730 int carrierId = -1;
1731 try {
1732 CarrierIdentifier carrierIdentifier =
1733 carrierRestrictionRules.getAllowedCarriers().get(0);
1734 carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp,
1735 carrierIdentifier);
1736 } catch (NullPointerException | IndexOutOfBoundsException ex) {
1737 Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex);
1738 }
1739 lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus();
1740 if (carrierId != -1 && callerCarrierId == carrierId && lockStatus
1741 == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001742 lockStatus = TelephonyManager
1743 .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER;
arunvoddud7401012022-12-15 16:08:12 +00001744 }
1745 } else {
1746 Rlog.e(LOG_TAG,
1747 "getCarrierRestrictionStatus: exception ex = " + ar.exception);
1748 }
1749 callback.accept(lockStatus);
1750 } else {
1751 // This is for the implementation of getAllowedCarriers.
1752 notifyRequester(request);
1753 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001754 break;
1755
Nathan Haroldb3014052017-01-25 15:57:32 -08001756 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1757 ar = (AsyncResult) msg.obj;
1758 request = (MainThreadRequest) ar.userObj;
1759 if (ar.exception == null && ar.result != null) {
1760 request.result = ar.result;
1761 } else {
1762 request.result = new IllegalArgumentException(
1763 "Failed to retrieve Forbidden Plmns");
1764 if (ar.result == null) {
1765 loge("getForbiddenPlmns: Empty response");
1766 } else {
1767 loge("getForbiddenPlmns: Unknown exception");
1768 }
1769 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001770 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001771 break;
1772
1773 case CMD_GET_FORBIDDEN_PLMNS:
1774 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001775 uiccPort = getUiccPortFromRequest(request);
1776 if (uiccPort == null) {
1777 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001778 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001779 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001780 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001781 break;
1782 }
1783 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001784 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001785 if (uiccApp == null) {
1786 loge("getForbiddenPlmns() no app with specified type -- "
1787 + appType);
1788 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001789 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001790 break;
1791 } else {
1792 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1793 + " specified type -- " + appType);
1794 }
1795 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1796 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08001797 onCompleted);
Nathan Haroldb3014052017-01-25 15:57:32 -08001798 break;
1799
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001800 case CMD_SWITCH_SLOTS:
1801 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001802 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001803 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001804 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001805 break;
1806
1807 case EVENT_SWITCH_SLOTS_DONE:
1808 ar = (AsyncResult) msg.obj;
1809 request = (MainThreadRequest) ar.userObj;
1810 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001811 notifyRequester(request);
1812 break;
1813 case CMD_GET_NETWORK_SELECTION_MODE:
1814 request = (MainThreadRequest) msg.obj;
1815 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1816 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1817 break;
1818
1819 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1820 ar = (AsyncResult) msg.obj;
1821 request = (MainThreadRequest) ar.userObj;
1822 if (ar.exception != null) {
1823 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1824 } else {
1825 int mode = ((int[]) ar.result)[0];
1826 if (mode == 0) {
1827 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1828 } else {
1829 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1830 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001831 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001832 notifyRequester(request);
1833 break;
1834 case CMD_GET_CDMA_ROAMING_MODE:
1835 request = (MainThreadRequest) msg.obj;
1836 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1837 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1838 break;
1839 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1840 ar = (AsyncResult) msg.obj;
1841 request = (MainThreadRequest) ar.userObj;
1842 if (ar.exception != null) {
1843 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1844 } else {
1845 request.result = ((int[]) ar.result)[0];
1846 }
1847 notifyRequester(request);
1848 break;
1849 case CMD_SET_CDMA_ROAMING_MODE:
1850 request = (MainThreadRequest) msg.obj;
1851 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1852 int mode = (int) request.argument;
1853 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1854 break;
1855 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1856 ar = (AsyncResult) msg.obj;
1857 request = (MainThreadRequest) ar.userObj;
1858 request.result = ar.exception == null;
1859 notifyRequester(request);
1860 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001861 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1862 request = (MainThreadRequest) msg.obj;
1863 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1864 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1865 break;
1866 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1867 ar = (AsyncResult) msg.obj;
1868 request = (MainThreadRequest) ar.userObj;
1869 if (ar.exception != null) {
1870 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1871 } else {
1872 request.result = ((int[]) ar.result)[0];
1873 }
1874 notifyRequester(request);
1875 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001876 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1877 request = (MainThreadRequest) msg.obj;
1878 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1879 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001880 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1881 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001882 break;
1883 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1884 ar = (AsyncResult) msg.obj;
1885 request = (MainThreadRequest) ar.userObj;
1886 request.result = ar.exception == null;
1887 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001888 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001889 case CMD_GET_ALL_CELL_INFO:
1890 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001891 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001892 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001893 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001894 case EVENT_GET_ALL_CELL_INFO_DONE:
1895 ar = (AsyncResult) msg.obj;
1896 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001897 // If a timeout occurs, the response will be null
1898 request.result = (ar.exception == null && ar.result != null)
1899 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001900 synchronized (request) {
1901 request.notifyAll();
1902 }
1903 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001904 case CMD_REQUEST_CELL_INFO_UPDATE:
1905 request = (MainThreadRequest) msg.obj;
1906 request.phone.requestCellInfoUpdate(request.workSource,
1907 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1908 break;
1909 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1910 ar = (AsyncResult) msg.obj;
1911 request = (MainThreadRequest) ar.userObj;
1912 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1913 try {
1914 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001915 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001916 cb.onError(
1917 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1918 ar.exception.getClass().getName(),
1919 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001920 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001921 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001922 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001923 } else {
1924 // use the result as returned
1925 cb.onCellInfo((List<CellInfo>) ar.result);
1926 }
1927 } catch (RemoteException re) {
1928 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1929 }
1930 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001931 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001932 request = (MainThreadRequest) msg.obj;
1933 WorkSource ws = (WorkSource) request.argument;
1934 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001935 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001936 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001937 }
1938 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001939 ar = (AsyncResult) msg.obj;
1940 request = (MainThreadRequest) ar.userObj;
1941 if (ar.exception == null) {
1942 request.result = ar.result;
1943 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001944 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001945 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001946 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001947 }
1948
1949 synchronized (request) {
1950 request.notifyAll();
1951 }
1952 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001953 }
chen xu6dac5ab2018-10-26 17:39:23 -07001954 case CMD_MODEM_REBOOT:
1955 request = (MainThreadRequest) msg.obj;
1956 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001957 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001958 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001959 case EVENT_CMD_MODEM_REBOOT_DONE:
1960 handleNullReturnEvent(msg, "rebootModem");
1961 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001962 case CMD_REQUEST_ENABLE_MODEM: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001963 request = (MainThreadRequest) msg.obj;
1964 boolean enable = (boolean) request.argument;
1965 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001966 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001967 PhoneConfigurationManager.getInstance()
1968 .enablePhone(request.phone, enable, onCompleted);
1969 break;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08001970 }
Michele Berionne5e411512020-11-13 02:36:59 +00001971 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001972 ar = (AsyncResult) msg.obj;
1973 request = (MainThreadRequest) ar.userObj;
1974 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001975 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001976 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001977 if ((boolean) request.result) {
1978 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1979 updateModemStateMetrics();
1980 } else {
1981 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1982 + ar.exception);
1983 }
1984 notifyRequester(request);
1985 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001986 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001987 case CMD_GET_MODEM_STATUS:
1988 request = (MainThreadRequest) msg.obj;
1989 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1990 PhoneConfigurationManager.getInstance()
1991 .getPhoneStatusFromModem(request.phone, onCompleted);
1992 break;
1993 case EVENT_GET_MODEM_STATUS_DONE:
1994 ar = (AsyncResult) msg.obj;
1995 request = (MainThreadRequest) ar.userObj;
1996 int id = request.phone.getPhoneId();
1997 if (ar.exception == null && ar.result != null) {
1998 request.result = ar.result;
1999 //update the cache as modem status has changed
2000 mPhoneConfigurationManager.addToPhoneStatusCache(id,
2001 (boolean) request.result);
2002 } else {
2003 // Return true if modem status cannot be retrieved. For most cases,
2004 // modem status is on. And for older version modems, GET_MODEM_STATUS
2005 // and disable modem are not supported. Modem is always on.
2006 // TODO: this should be fixed in R to support a third
2007 // status UNKNOWN b/131631629
2008 request.result = true;
2009 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
2010 + ar.exception);
2011 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08002012 notifyRequester(request);
2013 break;
Hall Liu73f5d362020-01-20 13:42:00 -08002014 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
2015 request = (MainThreadRequest) msg.obj;
2016 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
2017 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
2018 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
2019 request.phone.setSystemSelectionChannels(args.first, onCompleted);
2020 break;
2021 }
2022 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
2023 ar = (AsyncResult) msg.obj;
2024 request = (MainThreadRequest) ar.userObj;
2025 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
2026 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
2027 args.second.accept(ar.exception == null);
2028 notifyRequester(request);
2029 break;
2030 }
Sarah Chin679c08a2020-11-18 13:39:35 -08002031 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
2032 request = (MainThreadRequest) msg.obj;
2033 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
2034 Phone phone = getPhoneFromRequest(request);
2035 if (phone != null) {
2036 phone.getSystemSelectionChannels(onCompleted);
2037 } else {
2038 loge("getSystemSelectionChannels: No phone object");
2039 request.result = new ArrayList<RadioAccessSpecifier>();
2040 notifyRequester(request);
2041 }
2042 break;
2043 }
2044 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
2045 ar = (AsyncResult) msg.obj;
2046 request = (MainThreadRequest) ar.userObj;
2047 if (ar.exception == null && ar.result != null) {
2048 request.result = ar.result;
2049 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08002050 request.result = new IllegalStateException(
2051 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08002052 if (ar.result == null) {
2053 loge("getSystemSelectionChannels: Empty response");
2054 } else {
2055 loge("getSystemSelectionChannels: Unknown exception");
2056 }
2057 }
2058 notifyRequester(request);
2059 break;
yincheng zhao2737e882019-09-06 17:06:54 -07002060 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
2061 ar = (AsyncResult) msg.obj;
2062 request = (MainThreadRequest) ar.userObj;
2063 if (ar.exception == null && ar.result != null) {
2064 request.result = ar.result;
2065 } else {
2066 request.result = -1;
2067 loge("Failed to set Forbidden Plmns");
2068 if (ar.result == null) {
2069 loge("setForbidenPlmns: Empty response");
2070 } else if (ar.exception != null) {
2071 loge("setForbiddenPlmns: Exception: " + ar.exception);
2072 request.result = -1;
2073 } else {
2074 loge("setForbiddenPlmns: Unknown exception");
2075 }
2076 }
2077 notifyRequester(request);
2078 break;
2079 case CMD_SET_FORBIDDEN_PLMNS:
2080 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002081 uiccPort = getUiccPortFromRequest(request);
2082 if (uiccPort == null) {
2083 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07002084 request.result = -1;
2085 notifyRequester(request);
2086 break;
2087 }
2088 Pair<Integer, List<String>> setFplmnsArgs =
2089 (Pair<Integer, List<String>>) request.argument;
2090 appType = setFplmnsArgs.first;
2091 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002092 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07002093 if (uiccApp == null) {
2094 loge("setForbiddenPlmns: no app with specified type -- " + appType);
2095 request.result = -1;
2096 loge("Failed to get UICC App");
2097 notifyRequester(request);
2098 } else {
2099 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
2100 ((SIMRecords) uiccApp.getIccRecords())
2101 .setForbiddenPlmns(onCompleted, fplmns);
2102 }
yinchengzhao4d163c02019-12-12 15:21:47 -08002103 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07002104 case CMD_ERASE_MODEM_CONFIG:
2105 request = (MainThreadRequest) msg.obj;
2106 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
2107 defaultPhone.eraseModemConfig(onCompleted);
2108 break;
2109 case EVENT_ERASE_MODEM_CONFIG_DONE:
2110 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07002111 break;
zoey chene02881a2019-12-30 16:11:23 +08002112
Kai Shif70f46f2021-03-03 13:59:46 -08002113 case CMD_ERASE_DATA_SHARED_PREFERENCES:
2114 request = (MainThreadRequest) msg.obj;
2115 request.result = defaultPhone.eraseDataInSharedPreferences();
2116 notifyRequester(request);
2117 break;
2118
zoey chene02881a2019-12-30 16:11:23 +08002119 case CMD_CHANGE_ICC_LOCK_PASSWORD:
2120 request = (MainThreadRequest) msg.obj;
2121 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
2122 Pair<String, String> changed = (Pair<String, String>) request.argument;
2123 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
2124 changed.first, changed.second, onCompleted);
2125 break;
2126 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
2127 ar = (AsyncResult) msg.obj;
2128 request = (MainThreadRequest) ar.userObj;
2129 if (ar.exception == null) {
2130 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002131 // If the operation is successful, update the PIN storage
2132 Pair<String, String> passwords = (Pair<String, String>) request.argument;
2133 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00002134 UiccController.getInstance().getPinStorage()
2135 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08002136 } else {
2137 request.result = msg.arg1;
2138 }
2139 notifyRequester(request);
2140 break;
2141
Michele Berionne5e411512020-11-13 02:36:59 +00002142 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08002143 request = (MainThreadRequest) msg.obj;
2144 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
2145 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2146 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
2147 enabled.first, enabled.second, onCompleted);
2148 break;
Michele Berionne5e411512020-11-13 02:36:59 +00002149 }
zoey chene02881a2019-12-30 16:11:23 +08002150 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
2151 ar = (AsyncResult) msg.obj;
2152 request = (MainThreadRequest) ar.userObj;
2153 if (ar.exception == null) {
2154 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00002155 // If the operation is successful, update the PIN storage
2156 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
2157 int phoneId = getPhoneFromRequest(request).getPhoneId();
2158 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002159 UiccController.getInstance().getPinStorage()
2160 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002161 } else {
2162 UiccController.getInstance().getPinStorage().clearPin(phoneId);
2163 }
zoey chene02881a2019-12-30 16:11:23 +08002164 } else {
2165 request.result = msg.arg1;
2166 }
Michele Berionne5e411512020-11-13 02:36:59 +00002167
2168
zoey chene02881a2019-12-30 16:11:23 +08002169 notifyRequester(request);
2170 break;
2171
Peter Wangdafb9ac2020-01-15 14:13:38 -08002172 case MSG_NOTIFY_USER_ACTIVITY:
2173 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08002174 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08002175 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
2176 getDefaultPhone().getContext().sendBroadcastAsUser(
2177 intent, UserHandle.ALL, permission.USER_ACTIVITY);
2178 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002179
2180 case CMD_SET_DATA_THROTTLING: {
2181 request = (MainThreadRequest) msg.obj;
2182 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
2183 DataThrottlingRequest dataThrottlingRequest =
2184 (DataThrottlingRequest) request.argument;
2185 Phone phone = getPhoneFromRequest(request);
2186 if (phone != null) {
2187 phone.setDataThrottling(onCompleted,
2188 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
2189 dataThrottlingRequest.getCompletionDurationMillis());
2190 } else {
2191 loge("setDataThrottling: No phone object");
2192 request.result =
2193 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2194 notifyRequester(request);
2195 }
2196
2197 break;
2198 }
2199 case EVENT_SET_DATA_THROTTLING_DONE:
2200 ar = (AsyncResult) msg.obj;
2201 request = (MainThreadRequest) ar.userObj;
2202
2203 if (ar.exception == null) {
2204 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
2205 } else if (ar.exception instanceof CommandException) {
2206 loge("setDataThrottling: CommandException: " + ar.exception);
2207 CommandException.Error error =
2208 ((CommandException) (ar.exception)).getCommandError();
2209
2210 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2211 request.result = TelephonyManager
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002212 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002213 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2214 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002215 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2216 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002217 } else {
2218 request.result =
2219 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2220 }
2221 } else {
2222 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2223 }
2224 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2225 notifyRequester(request);
2226 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002227
2228 case CMD_SET_SIM_POWER: {
2229 request = (MainThreadRequest) msg.obj;
2230 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2231 request = (MainThreadRequest) msg.obj;
2232 int stateToSet =
2233 ((Pair<Integer, IIntegerConsumer>)
2234 request.argument).first;
2235 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2236 break;
2237 }
2238 case EVENT_SET_SIM_POWER_DONE: {
2239 ar = (AsyncResult) msg.obj;
2240 request = (MainThreadRequest) ar.userObj;
2241 IIntegerConsumer callback =
2242 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2243 if (ar.exception != null) {
2244 loge("setSimPower exception: " + ar.exception);
2245 int errorCode = TelephonyManager.CallForwardingInfoCallback
2246 .RESULT_ERROR_UNKNOWN;
2247 if (ar.exception instanceof CommandException) {
2248 CommandException.Error error =
2249 ((CommandException) (ar.exception)).getCommandError();
2250 if (error == CommandException.Error.SIM_ERR) {
2251 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2252 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2253 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2254 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2255 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2256 } else {
2257 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2258 }
2259 }
2260 try {
2261 callback.accept(errorCode);
2262 } catch (RemoteException e) {
2263 // Ignore if the remote process is no longer available to call back.
2264 Log.w(LOG_TAG, "setSimPower: callback not available.");
2265 }
2266 } else {
2267 try {
2268 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2269 } catch (RemoteException e) {
2270 // Ignore if the remote process is no longer available to call back.
2271 Log.w(LOG_TAG, "setSimPower: callback not available.");
2272 }
2273 }
2274 break;
2275 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002276 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2277 request = (MainThreadRequest) msg.obj;
2278
2279 final Phone phone = getPhoneFromRequest(request);
2280 if (phone == null || phone.getServiceStateTracker() == null) {
2281 request.result = new IllegalStateException("Phone or SST is null");
2282 notifyRequester(request);
2283 break;
2284 }
2285
2286 Pair<Integer, SignalStrengthUpdateRequest> pair =
2287 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2288 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2289 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002290 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002291 request.subId, pair.first /*callingUid*/,
2292 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002293 break;
2294 }
2295 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2296 ar = (AsyncResult) msg.obj;
2297 request = (MainThreadRequest) ar.userObj;
2298 // request.result will be the exception of ar if present, true otherwise.
2299 // Be cautious not to leave result null which will wait() forever
2300 request.result = ar.exception != null ? ar.exception : true;
2301 notifyRequester(request);
2302 break;
2303 }
2304 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2305 request = (MainThreadRequest) msg.obj;
2306
2307 Phone phone = getPhoneFromRequest(request);
2308 if (phone == null || phone.getServiceStateTracker() == null) {
2309 request.result = new IllegalStateException("Phone or SST is null");
2310 notifyRequester(request);
2311 break;
2312 }
2313
2314 Pair<Integer, SignalStrengthUpdateRequest> pair =
2315 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2316 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2317 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002318 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002319 request.subId, pair.first /*callingUid*/,
2320 pair.second /*request*/, onCompleted);
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002321 break;
2322 }
2323 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2324 ar = (AsyncResult) msg.obj;
2325 request = (MainThreadRequest) ar.userObj;
2326 request.result = ar.exception != null ? ar.exception : true;
2327 notifyRequester(request);
2328 break;
2329 }
Jordan Liu109698e2020-11-24 14:50:34 -08002330
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002331 case CMD_GET_SLICING_CONFIG: {
2332 request = (MainThreadRequest) msg.obj;
2333 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2334 request.phone.getSlicingConfig(onCompleted);
2335 break;
2336 }
2337 case EVENT_GET_SLICING_CONFIG_DONE: {
2338 ar = (AsyncResult) msg.obj;
2339 request = (MainThreadRequest) ar.userObj;
2340 ResultReceiver result = (ResultReceiver) request.argument;
2341
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002342 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002343 Bundle bundle = new Bundle();
2344 int resultCode = 0;
2345 if (ar.exception != null) {
2346 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2347 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002348 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002349 } else if (ar.result == null) {
2350 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002351 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002352 } else {
2353 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002354 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2355 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002356 }
2357
2358 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002359 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002360 }
2361 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2362 result.send(resultCode, bundle);
2363 notifyRequester(request);
2364 break;
2365 }
2366
Sarah Chin71b3a852022-09-28 15:54:19 -07002367 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002368 request = (MainThreadRequest) msg.obj;
2369 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002370 PurchasePremiumCapabilityArgument arg =
2371 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002372 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chinb8218c22023-01-04 13:35:29 -08002373 arg.capability, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002374 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002375 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002376
Sarah Chin71b3a852022-09-28 15:54:19 -07002377 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002378 ar = (AsyncResult) msg.obj;
2379 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002380 PurchasePremiumCapabilityArgument arg =
2381 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002382 try {
2383 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002384 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002385 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002386 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002387 + ", result= "
2388 + TelephonyManager.convertPurchaseResultToString(result));
2389 } catch (RemoteException e) {
2390 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002391 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002392 + " failed: " + e;
2393 if (DBG) log(logStr);
2394 AnomalyReporter.reportAnomaly(
2395 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2396 }
2397 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002398 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002399
Michele Berionne5e411512020-11-13 02:36:59 +00002400 case CMD_PREPARE_UNATTENDED_REBOOT:
2401 request = (MainThreadRequest) msg.obj;
2402 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002403 UiccController.getInstance().getPinStorage()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002404 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002405 notifyRequester(request);
2406 break;
2407
Sarah Chineccfbd12023-01-20 19:00:35 -08002408 case CMD_START_SATELLITE_POSITION_UPDATES: {
2409 request = (MainThreadRequest) msg.obj;
2410 onCompleted =
2411 obtainMessage(EVENT_START_SATELLITE_POSITION_UPDATES_DONE, request);
2412 Phone phone = getPhoneFromRequest(request);
2413 if (phone != null) {
2414 phone.startSatellitePositionUpdates(onCompleted);
2415 } else {
2416 loge("startSatellitePositionUpdates: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002417 ((Consumer<Integer>) request.argument).accept(
2418 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Sarah Chineccfbd12023-01-20 19:00:35 -08002419 }
2420 break;
2421 }
2422
2423 case EVENT_START_SATELLITE_POSITION_UPDATES_DONE: {
2424 ar = (AsyncResult) msg.obj;
2425 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002426 int error = getSatelliteError(ar, "startSatellitePositionUpdates", false);
2427 ((Consumer<Integer>) request.argument).accept(error);
Sarah Chineccfbd12023-01-20 19:00:35 -08002428 break;
2429 }
2430
2431 case CMD_STOP_SATELLITE_POSITION_UPDATES: {
2432 request = (MainThreadRequest) msg.obj;
2433 onCompleted =
2434 obtainMessage(EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE, request);
2435 Phone phone = getPhoneFromRequest(request);
2436 if (phone != null) {
2437 phone.stopSatellitePositionUpdates(onCompleted);
2438 } else {
2439 loge("stopSatellitePositionUpdates: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002440 ((Consumer<Integer>) request.argument).accept(
2441 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Sarah Chineccfbd12023-01-20 19:00:35 -08002442 }
2443 break;
2444 }
2445
2446 case EVENT_STOP_SATELLITE_POSITION_UPDATES_DONE: {
2447 ar = (AsyncResult) msg.obj;
2448 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002449 int error = getSatelliteError(ar, "stopSatellitePositionUpdates", false);
2450 ((Consumer<Integer>) request.argument).accept(error);
Sarah Chineccfbd12023-01-20 19:00:35 -08002451 break;
2452 }
2453
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002454 case CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG: {
2455 request = (MainThreadRequest) msg.obj;
2456 onCompleted = obtainMessage(EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE,
2457 request);
2458 Phone phone = getPhoneFromRequest(request);
2459 if (phone != null) {
2460 phone.getMaxCharactersPerSatelliteTextMessage(onCompleted);
2461 } else {
2462 loge("getMaxCharactersPerSatelliteTextMessage: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002463 ((ResultReceiver) request.argument).send(
2464 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002465 }
2466 break;
2467 }
2468
2469 case EVENT_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG_DONE: {
2470 ar = (AsyncResult) msg.obj;
2471 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002472 int error =
2473 getSatelliteError(ar, "getMaxCharactersPerSatelliteTextMessage", true);
2474 Bundle bundle = new Bundle();
2475 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002476 int maxCharLimit = ((int[]) ar.result)[0];
Sarah Chin503828c2023-02-01 23:54:20 -08002477 if (DBG) log("getMaxCharactersPerSatelliteTextMessage: " + maxCharLimit);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002478 bundle.putInt(SatelliteManager.KEY_MAX_CHARACTERS_PER_SATELLITE_TEXT,
2479 maxCharLimit);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002480 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002481 ((ResultReceiver) request.argument).send(error, bundle);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00002482 break;
2483 }
2484
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002485 case CMD_PROVISION_SATELLITE_SERVICE: {
2486 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002487 onCompleted = obtainMessage(EVENT_PROVISION_SATELLITE_SERVICE_DONE, request);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002488 Phone phone = getPhoneFromRequest(request);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002489 ProvisionSatelliteServiceArgument argument =
2490 (ProvisionSatelliteServiceArgument) request.argument;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002491 if (phone != null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002492 handleCmdProvisionSatelliteService(argument, phone, onCompleted);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002493 } else {
2494 loge("provisionSatelliteService: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002495 argument.callback.accept(
2496 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002497 notifyRequester(request);
2498 }
2499 break;
2500 }
2501
2502 case EVENT_PROVISION_SATELLITE_SERVICE_DONE: {
2503 ar = (AsyncResult) msg.obj;
2504 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002505 int errorCode = getSatelliteError(ar, "provisionSatelliteService", false);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002506 handleEventProvisionSatelliteServiceDone(
2507 (ProvisionSatelliteServiceArgument) request.argument, errorCode);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002508 notifyRequester(request);
2509 break;
2510 }
2511
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002512 case CMD_DEPROVISION_SATELLITE_SERVICE: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002513 request = (MainThreadRequest) msg.obj;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002514 onCompleted = obtainMessage(EVENT_DEPROVISION_SATELLITE_SERVICE_DONE, request);
2515 Phone phone = getPhoneFromRequest(request);
2516 ProvisionSatelliteServiceArgument argument =
2517 (ProvisionSatelliteServiceArgument) request.argument;
2518 if (phone != null) {
2519 handleCmdDeprovisionSatelliteService(argument, phone, onCompleted);
2520 } else {
2521 loge("deprovisionSatelliteService: No phone object");
2522 if (argument.callback != null) {
2523 argument.callback.accept(
2524 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
2525 }
2526 notifyRequester(request);
2527 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002528 break;
2529 }
2530
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002531 case EVENT_DEPROVISION_SATELLITE_SERVICE_DONE: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002532 ar = (AsyncResult) msg.obj;
2533 request = (MainThreadRequest) ar.userObj;
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -08002534 int errorCode = getSatelliteError(ar, "deprovisionSatelliteService", false);
2535 handleEventDeprovisionSatelliteServiceDone(
2536 (ProvisionSatelliteServiceArgument) request.argument, errorCode);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002537 notifyRequester(request);
2538 break;
2539 }
2540
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002541 case CMD_SET_SATELLITE_ENABLED: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002542 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002543 onCompleted = obtainMessage(EVENT_SET_SATELLITE_ENABLED_DONE, request);
2544 Pair<Boolean, Consumer<Integer>> argument =
2545 (Pair<Boolean, Consumer<Integer>>) request.argument;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002546 Phone phone = getPhoneFromRequest(request);
2547 if (phone != null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002548 boolean enable = argument.first.booleanValue();
2549 phone.setSatellitePower(onCompleted, enable);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002550 } else {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002551 loge("setSatelliteEnabled: No phone object");
2552 argument.second.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002553 notifyRequester(request);
2554 }
2555 break;
2556 }
2557
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002558 case EVENT_SET_SATELLITE_ENABLED_DONE: {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002559 ar = (AsyncResult) msg.obj;
2560 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002561 Pair<Boolean, Consumer<Integer>> argument =
2562 (Pair<Boolean, Consumer<Integer>>) request.argument;
2563 int error = getSatelliteError(ar, "setSatelliteEnabled", false);
2564 argument.second.accept(error);
Thomas Nguyen8ee49682023-02-01 11:46:09 -08002565 break;
2566 }
2567
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002568 case CMD_IS_SATELLITE_ENABLED: {
Sarah Chin503828c2023-02-01 23:54:20 -08002569 request = (MainThreadRequest) msg.obj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002570 onCompleted = obtainMessage(EVENT_IS_SATELLITE_ENABLED_DONE, request);
Sarah Chin503828c2023-02-01 23:54:20 -08002571 Phone phone = getPhoneFromRequest(request);
2572 if (phone != null) {
2573 phone.isSatellitePowerOn(onCompleted);
2574 } else {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002575 loge("isSatelliteEnabled: No phone object");
2576 ((ResultReceiver) request.argument).send(
2577 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002578 }
2579 break;
2580 }
2581
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002582 case EVENT_IS_SATELLITE_ENABLED_DONE: {
Sarah Chin503828c2023-02-01 23:54:20 -08002583 ar = (AsyncResult) msg.obj;
2584 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002585 int error = getSatelliteError(ar, "isSatelliteEnabled", true);
2586 Bundle bundle = new Bundle();
2587 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
2588 boolean enabled = ((int[]) ar.result)[0] == 1;
2589 if (DBG) log("isSatelliteEnabled: " + enabled);
2590 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_ENABLED, enabled);
Sarah Chin503828c2023-02-01 23:54:20 -08002591 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002592 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002593 break;
2594 }
2595
2596 case CMD_IS_SATELLITE_SUPPORTED: {
2597 request = (MainThreadRequest) msg.obj;
2598 onCompleted = obtainMessage(EVENT_IS_SATELLITE_SUPPORTED_DONE, request);
2599 Phone phone = getPhoneFromRequest(request);
2600 if (phone != null) {
2601 phone.isSatelliteSupported(onCompleted);
2602 } else {
2603 loge("isSatelliteSupported: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002604 ((ResultReceiver) request.argument).send(
2605 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002606 }
2607 break;
2608 }
2609
2610 case EVENT_IS_SATELLITE_SUPPORTED_DONE: {
2611 ar = (AsyncResult) msg.obj;
2612 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002613 int error = getSatelliteError(ar, "isSatelliteSupported", true);
2614 Bundle bundle = new Bundle();
2615 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
2616 boolean supported = ((int[]) ar.result)[0] == 1;
2617 if (DBG) log("isSatelliteSupported: " + supported);
2618 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, supported);
Thomas Nguyene77de6d2023-02-10 17:42:43 -08002619 synchronized (mIsSatelliteSupportedLock) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002620 mIsSatelliteSupported = supported;
2621 }
2622 } else {
2623 synchronized (mIsSatelliteSupportedLock) {
2624 mIsSatelliteSupported = null;
Thomas Nguyene77de6d2023-02-10 17:42:43 -08002625 }
Sarah Chin503828c2023-02-01 23:54:20 -08002626 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002627 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002628 break;
2629 }
2630
2631 case CMD_GET_SATELLITE_CAPABILITIES: {
2632 request = (MainThreadRequest) msg.obj;
2633 onCompleted = obtainMessage(EVENT_GET_SATELLITE_CAPABILITIES_DONE, request);
2634 Phone phone = getPhoneFromRequest(request);
2635 if (phone != null) {
2636 phone.getSatelliteCapabilities(onCompleted);
2637 } else {
2638 loge("getSatelliteCapabilities: No phone object");
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002639 ((ResultReceiver) request.argument).send(
2640 SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
Sarah Chin503828c2023-02-01 23:54:20 -08002641 }
2642 break;
2643 }
2644
2645 case EVENT_GET_SATELLITE_CAPABILITIES_DONE: {
2646 ar = (AsyncResult) msg.obj;
2647 request = (MainThreadRequest) ar.userObj;
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002648 int error = getSatelliteError(ar, "getSatelliteCapabilities", true);
2649 Bundle bundle = new Bundle();
2650 if (error == SatelliteManager.SATELLITE_ERROR_NONE) {
Sarah Chin503828c2023-02-01 23:54:20 -08002651 SatelliteCapabilities capabilities = (SatelliteCapabilities) ar.result;
2652 if (DBG) log("getSatelliteCapabilities: " + capabilities);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002653 bundle.putParcelable(SatelliteManager.KEY_SATELLITE_CAPABILITIES,
2654 capabilities);
Sarah Chin503828c2023-02-01 23:54:20 -08002655 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002656 ((ResultReceiver) request.argument).send(error, bundle);
Sarah Chin503828c2023-02-01 23:54:20 -08002657 break;
2658 }
2659
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002660 default:
2661 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2662 break;
2663 }
2664 }
Jake Hambye994d462014-02-03 13:10:13 -08002665
Pengquan Menga1bb6272018-09-06 09:59:22 -07002666 private void notifyRequester(MainThreadRequest request) {
2667 synchronized (request) {
2668 request.notifyAll();
2669 }
2670 }
2671
Jake Hambye994d462014-02-03 13:10:13 -08002672 private void handleNullReturnEvent(Message msg, String command) {
2673 AsyncResult ar = (AsyncResult) msg.obj;
2674 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2675 if (ar.exception == null) {
2676 request.result = true;
2677 } else {
2678 request.result = false;
2679 if (ar.exception instanceof CommandException) {
2680 loge(command + ": CommandException: " + ar.exception);
2681 } else {
2682 loge(command + ": Unknown exception");
2683 }
2684 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002685 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002686 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002687 }
2688
2689 /**
2690 * Posts the specified command to be executed on the main thread,
2691 * waits for the request to complete, and returns the result.
2692 * @see #sendRequestAsync
2693 */
2694 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002695 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2696 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002697 }
2698
2699 /**
2700 * Posts the specified command to be executed on the main thread,
2701 * waits for the request to complete, and returns the result.
2702 * @see #sendRequestAsync
2703 */
2704 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2705 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002706 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002707 }
2708
2709 /**
2710 * Posts the specified command to be executed on the main thread,
2711 * waits for the request to complete, and returns the result.
2712 * @see #sendRequestAsync
2713 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002714 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002715 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2716 }
2717
2718 /**
2719 * Posts the specified command to be executed on the main thread,
2720 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2721 * if not timeout or null otherwise.
2722 * @see #sendRequestAsync
2723 */
2724 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2725 long timeoutInMs) {
2726 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002727 }
2728
2729 /**
2730 * Posts the specified command to be executed on the main thread,
2731 * waits for the request to complete, and returns the result.
2732 * @see #sendRequestAsync
2733 */
Nathan Harold92bed182018-10-12 18:16:49 -07002734 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002735 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002736 }
2737
2738 /**
2739 * Posts the specified command to be executed on the main thread,
2740 * waits for the request to complete, and returns the result.
2741 * @see #sendRequestAsync
2742 */
2743 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002744 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2745 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002746 }
2747
2748 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002749 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2750 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2751 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002752 * @see #sendRequestAsync
2753 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002754 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2755 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002756 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2757 throw new RuntimeException("This method will deadlock if called from the main thread.");
2758 }
2759
Nathan Harold92bed182018-10-12 18:16:49 -07002760 MainThreadRequest request = null;
2761 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2762 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2763 } else if (phone != null) {
2764 request = new MainThreadRequest(argument, phone, workSource);
2765 } else {
2766 request = new MainThreadRequest(argument, subId, workSource);
2767 }
2768
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002769 Message msg = mMainThreadHandler.obtainMessage(command, request);
2770 msg.sendToTarget();
2771
Rambo Wang0f050d82021-02-12 11:43:36 -08002772
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002773 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002774 if (timeoutInMs >= 0) {
2775 // Wait for at least timeoutInMs before returning null request result
2776 long now = SystemClock.elapsedRealtime();
2777 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002778 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002779 try {
2780 request.wait(deadline - now);
2781 } catch (InterruptedException e) {
2782 // Do nothing, go back and check if request is completed or timeout
2783 } finally {
2784 now = SystemClock.elapsedRealtime();
2785 }
2786 }
2787 } else {
2788 // Wait for the request to complete
2789 while (request.result == null) {
2790 try {
2791 request.wait();
2792 } catch (InterruptedException e) {
2793 // Do nothing, go back and wait until the request is complete
2794 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002795 }
2796 }
2797 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002798 if (request.result == null) {
2799 Log.wtf(LOG_TAG,
2800 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2801 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002802 return request.result;
2803 }
2804
2805 /**
2806 * Asynchronous ("fire and forget") version of sendRequest():
2807 * Posts the specified command to be executed on the main thread, and
2808 * returns immediately.
2809 * @see #sendRequest
2810 */
2811 private void sendRequestAsync(int command) {
2812 mMainThreadHandler.sendEmptyMessage(command);
2813 }
2814
2815 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002816 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002817 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002818 */
2819 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002820 sendRequestAsync(command, argument, null, null);
2821 }
2822
2823 /**
2824 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2825 * @see {@link #sendRequest(int,Object)}
2826 */
2827 private void sendRequestAsync(
2828 int command, Object argument, Phone phone, WorkSource workSource) {
2829 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002830 Message msg = mMainThreadHandler.obtainMessage(command, request);
2831 msg.sendToTarget();
2832 }
2833
2834 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002835 * Initialize the singleton PhoneInterfaceManager instance.
2836 * This is only done once, at startup, from PhoneApp.onCreate().
2837 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002838 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002839 synchronized (PhoneInterfaceManager.class) {
2840 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002841 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002842 } else {
2843 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2844 }
2845 return sInstance;
2846 }
2847 }
2848
2849 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002850 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002851 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002852 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002853 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002854 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002855 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002856 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002857 mMainThreadHandler = new MainThreadHandler();
Jack Yue37dd262022-12-16 11:53:37 -08002858 if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) {
2859 mSubscriptionController = SubscriptionController.getInstance();
2860 } else {
2861 mSubscriptionController = null;
2862 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002863 mTelephonySharedPreferences =
2864 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002865 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002866 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002867 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002868 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002869 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002870 publish();
arunvoddud7401012022-12-15 16:08:12 +00002871 CarrierAllowListInfo.loadInstance(mApp);
Sarah Chin4a9e8b82023-02-10 21:10:57 -08002872 mSatelliteSupportedReceiver = new ResultReceiver(mMainThreadHandler) {
2873 @Override
2874 protected void onReceiveResult(int resultCode, Bundle resultData) {
2875 if (resultCode == SatelliteManager.SATELLITE_ERROR_NONE
2876 && resultData.containsKey(SatelliteManager.KEY_SATELLITE_SUPPORTED)) {
2877 synchronized (mIsSatelliteSupportedLock) {
2878 mIsSatelliteSupported = resultData.getBoolean(
2879 SatelliteManager.KEY_SATELLITE_SUPPORTED);
2880 }
2881 } else {
2882 synchronized (mIsSatelliteSupportedLock) {
2883 mIsSatelliteSupported = null;
2884 }
2885 }
2886 }
2887 };
2888 requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
2889 mSatelliteSupportedReceiver);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002890 }
2891
Gil Cukierman1c0eb932022-12-06 22:28:24 +00002892 @VisibleForTesting
2893 public SharedPreferences getSharedPreferences() {
2894 return mTelephonySharedPreferences;
2895 }
2896
Gil Cukierman92cc7db2023-01-06 19:25:53 +00002897 /**
2898 * Get the default phone for this device.
2899 */
2900 @VisibleForTesting
2901 public Phone getDefaultPhone() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002902 Phone thePhone = getPhone(getDefaultSubscription());
2903 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2904 }
2905
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002906 private void publish() {
2907 if (DBG) log("publish: " + this);
2908
Peter Wangc035ce42020-01-08 21:00:22 -08002909 TelephonyFrameworkInitializer
2910 .getTelephonyServiceManager()
2911 .getTelephonyServiceRegisterer()
2912 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002913 }
2914
Stuart Scott584921c2015-01-15 17:10:34 -08002915 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002916 if (request.phone != null) {
2917 return request.phone;
2918 } else {
2919 return getPhoneFromSubId(request.subId);
2920 }
2921 }
2922
2923 private Phone getPhoneFromSubId(int subId) {
2924 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2925 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002926 }
2927
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +00002928 /**
2929 * Get phone object associated with a subscription.
2930 * Return default phone if phone object associated with subscription is null
2931 * @param subId - subscriptionId
2932 * @return phone object associated with a subscription or default phone if null.
2933 */
2934 private Phone getPhoneFromSubIdOrDefault(int subId) {
2935 Phone phone = getPhoneFromSubId(subId);
2936 if (phone == null) {
2937 phone = getDefaultPhone();
2938 }
2939 return phone;
2940 }
2941
Rambo Wange53e07d2022-05-10 13:01:13 -07002942 @Nullable
2943 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002944 Phone phone = getPhoneFromRequest(request);
2945 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002946 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002947 }
2948
Wink Saville36469e72014-06-11 15:17:00 -07002949 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002950 private Phone getPhone(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08002951 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002953
Kai Shif70f46f2021-03-03 13:59:46 -08002954 private void sendEraseModemConfig(@NonNull Phone phone) {
2955 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2956 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2957 }
2958
2959 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2960 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2961 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002962 }
2963
Peter Wang44b186e2020-01-13 23:33:09 -08002964 private boolean isImsAvailableOnDevice() {
2965 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2966 if (pm == null) {
2967 // For some reason package manger is not available.. This will fail internally anyway,
2968 // so do not throw error and allow.
2969 return true;
2970 }
2971 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2972 }
2973
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002974 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002975 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002976 }
2977
Wink Savilleb564aae2014-10-23 10:18:09 -07002978 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002979 if (DBG) log("dial: " + number);
2980 // No permission check needed here: This is just a wrapper around the
2981 // ACTION_DIAL intent, which is available to any app since it puts up
2982 // the UI before it does anything.
2983
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002984 final long identity = Binder.clearCallingIdentity();
2985 try {
2986 String url = createTelUrl(number);
2987 if (url == null) {
2988 return;
2989 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002990
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002991 // PENDING: should we just silently fail if phone is offhook or ringing?
2992 PhoneConstants.State state = mCM.getState(subId);
2993 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2994 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2995 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2996 mApp.startActivity(intent);
2997 }
2998 } finally {
2999 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003000 }
3001 }
3002
3003 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003004 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07003005 }
3006
Wink Savilleb564aae2014-10-23 10:18:09 -07003007 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003008 if (DBG) log("call: " + number);
3009
3010 // This is just a wrapper around the ACTION_CALL intent, but we still
3011 // need to do a permission check since we're calling startActivity()
3012 // from the context of the phone app.
3013 enforceCallPermission();
3014
Jordan Liu1617b712019-07-10 15:06:26 -07003015 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003016 != AppOpsManager.MODE_ALLOWED) {
3017 return;
3018 }
3019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003020 final long identity = Binder.clearCallingIdentity();
3021 try {
3022 String url = createTelUrl(number);
3023 if (url == null) {
3024 return;
3025 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003027 boolean isValid = false;
3028 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
3029 if (slist != null) {
3030 for (SubscriptionInfo subInfoRecord : slist) {
3031 if (subInfoRecord.getSubscriptionId() == subId) {
3032 isValid = true;
3033 break;
3034 }
Wink Saville3ab207e2014-11-20 13:07:20 -08003035 }
Wink Saville08874612014-08-31 19:19:58 -07003036 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003037 if (!isValid) {
3038 return;
3039 }
Wink Saville08874612014-08-31 19:19:58 -07003040
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003041 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
3042 intent.putExtra(SUBSCRIPTION_KEY, subId);
3043 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3044 mApp.startActivity(intent);
3045 } finally {
3046 Binder.restoreCallingIdentity(identity);
3047 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003048 }
3049
Wink Savilleb564aae2014-10-23 10:18:09 -07003050 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003051 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07003052 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
3053 }
3054
Wink Savilleb564aae2014-10-23 10:18:09 -07003055 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003056 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07003057 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
3058 }
3059
Wink Savilleb564aae2014-10-23 10:18:09 -07003060 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003061 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003062
3063 final long identity = Binder.clearCallingIdentity();
3064 try {
Michele Berionne5e411512020-11-13 02:36:59 +00003065 Phone phone = getPhone(subId);
3066 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003067 checkSimPin.start();
3068 return checkSimPin.unlockSim(null, pin);
3069 } finally {
3070 Binder.restoreCallingIdentity(identity);
3071 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003072 }
3073
Wink Savilleb564aae2014-10-23 10:18:09 -07003074 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003075 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003076
3077 final long identity = Binder.clearCallingIdentity();
3078 try {
Michele Berionne5e411512020-11-13 02:36:59 +00003079 Phone phone = getPhone(subId);
3080 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003081 checkSimPuk.start();
3082 return checkSimPuk.unlockSim(puk, pin);
3083 } finally {
3084 Binder.restoreCallingIdentity(identity);
3085 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003086 }
3087
3088 /**
Wink Saville9de0f752013-10-22 19:04:03 -07003089 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003090 * a synchronous one.
3091 */
3092 private static class UnlockSim extends Thread {
3093
3094 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00003095 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003096
3097 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07003098 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
3099 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003100
3101 // For replies from SimCard interface
3102 private Handler mHandler;
3103
3104 // For async handler to identify request type
3105 private static final int SUPPLY_PIN_COMPLETE = 100;
3106
Michele Berionne5e411512020-11-13 02:36:59 +00003107 UnlockSim(int phoneId, IccCard simCard) {
3108 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003109 mSimCard = simCard;
3110 }
3111
3112 @Override
3113 public void run() {
3114 Looper.prepare();
3115 synchronized (UnlockSim.this) {
3116 mHandler = new Handler() {
3117 @Override
3118 public void handleMessage(Message msg) {
3119 AsyncResult ar = (AsyncResult) msg.obj;
3120 switch (msg.what) {
3121 case SUPPLY_PIN_COMPLETE:
3122 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
3123 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07003124 mRetryCount = msg.arg1;
3125 if (ar.exception != null) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -08003126 CommandException.Error error = null;
3127 if (ar.exception instanceof CommandException) {
3128 error = ((CommandException) (ar.exception))
3129 .getCommandError();
3130 }
3131 if (error == CommandException.Error.PASSWORD_INCORRECT) {
Wink Saville9de0f752013-10-22 19:04:03 -07003132 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
Thomas Nguyen8ee49682023-02-01 11:46:09 -08003133 } else if (error == CommandException.Error.ABORTED) {
3134 /* When UiccCardApp dispose, handle message and return
3135 exception */
vivi.lib5e9ada2019-09-12 16:04:24 +08003136 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07003137 } else {
3138 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
3139 }
3140 } else {
3141 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
3142 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003143 mDone = true;
3144 UnlockSim.this.notifyAll();
3145 }
3146 break;
3147 }
3148 }
3149 };
3150 UnlockSim.this.notifyAll();
3151 }
3152 Looper.loop();
3153 }
3154
3155 /*
3156 * Use PIN or PUK to unlock SIM card
3157 *
3158 * If PUK is null, unlock SIM card with PIN
3159 *
3160 * If PUK is not null, unlock SIM card with PUK and set PIN code
3161 */
Wink Saville9de0f752013-10-22 19:04:03 -07003162 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003163
3164 while (mHandler == null) {
3165 try {
3166 wait();
3167 } catch (InterruptedException e) {
3168 Thread.currentThread().interrupt();
3169 }
3170 }
3171 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
3172
3173 if (puk == null) {
3174 mSimCard.supplyPin(pin, callback);
3175 } else {
3176 mSimCard.supplyPuk(puk, pin, callback);
3177 }
3178
3179 while (!mDone) {
3180 try {
3181 Log.d(LOG_TAG, "wait for done");
3182 wait();
3183 } catch (InterruptedException e) {
3184 // Restore the interrupted status
3185 Thread.currentThread().interrupt();
3186 }
3187 }
3188 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07003189 int[] resultArray = new int[2];
3190 resultArray[0] = mResult;
3191 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00003192
3193 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00003194 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00003195 }
3196
Wink Saville9de0f752013-10-22 19:04:03 -07003197 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003198 }
3199 }
3200
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003201 /**
3202 * This method has been removed due to privacy and stability concerns.
3203 */
3204 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003205 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003206 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
3207 return;
Wink Saville36469e72014-06-11 15:17:00 -07003208 }
3209
Nathan Harold1f889d82020-06-04 17:05:26 -07003210 @Override
3211 public void updateServiceLocationWithPackageName(String callingPackage) {
3212 mApp.getSystemService(AppOpsManager.class)
3213 .checkPackage(Binder.getCallingUid(), callingPackage);
3214
Nathan Haroldf096d982020-11-18 17:18:06 -08003215 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07003216 if (targetSdk > android.os.Build.VERSION_CODES.R) {
3217 // Callers targeting S have no business invoking this method.
3218 return;
3219 }
3220
3221 LocationAccessPolicy.LocationPermissionResult locationResult =
3222 LocationAccessPolicy.checkLocationPermission(mApp,
3223 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3224 .setCallingPackage(callingPackage)
3225 .setCallingFeatureId(null)
3226 .setCallingPid(Binder.getCallingPid())
3227 .setCallingUid(Binder.getCallingUid())
3228 .setMethod("updateServiceLocation")
3229 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3230 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3231 .build());
3232 // Apps that lack location permission have no business calling this method;
3233 // however, because no permission was declared in the public API, denials must
3234 // all be "soft".
3235 switch (locationResult) {
3236 case DENIED_HARD: /* fall through */
3237 case DENIED_SOFT:
3238 return;
3239 }
3240
3241 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003242 final long identity = Binder.clearCallingIdentity();
3243 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07003244 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003245 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07003246 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003247 }
3248 } finally {
3249 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003251 }
3252
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003253 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003254 @Override
3255 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003256 return isRadioOnWithFeature(callingPackage, null);
3257 }
3258
3259
3260 @Override
3261 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
3262 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
3263 callingFeatureId);
3264 }
3265
3266 @Deprecated
3267 @Override
3268 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
3269 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07003270 }
3271
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003272 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003273 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
3274 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003275 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003276 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003277 return false;
3278 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003279
3280 final long identity = Binder.clearCallingIdentity();
3281 try {
3282 return isRadioOnForSubscriber(subId);
3283 } finally {
3284 Binder.restoreCallingIdentity(identity);
3285 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003286 }
3287
3288 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003289 final long identity = Binder.clearCallingIdentity();
3290 try {
3291 final Phone phone = getPhone(subId);
3292 if (phone != null) {
3293 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
3294 } else {
3295 return false;
3296 }
3297 } finally {
3298 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003300 }
3301
3302 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003303 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003304 }
Wink Saville36469e72014-06-11 15:17:00 -07003305
Wink Savilleb564aae2014-10-23 10:18:09 -07003306 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003307 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003308
3309 final long identity = Binder.clearCallingIdentity();
3310 try {
3311 final Phone phone = getPhone(subId);
3312 if (phone != null) {
3313 phone.setRadioPower(!isRadioOnForSubscriber(subId));
3314 }
3315 } finally {
3316 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003317 }
Wink Saville36469e72014-06-11 15:17:00 -07003318 }
3319
3320 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003321 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07003322 }
3323
Wink Savilleb564aae2014-10-23 10:18:09 -07003324 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07003325 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003326
3327 final long identity = Binder.clearCallingIdentity();
3328 try {
3329 final Phone phone = getPhone(subId);
3330 if (phone == null) {
3331 return false;
3332 }
3333 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
3334 toggleRadioOnOffForSubscriber(subId);
3335 }
3336 return true;
3337 } finally {
3338 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003339 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003340 }
Wink Saville36469e72014-06-11 15:17:00 -07003341
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003342 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08003343 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003344 /*
3345 * If any of the Radios are available, it will need to be
3346 * shutdown. So return true if any Radio is available.
3347 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003348 final long identity = Binder.clearCallingIdentity();
3349 try {
3350 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3351 Phone phone = PhoneFactory.getPhone(i);
3352 if (phone != null && phone.isRadioAvailable()) return true;
3353 }
3354 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
3355 return false;
3356 } finally {
3357 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003358 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003359 }
3360
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003361 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003362 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003363 enforceModifyPermission();
3364
3365 final long identity = Binder.clearCallingIdentity();
3366 try {
3367 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3368 logv("Shutting down Phone " + i);
3369 shutdownRadioUsingPhoneId(i);
3370 }
3371 } finally {
3372 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003373 }
3374 }
3375
3376 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003377 Phone phone = PhoneFactory.getPhone(phoneId);
3378 if (phone != null && phone.isRadioAvailable()) {
3379 phone.shutdownRadio();
3380 }
3381 }
3382
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003383 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07003384 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003385
Ling Ma83dc5ea2023-01-12 15:06:04 -08003386 if (!turnOn) {
3387 log("setRadioPower off: callingPackage=" + getCurrentPackageName());
3388 }
3389
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003390 final long identity = Binder.clearCallingIdentity();
3391 try {
3392 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
3393 if (defaultPhone != null) {
3394 defaultPhone.setRadioPower(turnOn);
3395 return true;
3396 } else {
3397 loge("There's no default phone.");
3398 return false;
3399 }
3400 } finally {
3401 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07003402 }
Wink Saville36469e72014-06-11 15:17:00 -07003403 }
3404
Wink Savilleb564aae2014-10-23 10:18:09 -07003405 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003406 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003407
Ling Ma83dc5ea2023-01-12 15:06:04 -08003408 if (!turnOn) {
3409 log("setRadioPowerForSubscriber off: subId=" + subId
3410 + ",callingPackage=" + getCurrentPackageName());
3411 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003412 final long identity = Binder.clearCallingIdentity();
3413 try {
3414 final Phone phone = getPhone(subId);
3415 if (phone != null) {
3416 phone.setRadioPower(turnOn);
3417 return true;
3418 } else {
3419 return false;
3420 }
3421 } finally {
3422 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003423 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003424 }
3425
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003426 /**
3427 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
3428 * no reason to power it off. When any of the voters want to power it off, it will be turned
3429 * off. In case of emergency, the radio will be turned on even if there are some reasons for
3430 * powering it off, and these radio off votes will be cleared.
3431 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
3432 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
3433 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
3434 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
3435 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
3436 * check its vote.
3437 *
3438 * @param subId The subscription ID.
3439 * @param reason The reason for powering off radio.
3440 * @return true on success and false on failure.
3441 */
3442 public boolean requestRadioPowerOffForReason(int subId,
3443 @TelephonyManager.RadioPowerReason int reason) {
3444 enforceModifyPermission();
3445
Ling Ma83dc5ea2023-01-12 15:06:04 -08003446 log("requestRadioPowerOffForReason: subId=" + subId
3447 + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName());
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00003448 final long identity = Binder.clearCallingIdentity();
3449 try {
3450 final Phone phone = getPhone(subId);
3451 if (phone != null) {
3452 phone.setRadioPowerForReason(false, reason);
3453 return true;
3454 } else {
3455 return false;
3456 }
3457 } finally {
3458 Binder.restoreCallingIdentity(identity);
3459 }
3460 }
3461
3462 /**
3463 * Remove the vote on powering off the radio for a reason, as requested by
3464 * {@link requestRadioPowerOffForReason}.
3465 *
3466 * @param subId The subscription ID.
3467 * @param reason The reason for powering off radio.
3468 * @return true on success and false on failure.
3469 */
3470 public boolean clearRadioPowerOffForReason(int subId,
3471 @TelephonyManager.RadioPowerReason int reason) {
3472 enforceModifyPermission();
3473
3474 final long identity = Binder.clearCallingIdentity();
3475 try {
3476 final Phone phone = getPhone(subId);
3477 if (phone != null) {
3478 phone.setRadioPowerForReason(true, reason);
3479 return true;
3480 } else {
3481 return false;
3482 }
3483 } finally {
3484 Binder.restoreCallingIdentity(identity);
3485 }
3486 }
3487
3488 /**
3489 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
3490 *
3491 * @param subId The subscription ID.
3492 * @param callingPackage The package making the call.
3493 * @param callingFeatureId The feature in the package.
3494 * @return List of reasons for powering off radio.
3495 */
3496 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
3497 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
3498
3499 final long identity = Binder.clearCallingIdentity();
3500 List result = new ArrayList();
3501 try {
3502 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
3503 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
3504 return result;
3505 }
3506
3507 final Phone phone = getPhone(subId);
3508 if (phone != null) {
3509 result.addAll(phone.getRadioPowerOffReasons());
3510 }
3511 } finally {
3512 Binder.restoreCallingIdentity(identity);
3513 }
3514 return result;
3515 }
3516
Wink Saville36469e72014-06-11 15:17:00 -07003517 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003518 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003519 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003520 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003521
3522 final long identity = Binder.clearCallingIdentity();
3523 try {
Jack Yu285100e2022-12-02 22:48:35 -08003524 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003525 final Phone phone = getPhone(subId);
3526 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003527 phone.getDataSettingsManager().setDataEnabled(
3528 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003529 return true;
3530 } else {
3531 return false;
3532 }
3533 } finally {
3534 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003535 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003536 }
3537
Wink Saville36469e72014-06-11 15:17:00 -07003538 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003539 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003540 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003541 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003542
3543 final long identity = Binder.clearCallingIdentity();
3544 try {
Jack Yu285100e2022-12-02 22:48:35 -08003545 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003546 final Phone phone = getPhone(subId);
3547 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003548 phone.getDataSettingsManager().setDataEnabled(
3549 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003550 return true;
3551 } else {
3552 return false;
3553 }
3554 } finally {
3555 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003556 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003557 }
3558
Sanket Padawe356d7632015-06-22 14:03:32 -07003559 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003560 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003561 final long identity = Binder.clearCallingIdentity();
3562 try {
3563 final Phone phone = getPhone(subId);
3564 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003565 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003566 } else {
3567 return false;
3568 }
3569 } finally {
3570 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003571 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003572 }
3573
3574 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003575 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003576 }
3577
pkanwarae03a6b2016-11-06 20:37:09 -08003578 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003579 enforceCallPermission();
3580
3581 final long identity = Binder.clearCallingIdentity();
3582 try {
3583 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3584 return;
3585 }
3586 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3587 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3588 } finally {
3589 Binder.restoreCallingIdentity(identity);
3590 }
pkanwar32d516d2016-10-14 19:37:38 -07003591 };
3592
Wink Savilleb564aae2014-10-23 10:18:09 -07003593 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003594 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003595
3596 final long identity = Binder.clearCallingIdentity();
3597 try {
3598 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3599 return false;
3600 }
3601 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3602 } finally {
3603 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003604 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003605 }
3606
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003607 /**
3608 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3609 * tag on getCallState Binder call.
3610 */
3611 @Deprecated
3612 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003613 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003614 if (CompatChanges.isChangeEnabled(
3615 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3616 Binder.getCallingUid())) {
3617 // Do not allow this API to be called on API version 31+, it should only be
3618 // called on old apps using this Binder call directly.
3619 throw new SecurityException("This method can only be used for applications "
3620 + "targeting API version 30 or less.");
3621 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003622 final long identity = Binder.clearCallingIdentity();
3623 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003624 Phone phone = getPhone(getDefaultSubscription());
3625 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3626 PhoneConstantConversions.convertCallState(phone.getState());
3627 } finally {
3628 Binder.restoreCallingIdentity(identity);
3629 }
3630 }
3631
3632 @Override
3633 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3634 if (CompatChanges.isChangeEnabled(
3635 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3636 Binder.getCallingUid())) {
3637 // Check READ_PHONE_STATE for API version 31+
3638 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3639 featureId, "getCallStateForSubscription")) {
3640 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3641 + "targeting API level 31+.");
3642 }
3643 }
3644 final long identity = Binder.clearCallingIdentity();
3645 try {
3646 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003647 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3648 PhoneConstantConversions.convertCallState(phone.getState());
3649 } finally {
3650 Binder.restoreCallingIdentity(identity);
3651 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003652 }
3653
Sanket Padawe356d7632015-06-22 14:03:32 -07003654 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003655 public int getDataState() {
Jack Yu285100e2022-12-02 22:48:35 -08003656 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003657 }
3658
3659 @Override
3660 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003661 final long identity = Binder.clearCallingIdentity();
3662 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003663 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003664 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003665 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003666 } else {
3667 return PhoneConstantConversions.convertDataState(
3668 PhoneConstants.DataState.DISCONNECTED);
3669 }
3670 } finally {
3671 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003672 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003673 }
3674
Sanket Padawe356d7632015-06-22 14:03:32 -07003675 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003676 public @DataActivityType int getDataActivity() {
Jack Yu285100e2022-12-02 22:48:35 -08003677 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003678 }
3679
3680 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003681 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003682 final long identity = Binder.clearCallingIdentity();
3683 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003684 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003685 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003686 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003687 } else {
3688 return TelephonyManager.DATA_ACTIVITY_NONE;
3689 }
3690 } finally {
3691 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003692 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003693 }
3694
3695 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003696 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003697 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003698 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003699
3700 LocationAccessPolicy.LocationPermissionResult locationResult =
3701 LocationAccessPolicy.checkLocationPermission(mApp,
3702 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3703 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003704 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003705 .setCallingPid(Binder.getCallingPid())
3706 .setCallingUid(Binder.getCallingUid())
3707 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003708 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003709 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3710 .build());
3711 switch (locationResult) {
3712 case DENIED_HARD:
3713 throw new SecurityException("Not allowed to access cell location");
3714 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003715 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3716 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003717 }
3718
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003719 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003720 final long identity = Binder.clearCallingIdentity();
3721 try {
3722 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yu285100e2022-12-02 22:48:35 -08003723 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003724 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003725 } finally {
3726 Binder.restoreCallingIdentity(identity);
3727 }
Svetoslav64fad262015-04-14 14:35:21 -07003728 }
3729
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003730 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003731 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003732 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3733 // registered cell info, so return a NULL country instead.
3734 final long identity = Binder.clearCallingIdentity();
3735 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003736 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3737 // Get default phone in this case.
3738 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3739 }
Jack Yu285100e2022-12-02 22:48:35 -08003740 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003741 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003742 if (phone == null) return "";
3743 ServiceStateTracker sst = phone.getServiceStateTracker();
3744 if (sst == null) return "";
3745 LocaleTracker lt = sst.getLocaleTracker();
3746 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003747 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003748 } finally {
3749 Binder.restoreCallingIdentity(identity);
3750 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003751 }
3752
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003753 /**
3754 * This method was removed due to potential issues caused by performing partial
3755 * updates of service state, and lack of a credible use case.
3756 *
3757 * This has the ability to break the telephony implementation by disabling notification of
3758 * changes in device connectivity. DO NOT USE THIS!
3759 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003760 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003761 public void enableLocationUpdates() {
3762 mApp.enforceCallingOrSelfPermission(
3763 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003764 }
3765
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003766 /**
3767 * This method was removed due to potential issues caused by performing partial
3768 * updates of service state, and lack of a credible use case.
3769 *
3770 * This has the ability to break the telephony implementation by disabling notification of
3771 * changes in device connectivity. DO NOT USE THIS!
3772 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003773 @Override
3774 public void disableLocationUpdates() {
3775 mApp.enforceCallingOrSelfPermission(
3776 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003777 }
3778
3779 @Override
3780 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003781 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3782 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003783 try {
3784 mApp.getSystemService(AppOpsManager.class)
3785 .checkPackage(Binder.getCallingUid(), callingPackage);
3786 } catch (SecurityException e) {
3787 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3788 throw e;
3789 }
3790
Nathan Haroldf096d982020-11-18 17:18:06 -08003791 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003792 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3793 throw new SecurityException(
3794 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3795 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003796
Jordan Liu1617b712019-07-10 15:06:26 -07003797 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003798 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3799 return null;
3800 }
Svetoslav64fad262015-04-14 14:35:21 -07003801
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003802 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003803
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003804 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003805 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003806
Nathan Haroldf180aac2018-06-01 18:43:55 -07003807 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3808 for (CellInfo ci : info) {
3809 if (ci instanceof CellInfoGsm) {
3810 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3811 } else if (ci instanceof CellInfoWcdma) {
3812 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3813 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003814 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003815 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003816 }
3817
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003818 private List<CellInfo> getCachedCellInfo() {
3819 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3820 for (Phone phone : PhoneFactory.getPhones()) {
3821 List<CellInfo> info = phone.getAllCellInfo();
3822 if (info != null) cellInfos.addAll(info);
3823 }
3824 return cellInfos;
3825 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003826
3827 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003828 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003829 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003830 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003831
3832 LocationAccessPolicy.LocationPermissionResult locationResult =
3833 LocationAccessPolicy.checkLocationPermission(mApp,
3834 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3835 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003836 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003837 .setCallingPid(Binder.getCallingPid())
3838 .setCallingUid(Binder.getCallingUid())
3839 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003840 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003841 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3842 .build());
3843 switch (locationResult) {
3844 case DENIED_HARD:
3845 throw new SecurityException("Not allowed to access cell info");
3846 case DENIED_SOFT:
3847 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003848 }
3849
Nathan Haroldf096d982020-11-18 17:18:06 -08003850 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003851 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3852 return getCachedCellInfo();
3853 }
3854
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003855 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003856 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003857 final long identity = Binder.clearCallingIdentity();
3858 try {
3859 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3860 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003861 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003862 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003863 if (info != null) cellInfos.addAll(info);
3864 }
3865 return cellInfos;
3866 } finally {
3867 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003868 }
3869 }
3870
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003871 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003872 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3873 String callingFeatureId) {
3874 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3875 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003876 }
3877
3878 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003879 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3880 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003881 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003882 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003883 }
3884
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003885 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3886 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003887 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003888 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003889
3890 LocationAccessPolicy.LocationPermissionResult locationResult =
3891 LocationAccessPolicy.checkLocationPermission(mApp,
3892 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3893 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003894 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003895 .setCallingPid(Binder.getCallingPid())
3896 .setCallingUid(Binder.getCallingUid())
3897 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003898 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3899 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003900 .build());
3901 switch (locationResult) {
3902 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003903 if (TelephonyPermissions
3904 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003905 // Safetynet logging for b/154934934
3906 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3907 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003908 throw new SecurityException("Not allowed to access cell info");
3909 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003910 if (TelephonyPermissions
3911 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003912 // Safetynet logging for b/154934934
3913 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3914 }
Nathan Harold5320c422019-05-09 10:26:08 -07003915 try {
3916 cb.onCellInfo(new ArrayList<CellInfo>());
3917 } catch (RemoteException re) {
3918 // Drop without consequences
3919 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003920 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003921 }
3922
Nathan Harolda939a962019-05-09 10:13:47 -07003923
3924 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003925 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3926
3927 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3928 }
3929
3930 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003931 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003932 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003933 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003934
3935 final long identity = Binder.clearCallingIdentity();
3936 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003937 Phone phone = getPhone(subId);
3938 if (phone == null) {
3939 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3940 } else {
3941 phone.setCellInfoListRate(rateInMillis, workSource);
3942 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003943 } finally {
3944 Binder.restoreCallingIdentity(identity);
3945 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003946 }
3947
Shishir Agrawala9f32182016-04-12 12:00:16 -07003948 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003949 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003950 Phone phone = PhoneFactory.getPhone(slotIndex);
3951 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003952 return null;
3953 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003954 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003955 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003956 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003957 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003958 return null;
3959 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003960
3961 final long identity = Binder.clearCallingIdentity();
3962 try {
3963 return phone.getImei();
3964 } finally {
3965 Binder.restoreCallingIdentity(identity);
3966 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003967 }
3968
3969 @Override
arunvoddud5c6ce02022-12-11 06:03:12 +00003970 public String getPrimaryImei(String callingPackage, String callingFeatureId) {
3971 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei");
3972 if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage,
3973 callingFeatureId, "getPrimaryImei")) {
3974 throw new SecurityException("Caller does not have permission");
3975 }
3976 final long identity = Binder.clearCallingIdentity();
3977 try {
3978 for (Phone phone : PhoneFactory.getPhones()) {
3979 if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) {
3980 return phone.getImei();
3981 }
3982 }
3983 throw new UnsupportedOperationException("Operation not supported");
3984 } finally {
3985 Binder.restoreCallingIdentity(identity);
3986 }
3987 }
3988
3989 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003990 public String getTypeAllocationCodeForSlot(int slotIndex) {
3991 Phone phone = PhoneFactory.getPhone(slotIndex);
3992 String tac = null;
3993 if (phone != null) {
3994 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003995 try {
3996 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3997 } catch (IndexOutOfBoundsException e) {
3998 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3999 return null;
4000 }
David Kelly5e06a7f2018-03-12 14:10:59 +00004001 }
4002 return tac;
4003 }
4004
4005 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004006 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004007 try {
4008 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4009 } catch (SecurityException se) {
4010 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
4011 throw new SecurityException("Package " + callingPackage + " does not belong to "
4012 + Binder.getCallingUid());
4013 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004014 Phone phone = PhoneFactory.getPhone(slotIndex);
4015 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07004016 return null;
4017 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004018
Jeff Davidson913390f2018-02-23 17:11:49 -08004019 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07004020 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004021 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004022 return null;
4023 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004024
4025 final long identity = Binder.clearCallingIdentity();
4026 try {
4027 return phone.getMeid();
4028 } finally {
4029 Binder.restoreCallingIdentity(identity);
4030 }
Jack Yu2af8d712017-03-15 17:14:14 -07004031 }
4032
4033 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00004034 public String getManufacturerCodeForSlot(int slotIndex) {
4035 Phone phone = PhoneFactory.getPhone(slotIndex);
4036 String manufacturerCode = null;
4037 if (phone != null) {
4038 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07004039 try {
4040 manufacturerCode =
4041 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
4042 } catch (IndexOutOfBoundsException e) {
4043 Log.e(LOG_TAG, "MEID length shorter than upper index.");
4044 return null;
4045 }
David Kelly5e06a7f2018-03-12 14:10:59 +00004046 }
4047 return manufacturerCode;
4048 }
4049
4050 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004051 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
4052 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004053 Phone phone = PhoneFactory.getPhone(slotIndex);
4054 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004055 return null;
4056 }
Jeff Davidson913390f2018-02-23 17:11:49 -08004057 int subId = phone.getSubId();
4058 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004059 mApp, subId, callingPackage, callingFeatureId,
4060 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004061 return null;
4062 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004063
4064 final long identity = Binder.clearCallingIdentity();
4065 try {
4066 return phone.getDeviceSvn();
4067 } finally {
4068 Binder.restoreCallingIdentity(identity);
4069 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07004070 }
4071
fionaxu43304da2017-11-27 22:51:16 -08004072 @Override
4073 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004074 final long identity = Binder.clearCallingIdentity();
4075 try {
4076 final Phone phone = getPhone(subId);
4077 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
4078 } finally {
4079 Binder.restoreCallingIdentity(identity);
4080 }
fionaxu43304da2017-11-27 22:51:16 -08004081 }
4082
4083 @Override
4084 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004085 final long identity = Binder.clearCallingIdentity();
4086 try {
4087 final Phone phone = getPhone(subId);
4088 return phone == null ? null : phone.getCarrierName();
4089 } finally {
4090 Binder.restoreCallingIdentity(identity);
4091 }
fionaxu43304da2017-11-27 22:51:16 -08004092 }
4093
calvinpanffe225e2018-11-01 19:43:06 +08004094 @Override
chen xu0026ca62019-03-06 15:28:50 -08004095 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08004096 final long identity = Binder.clearCallingIdentity();
4097 try {
4098 final Phone phone = getPhone(subId);
4099 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08004100 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08004101 } finally {
4102 Binder.restoreCallingIdentity(identity);
4103 }
4104 }
4105
4106 @Override
chen xu0026ca62019-03-06 15:28:50 -08004107 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08004108 final long identity = Binder.clearCallingIdentity();
4109 try {
4110 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08004111 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08004112 } finally {
4113 Binder.restoreCallingIdentity(identity);
4114 }
4115 }
4116
chen xu651eec72018-11-11 19:03:44 -08004117 @Override
chen xu864e11c2018-12-06 22:10:03 -08004118 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
4119 if (!isSubscriptionMccMnc) {
4120 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
4121 }
chen xu651eec72018-11-11 19:03:44 -08004122 final Phone phone = PhoneFactory.getPhone(slotIndex);
4123 if (phone == null) {
4124 return TelephonyManager.UNKNOWN_CARRIER_ID;
4125 }
4126 final long identity = Binder.clearCallingIdentity();
4127 try {
4128 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
4129 } finally {
4130 Binder.restoreCallingIdentity(identity);
4131 }
4132 }
4133
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004134 //
4135 // Internal helper methods.
4136 //
4137
Sanket Padaweee13a9b2016-03-08 17:30:28 -08004138 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07004139 * Make sure the caller is the calling package itself
4140 *
4141 * @throws SecurityException if the caller is not the calling package
4142 */
4143 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
4144 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07004145 PackageManager pm = mApp.getBaseContext().createContextAsUser(
4146 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07004147 try {
Grace Jiadbefca02021-04-26 15:13:31 -07004148 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07004149 } catch (PackageManager.NameNotFoundException e) {
4150 // packageUid is -1
4151 }
4152 if (packageUid != callingUid) {
4153 throw new SecurityException(message + ": Package " + callingPackage
4154 + " does not belong to " + callingUid);
4155 }
4156 }
4157
4158 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004159 * Make sure the caller has the MODIFY_PHONE_STATE permission.
4160 *
4161 * @throws SecurityException if the caller does not have the required permission
4162 */
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004163 @VisibleForTesting
4164 public void enforceModifyPermission() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004165 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
4166 }
4167
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004168 /**
arunvoddud7401012022-12-15 16:08:12 +00004169 * Make sure the caller has the READ_PHONE_STATE permission.
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004170 *
4171 * @throws SecurityException if the caller does not have the required permission
4172 */
4173 @VisibleForTesting
4174 public void enforceReadPermission() {
arunvoddud7401012022-12-15 16:08:12 +00004175 enforceReadPermission(null);
4176 }
4177
4178 /**
4179 * Make sure the caller has the READ_PHONE_STATE permissions.
4180 *
4181 * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission.
4182 */
4183 @VisibleForTesting
4184 public void enforceReadPermission(String msg) {
4185 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg);
Gil Cukierman1c0eb932022-12-06 22:28:24 +00004186 }
4187
Shuo Qian3b6ee772019-11-13 17:43:31 -08004188 private void enforceActiveEmergencySessionPermission() {
4189 mApp.enforceCallingOrSelfPermission(
4190 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
4191 }
4192
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004193 /**
4194 * Make sure the caller has the CALL_PHONE permission.
4195 *
4196 * @throws SecurityException if the caller does not have the required permission
4197 */
4198 private void enforceCallPermission() {
4199 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
4200 }
4201
paulhu5a773602019-08-23 19:17:33 +08004202 private void enforceSettingsPermission() {
4203 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07004204 }
4205
Michele Berionne5e411512020-11-13 02:36:59 +00004206 private void enforceRebootPermission() {
4207 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
4208 }
4209
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +00004210 /**
4211 * Make sure the caller has SATELLITE_COMMUNICATION permission.
4212 * @param message - log message to print.
4213 * @throws SecurityException if the caller does not have the required permission
4214 */
4215 private void enforceSatelliteCommunicationPermission(String message) {
4216 mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message);
4217 }
4218
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004219 private String createTelUrl(String number) {
4220 if (TextUtils.isEmpty(number)) {
4221 return null;
4222 }
4223
Jake Hambye994d462014-02-03 13:10:13 -08004224 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004225 }
4226
Ihab Awadf9e92732013-12-05 18:02:52 -08004227 private static void log(String msg) {
Ling Ma83dc5ea2023-01-12 15:06:04 -08004228 Log.d(LOG_TAG, msg);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004229 }
4230
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07004231 private static void logv(String msg) {
4232 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
4233 }
4234
Ihab Awadf9e92732013-12-05 18:02:52 -08004235 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004236 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
4237 }
4238
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004239 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004240 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07004241 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07004242 }
4243
Sanket Padawe356d7632015-06-22 14:03:32 -07004244 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004245 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004246 final long identity = Binder.clearCallingIdentity();
4247 try {
4248 final Phone phone = PhoneFactory.getPhone(slotIndex);
4249 if (phone == null) {
4250 return PhoneConstants.PHONE_TYPE_NONE;
4251 } else {
4252 return phone.getPhoneType();
4253 }
4254 } finally {
4255 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004256 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004257 }
4258
4259 /**
4260 * Returns the CDMA ERI icon index to display
4261 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004262 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004263 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
4264 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
4265 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004266 }
4267
Sanket Padawe356d7632015-06-22 14:03:32 -07004268 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004269 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
4270 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004271 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004272 mApp, subId, callingPackage, callingFeatureId,
4273 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004274 return -1;
4275 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004276
4277 final long identity = Binder.clearCallingIdentity();
4278 try {
4279 final Phone phone = getPhone(subId);
4280 if (phone != null) {
4281 return phone.getCdmaEriIconIndex();
4282 } else {
4283 return -1;
4284 }
4285 } finally {
4286 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004287 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004288 }
4289
4290 /**
4291 * Returns the CDMA ERI icon mode,
4292 * 0 - ON
4293 * 1 - FLASHING
4294 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004295 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004296 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
4297 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
4298 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004299 }
4300
Sanket Padawe356d7632015-06-22 14:03:32 -07004301 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004302 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
4303 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004304 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004305 mApp, subId, callingPackage, callingFeatureId,
4306 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004307 return -1;
4308 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004309
4310 final long identity = Binder.clearCallingIdentity();
4311 try {
4312 final Phone phone = getPhone(subId);
4313 if (phone != null) {
4314 return phone.getCdmaEriIconMode();
4315 } else {
4316 return -1;
4317 }
4318 } finally {
4319 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004320 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004321 }
4322
4323 /**
4324 * Returns the CDMA ERI text,
4325 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004326 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004327 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
4328 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
4329 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004330 }
4331
Sanket Padawe356d7632015-06-22 14:03:32 -07004332 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004333 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
4334 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004335 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004336 mApp, subId, callingPackage, callingFeatureId,
4337 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004338 return null;
4339 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004340
4341 final long identity = Binder.clearCallingIdentity();
4342 try {
4343 final Phone phone = getPhone(subId);
4344 if (phone != null) {
4345 return phone.getCdmaEriText();
4346 } else {
4347 return null;
4348 }
4349 } finally {
4350 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004352 }
4353
4354 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07004355 * Returns the CDMA MDN.
4356 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004357 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004358 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4360 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004361
4362 final long identity = Binder.clearCallingIdentity();
4363 try {
4364 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004365 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004366 return phone.getLine1Number();
4367 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004368 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004369 return null;
4370 }
4371 } finally {
4372 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004373 }
4374 }
4375
4376 /**
4377 * Returns the CDMA MIN.
4378 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004379 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07004380 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4382 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004383
4384 final long identity = Binder.clearCallingIdentity();
4385 try {
4386 final Phone phone = getPhone(subId);
4387 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
4388 return phone.getCdmaMin();
4389 } else {
4390 return null;
4391 }
4392 } finally {
4393 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07004394 }
4395 }
4396
Hall Liud892bec2018-11-30 14:51:45 -08004397 @Override
4398 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
4399 INumberVerificationCallback callback, String callingPackage) {
4400 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
4401 != PERMISSION_GRANTED) {
4402 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
4403 }
4404 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4405
4406 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
4407 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08004408 throw new SecurityException("Calling package must be configured in the device config: "
4409 + "calling package: " + callingPackage
4410 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08004411 }
4412
4413 if (range == null) {
4414 throw new NullPointerException("Range must be non-null");
4415 }
4416
4417 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08004418 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08004419
4420 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
4421 }
4422
Junda Liuca05d5d2014-08-14 22:36:34 -07004423 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004424 * Returns true if CDMA provisioning needs to run.
4425 */
4426 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004427 final long identity = Binder.clearCallingIdentity();
4428 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004429 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004430 } finally {
4431 Binder.restoreCallingIdentity(identity);
4432 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004433 }
4434
4435 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004436 * Sets the voice mail number of a given subId.
4437 */
4438 @Override
4439 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004440 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4441 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004442
4443 final long identity = Binder.clearCallingIdentity();
4444 try {
4445 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
4446 new Pair<String, String>(alphaTag, number), new Integer(subId));
4447 return success;
4448 } finally {
4449 Binder.restoreCallingIdentity(identity);
4450 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004451 }
4452
Ta-wei Yen87c49842016-05-13 21:19:52 -07004453 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004454 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
4455 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004456 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
4457 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004458 if (!TextUtils.equals(callingPackage, systemDialer)) {
4459 throw new SecurityException("caller must be system dialer");
4460 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004461
4462 final long identity = Binder.clearCallingIdentity();
4463 try {
4464 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
4465 if (phoneAccountHandle == null) {
4466 return null;
4467 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004468 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004469 } finally {
4470 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004471 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07004472 }
4473
4474 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004475 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
4476 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004477 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004478 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004479 mApp, subId, callingPackage, callingFeatureId,
4480 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08004481 return null;
4482 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004483
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004484 final long identity = Binder.clearCallingIdentity();
4485 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004486 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07004487 } finally {
4488 Binder.restoreCallingIdentity(identity);
4489 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08004490 }
4491
4492 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004493 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
4494 VisualVoicemailSmsFilterSettings settings) {
4495 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004496
4497 final long identity = Binder.clearCallingIdentity();
4498 try {
4499 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004500 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004501 } finally {
4502 Binder.restoreCallingIdentity(identity);
4503 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004504 }
4505
4506 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004507 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
4508 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004509
4510 final long identity = Binder.clearCallingIdentity();
4511 try {
4512 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004513 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004514 } finally {
4515 Binder.restoreCallingIdentity(identity);
4516 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004517 }
4518
4519 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07004520 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
4521 String callingPackage, int subId) {
4522 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004523
4524 final long identity = Binder.clearCallingIdentity();
4525 try {
4526 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004527 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004528 } finally {
4529 Binder.restoreCallingIdentity(identity);
4530 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07004531 }
4532
4533 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004534 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004535 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004536
4537 final long identity = Binder.clearCallingIdentity();
4538 try {
4539 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004540 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004541 } finally {
4542 Binder.restoreCallingIdentity(identity);
4543 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004544 }
4545
4546 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004547 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
4548 String callingAttributionTag, int subId, String number, int port, String text,
4549 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004550 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08004551 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08004552 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07004553 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07004554 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
4555 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07004556 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07004557
Shishir Agrawal76d5da92014-11-09 16:17:25 -08004558 /**
fionaxu0152e512016-11-14 13:36:14 -08004559 * Sets the voice activation state of a given subId.
4560 */
4561 @Override
4562 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4564 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004565
4566 final long identity = Binder.clearCallingIdentity();
4567 try {
4568 final Phone phone = getPhone(subId);
4569 if (phone != null) {
4570 phone.setVoiceActivationState(activationState);
4571 } else {
4572 loge("setVoiceActivationState fails with invalid subId: " + subId);
4573 }
4574 } finally {
4575 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004576 }
4577 }
4578
4579 /**
4580 * Sets the data activation state of a given subId.
4581 */
4582 @Override
4583 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4585 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004586
4587 final long identity = Binder.clearCallingIdentity();
4588 try {
4589 final Phone phone = getPhone(subId);
4590 if (phone != null) {
4591 phone.setDataActivationState(activationState);
4592 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004593 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004594 }
4595 } finally {
4596 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004597 }
4598 }
4599
4600 /**
4601 * Returns the voice activation state of a given subId.
4602 */
4603 @Override
4604 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004605 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004606
fionaxu0152e512016-11-14 13:36:14 -08004607 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004608 final long identity = Binder.clearCallingIdentity();
4609 try {
4610 if (phone != null) {
4611 return phone.getVoiceActivationState();
4612 } else {
4613 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4614 }
4615 } finally {
4616 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004617 }
4618 }
4619
4620 /**
4621 * Returns the data activation state of a given subId.
4622 */
4623 @Override
4624 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004625 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004626
fionaxu0152e512016-11-14 13:36:14 -08004627 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004628 final long identity = Binder.clearCallingIdentity();
4629 try {
4630 if (phone != null) {
4631 return phone.getDataActivationState();
4632 } else {
4633 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4634 }
4635 } finally {
4636 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004637 }
4638 }
4639
4640 /**
Wink Saville36469e72014-06-11 15:17:00 -07004641 * Returns the unread count of voicemails for a subId
4642 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004643 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004644 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4645 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004646 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004647 mApp, subId, callingPackage, callingFeatureId,
4648 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004649 return 0;
4650 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004651 final long identity = Binder.clearCallingIdentity();
4652 try {
4653 final Phone phone = getPhone(subId);
4654 if (phone != null) {
4655 return phone.getVoiceMessageCount();
4656 } else {
4657 return 0;
4658 }
4659 } finally {
4660 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004661 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004662 }
4663
4664 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004665 * returns true, if the device is in a state where both voice and data
4666 * are supported simultaneously. This can change based on location or network condition.
pkanwar8a4dcfb2017-01-19 13:43:16 -08004667 */
4668 @Override
4669 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004670 final long identity = Binder.clearCallingIdentity();
4671 try {
4672 final Phone phone = getPhone(subId);
4673 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4674 } finally {
4675 Binder.restoreCallingIdentity(identity);
4676 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004677 }
4678
4679 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004680 * Send the dialer code if called from the current default dialer or the caller has
4681 * carrier privilege.
4682 * @param inputCode The dialer code to send
4683 */
4684 @Override
4685 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004686 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004687 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004688 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4689 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004690 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004691 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004692 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004693 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004694
4695 final long identity = Binder.clearCallingIdentity();
4696 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004697 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004698 } finally {
4699 Binder.restoreCallingIdentity(identity);
4700 }
fionaxu235cc5e2017-03-06 22:25:57 -08004701 }
4702
Pengquan Menga1bb6272018-09-06 09:59:22 -07004703 @Override
4704 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004705 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08004706 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4707 mApp, subId, "getNetworkSelectionMode");
shilufc958392020-01-20 11:36:01 -08004708 final long identity = Binder.clearCallingIdentity();
4709 try {
4710 if (!isActiveSubscription(subId)) {
4711 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4712 }
4713 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4714 } finally {
4715 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004716 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004717 }
4718
Brad Ebinger35c841c2018-10-01 10:40:55 -07004719 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004720 public boolean isInEmergencySmsMode() {
4721 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4722 final long identity = Binder.clearCallingIdentity();
4723 try {
4724 for (Phone phone : PhoneFactory.getPhones()) {
4725 if (phone.isInEmergencySmsMode()) {
4726 return true;
4727 }
4728 }
4729 } finally {
4730 Binder.restoreCallingIdentity(identity);
4731 }
4732 return false;
4733 }
4734
shilu366312e2019-12-17 09:28:10 -08004735 /**
4736 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4737 * @param subId The subscription to use to check the configuration.
4738 * @param c The callback that will be used to send the result.
4739 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004740 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004741 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4742 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004743 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004744 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004745
4746 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4747 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4748 "IMS not available on device.");
4749 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004750 final long token = Binder.clearCallingIdentity();
4751 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004752 int slotId = getSlotIndexOrException(subId);
4753 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004754
4755 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4756 if (controller != null) {
4757 ImsManager imsManager = controller.getImsManager(subId);
4758 if (imsManager != null) {
4759 imsManager.addRegistrationCallbackForSubscription(c, subId);
4760 } else {
4761 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4762 }
4763 } else {
4764 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4765 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004766 } catch (ImsException e) {
4767 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004768 } finally {
4769 Binder.restoreCallingIdentity(token);
4770 }
4771 }
4772
shilu366312e2019-12-17 09:28:10 -08004773 /**
4774 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4775 * @param subId The subscription to use to check the configuration.
4776 * @param c The callback that will be used to send the result.
4777 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004778 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004779 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004780 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004781 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004782 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4783 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4784 }
Meng Wangafbc5852019-09-19 17:37:13 -07004785 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004786
Meng Wangafbc5852019-09-19 17:37:13 -07004787 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004788 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4789 if (controller != null) {
4790 ImsManager imsManager = controller.getImsManager(subId);
4791 if (imsManager != null) {
4792 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4793 } else {
4794 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4795 + "is inactive, ignoring unregister.");
4796 // If the ImsManager is not valid, just return, since the callback
4797 // will already have been removed internally.
4798 }
4799 }
Meng Wangafbc5852019-09-19 17:37:13 -07004800 } finally {
4801 Binder.restoreCallingIdentity(token);
4802 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004803 }
4804
Brad Ebingera34a6c22019-10-22 17:36:18 -07004805 /**
4806 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4807 */
4808 @Override
4809 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4810 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4811 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4812 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4813 "IMS not available on device.");
4814 }
4815 final long token = Binder.clearCallingIdentity();
4816 try {
4817 Phone phone = getPhone(subId);
4818 if (phone == null) {
4819 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4820 + subId + "'");
4821 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4822 }
4823 phone.getImsRegistrationState(regState -> {
4824 try {
4825 consumer.accept((regState == null)
4826 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4827 } catch (RemoteException e) {
4828 // Ignore if the remote process is no longer available to call back.
4829 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4830 }
4831 });
4832 } finally {
4833 Binder.restoreCallingIdentity(token);
4834 }
4835 }
4836
4837 /**
4838 * Get the transport type for the IMS service registration state.
4839 */
4840 @Override
4841 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004842 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004843 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004844 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4845 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4846 "IMS not available on device.");
4847 }
4848 final long token = Binder.clearCallingIdentity();
4849 try {
4850 Phone phone = getPhone(subId);
4851 if (phone == null) {
4852 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4853 + subId + "'");
4854 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4855 }
4856 phone.getImsRegistrationTech(regTech -> {
4857 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4858 int regTechConverted = (regTech == null)
4859 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4860 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4861 regTechConverted);
4862 try {
4863 consumer.accept(regTechConverted);
4864 } catch (RemoteException e) {
4865 // Ignore if the remote process is no longer available to call back.
4866 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4867 }
4868 });
4869 } finally {
4870 Binder.restoreCallingIdentity(token);
4871 }
4872 }
4873
shilu366312e2019-12-17 09:28:10 -08004874 /**
4875 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4876 * @param subId The subscription to use to check the configuration.
4877 * @param c The callback that will be used to send the result.
4878 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004879 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004880 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4881 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004882 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004883 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004884 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4885 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4886 "IMS not available on device.");
4887 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004888 final long token = Binder.clearCallingIdentity();
4889 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004890 int slotId = getSlotIndexOrException(subId);
4891 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004892
4893 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4894 if (controller != null) {
4895 ImsManager imsManager = controller.getImsManager(subId);
4896 if (imsManager != null) {
4897 imsManager.addCapabilitiesCallbackForSubscription(c, subId);
4898 } else {
4899 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4900 }
4901 } else {
4902 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4903 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004904 } catch (ImsException e) {
4905 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004906 } finally {
4907 Binder.restoreCallingIdentity(token);
4908 }
4909 }
4910
shilu366312e2019-12-17 09:28:10 -08004911 /**
4912 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4913 * @param subId The subscription to use to check the configuration.
4914 * @param c The callback that will be used to send the result.
4915 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004916 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004917 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004918 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004919 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004920 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4921 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4922 }
Meng Wangafbc5852019-09-19 17:37:13 -07004923
4924 final long token = Binder.clearCallingIdentity();
4925 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00004926 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4927 if (controller != null) {
4928 ImsManager imsManager = controller.getImsManager(subId);
4929 if (imsManager != null) {
4930 imsManager.removeCapabilitiesCallbackForSubscription(c, subId);
4931 } else {
4932 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4933 + " is inactive, ignoring unregister.");
4934 // If the ImsManager is not valid, just return, since the callback
4935 // will already have been removed internally.
4936 }
4937 }
Meng Wangafbc5852019-09-19 17:37:13 -07004938 } finally {
4939 Binder.restoreCallingIdentity(token);
4940 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004941 }
4942
4943 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004944 public boolean isCapable(int subId, int capability, int regTech) {
4945 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004946 final long token = Binder.clearCallingIdentity();
4947 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004948 int slotId = getSlotIndexOrException(subId);
4949 verifyImsMmTelConfiguredOrThrow(slotId);
4950 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4951 } catch (com.android.ims.ImsException e) {
4952 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4953 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004954 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004955 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4956 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004957 } finally {
4958 Binder.restoreCallingIdentity(token);
4959 }
4960 }
4961
4962 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004963 public boolean isAvailable(int subId, int capability, int regTech) {
4964 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004965 final long token = Binder.clearCallingIdentity();
4966 try {
4967 Phone phone = getPhone(subId);
4968 if (phone == null) return false;
4969 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004970 } catch (com.android.ims.ImsException e) {
4971 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4972 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004973 } finally {
4974 Binder.restoreCallingIdentity(token);
4975 }
4976 }
4977
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004978 /**
4979 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4980 * subscription.
4981 * @param subId The subscription to use to check the configuration.
4982 * @param callback The callback that will be used to send the result.
4983 * @param capability The MmTelFeature capability that will be used to send the result.
4984 * @param transportType The transport type of the MmTelFeature capability.
4985 */
4986 @Override
4987 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4988 int transportType) {
4989 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004990 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4991 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4992 "IMS not available on device.");
4993 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004994 final long token = Binder.clearCallingIdentity();
4995 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004996 int slotId = getSlotIndex(subId);
4997 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4998 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4999 + subId + "'");
5000 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5001 }
5002 verifyImsMmTelConfiguredOrThrow(slotId);
5003 ImsManager.getInstance(mApp, slotId).isSupported(capability,
5004 transportType, aBoolean -> {
5005 try {
5006 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
5007 } catch (RemoteException e) {
5008 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
5009 + "running. Ignore");
5010 }
5011 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005012 } catch (ImsException e) {
5013 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005014 } finally {
5015 Binder.restoreCallingIdentity(token);
5016 }
5017 }
5018
shilu366312e2019-12-17 09:28:10 -08005019 /**
5020 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5021 * @param subId The subscription to use to check the configuration.
5022 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005023 @Override
5024 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005025 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005026 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08005027
Brad Ebinger35c841c2018-10-01 10:40:55 -07005028 final long token = Binder.clearCallingIdentity();
5029 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005030 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005031 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005032 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005033 } catch (ImsException e) {
5034 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005035 } finally {
5036 Binder.restoreCallingIdentity(token);
5037 }
5038 }
5039
5040 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005041 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005043 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005044 final long identity = Binder.clearCallingIdentity();
5045 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005046 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005047 // This setting doesn't require an active ImsService connection, so do not verify. The
5048 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005049 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005050 } catch (ImsException e) {
5051 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005052 } finally {
5053 Binder.restoreCallingIdentity(identity);
5054 }
5055 }
5056
shilu366312e2019-12-17 09:28:10 -08005057 /**
5058 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5059 * @param subId The subscription to use to check the configuration.
5060 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005061 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08005062 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005063 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005064 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005065 final long identity = Binder.clearCallingIdentity();
5066 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005067 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005068 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005069 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005070 } catch (ImsException e) {
5071 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005072 } finally {
5073 Binder.restoreCallingIdentity(identity);
5074 }
5075 }
5076
5077 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005078 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005080 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005081 final long identity = Binder.clearCallingIdentity();
5082 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005083 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005084 // This setting doesn't require an active ImsService connection, so do not verify. The
5085 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005086 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005087 } catch (ImsException e) {
5088 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005089 } finally {
5090 Binder.restoreCallingIdentity(identity);
5091 }
5092 }
5093
shilu366312e2019-12-17 09:28:10 -08005094 /**
5095 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5096 * @param subId The subscription to use to check the configuration.
5097 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005098 @Override
5099 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005100 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005101 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005102 final long identity = Binder.clearCallingIdentity();
5103 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005104 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005105 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005106 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005107 } catch (ImsException e) {
5108 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005109 } finally {
5110 Binder.restoreCallingIdentity(identity);
5111 }
5112 }
5113
5114 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005115 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005116 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005117 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005118 final long identity = Binder.clearCallingIdentity();
5119 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005120 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005121 // This setting doesn't require an active ImsService connection, so do not verify. The
5122 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005123 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005124 } catch (ImsException e) {
5125 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005126 } finally {
5127 Binder.restoreCallingIdentity(identity);
5128 }
5129 }
5130
shilu366312e2019-12-17 09:28:10 -08005131 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005132 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
5133 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5134 * @param subId The subscription to use to check the configuration.
5135 */
5136 @Override
5137 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005138 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005139 mApp, subId, "isCrossSimCallingEnabledByUser");
5140 final long identity = Binder.clearCallingIdentity();
5141 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005142 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005143 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005144 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005145 } catch (ImsException e) {
5146 throw new ServiceSpecificException(e.getCode());
5147 } finally {
5148 Binder.restoreCallingIdentity(identity);
5149 }
5150 }
5151
5152 /**
5153 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
5154 * Requires MODIFY_PHONE_STATE permission.
5155 * @param subId The subscription to use to check the configuration.
5156 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
5157 * false otherwise
5158 */
5159 @Override
5160 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
5161 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5162 "setCrossSimCallingEnabled");
5163 final long identity = Binder.clearCallingIdentity();
5164 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005165 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005166 // This setting doesn't require an active ImsService connection, so do not verify. The
5167 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005168 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08005169 } catch (ImsException e) {
5170 throw new ServiceSpecificException(e.getCode());
5171 } finally {
5172 Binder.restoreCallingIdentity(identity);
5173 }
5174 }
5175
5176 /**
shilu366312e2019-12-17 09:28:10 -08005177 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5178 * @param subId The subscription to use to check the configuration.
5179 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005180 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07005181
Brad Ebinger35c841c2018-10-01 10:40:55 -07005182 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005183 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005184 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005185 final long identity = Binder.clearCallingIdentity();
5186 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005187 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005188 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005189 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005190 } catch (ImsException e) {
5191 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005192 } finally {
5193 Binder.restoreCallingIdentity(identity);
5194 }
5195 }
5196
5197 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08005198 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005199 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08005200 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005201 final long identity = Binder.clearCallingIdentity();
5202 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005203 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005204 // This setting doesn't require an active ImsService connection, so do not verify. The
5205 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005206 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005207 } catch (ImsException e) {
5208 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005209 } finally {
5210 Binder.restoreCallingIdentity(identity);
5211 }
5212 }
5213
5214 @Override
5215 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
5216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5217 "setVoWiFiNonPersistent");
5218 final long identity = Binder.clearCallingIdentity();
5219 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005220 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005221 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005222 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005223 } catch (ImsException e) {
5224 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005225 } finally {
5226 Binder.restoreCallingIdentity(identity);
5227 }
5228 }
5229
shilu366312e2019-12-17 09:28:10 -08005230 /**
5231 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5232 * @param subId The subscription to use to check the configuration.
5233 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005234 @Override
5235 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005236 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005237 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005238 final long identity = Binder.clearCallingIdentity();
5239 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005240 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005241 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005242 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005243 } catch (ImsException e) {
5244 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005245 } finally {
5246 Binder.restoreCallingIdentity(identity);
5247 }
5248 }
5249
5250 @Override
5251 public void setVoWiFiModeSetting(int subId, int mode) {
5252 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5253 "setVoWiFiModeSetting");
5254 final long identity = Binder.clearCallingIdentity();
5255 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005256 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005257 // This setting doesn't require an active ImsService connection, so do not verify. The
5258 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005259 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005260 } catch (ImsException e) {
5261 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005262 } finally {
5263 Binder.restoreCallingIdentity(identity);
5264 }
5265 }
5266
5267 @Override
5268 public int getVoWiFiRoamingModeSetting(int subId) {
5269 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
5270 final long identity = Binder.clearCallingIdentity();
5271 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005272 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005273 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005274 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005275 } catch (ImsException e) {
5276 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005277 } finally {
5278 Binder.restoreCallingIdentity(identity);
5279 }
5280 }
5281
5282 @Override
5283 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
5284 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5285 "setVoWiFiRoamingModeSetting");
5286 final long identity = Binder.clearCallingIdentity();
5287 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005288 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005289 // This setting doesn't require an active ImsService connection, so do not verify. The
5290 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005291 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005292 } catch (ImsException e) {
5293 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005294 } finally {
5295 Binder.restoreCallingIdentity(identity);
5296 }
5297 }
5298
5299 @Override
5300 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
5301 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5302 "setRttCapabilityEnabled");
5303 final long identity = Binder.clearCallingIdentity();
5304 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005305 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005306 // This setting doesn't require an active ImsService connection, so do not verify. The
5307 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07005308 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005309 } catch (ImsException e) {
5310 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005311 } finally {
5312 Binder.restoreCallingIdentity(identity);
5313 }
5314 }
5315
shilu366312e2019-12-17 09:28:10 -08005316 /**
5317 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
5318 * @param subId The subscription to use to check the configuration.
5319 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005320 @Override
5321 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07005322 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08005323 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07005324 final long identity = Binder.clearCallingIdentity();
5325 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07005326 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07005327 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07005328 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005329 } catch (ImsException e) {
5330 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07005331 } finally {
5332 Binder.restoreCallingIdentity(identity);
5333 }
5334 }
5335
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005336 @Override
5337 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5338 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005339
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005340 final long identity = Binder.clearCallingIdentity();
5341 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005342 if (!isImsAvailableOnDevice()) {
5343 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5344 "IMS not available on device.");
5345 }
5346 int slotId = getSlotIndexOrException(subId);
5347 verifyImsMmTelConfiguredOrThrow(slotId);
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005348
5349 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5350 if (controller != null) {
5351 ImsManager imsManager = controller.getImsManager(subId);
5352 if (imsManager != null) {
5353 imsManager.addProvisioningCallbackForSubscription(callback, subId);
5354 } else {
5355 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
5356 }
5357 } else {
5358 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5359 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005360 } catch (ImsException e) {
5361 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005362 } finally {
5363 Binder.restoreCallingIdentity(identity);
5364 }
5365 }
5366
5367 @Override
5368 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
5369 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00005370
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005371 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08005372 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5373 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5374 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005375 try {
Hwangoo Park8646b0d2023-01-13 02:42:34 +00005376 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
5377 if (controller != null) {
5378 ImsManager imsManager = controller.getImsManager(subId);
5379 if (imsManager != null) {
5380 imsManager.removeProvisioningCallbackForSubscription(callback, subId);
5381 } else {
5382 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
5383 + " is inactive, ignoring unregister.");
5384 // If the ImsManager is not valid, just return, since the callback will already
5385 // have been removed internally.
5386 }
5387 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005388 } finally {
5389 Binder.restoreCallingIdentity(identity);
5390 }
5391 }
5392
joonhunshincffb7fc2021-11-28 07:32:01 +00005393 @Override
5394 public void registerFeatureProvisioningChangedCallback(int subId,
5395 IFeatureProvisioningCallback callback) {
5396 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5397 mApp, subId, "registerFeatureProvisioningChangedCallback");
5398
5399 final long identity = Binder.clearCallingIdentity();
5400 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5401 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5402 }
5403
joonhunshin91bc1952022-04-29 08:47:15 +00005404 try {
5405 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5406 if (controller == null) {
5407 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5408 "Device does not support IMS");
5409 }
5410 controller.addFeatureProvisioningChangedCallback(subId, callback);
5411 } finally {
5412 Binder.restoreCallingIdentity(identity);
5413 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005414 }
5415
5416 @Override
5417 public void unregisterFeatureProvisioningChangedCallback(int subId,
5418 IFeatureProvisioningCallback callback) {
5419 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5420 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
5421
5422 final long identity = Binder.clearCallingIdentity();
5423 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5424 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
5425 }
5426
joonhunshin91bc1952022-04-29 08:47:15 +00005427 try {
5428 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5429 if (controller == null) {
5430 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
5431 return;
5432 }
5433 controller.removeFeatureProvisioningChangedCallback(subId, callback);
5434 } finally {
5435 Binder.restoreCallingIdentity(identity);
5436 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005437 }
allenwtsu99c623b2020-01-03 18:24:23 +08005438
5439 private void checkModifyPhoneStatePermission(int subId, String message) {
5440 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5441 message);
5442 }
5443
allenwtsu99c623b2020-01-03 18:24:23 +08005444 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005445 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08005446 boolean isProvisioned) {
5447 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
5448
5449 final long identity = Binder.clearCallingIdentity();
5450 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005451 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5452 if (controller == null) {
5453 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
5454 return;
5455 }
5456 controller.setRcsProvisioningStatusForCapability(
5457 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08005458 } finally {
5459 Binder.restoreCallingIdentity(identity);
5460 }
allenwtsu99c623b2020-01-03 18:24:23 +08005461 }
5462
5463
5464 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005465 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
5466 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5467 mApp, subId, "getRcsProvisioningStatusForCapability");
5468
allenwtsu99c623b2020-01-03 18:24:23 +08005469 final long identity = Binder.clearCallingIdentity();
5470 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005471 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5472 if (controller == null) {
5473 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
5474
5475 // device does not support IMS, this method will return true always.
5476 return true;
5477 }
5478 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08005479 } finally {
5480 Binder.restoreCallingIdentity(identity);
5481 }
5482 }
5483
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005484 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005485 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
5486 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08005487 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00005488
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005489 final long identity = Binder.clearCallingIdentity();
5490 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005491 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5492 if (controller == null) {
5493 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
5494 return;
5495 }
5496 controller.setImsProvisioningStatusForCapability(
5497 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005498 } finally {
5499 Binder.restoreCallingIdentity(identity);
5500 }
5501 }
5502
5503 @Override
5504 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00005505 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5506 mApp, subId, "getProvisioningStatusForCapability");
5507
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005508 final long identity = Binder.clearCallingIdentity();
5509 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005510 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5511 if (controller == null) {
5512 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005513
joonhunshin91bc1952022-04-29 08:47:15 +00005514 // device does not support IMS, this method will return true always.
5515 return true;
5516 }
5517 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005518 } finally {
5519 Binder.restoreCallingIdentity(identity);
5520 }
5521 }
5522
5523 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005524 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
5525 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5526 mApp, subId, "isProvisioningRequiredForCapability");
5527
5528 final long identity = Binder.clearCallingIdentity();
5529 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005530 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5531 if (controller == null) {
5532 loge("isProvisioningRequiredForCapability: Device does not support IMS");
5533
5534 // device does not support IMS, this method will return false
5535 return false;
5536 }
5537 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005538 } finally {
5539 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005540 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005541 }
5542
5543 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00005544 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
5545 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5546 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005547
joonhunshincffb7fc2021-11-28 07:32:01 +00005548 final long identity = Binder.clearCallingIdentity();
5549 try {
joonhunshin91bc1952022-04-29 08:47:15 +00005550 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5551 if (controller == null) {
5552 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
5553
5554 // device does not support IMS, this method will return false
5555 return false;
5556 }
5557 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00005558 } finally {
5559 Binder.restoreCallingIdentity(identity);
5560 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005561 }
5562
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005563 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005564 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005565 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5566 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5567 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005568 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5569 mApp, subId, "getImsProvisioningInt");
5570
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005571 final long identity = Binder.clearCallingIdentity();
5572 try {
5573 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005574 int slotId = getSlotIndex(subId);
5575 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5576 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
5577 + subId + "' for key:" + key);
5578 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5579 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005580
joonhunshin91bc1952022-04-29 08:47:15 +00005581 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5582 if (controller == null) {
5583 loge("getImsProvisioningInt: Device does not support IMS");
5584
5585 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
5586 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
5587 }
5588 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00005589 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5590 return retVal;
5591 }
5592
calvinpanb5a34062021-02-08 19:59:36 +08005593 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005594 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005595 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
5596 + subId + "' for key:" + key);
5597 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005598 } finally {
5599 Binder.restoreCallingIdentity(identity);
5600 }
5601 }
5602
5603 @Override
5604 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005605 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5606 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5607 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005608 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5609 mApp, subId, "getImsProvisioningString");
5610
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005611 final long identity = Binder.clearCallingIdentity();
5612 try {
5613 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005614 int slotId = getSlotIndex(subId);
5615 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5616 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5617 + subId + "' for key:" + key);
5618 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5619 }
calvinpanb5a34062021-02-08 19:59:36 +08005620 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005621 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005622 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5623 + subId + "' for key:" + key);
5624 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005625 } finally {
5626 Binder.restoreCallingIdentity(identity);
5627 }
5628 }
5629
5630 @Override
5631 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005632 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5633 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5634 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5636 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005637
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005638 final long identity = Binder.clearCallingIdentity();
5639 try {
5640 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005641 int slotId = getSlotIndex(subId);
5642 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5643 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5644 + subId + "' for key:" + key);
5645 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5646 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005647
joonhunshin91bc1952022-04-29 08:47:15 +00005648 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5649 if (controller == null) {
5650 loge("setImsProvisioningInt: Device does not support IMS");
5651
5652 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5653 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5654 }
5655 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005656 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5657 return retVal;
5658 }
5659
calvinpanb5a34062021-02-08 19:59:36 +08005660 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5661 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005662 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005663 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005664 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005665 } finally {
5666 Binder.restoreCallingIdentity(identity);
5667 }
5668 }
5669
5670 @Override
5671 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005672 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5673 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5674 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5676 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005677 final long identity = Binder.clearCallingIdentity();
5678 try {
5679 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005680 int slotId = getSlotIndex(subId);
5681 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5682 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5683 + subId + "' for key:" + key);
5684 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5685 }
calvinpanb5a34062021-02-08 19:59:36 +08005686 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5687 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005688 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005689 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005690 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005691 } finally {
5692 Binder.restoreCallingIdentity(identity);
5693 }
5694 }
5695
Brad Ebinger919631e2021-06-02 17:46:35 -07005696 /**
5697 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5698 * for the given slot ID or no ImsResolver instance has been created.
5699 * @param slotId The slot ID that the IMS service is created for.
5700 * @throws ImsException If there is no ImsService configured for this slot.
5701 */
5702 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5703 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5704 ImsFeature.FEATURE_MMTEL)) {
5705 throw new ImsException("This subscription does not support MMTEL over IMS",
5706 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5707 }
5708 }
5709
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005710 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005711 int slotId = SubscriptionManager.getSlotIndex(subId);
5712 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005713 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5714 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005715 }
5716 return slotId;
5717 }
5718
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005719 private int getSlotIndex(int subId) {
5720 int slotId = SubscriptionManager.getSlotIndex(subId);
5721 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5722 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5723 }
5724 return slotId;
5725 }
5726
Wink Saville36469e72014-06-11 15:17:00 -07005727 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005728 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005729 */
5730 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005731 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5732 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005733 try {
5734 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5735 } catch (SecurityException se) {
5736 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5737 throw new SecurityException("Package " + callingPackage + " does not belong to "
5738 + Binder.getCallingUid());
5739 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005740 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005741 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005742 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005743 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005744 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005745 mApp, subId, callingPackage, callingFeatureId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005746 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005747 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5748 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005749
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005750 final long identity = Binder.clearCallingIdentity();
5751 try {
5752 final Phone phone = getPhone(subId);
5753 if (phone != null) {
5754 return phone.getServiceState().getDataNetworkType();
5755 } else {
5756 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5757 }
5758 } finally {
5759 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005760 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005761 }
5762
5763 /**
5764 * Returns the data network type
5765 */
5766 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005767 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yu285100e2022-12-02 22:48:35 -08005768 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005769 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005770 }
5771
5772 /**
5773 * Returns the data network type for a subId
5774 */
5775 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005776 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5777 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005778 String functionName = "getDataNetworkTypeForSubscriber";
5779 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5780 mApp, functionName)) {
5781 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5782 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5783 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5784 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005785 }
5786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005787 final long identity = Binder.clearCallingIdentity();
5788 try {
5789 final Phone phone = getPhone(subId);
5790 if (phone != null) {
5791 return phone.getServiceState().getDataNetworkType();
5792 } else {
5793 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5794 }
5795 } finally {
5796 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005797 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005798 }
5799
5800 /**
Wink Saville36469e72014-06-11 15:17:00 -07005801 * Returns the Voice network type for a subId
5802 */
5803 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005804 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5805 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005806 String functionName = "getVoiceNetworkTypeForSubscriber";
5807 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5808 mApp, functionName)) {
5809 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5810 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5811 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5812 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005813 }
5814
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005815 final long identity = Binder.clearCallingIdentity();
5816 try {
5817 final Phone phone = getPhone(subId);
5818 if (phone != null) {
5819 return phone.getServiceState().getVoiceNetworkType();
5820 } else {
5821 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5822 }
5823 } finally {
5824 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005825 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005826 }
5827
5828 /**
5829 * @return true if a ICC card is present
5830 */
5831 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005832 // FIXME Make changes to pass defaultSimId of type int
Jack Yu285100e2022-12-02 22:48:35 -08005833 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005834 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005835 }
5836
5837 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005838 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005839 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005840 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005841 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005842 final long identity = Binder.clearCallingIdentity();
5843 try {
5844 final Phone phone = PhoneFactory.getPhone(slotIndex);
5845 if (phone != null) {
5846 return phone.getIccCard().hasIccCard();
5847 } else {
5848 return false;
5849 }
5850 } finally {
5851 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005852 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005853 }
5854
5855 /**
5856 * Return if the current radio is LTE on CDMA. This
5857 * is a tri-state return value as for a period of time
5858 * the mode may be unknown.
5859 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005860 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005861 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005862 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005863 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005864 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005865 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5866 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5867 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005868 }
5869
Sanket Padawe356d7632015-06-22 14:03:32 -07005870 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005871 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5872 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005873 try {
5874 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5875 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005876 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5877 }
5878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005879 final long identity = Binder.clearCallingIdentity();
5880 try {
5881 final Phone phone = getPhone(subId);
5882 if (phone == null) {
5883 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5884 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005885 return TelephonyProperties.lte_on_cdma_device()
5886 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005887 }
5888 } finally {
5889 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005890 }
Wink Saville36469e72014-06-11 15:17:00 -07005891 }
5892
Wink Saville36469e72014-06-11 15:17:00 -07005893 /**
5894 * {@hide}
5895 * Returns Default subId, 0 in the case of single standby.
5896 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005897 private int getDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005898 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005899 }
5900
Shishir Agrawala9f32182016-04-12 12:00:16 -07005901 private int getSlotForDefaultSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005902 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005903 }
5904
Wink Savilleb564aae2014-10-23 10:18:09 -07005905 private int getPreferredVoiceSubscription() {
Jack Yu285100e2022-12-02 22:48:35 -08005906 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005907 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005908
Pengquan Menge92a50d2018-09-21 15:54:48 -07005909 private boolean isActiveSubscription(int subId) {
Jack Yu285100e2022-12-02 22:48:35 -08005910 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08005911 return getSubscriptionManagerService().isActiveSubId(subId,
Jack Yu285100e2022-12-02 22:48:35 -08005912 mApp.getOpPackageName(), mApp.getFeatureId());
5913 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005914 return mSubscriptionController.isActiveSubId(subId);
5915 }
5916
Ihab Awadf2177b72013-11-25 13:33:23 -08005917 /**
5918 * @see android.telephony.TelephonyManager.WifiCallingChoices
5919 */
5920 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005921 final long identity = Binder.clearCallingIdentity();
5922 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005923 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005924 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5925 getWhenToMakeWifiCallsDefaultPreference());
5926 } finally {
5927 Binder.restoreCallingIdentity(identity);
5928 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005929 }
5930
5931 /**
5932 * @see android.telephony.TelephonyManager.WifiCallingChoices
5933 */
5934 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005935 final long identity = Binder.clearCallingIdentity();
5936 try {
5937 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005938 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005939 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5940 } finally {
5941 Binder.restoreCallingIdentity(identity);
5942 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005943 }
5944
Sailesh Nepald1e68152013-12-12 19:08:02 -08005945 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005946 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005947 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005948 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005949
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005950 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5951 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5952 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005953 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005954 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
Thomas Nguyen8ee49682023-02-01 11:46:09 -08005955 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005956 }
5957 return PhoneFactory.getPhone(phoneId);
5958 }
5959
Shishir Agrawal566b7612013-10-28 14:41:00 -07005960 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005961 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005962 @NonNull IccLogicalChannelRequest request) {
5963 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5964 /*message=*/ "iccOpenLogicalChannel");
5965
5966 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5967 // Verify that the callingPackage in the request belongs to the calling UID
5968 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5969
5970 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005971 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005972
Rambo Wanga1782702021-11-10 20:15:19 -08005973 private Phone getPhoneFromValidIccLogicalChannelRequest(
5974 @NonNull IccLogicalChannelRequest request, String message) {
5975 Phone phone;
5976 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5978 mApp, request.subId, message);
5979 phone = getPhoneFromSubId(request.subId);
5980 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5981 enforceModifyPermission();
5982 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5983 } else {
5984 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005985 }
Rambo Wanga1782702021-11-10 20:15:19 -08005986 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005987 }
5988
5989 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005990 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005991 final long identity = Binder.clearCallingIdentity();
5992 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005993 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005995 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5996 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005997 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5998 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005999 loge("The calling package is not allowed to access ISD-R.");
6000 throw new SecurityException(
6001 "The calling package is not allowed to access ISD-R.");
6002 }
Derek Tan740e1672017-06-27 14:56:27 -07006003 }
Derek Tan740e1672017-06-27 14:56:27 -07006004
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006005 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08006006 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
6007 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006008 return response;
6009 } finally {
6010 Binder.restoreCallingIdentity(identity);
6011 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006012 }
6013
6014 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08006015 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
6016 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
6017 /*message=*/"iccCloseLogicalChannel");
6018
6019 if (DBG) log("iccCloseLogicalChannel: request=" + request);
6020
6021 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08006022 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006023
Rambo Wanga1782702021-11-10 20:15:19 -08006024 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
6025 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08006026 // before this feature is enabled, this API should only return false if
6027 // the operation fails instead of throwing runtime exception for
6028 // backward-compatibility.
6029 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
6030 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006031 final long identity = Binder.clearCallingIdentity();
6032 try {
Rambo Wanga1782702021-11-10 20:15:19 -08006033 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08006034 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006035 }
Chen Xue9d737e2022-01-01 23:41:31 -08006036 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08006037 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08006038 Boolean success = false;
6039 if (result instanceof RuntimeException) {
6040 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08006041 if (shouldThrowExceptionOnFailure) {
6042 throw (RuntimeException) result;
6043 } else {
6044 return false;
6045 }
Chen Xue9d737e2022-01-01 23:41:31 -08006046 } else if (result instanceof Boolean) {
6047 success = (Boolean) result;
6048 } else {
6049 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
6050 }
Rambo Wanga1782702021-11-10 20:15:19 -08006051 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006052 return success;
6053 } finally {
6054 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006055 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006056 }
6057
6058 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006059 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07006060 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6062 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08006063 if (DBG) {
6064 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
6065 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
6066 + p3 + " data=" + data);
6067 }
6068 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
6069 command, p1, p2, p3, data);
6070 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006071
Jordan Liu4c733742019-02-28 12:03:40 -08006072 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006073 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006074 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006075 enforceModifyPermission();
6076 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006077 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006078 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
6079 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006080 }
6081 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006082 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
6083 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006084 }
6085
6086 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
6087 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006088 final long identity = Binder.clearCallingIdentity();
6089 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07006090 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 return "";
6092 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006093
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006094 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006095 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
6096 null /* workSource */);
6097 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07006098
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006099 // Append the returned status code to the end of the response payload.
6100 String s = Integer.toHexString(
6101 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6102 if (response.payload != null) {
6103 s = IccUtils.bytesToHexString(response.payload) + s;
6104 }
6105 return s;
6106 } finally {
6107 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006108 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07006109 }
Jake Hambye994d462014-02-03 13:10:13 -08006110
Evan Charltonc66da362014-05-16 14:06:40 -07006111 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006112 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
6113 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006114 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6115 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006116 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08006117 if (DBG) {
6118 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
6119 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
6120 }
6121 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
6122 cla, command, p1, p2, p3, data);
6123 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006124
Jordan Liu4c733742019-02-28 12:03:40 -08006125 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006126 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006127 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08006128 enforceModifyPermission();
6129 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6130 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006131 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006132 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
6133 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08006134 }
6135
6136 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00006137 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
6138 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08006139 }
6140
6141 // open APDU basic channel assuming the caller has sufficient permissions
6142 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
6143 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006144 final long identity = Binder.clearCallingIdentity();
6145 try {
6146 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
6147 && TextUtils.equals(ISDR_AID, data)) {
6148 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006149 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
6150 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006151 if (bestComponent == null
6152 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
6153 loge("The calling package is not allowed to select ISD-R.");
6154 throw new SecurityException(
6155 "The calling package is not allowed to select ISD-R.");
6156 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006157 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08006158
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08006160 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
6161 null /* workSource */);
6162 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006163
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164 // Append the returned status code to the end of the response payload.
6165 String s = Integer.toHexString(
6166 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6167 if (response.payload != null) {
6168 s = IccUtils.bytesToHexString(response.payload) + s;
6169 }
6170 return s;
6171 } finally {
6172 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07006173 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006174 }
6175
6176 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006177 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006178 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006179 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6180 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006181
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006182 final long identity = Binder.clearCallingIdentity();
6183 try {
6184 if (DBG) {
6185 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
6186 + p1 + " " + p2 + " " + p3 + ":" + filePath);
6187 }
6188
6189 IccIoResult response =
6190 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
6191 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
6192 subId);
6193
6194 if (DBG) {
6195 log("Exchange SIM_IO [R]" + response);
6196 }
6197
6198 byte[] result = null;
6199 int length = 2;
6200 if (response.payload != null) {
6201 length = 2 + response.payload.length;
6202 result = new byte[length];
6203 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
6204 } else {
6205 result = new byte[length];
6206 }
6207
6208 result[length - 1] = (byte) response.sw2;
6209 result[length - 2] = (byte) response.sw1;
6210 return result;
6211 } finally {
6212 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006213 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006214 }
6215
Nathan Haroldb3014052017-01-25 15:57:32 -08006216 /**
6217 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
6218 * on a particular subscription
6219 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006220 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
6221 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07006222 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006223 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07006224 return null;
6225 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006226
6227 final long identity = Binder.clearCallingIdentity();
6228 try {
6229 if (appType != TelephonyManager.APPTYPE_USIM
6230 && appType != TelephonyManager.APPTYPE_SIM) {
6231 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
6232 return null;
6233 }
6234 Object response = sendRequest(
6235 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
6236 if (response instanceof String[]) {
6237 return (String[]) response;
6238 }
yincheng zhao2737e882019-09-06 17:06:54 -07006239 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006240 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08006241 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006242 } finally {
6243 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08006244 }
Nathan Haroldb3014052017-01-25 15:57:32 -08006245 }
6246
yincheng zhao2737e882019-09-06 17:06:54 -07006247 /**
6248 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
6249 * subscription.
6250 *
6251 * @param subId the id of the subscription.
6252 * @param appType the uicc app type, must be USIM or SIM.
6253 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
6254 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006255 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07006256 * @return number of fplmns that is successfully written to the SIM.
6257 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006258 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
6259 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07006260 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6261 mApp, subId, "setForbiddenPlmns");
6262
yincheng zhao2737e882019-09-06 17:06:54 -07006263 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
6264 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
6265 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
6266 }
6267 if (fplmns == null) {
6268 throw new IllegalArgumentException("Fplmn List provided is null");
6269 }
6270 for (String fplmn : fplmns) {
6271 if (!CellIdentity.isValidPlmn(fplmn)) {
6272 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
6273 }
6274 }
6275 final long identity = Binder.clearCallingIdentity();
6276 try {
6277 Object response = sendRequest(
6278 CMD_SET_FORBIDDEN_PLMNS,
6279 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
6280 subId);
6281 return (int) response;
6282 } finally {
6283 Binder.restoreCallingIdentity(identity);
6284 }
6285 }
6286
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07006287 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006288 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006289 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6290 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07006291
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006292 final long identity = Binder.clearCallingIdentity();
6293 try {
6294 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
6295 if (response.payload == null) {
6296 return "";
6297 }
Evan Charltonc66da362014-05-16 14:06:40 -07006298
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006299 // Append the returned status code to the end of the response payload.
6300 String s = Integer.toHexString(
6301 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
6302 s = IccUtils.bytesToHexString(response.payload) + s;
6303 return s;
6304 } finally {
6305 Binder.restoreCallingIdentity(identity);
6306 }
Evan Charltonc66da362014-05-16 14:06:40 -07006307 }
6308
Jake Hambye994d462014-02-03 13:10:13 -08006309 /**
6310 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6311 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6312 *
6313 * @param itemID the ID of the item to read
6314 * @return the NV item as a String, or null on error.
6315 */
6316 @Override
6317 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006318 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006319 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6320 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006321
6322 final long identity = Binder.clearCallingIdentity();
6323 try {
6324 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07006325 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006326 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
6327 return value;
6328 } finally {
6329 Binder.restoreCallingIdentity(identity);
6330 }
Jake Hambye994d462014-02-03 13:10:13 -08006331 }
6332
6333 /**
6334 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
6335 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
6336 *
6337 * @param itemID the ID of the item to read
6338 * @param itemValue the value to write, as a String
6339 * @return true on success; false on any failure
6340 */
6341 @Override
6342 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006343 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08006344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6345 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006346
6347 final long identity = Binder.clearCallingIdentity();
6348 try {
6349 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
6350 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07006351 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006352 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
6353 return success;
6354 } finally {
6355 Binder.restoreCallingIdentity(identity);
6356 }
Jake Hambye994d462014-02-03 13:10:13 -08006357 }
6358
6359 /**
6360 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
6361 * Used for device configuration by some CDMA operators.
6362 *
6363 * @param preferredRoamingList byte array containing the new PRL
6364 * @return true on success; false on any failure
6365 */
6366 @Override
6367 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6369 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006370
6371 final long identity = Binder.clearCallingIdentity();
6372 try {
6373 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
6374 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
6375 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
6376 return success;
6377 } finally {
6378 Binder.restoreCallingIdentity(identity);
6379 }
Jake Hambye994d462014-02-03 13:10:13 -08006380 }
6381
6382 /**
chen xu6dac5ab2018-10-26 17:39:23 -07006383 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08006384 * Used for device configuration by some CDMA operators.
6385 *
chen xu6dac5ab2018-10-26 17:39:23 -07006386 * @param slotIndex - device slot.
6387 *
Jake Hambye994d462014-02-03 13:10:13 -08006388 * @return true on success; false on any failure
6389 */
6390 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07006391 public boolean resetModemConfig(int slotIndex) {
6392 Phone phone = PhoneFactory.getPhone(slotIndex);
6393 if (phone != null) {
6394 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6395 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006396
chen xu6dac5ab2018-10-26 17:39:23 -07006397 final long identity = Binder.clearCallingIdentity();
6398 try {
6399 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
6400 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
6401 return success;
6402 } finally {
6403 Binder.restoreCallingIdentity(identity);
6404 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405 }
chen xu6dac5ab2018-10-26 17:39:23 -07006406 return false;
6407 }
6408
6409 /**
6410 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
6411 *
6412 * @param slotIndex - device slot.
6413 *
6414 * @return true on success; false on any failure
6415 */
6416 @Override
6417 public boolean rebootModem(int slotIndex) {
6418 Phone phone = PhoneFactory.getPhone(slotIndex);
6419 if (phone != null) {
6420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6421 mApp, phone.getSubId(), "rebootModem");
6422
6423 final long identity = Binder.clearCallingIdentity();
6424 try {
6425 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
6426 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
6427 return success;
6428 } finally {
6429 Binder.restoreCallingIdentity(identity);
6430 }
6431 }
6432 return false;
Jake Hambye994d462014-02-03 13:10:13 -08006433 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006434
Brad Ebinger51f743a2017-01-23 13:50:20 -08006435 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006436 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
6437 * {@link #disableIms(int)}.
6438 * @param slotIndex device slot.
6439 */
6440 public void resetIms(int slotIndex) {
6441 enforceModifyPermission();
6442
6443 final long identity = Binder.clearCallingIdentity();
6444 try {
6445 if (mImsResolver == null) {
6446 // may happen if the does not support IMS.
6447 return;
6448 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00006449 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08006450 } finally {
6451 Binder.restoreCallingIdentity(identity);
6452 }
6453 }
6454
6455 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006456 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
6457 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08006458 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006459 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08006460 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006461
6462 final long identity = Binder.clearCallingIdentity();
6463 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006464 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006465 // may happen if the device does not support IMS.
6466 return;
6467 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006468 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006469 } finally {
6470 Binder.restoreCallingIdentity(identity);
6471 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006472 }
6473
6474 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006475 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
6476 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08006477 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006478 public void disableIms(int slotId) {
6479 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006480
6481 final long identity = Binder.clearCallingIdentity();
6482 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006483 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006484 // may happen if the device does not support IMS.
6485 return;
6486 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006487 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006488 } finally {
6489 Binder.restoreCallingIdentity(identity);
6490 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006491 }
6492
6493 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07006494 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
6495 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006496 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006497 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07006498 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08006499 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006500
6501 final long identity = Binder.clearCallingIdentity();
6502 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006503 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07006504 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6505 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006506 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07006507 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006508 } finally {
6509 Binder.restoreCallingIdentity(identity);
6510 }
Brad Ebinger34bef922017-11-09 10:27:08 -08006511 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006512 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006513 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
6514 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07006515 @Override
6516 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006517 enforceModifyPermission();
6518
6519 final long identity = Binder.clearCallingIdentity();
6520 try {
6521 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07006522 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07006523 } finally {
6524 Binder.restoreCallingIdentity(identity);
6525 }
6526 }
6527
6528 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08006529 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006530 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08006531 */
6532 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
6533 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006534
6535 final long identity = Binder.clearCallingIdentity();
6536 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006537 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006538 // may happen if the device does not support IMS.
6539 return null;
6540 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006541 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006542 } finally {
6543 Binder.restoreCallingIdentity(identity);
6544 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08006545 }
6546
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006547 /**
6548 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006549 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006550 */
6551 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
6552 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006553
6554 final long identity = Binder.clearCallingIdentity();
6555 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006556 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006557 // may happen if the device does not support IMS.
6558 return null;
6559 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006560 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006561 } finally {
6562 Binder.restoreCallingIdentity(identity);
6563 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08006564 }
6565
Brad Ebinger884c07b2018-02-15 16:17:40 -08006566 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07006567 * Sets the ImsService Package Name that Telephony will bind to.
6568 *
Brad Ebinger24c29992019-12-05 13:03:21 -08006569 * @param slotIndex the slot ID that the ImsService should bind for.
6570 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07006571 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08006572 * @param featureTypes An integer array of feature types associated with a packageName.
6573 * @param packageName The name of the package that the current configuration will be replaced
6574 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006575 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006576 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006577 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
6578 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006579 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006581 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07006582
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006583 final long identity = Binder.clearCallingIdentity();
6584 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006585 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006586 // may happen if the device does not support IMS.
6587 return false;
6588 }
Brad Ebinger24c29992019-12-05 13:03:21 -08006589 Map<Integer, String> featureConfig = new HashMap<>();
6590 for (int featureType : featureTypes) {
6591 featureConfig.put(featureType, packageName);
6592 }
6593 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
6594 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006595 } finally {
6596 Binder.restoreCallingIdentity(identity);
6597 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006598 }
6599
6600 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006601 * Clears any carrier ImsService overrides for the slot index specified that were previously
6602 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6603 *
6604 * This should only be used for testing.
6605 *
6606 * @param slotIndex the slot ID that the ImsService should bind for.
6607 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6608 */
6609 @Override
6610 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08006611 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6612 "clearCarrierImsServiceOverride");
6613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yu00ece8c2022-11-19 22:29:12 -08006614 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08006615
6616 final long identity = Binder.clearCallingIdentity();
6617 try {
6618 if (mImsResolver == null) {
6619 // may happen if the device does not support IMS.
6620 return false;
6621 }
6622 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6623 } finally {
6624 Binder.restoreCallingIdentity(identity);
6625 }
6626 }
6627
6628 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006629 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006630 *
6631 * @param slotId The slot that the ImsService is associated with.
6632 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6633 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006634 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006635 * @return the package name of the ImsService configuration.
6636 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006637 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6638 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08006639 TelephonyPermissions
Jack Yu00ece8c2022-11-19 22:29:12 -08006640 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
6641 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006642
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006643 final long identity = Binder.clearCallingIdentity();
6644 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006645 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006646 // may happen if the device does not support IMS.
6647 return "";
6648 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006649 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006650 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6651 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006652 } finally {
6653 Binder.restoreCallingIdentity(identity);
6654 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006655 }
6656
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006657 /**
6658 * Get the MmTelFeature state associated with the requested subscription id.
6659 * @param subId The subscription that the MmTelFeature is associated with.
6660 * @param callback A callback with an integer containing the
6661 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6662 */
6663 @Override
6664 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6665 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006666 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6667 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6668 "IMS not available on device.");
6669 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006670 final long token = Binder.clearCallingIdentity();
6671 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006672 int slotId = getSlotIndex(subId);
6673 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6674 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6675 + subId + "'");
6676 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6677 }
6678 verifyImsMmTelConfiguredOrThrow(slotId);
6679 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6680 try {
6681 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6682 } catch (RemoteException e) {
6683 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6684 + "Ignore");
6685 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006686 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006687 } catch (ImsException e) {
6688 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006689 } finally {
6690 Binder.restoreCallingIdentity(token);
6691 }
6692 }
6693
Daniel Brightbb5840b2021-01-12 15:48:18 -08006694 /**
6695 * Sets the ims registration state on all valid {@link Phone}s.
6696 */
6697 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006698 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006699
6700 final long identity = Binder.clearCallingIdentity();
6701 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006702 // NOTE: Before S, this method only set the default phone.
6703 for (final Phone phone : PhoneFactory.getPhones()) {
6704 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6705 phone.setImsRegistrationState(registered);
6706 }
6707 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006708 } finally {
6709 Binder.restoreCallingIdentity(identity);
6710 }
Wink Saville36469e72014-06-11 15:17:00 -07006711 }
6712
6713 /**
Stuart Scott54788802015-03-30 13:18:01 -07006714 * Set the network selection mode to automatic.
6715 *
6716 */
6717 @Override
6718 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006719 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6720 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006721
6722 final long identity = Binder.clearCallingIdentity();
6723 try {
shilufc958392020-01-20 11:36:01 -08006724 if (!isActiveSubscription(subId)) {
6725 return;
6726 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006727 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006728 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6729 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006730 } finally {
6731 Binder.restoreCallingIdentity(identity);
6732 }
Stuart Scott54788802015-03-30 13:18:01 -07006733 }
6734
Jack Yud10cdd42020-09-28 20:28:01 -07006735 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006736 * Ask the radio to connect to the input network and change selection mode to manual.
6737 *
6738 * @param subId the id of the subscription.
6739 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6740 * the operator to attach to.
6741 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6742 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6743 * normal network selection next time.
6744 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006745 */
6746 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006747 public boolean setNetworkSelectionModeManual(
6748 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6750 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006751
Jack Yu285100e2022-12-02 22:48:35 -08006752 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07006753 if (!isActiveSubscription(subId)) {
6754 return false;
6755 }
6756
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006757 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006758 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006759 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006760 if (DBG) {
6761 log("setNetworkSelectionModeManual: subId: " + subId
6762 + " operator: " + operatorInfo);
6763 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006764 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6765 } finally {
6766 Binder.restoreCallingIdentity(identity);
6767 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006768 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006769 /**
shilu84f6e8b2019-12-19 13:58:01 -08006770 * Get the manual network selection
6771 *
6772 * @param subId the id of the subscription.
6773 *
6774 * @return the previously saved user selected PLMN
6775 */
6776 @Override
6777 public String getManualNetworkSelectionPlmn(int subId) {
6778 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006779 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6780 mApp, subId, "getManualNetworkSelectionPlmn");
shilu84f6e8b2019-12-19 13:58:01 -08006781
6782 final long identity = Binder.clearCallingIdentity();
6783 try {
6784 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006785 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006786 }
6787
6788 final Phone phone = getPhone(subId);
6789 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006790 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006791 }
6792 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6793 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006794 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
shilu84f6e8b2019-12-19 13:58:01 -08006795 } finally {
6796 Binder.restoreCallingIdentity(identity);
6797 }
6798 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006799
6800 /**
6801 * Scans for available networks.
6802 */
6803 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006804 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6805 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006806 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6807 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006808 LocationAccessPolicy.LocationPermissionResult locationResult =
6809 LocationAccessPolicy.checkLocationPermission(mApp,
6810 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6811 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006812 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006813 .setCallingPid(Binder.getCallingPid())
6814 .setCallingUid(Binder.getCallingUid())
6815 .setMethod("getCellNetworkScanResults")
6816 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006817 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6818 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006819 .build());
6820 switch (locationResult) {
6821 case DENIED_HARD:
6822 throw new SecurityException("Not allowed to access scan results -- location");
6823 case DENIED_SOFT:
6824 return null;
6825 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006826
Pengquan Menga1bb6272018-09-06 09:59:22 -07006827 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006828 try {
6829 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006830 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006831 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006832 } finally {
6833 Binder.restoreCallingIdentity(identity);
6834 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006835 }
6836
6837 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006838 * Get the call forwarding info, given the call forwarding reason.
6839 */
6840 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006841 public void getCallForwarding(int subId, int callForwardingReason,
6842 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006843 enforceReadPrivilegedPermission("getCallForwarding");
6844 long identity = Binder.clearCallingIdentity();
6845 try {
6846 if (DBG) {
6847 log("getCallForwarding: subId " + subId
6848 + " callForwardingReason" + callForwardingReason);
6849 }
Hall Liu27d24262020-09-18 19:04:59 -07006850
6851 Phone phone = getPhone(subId);
6852 if (phone == null) {
6853 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006854 callback.onError(
6855 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006856 } catch (RemoteException e) {
6857 // ignore
6858 }
6859 return;
6860 }
6861
6862 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6863 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6864 @Override
6865 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6866 try {
6867 callback.onCallForwardingInfoAvailable(info);
6868 } catch (RemoteException e) {
6869 // ignore
6870 }
6871 }
6872
6873 @Override
6874 public void onError(int error) {
6875 try {
6876 callback.onError(error);
6877 } catch (RemoteException e) {
6878 // ignore
6879 }
6880 }
6881 });
6882 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006883 } finally {
6884 Binder.restoreCallingIdentity(identity);
6885 }
6886 }
6887
6888 /**
6889 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6890 * reason, the number to forward, and the timeout before the forwarding is attempted.
6891 */
6892 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006893 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6894 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006895 enforceModifyPermission();
6896 long identity = Binder.clearCallingIdentity();
6897 try {
6898 if (DBG) {
6899 log("setCallForwarding: subId " + subId
6900 + " callForwardingInfo" + callForwardingInfo);
6901 }
Hall Liu27d24262020-09-18 19:04:59 -07006902
6903 Phone phone = getPhone(subId);
6904 if (phone == null) {
6905 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006906 callback.accept(
6907 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006908 } catch (RemoteException e) {
6909 // ignore
6910 }
6911 return;
6912 }
6913
6914 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6915 FunctionalUtils.ignoreRemoteException(callback::accept));
6916
6917 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006918 } finally {
6919 Binder.restoreCallingIdentity(identity);
6920 }
6921 }
6922
6923 /**
Hall Liu27d24262020-09-18 19:04:59 -07006924 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006925 */
6926 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006927 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006928 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006929 long identity = Binder.clearCallingIdentity();
6930 try {
Hall Liu27d24262020-09-18 19:04:59 -07006931 Phone phone = getPhone(subId);
6932 if (phone == null) {
6933 try {
6934 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6935 } catch (RemoteException e) {
6936 // ignore
6937 }
6938 return;
6939 }
SongFerngWang0e767992021-03-31 22:08:45 +08006940 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6941 PersistableBundle c = configManager.getConfigForSubId(subId);
6942 boolean requireUssd = c.getBoolean(
6943 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006944
Shuo Qian4a594052020-01-23 11:59:30 -08006945 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006946 if (requireUssd) {
6947 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6948 getSubscriptionCarrierId(subId));
6949 String newUssdCommand = "";
6950 try {
6951 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08006952 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08006953 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6954 } catch (NullPointerException e) {
6955 loge("Failed to generate USSD number" + e);
6956 }
6957 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6958 mMainThreadHandler, callback, carrierXmlParser,
6959 CarrierXmlParser.SsEntry.SSAction.QUERY);
6960 final String ussdCommand = newUssdCommand;
6961 Executors.newSingleThreadExecutor().execute(() -> {
6962 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6963 });
6964 } else {
6965 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6966 callback::accept);
6967 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6968 }
Shuo Qian4a594052020-01-23 11:59:30 -08006969 } finally {
6970 Binder.restoreCallingIdentity(identity);
6971 }
6972 }
6973
6974 /**
Hall Liu27d24262020-09-18 19:04:59 -07006975 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006976 */
6977 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006978 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006979 enforceModifyPermission();
6980 long identity = Binder.clearCallingIdentity();
6981 try {
Hall Liu27d24262020-09-18 19:04:59 -07006982 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6983
6984 Phone phone = getPhone(subId);
6985 if (phone == null) {
6986 try {
6987 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6988 } catch (RemoteException e) {
6989 // ignore
6990 }
6991 return;
6992 }
6993
SongFerngWang0e767992021-03-31 22:08:45 +08006994 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6995 PersistableBundle c = configManager.getConfigForSubId(subId);
6996 boolean requireUssd = c.getBoolean(
6997 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006998
SongFerngWang0e767992021-03-31 22:08:45 +08006999 if (DBG) log("getCallWaitingStatus: subId " + subId);
7000 if (requireUssd) {
7001 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
7002 getSubscriptionCarrierId(subId));
7003 CarrierXmlParser.SsEntry.SSAction ssAction =
7004 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
7005 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
7006 String newUssdCommand = "";
7007 try {
7008 newUssdCommand = carrierXmlParser.getFeature(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007009 CarrierXmlParser.FEATURE_CALL_WAITING)
SongFerngWang0e767992021-03-31 22:08:45 +08007010 .makeCommand(ssAction, null);
7011 } catch (NullPointerException e) {
7012 loge("Failed to generate USSD number" + e);
7013 }
7014 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
7015 mMainThreadHandler, callback, carrierXmlParser, ssAction);
7016 final String ussdCommand = newUssdCommand;
7017 Executors.newSingleThreadExecutor().execute(() -> {
7018 handleUssdRequest(subId, ussdCommand, wrappedCallback);
7019 });
7020 } else {
7021 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
7022 FunctionalUtils.ignoreRemoteException(callback::accept));
7023
7024 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
7025 }
Shuo Qian4a594052020-01-23 11:59:30 -08007026 } finally {
7027 Binder.restoreCallingIdentity(identity);
7028 }
7029 }
7030
7031 /**
yinxub1bed742017-04-17 11:45:04 -07007032 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07007033 *
yinxub1bed742017-04-17 11:45:04 -07007034 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007035 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
7036 * location related information which will be sent if the caller already possess
7037 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07007038 * @param request contains the radio access networks with bands/channels to scan
7039 * @param messenger callback messenger for scan results or errors
7040 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07007041 * @return the id of the requested scan which can be used to stop the scan.
7042 */
7043 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007044 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
7045 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007046 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007047 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7048 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08007049 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007050 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
7051 if (!renounceFineLocationAccess) {
7052 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007053 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7054 .setCallingPackage(callingPackage)
7055 .setCallingFeatureId(callingFeatureId)
7056 .setCallingPid(Binder.getCallingPid())
7057 .setCallingUid(Binder.getCallingUid())
7058 .setMethod("requestNetworkScan")
7059 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7060 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7061 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7062 .build());
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007063 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08007064 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07007065 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
7066 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08007067 if (e != null) {
7068 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
7069 throw e;
7070 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07007071 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08007072 return TelephonyScanManager.INVALID_SCAN_ID;
7073 }
7074 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007075 }
Hall Liu912dfd32019-04-25 14:02:26 -07007076 int callingUid = Binder.getCallingUid();
7077 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07007078 final long identity = Binder.clearCallingIdentity();
7079 try {
7080 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007081 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07007082 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07007083 } finally {
7084 Binder.restoreCallingIdentity(identity);
7085 }
yinxu504e1392017-04-12 16:03:22 -07007086 }
7087
Hall Liub2ac8ef2019-02-28 15:56:23 -08007088 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07007089 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00007090 boolean hasCarrierPriv;
7091 final long identity = Binder.clearCallingIdentity();
7092 try {
7093 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
7094 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
7095 } finally {
7096 Binder.restoreCallingIdentity(identity);
7097 }
Hall Liu558027f2019-05-15 19:14:05 -07007098 boolean hasNetworkScanPermission =
7099 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08007100 == PERMISSION_GRANTED;
Hall Liu558027f2019-05-15 19:14:05 -07007101
7102 if (!hasCarrierPriv && !hasNetworkScanPermission) {
7103 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
7104 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08007105 }
7106
7107 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
7108 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08007109 if (ras.getChannels() != null && ras.getChannels().length > 0) {
7110 return new SecurityException("Specific channels must not be"
7111 + " scanned without location access.");
7112 }
7113 }
7114 }
7115
Hall Liub2ac8ef2019-02-28 15:56:23 -08007116 return null;
7117 }
7118
yinxu504e1392017-04-12 16:03:22 -07007119 /**
7120 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07007121 *
7122 * @param subId id of the subscription
7123 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07007124 */
7125 @Override
7126 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007127 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7128 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007129
Hall Liu912dfd32019-04-25 14:02:26 -07007130 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007131 final long identity = Binder.clearCallingIdentity();
7132 try {
Hall Liu912dfd32019-04-25 14:02:26 -07007133 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007134 } finally {
7135 Binder.restoreCallingIdentity(identity);
7136 }
yinxu504e1392017-04-12 16:03:22 -07007137 }
7138
7139 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08007140 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07007141 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08007142 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07007143 */
7144 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08007145 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08007146 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007147 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08007148 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007149
7150 final long identity = Binder.clearCallingIdentity();
7151 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007152 if (DBG) log("getAllowedNetworkTypesBitmask");
7153 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
7154 int networkTypesBitmask = (result != null ? result[0] : -1);
7155 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
7156 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007157 } finally {
7158 Binder.restoreCallingIdentity(identity);
7159 }
Jake Hamby7c27be32014-03-03 13:25:59 -08007160 }
7161
7162 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007163 * Get the allowed network types for certain reason.
7164 *
7165 * @param subId the id of the subscription.
7166 * @param reason the reason the allowed network type change is taking place
7167 * @return the allowed network types.
7168 */
7169 @Override
7170 public long getAllowedNetworkTypesForReason(int subId,
7171 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07007172 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007173 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007174 final long identity = Binder.clearCallingIdentity();
7175 try {
7176 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
7177 } finally {
7178 Binder.restoreCallingIdentity(identity);
7179 }
7180 }
7181
7182 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07007183 * Enable/Disable E-UTRA-NR Dual Connectivity
7184 * @param subId subscription id of the sim card
7185 * @param nrDualConnectivityState expected NR dual connectivity state
7186 * This can be passed following states
7187 * <ol>
7188 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
7189 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
7190 * <li>Disable NR dual connectivity and force secondary cell to be released
7191 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
7192 * </ol>
7193 * @return operation result.
7194 */
7195 @Override
7196 public int setNrDualConnectivityState(int subId,
7197 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
7198 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7199 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007200 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007201 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7202 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
7203 }
7204
Sooraj Sasindran37444802020-08-11 10:40:43 -07007205 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7206 final long identity = Binder.clearCallingIdentity();
7207 try {
7208 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
7209 nrDualConnectivityState, subId,
7210 workSource);
7211 if (DBG) log("enableNRDualConnectivity result: " + result);
7212 return result;
7213 } finally {
7214 Binder.restoreCallingIdentity(identity);
7215 }
7216 }
7217
7218 /**
7219 * Is E-UTRA-NR Dual Connectivity enabled
7220 * @return true if dual connectivity is enabled else false
7221 */
7222 @Override
7223 public boolean isNrDualConnectivityEnabled(int subId) {
7224 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007225 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07007226 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07007227 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08007228 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
7229 return false;
7230 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07007231 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7232 final long identity = Binder.clearCallingIdentity();
7233 try {
7234 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
7235 null, subId, workSource);
7236 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
7237 return isEnabled;
7238 } finally {
7239 Binder.restoreCallingIdentity(identity);
7240 }
7241 }
7242
7243 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007244 * Set the allowed network types of the device and
7245 * provide the reason triggering the allowed network change.
7246 *
7247 * @param subId the id of the subscription.
7248 * @param reason the reason the allowed network type change is taking place
7249 * @param allowedNetworkTypes the allowed network types.
7250 * @return true on success; false on any failure.
7251 */
7252 @Override
7253 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08007254 @TelephonyManager.AllowedNetworkTypesReason int reason,
7255 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007256 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7257 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007258 // If the caller only has carrier privileges, then they should not be able to override
7259 // any network types which were set for security reasons.
7260 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
7261 != PERMISSION_GRANTED
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007262 && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) {
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007263 throw new SecurityException(
7264 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
Gil Cukierman2a8f48b2023-01-26 20:26:20 +00007265 + " reason " + reason);
Gil Cukierman1d3d3752022-10-03 21:31:33 +00007266 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08007267 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007268 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
SongFerngWang7ffc2732021-04-15 19:46:33 +08007269 return false;
7270 }
7271 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
7272 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08007273 return false;
7274 }
7275
Jack Yu5b494332023-01-23 18:18:04 +00007276 log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: "
7277 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007278
Jack Yue37dd262022-12-16 11:53:37 -08007279 Phone phone = getPhone(subId);
7280 if (phone == null) {
7281 return false;
7282 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007283
Jack Yue37dd262022-12-16 11:53:37 -08007284 if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) {
Jack Yu5b494332023-01-23 18:18:04 +00007285 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007286 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08007287 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007288
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007289 final long identity = Binder.clearCallingIdentity();
7290 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08007291 Boolean success = (Boolean) sendRequest(
7292 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
7293 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
7294
7295 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
7296 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07007297 } finally {
7298 Binder.restoreCallingIdentity(identity);
7299 }
7300 }
7301
7302 /**
Miaoa84611c2019-03-15 09:21:10 +08007303 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08007304 *
Miaoa84611c2019-03-15 09:21:10 +08007305 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07007306 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08007307 * @hide
7308 */
7309 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08007310 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007311 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007312 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08007313 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007314 try {
Miaoa84611c2019-03-15 09:21:10 +08007315 if (phone != null) {
7316 return phone.hasMatchedTetherApnSetting();
7317 } else {
7318 return false;
7319 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007320 } finally {
7321 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08007322 }
Junda Liu475951f2014-11-07 16:45:03 -08007323 }
7324
7325 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08007326 * Get the user enabled state of Mobile Data.
7327 *
7328 * TODO: remove and use isUserDataEnabled.
7329 * This can't be removed now because some vendor codes
7330 * calls through ITelephony directly while they should
7331 * use TelephonyManager.
7332 *
7333 * @return true on enabled
7334 */
7335 @Override
7336 public boolean getDataEnabled(int subId) {
7337 return isUserDataEnabled(subId);
7338 }
7339
7340 /**
7341 * Get whether mobile data is enabled per user setting.
7342 *
7343 * There are other factors deciding whether mobile data is actually enabled, but they are
7344 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07007345 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007346 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
7347 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07007348 *
7349 * @return {@code true} if data is enabled else {@code false}
7350 */
7351 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08007352 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007353 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07007354 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007355 try {
7356 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7357 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007358 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007359 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
7360 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007361 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007362 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007363 mApp, subId, functionName);
7364
Robert Greenwalt646120a2014-05-23 11:54:03 -07007365 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366
7367 final long identity = Binder.clearCallingIdentity();
7368 try {
Jack Yu285100e2022-12-02 22:48:35 -08007369 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007370 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
7371 Phone phone = PhoneFactory.getPhone(phoneId);
7372 if (phone != null) {
7373 boolean retVal = phone.isUserDataEnabled();
7374 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
7375 return retVal;
7376 } else {
7377 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
7378 return false;
7379 }
7380 } finally {
7381 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08007382 }
7383 }
7384
7385 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08007386 * Checks if the device is capable of mobile data by considering whether whether the
7387 * user has enabled mobile data, whether the carrier has enabled mobile data, and
7388 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08007389 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08007390 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08007391 */
7392 @Override
7393 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007394 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007395 try {
7396 try {
7397 mApp.enforceCallingOrSelfPermission(
7398 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007399 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007400 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007401 try {
7402 mApp.enforceCallingOrSelfPermission(
7403 android.Manifest.permission.READ_PHONE_STATE,
7404 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007405 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007406 mApp.enforceCallingOrSelfPermission(
7407 permission.READ_BASIC_PHONE_STATE, functionName);
7408 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007409 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007410 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007411 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007412 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007413
7414 final long identity = Binder.clearCallingIdentity();
7415 try {
Jack Yu285100e2022-12-02 22:48:35 -08007416 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007417 Phone phone = PhoneFactory.getPhone(phoneId);
7418 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07007419 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08007420 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007421 return retVal;
7422 } else {
7423 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
7424 return false;
7425 }
7426 } finally {
7427 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08007428 }
Robert Greenwalted86e582014-05-21 20:03:20 -07007429 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007430
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007431 /**
7432 * Check if data is enabled for a specific reason
7433 * @param subId Subscription index
7434 * @param reason the reason the data enable change is taking place
7435 * @return {@code true} if the overall data is enabled; {@code false} if not.
7436 */
7437 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007438 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007439 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007440 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007441 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007442 try {
7443 mApp.enforceCallingOrSelfPermission(
7444 android.Manifest.permission.ACCESS_NETWORK_STATE,
7445 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007446 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007447 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
7448 functionName);
7449 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007450 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007451 try {
7452 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007453 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07007454 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07007456 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08007457 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007458 }
7459
7460
7461 final long identity = Binder.clearCallingIdentity();
7462 try {
Jack Yu285100e2022-12-02 22:48:35 -08007463 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007464 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007465 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007466 + " reason=" + reason);
7467 }
7468 Phone phone = PhoneFactory.getPhone(phoneId);
7469 if (phone != null) {
7470 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07007471 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007472 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007473 return retVal;
7474 } else {
7475 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007476 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007477 + subId + " retVal=false");
7478 }
7479 return false;
7480 }
7481 } finally {
7482 Binder.restoreCallingIdentity(identity);
7483 }
7484 }
7485
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007486 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007487 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007488 // No permission needed; this only lets the caller inspect their own status.
7489 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07007490 }
Junda Liu29340342014-07-10 15:23:27 -07007491
7492 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08007493 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007494 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007495 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
7496 }
7497
7498 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
7499 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007500 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09007501 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007502 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7503 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007504 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7505 if (cpt == null) {
7506 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08007507 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7508 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007509 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08007510 }
7511
7512 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007513 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07007514 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07007515 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007516 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07007517 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007518 Phone phone = getPhone(subId);
7519 if (phone == null) {
7520 loge("checkCarrierPrivilegesForPackage: Invalid subId");
7521 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
7522 }
7523 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7524 if (cpt == null) {
7525 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07007526 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
7527 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007528 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007529 }
7530
7531 @Override
7532 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007533 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08007534 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
7535 }
7536
7537 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007538 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08007539 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007540 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007541 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007542 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
7543 Phone phone = PhoneFactory.getPhone(phoneId);
7544 if (phone == null) {
7545 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07007546 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007547 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7548 if (cpt == null) {
7549 continue;
7550 }
7551 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07007552 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7553 break;
7554 }
7555 }
Zach Johnson50ecba32015-05-19 00:24:21 -07007556 return result;
Junda Liu29340342014-07-10 15:23:27 -07007557 }
Derek Tan89e89d42014-07-08 17:00:10 -07007558
7559 @Override
Junda Liue64de782015-04-16 17:19:16 -07007560 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007561 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00007562 Phone phone = PhoneFactory.getPhone(phoneId);
7563 if (phone == null) {
7564 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07007565 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007566 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7567 if (cpt == null) {
7568 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007569 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00007570 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007571 }
7572
Amith Yamasani6e118872016-02-19 12:53:51 -08007573 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07007574 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07007575 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007576 Phone phone = PhoneFactory.getPhone(phoneId);
7577 if (phone == null) {
7578 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08007579 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007580 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7581 if (cpt == null) {
7582 return Collections.emptyList();
7583 }
7584 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08007585 }
7586
chen xuf7e9fe82019-05-09 19:31:02 -07007587 @Override
7588 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00007589 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007590 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00007591 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00007592 try {
7593 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
7594 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
7595 }
7596 } finally {
7597 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07007598 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08007599 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07007600 }
7601
Rambo Wang6812ffb2022-03-15 16:54:17 -07007602 @Override
7603 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
7604 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
7605
7606 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7607 if (phone == null) {
7608 return null;
7609 }
7610 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7611 if (cpt == null) {
7612 return null;
7613 }
7614 return cpt.getCarrierServicePackageName();
7615 }
7616
Wink Savilleb564aae2014-10-23 10:18:09 -07007617 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007618 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007619 UiccPort port = phone == null ? null : phone.getUiccPort();
7620 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007621 return null;
7622 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007623 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007624 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007625 return null;
7626 }
7627 return iccId;
7628 }
7629
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007630 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007631 public void setCallComposerStatus(int subId, int status) {
7632 enforceModifyPermission();
7633
7634 final long identity = Binder.clearCallingIdentity();
7635 try {
7636 Phone phone = getPhone(subId);
7637 if (phone != null) {
7638 Phone defaultPhone = phone.getImsPhone();
7639 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7640 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7641 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007642 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7643 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007644 }
7645 }
Shuo Qian284ae752020-12-22 19:10:14 -08007646 } catch (ImsException e) {
7647 throw new ServiceSpecificException(e.getCode());
7648 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007649 Binder.restoreCallingIdentity(identity);
7650 }
7651 }
7652
7653 @Override
7654 public int getCallComposerStatus(int subId) {
7655 enforceReadPrivilegedPermission("getCallComposerStatus");
7656
7657 final long identity = Binder.clearCallingIdentity();
7658 try {
7659 Phone phone = getPhone(subId);
7660 if (phone != null) {
7661 Phone defaultPhone = phone.getImsPhone();
7662 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7663 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7664 return imsPhone.getCallComposerStatus();
7665 }
7666 }
7667 } finally {
7668 Binder.restoreCallingIdentity(identity);
7669 }
7670 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7671 }
7672
7673 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007674 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7675 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007676 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007677 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007678
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007679 final long identity = Binder.clearCallingIdentity();
7680 try {
7681 final String iccId = getIccId(subId);
7682 final Phone phone = getPhone(subId);
7683 if (phone == null) {
7684 return false;
7685 }
7686 final String subscriberId = phone.getSubscriberId();
7687
7688 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007689 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007690 + subscriberId + " to " + number);
7691 }
7692
7693 if (TextUtils.isEmpty(iccId)) {
7694 return false;
7695 }
7696
7697 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7698
7699 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7700 if (alphaTag == null) {
7701 editor.remove(alphaTagPrefKey);
7702 } else {
7703 editor.putString(alphaTagPrefKey, alphaTag);
7704 }
7705
7706 // Record both the line number and IMSI for this ICCID, since we need to
7707 // track all merged IMSIs based on line number
7708 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7709 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7710 if (number == null) {
7711 editor.remove(numberPrefKey);
7712 editor.remove(subscriberPrefKey);
7713 } else {
7714 editor.putString(numberPrefKey, number);
7715 editor.putString(subscriberPrefKey, subscriberId);
7716 }
7717
7718 editor.commit();
7719 return true;
7720 } finally {
7721 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007722 }
Derek Tan7226c842014-07-02 17:42:23 -07007723 }
7724
7725 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007726 public String getLine1NumberForDisplay(int subId, String callingPackage,
7727 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007728 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007729 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007730 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007731 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007732 return null;
7733 }
Derek Tan97ebb422014-09-05 16:55:38 -07007734
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007735 final long identity = Binder.clearCallingIdentity();
7736 try {
7737 String iccId = getIccId(subId);
7738 if (iccId != null) {
7739 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7740 if (DBG_MERGE) {
7741 log("getLine1NumberForDisplay returning "
7742 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7743 }
7744 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007745 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007746 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7747 return null;
7748 } finally {
7749 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007750 }
Derek Tan7226c842014-07-02 17:42:23 -07007751 }
7752
7753 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007754 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7755 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007756 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007757 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007758 return null;
7759 }
Derek Tan97ebb422014-09-05 16:55:38 -07007760
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007761 final long identity = Binder.clearCallingIdentity();
7762 try {
7763 String iccId = getIccId(subId);
7764 if (iccId != null) {
7765 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7766 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7767 }
7768 return null;
7769 } finally {
7770 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007771 }
Derek Tan7226c842014-07-02 17:42:23 -07007772 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007773
7774 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007775 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7776 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007777 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7778 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007779 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007780 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007781 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007782 return null;
7783 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007784
Jordan Liub49b04b2019-05-06 14:45:15 -07007785 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7786 // the process, where TelephonyManager was instantiated.
7787 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007788 final long identity = Binder.clearCallingIdentity();
7789 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007790 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007791 final TelephonyManager tele = TelephonyManager.from(context);
7792 final SubscriptionManager sub = SubscriptionManager.from(context);
7793
7794 // Figure out what subscribers are currently active
7795 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007796
Jordan Liub49b04b2019-05-06 14:45:15 -07007797 // Only consider subs which match the current subId
7798 // This logic can be simplified. See b/131189269 for progress.
7799 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007800 activeSubscriberIds.add(tele.getSubscriberId(subId));
7801 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007802
7803 // First pass, find a number override for an active subscriber
7804 String mergeNumber = null;
7805 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7806 for (String key : prefs.keySet()) {
7807 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7808 final String subscriberId = (String) prefs.get(key);
7809 if (activeSubscriberIds.contains(subscriberId)) {
7810 final String iccId = key.substring(
7811 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7812 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7813 mergeNumber = (String) prefs.get(numberKey);
7814 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007815 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007816 + " for active subscriber " + subscriberId);
7817 }
7818 if (!TextUtils.isEmpty(mergeNumber)) {
7819 break;
7820 }
7821 }
7822 }
7823 }
7824
7825 // Shortcut when no active merged subscribers
7826 if (TextUtils.isEmpty(mergeNumber)) {
7827 return null;
7828 }
7829
7830 // Second pass, find all subscribers under that line override
7831 final ArraySet<String> result = new ArraySet<>();
7832 for (String key : prefs.keySet()) {
7833 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7834 final String number = (String) prefs.get(key);
7835 if (mergeNumber.equals(number)) {
7836 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7837 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7838 final String subscriberId = (String) prefs.get(subscriberKey);
7839 if (!TextUtils.isEmpty(subscriberId)) {
7840 result.add(subscriberId);
7841 }
7842 }
7843 }
7844 }
7845
7846 final String[] resultArray = result.toArray(new String[result.size()]);
7847 Arrays.sort(resultArray);
7848 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007849 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007850 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7851 }
7852 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007853 } finally {
7854 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007855 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007856 }
7857
7858 @Override
zoey chen38003472019-12-13 17:16:31 +08007859 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7860 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007861
7862 final long identity = Binder.clearCallingIdentity();
7863 try {
7864 final TelephonyManager telephonyManager = mApp.getSystemService(
7865 TelephonyManager.class);
7866 String subscriberId = telephonyManager.getSubscriberId(subId);
7867 if (subscriberId == null) {
7868 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007869 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007870 + subId);
7871 }
7872 return null;
7873 }
7874
Jack Yu285100e2022-12-02 22:48:35 -08007875 ParcelUuid groupUuid;
7876 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08007877 final SubscriptionInfo info = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08007878 .getSubscriptionInfo(subId);
7879 groupUuid = info.getGroupUuid();
7880 } else {
7881 final SubscriptionInfo info = mSubscriptionController
7882 .getSubscriptionInfo(subId);
7883 groupUuid = info.getGroupUuid();
7884 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007885 // If it doesn't belong to any group, return just subscriberId of itself.
7886 if (groupUuid == null) {
7887 return new String[]{subscriberId};
7888 }
7889
7890 // Get all subscriberIds from the group.
7891 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yu285100e2022-12-02 22:48:35 -08007892 List<SubscriptionInfo> groupInfos;
7893 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08007894 groupInfos = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08007895 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7896 mApp.getAttributionTag());
7897 } else {
7898 groupInfos = mSubscriptionController
7899 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7900 mApp.getAttributionTag());
7901 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007902 for (SubscriptionInfo subInfo : groupInfos) {
7903 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7904 if (subscriberId != null) {
7905 mergedSubscriberIds.add(subscriberId);
7906 }
7907 }
7908
7909 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7910 } finally {
7911 Binder.restoreCallingIdentity(identity);
7912
7913 }
7914 }
7915
7916 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007917 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007918 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007919 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007920
7921 final long identity = Binder.clearCallingIdentity();
7922 try {
7923 final Phone phone = getPhone(subId);
7924 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7925 } finally {
7926 Binder.restoreCallingIdentity(identity);
7927 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007928 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007929
7930 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007931 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007932 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7933 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007934 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7935 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007936
7937 final long identity = Binder.clearCallingIdentity();
7938 try {
7939 final Phone phone = getPhone(subId);
7940 if (phone == null) {
7941 return false;
7942 }
7943 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7944 cdmaNonRoamingList);
7945 } finally {
7946 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007947 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007948 }
7949
7950 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007951 @Deprecated
7952 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7953 enforceModifyPermission();
7954
7955 int returnValue = 0;
7956 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007957 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007958 if(result.exception == null) {
7959 if (result.result != null) {
7960 byte[] responseData = (byte[])(result.result);
7961 if(responseData.length > oemResp.length) {
7962 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7963 responseData.length + "bytes. Buffer Size is " +
7964 oemResp.length + "bytes.");
7965 }
7966 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7967 returnValue = responseData.length;
7968 }
7969 } else {
7970 CommandException ex = (CommandException) result.exception;
7971 returnValue = ex.getCommandError().ordinal();
7972 if(returnValue > 0) returnValue *= -1;
7973 }
7974 } catch (RuntimeException e) {
7975 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7976 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7977 if(returnValue > 0) returnValue *= -1;
7978 }
7979
7980 return returnValue;
7981 }
7982
7983 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007984 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007985 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007986 try {
7987 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007988 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007989 mApp, phone.getSubId(), "getRadioAccessFamily");
7990 } catch (SecurityException e) {
7991 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7992 throw e;
7993 }
chen xub97461a2018-10-26 14:17:57 -07007994 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007995 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007996 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007997 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007998 final long identity = Binder.clearCallingIdentity();
7999 try {
chen xub97461a2018-10-26 14:17:57 -07008000 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008001 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07008002 mApp, phone.getSubId(), "getRadioAccessFamily");
8003 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008004 } finally {
8005 Binder.restoreCallingIdentity(identity);
8006 }
chen xub97461a2018-10-26 14:17:57 -07008007 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07008008 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008009
8010 @Override
Hall Liu82694d52020-12-11 18:22:04 -08008011 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08008012 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08008013 try {
8014 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
8015 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008016 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008017 }
8018 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07008019 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08008020 }
8021 RoleManager rm = mApp.getSystemService(RoleManager.class);
8022 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
8023 if (!dialerRoleHolders.contains(callingPackage)) {
8024 throw new SecurityException("App must be the dialer role holder to"
8025 + " upload a call composer pic");
8026 }
8027
8028 Executors.newSingleThreadExecutor().execute(() -> {
8029 ByteArrayOutputStream output = new ByteArrayOutputStream(
8030 (int) TelephonyManager.getMaximumCallComposerPictureSize());
8031 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
8032 boolean readUntilEnd = false;
8033 int totalBytesRead = 0;
8034 byte[] buffer = new byte[16 * 1024];
8035 while (true) {
8036 int numRead;
8037 try {
8038 numRead = input.read(buffer);
8039 } catch (IOException e) {
8040 try {
8041 fd.checkError();
8042 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
8043 null);
8044 } catch (IOException e1) {
8045 // This means that the other side closed explicitly with an error. If this
8046 // happens, log and ignore.
8047 loge("Remote end of call composer picture pipe closed: " + e1);
8048 }
8049 break;
8050 }
8051 if (numRead == -1) {
8052 readUntilEnd = true;
8053 break;
8054 }
8055 totalBytesRead += numRead;
8056 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
8057 loge("Too many bytes read for call composer picture: " + totalBytesRead);
8058 try {
8059 input.close();
8060 } catch (IOException e) {
8061 // ignore
8062 }
8063 break;
8064 }
8065 output.write(buffer, 0, numRead);
8066 }
8067 // Generally, the remote end will close the file descriptors. The only case where we
8068 // close is above, where the picture size is too big.
8069
8070 try {
8071 fd.checkError();
8072 } catch (IOException e) {
8073 loge("Remote end for call composer closed with an error: " + e);
8074 return;
8075 }
8076
Hall Liuaa4211e2021-01-20 15:43:39 -08008077 if (!readUntilEnd) {
8078 loge("Did not finish reading entire image; aborting");
8079 return;
8080 }
Hall Liu82694d52020-12-11 18:22:04 -08008081
Hall Liuaa4211e2021-01-20 15:43:39 -08008082 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
8083 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
8084 new CallComposerPictureTransfer.Factory() {},
8085 imageData,
8086 (result) -> {
8087 if (result.first != null) {
8088 ParcelUuid parcelUuid = new ParcelUuid(result.first);
8089 Bundle outputResult = new Bundle();
8090 outputResult.putParcelable(
8091 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
8092 callback.send(TelephonyManager.CallComposerException.SUCCESS,
8093 outputResult);
8094 } else {
8095 callback.send(result.second, null);
8096 }
8097 }
8098 );
Hall Liu82694d52020-12-11 18:22:04 -08008099 });
8100 }
8101
8102 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07008103 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008104 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07008105 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008106
8107 final long identity = Binder.clearCallingIdentity();
8108 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008109 ImsManager.getInstance(defaultPhone.getContext(),
8110 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008111 } finally {
8112 Binder.restoreCallingIdentity(identity);
8113 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008114 }
8115
8116 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008117 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008118 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008119 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
8120 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00008121 return false;
8122 }
Svet Ganovb320e182015-04-16 12:30:10 -07008123
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008124 final long identity = Binder.clearCallingIdentity();
8125 try {
8126 // Check the user preference and the system-level IMS setting. Even if the user has
8127 // enabled video calling, if IMS is disabled we aren't able to support video calling.
8128 // In the long run, we may instead need to check if there exists a connection service
8129 // which can support video calling.
8130 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008131 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008132 return imsManager.isVtEnabledByPlatform()
8133 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
8134 && imsManager.isVtEnabledByUser();
8135 } finally {
8136 Binder.restoreCallingIdentity(identity);
8137 }
Andrew Leedf14ead2014-10-17 14:22:52 -07008138 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06008139
Andrew Leea1239f22015-03-02 17:44:07 -08008140 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008141 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
8142 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008143 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008144 mApp, subId, callingPackage, callingFeatureId,
8145 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008146 return false;
8147 }
8148
8149 final long identity = Binder.clearCallingIdentity();
8150 try {
8151 CarrierConfigManager configManager =
8152 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008153 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008154 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
8155 } finally {
8156 Binder.restoreCallingIdentity(identity);
8157 }
Andrew Leea1239f22015-03-02 17:44:07 -08008158 }
8159
8160 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008161 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008162 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008163 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008164 return false;
8165 }
8166
8167 final long identity = Binder.clearCallingIdentity();
8168 try {
8169 CarrierConfigManager configManager =
8170 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008171 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008172 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
8173 } finally {
8174 Binder.restoreCallingIdentity(identity);
8175 }
Andrew Leea1239f22015-03-02 17:44:07 -08008176 }
8177
Andrew Lee9431b832015-03-09 18:46:45 -07008178 @Override
8179 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008180 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08008181 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07008182 }
8183
8184 @Override
8185 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008186 final long identity = Binder.clearCallingIdentity();
8187 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008188 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008189 } finally {
8190 Binder.restoreCallingIdentity(identity);
8191 }
Andrew Lee9431b832015-03-09 18:46:45 -07008192 }
8193
Hall Liuf6668912018-10-31 17:05:23 -07008194 /**
8195 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
8196 * support for the feature and device firmware support.
8197 *
8198 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
8199 */
8200 @Override
8201 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008202 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008203 final Phone phone = getPhone(subscriptionId);
8204 if (phone == null) {
8205 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
8206 return false;
8207 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008208 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008209 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008210 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
8211 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008212 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008213 return isCarrierSupported && isDeviceSupported;
8214 } finally {
8215 Binder.restoreCallingIdentity(identity);
8216 }
Hall Liu98187582018-01-22 19:15:32 -08008217 }
8218
Hall Liuf6668912018-10-31 17:05:23 -07008219 /**
Hall Liuf2daa022019-07-23 18:39:00 -07008220 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
8221 * RTT setting, will return true if the device and carrier both support RTT.
8222 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07008223 */
8224 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008225 final long identity = Binder.clearCallingIdentity();
8226 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00008227 boolean isRttSupported = isRttSupported(subscriptionId);
8228 boolean isUserRttSettingOn = Settings.Secure.getInt(
8229 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
8230 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
8231 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
8232 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008233 } finally {
8234 Binder.restoreCallingIdentity(identity);
8235 }
Hall Liu3ad5f012018-04-06 16:23:39 -07008236 }
8237
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008238 @Deprecated
8239 @Override
8240 public String getDeviceId(String callingPackage) {
8241 return getDeviceIdWithFeature(callingPackage, null);
8242 }
8243
Sanket Padawe7310cc72015-01-14 09:53:20 -08008244 /**
8245 * Returns the unique device ID of phone, for example, the IMEI for
8246 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
8247 *
8248 * <p>Requires Permission:
8249 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
8250 */
8251 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008252 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07008253 try {
8254 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
8255 } catch (SecurityException se) {
8256 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
8257 throw new SecurityException("Package " + callingPackage + " does not belong to "
8258 + Binder.getCallingUid());
8259 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008260 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08008261 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08008262 return null;
8263 }
Jeff Davidson913390f2018-02-23 17:11:49 -08008264 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07008265 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008266 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08008267 return null;
8268 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008269
8270 final long identity = Binder.clearCallingIdentity();
8271 try {
8272 return phone.getDeviceId();
8273 } finally {
8274 Binder.restoreCallingIdentity(identity);
8275 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08008276 }
8277
Ping Sunc67b7c22016-03-02 19:16:45 +08008278 /**
8279 * {@hide}
8280 * Returns the IMS Registration Status on a particular subid
8281 *
8282 * @param subId
8283 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008284 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08008285 Phone phone = getPhone(subId);
8286 if (phone != null) {
8287 return phone.isImsRegistered();
8288 } else {
8289 return false;
8290 }
8291 }
8292
Santos Cordon7a1885b2015-02-03 11:15:19 -08008293 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07008294 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008295 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008296 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008297 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07008298 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8299 }
8300 final long identity = Binder.clearCallingIdentity();
8301 try {
8302 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
8303 } finally {
8304 Binder.restoreCallingIdentity(identity);
8305 }
8306 }
8307
8308 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07008309 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07008310 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008311 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008312 mApp,
8313 subscriptionId,
8314 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: "
8315 + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07008316 final long identity = Binder.clearCallingIdentity();
8317 try {
8318 Phone phone = getPhone(subscriptionId);
8319 if (phone == null) {
8320 return null;
8321 }
8322 return PhoneUtils.makePstnPhoneAccountHandle(phone);
8323 } finally {
8324 Binder.restoreCallingIdentity(identity);
8325 }
8326 }
8327
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008328 /**
8329 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07008330 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008331 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008332 final long identity = Binder.clearCallingIdentity();
8333 try {
8334 Phone phone = getPhone(subId);
8335 if (phone != null) {
8336 return phone.isWifiCallingEnabled();
8337 } else {
8338 return false;
8339 }
8340 } finally {
8341 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008342 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07008343 }
8344
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008345 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008346 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008347 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008348 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008349 final long identity = Binder.clearCallingIdentity();
8350 try {
8351 Phone phone = getPhone(subId);
8352 if (phone != null) {
8353 return phone.isVideoEnabled();
8354 } else {
8355 return false;
8356 }
8357 } finally {
8358 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008359 }
8360 }
8361
8362 /**
8363 * @return the IMS registration technology for the MMTEL feature. Valid return values are
8364 * defined in {@link ImsRegistrationImplBase}.
8365 */
8366 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008367 final long identity = Binder.clearCallingIdentity();
8368 try {
8369 Phone phone = getPhone(subId);
8370 if (phone != null) {
8371 return phone.getImsRegistrationTech();
8372 } else {
8373 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
8374 }
8375 } finally {
8376 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08008377 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07008378 }
8379
Stuart Scott8eef64f2015-04-08 15:13:54 -07008380 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07008381 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08008382 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07008383 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
8384 return;
8385 }
Kai Shif70f46f2021-03-03 13:59:46 -08008386 Phone defaultPhone = getDefaultPhone();
8387 if (defaultPhone != null) {
8388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8389 mApp, getDefaultPhone().getSubId(), "factoryReset");
8390 }
Svet Ganovcc087f82015-05-12 20:35:54 -07008391 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008392
Svet Ganovcc087f82015-05-12 20:35:54 -07008393 try {
Stuart Scott981d8582015-04-21 14:09:50 -07008394 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
8395 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008396 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07008397 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07008398 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08008399 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08008400 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008401 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08008402 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07008403 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008404 // There has been issues when Sms raw table somehow stores orphan
8405 // fragments. They lead to garbled message when new fragments come
8406 // in and combined with those stale ones. In case this happens again,
8407 // user can reset all network settings which will clean up this table.
8408 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07008409 // Clean up IMS settings as well here.
8410 int slotId = getSlotIndex(subId);
8411 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
8412 ImsManager.getInstance(mApp, slotId).factoryReset();
8413 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008414
Kai Shif70f46f2021-03-03 13:59:46 -08008415 if (defaultPhone == null) {
8416 return;
8417 }
Naina Nallurid63128d2019-09-17 14:10:30 -07008418 // Erase modem config if erase modem on network setting is enabled.
8419 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
8420 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
8421 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08008422 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07008423 }
Kai Shif70f46f2021-03-03 13:59:46 -08008424
8425 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07008426 } finally {
8427 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07008428 }
8429 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008430
SongFerngWangfd89b102021-05-27 22:44:54 +08008431 @VisibleForTesting
8432 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
8433 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
8434 return;
8435 }
8436 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
8437 RILConstants.PREFERRED_NETWORK_MODE);
8438 SubscriptionManager.setSubscriptionProperty(subId,
8439 SubscriptionManager.ALLOWED_NETWORK_TYPES,
8440 "user=" + defaultNetworkType);
8441 phone.loadAllowedNetworksFromSubscriptionDatabase();
8442 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
8443 defaultNetworkType, null);
8444 }
8445
Amit Mahajan7dbbd822019-03-13 17:33:47 -07008446 private void cleanUpSmsRawTable(Context context) {
8447 ContentResolver resolver = context.getContentResolver();
8448 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
8449 resolver.delete(uri, null, null);
8450 }
8451
Narayan Kamath1c496c22015-04-16 14:40:19 +01008452 @Override
chen xu5d3637b2019-01-21 23:31:38 -08008453 public String getSimLocaleForSubscriber(int subId) {
8454 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
8455 final Phone phone = getPhone(subId);
8456 if (phone == null) {
8457 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08008458 return null;
chen xu5d3637b2019-01-21 23:31:38 -08008459 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008460 final long identity = Binder.clearCallingIdentity();
8461 try {
Jack Yu285100e2022-12-02 22:48:35 -08008462 SubscriptionInfo info;
8463 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008464 info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId,
Jack Yu285100e2022-12-02 22:48:35 -08008465 phone.getContext().getOpPackageName(),
8466 phone.getContext().getAttributionTag());
8467 if (info == null) {
8468 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8469 return null;
8470 }
8471 } else {
8472 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
8473 phone.getContext().getOpPackageName(),
8474 phone.getContext().getAttributionTag());
8475 if (info == null) {
8476 log("getSimLocaleForSubscriber, inactive subId: " + subId);
8477 return null;
8478 }
chen xu6291c472019-02-04 12:55:53 -08008479 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008480 // Try and fetch the locale from the carrier properties or from the SIM language
8481 // preferences (EF-PL and EF-LI)...
8482 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008483 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08008484 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
8485 if (localeFromDefaultSim != null) {
8486 if (!localeFromDefaultSim.getCountry().isEmpty()) {
8487 if (DBG) log("Using locale from subId: " + subId + " locale: "
8488 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08008489 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08008490 } else {
8491 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008492 }
8493 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008494
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008495 // The SIM language preferences only store a language (e.g. fr = French), not an
8496 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
8497 // the SIM and carrier preferences does not include a country we add the country
8498 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08008499 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008500 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08008501 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08008502 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008503 }
8504
8505 if (DBG) log("No locale found - returning null");
8506 return null;
8507 } finally {
8508 Binder.restoreCallingIdentity(identity);
8509 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01008510 }
8511
tom hsu0b59d292022-09-29 23:49:21 +08008512 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08008513 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08008514 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08008515 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08008516 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08008517 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
8518 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08008519 Locale.forLanguageTag(localeTag).getCountry())) {
8520 return localeTag;
8521 }
8522 }
8523 return inputLocale.toLanguageTag();
8524 }
8525
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008526 /**
8527 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
8528 */
8529 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yu285100e2022-12-02 22:48:35 -08008530 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008531 return getSubscriptionManagerService().getActiveSubscriptionInfoList(
Jack Yu285100e2022-12-02 22:48:35 -08008532 mApp.getOpPackageName(), mApp.getAttributionTag());
8533 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008534 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08008535 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01008536 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008537
Gary Jian3aa9a762022-01-24 16:41:19 +08008538 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
8539 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08008540
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008541 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07008542 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
8543 * representing the state of the modem.
8544 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08008545 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
8546 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07008547 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008548 */
8549 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07008550 public void requestModemActivityInfo(ResultReceiver result) {
8551 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008552 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008553
8554 final long identity = Binder.clearCallingIdentity();
8555 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08008556 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008557 } finally {
8558 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08008559 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07008560 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008561
Gary Jian76280a42022-12-07 16:18:33 +08008562 // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be
Siddharth Rayb8114062018-06-17 15:02:38 -07008563 // less than total activity duration.
8564 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
8565 if (info == null) {
8566 return false;
8567 }
8568 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07008569 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
Gary Jian76280a42022-12-07 16:18:33 +08008570 activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS;
8571
Hall Liu49656c02020-10-09 19:00:11 -07008572 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
8573
Siddharth Rayb8114062018-06-17 15:02:38 -07008574 return (info.isValid()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008575 && (info.getSleepTimeMillis() <= activityDurationMs)
8576 && (info.getIdleTimeMillis() <= activityDurationMs));
Siddharth Rayb8114062018-06-17 15:02:38 -07008577 }
8578
Gary Jian3aa9a762022-01-24 16:41:19 +08008579 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
8580 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8581 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
8582 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
8583
8584 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8585 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8586 }
8587
8588 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
8589 mLastModemActivityInfo.setReceiveTimeMillis(
8590 rat,
8591 freq,
8592 info.getReceiveTimeMillis(rat, freq)
8593 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
8594 }
8595
8596 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
8597 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
8598 int[] txTimeMs = info.getTransmitTimeMillis(rat);
8599 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
8600
8601 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
8602 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
8603 }
8604 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
8605 mLastModemActivityInfo.setReceiveTimeMillis(
8606 rat,
8607 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
8608 }
8609
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008610 /**
8611 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
8612 * @param info recent ModemActivityInfo
8613 */
Gary Jian3aa9a762022-01-24 16:41:19 +08008614 private void mergeModemActivityInfo(ModemActivityInfo info) {
8615 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
Kai Shi917fdc62022-11-28 14:01:02 -08008616 ActivityStatsTechSpecificInfo deltaSpecificInfo;
Gary Jian3aa9a762022-01-24 16:41:19 +08008617 boolean matched;
8618 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
8619 matched = false;
8620 int rat = info.getSpecificInfoRat(i);
8621 int freq = info.getSpecificInfoFrequencyRange(i);
8622 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
8623 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
8624 //if it already exists
8625 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
8626 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
8627 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
8628 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
8629 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
8630 updateLastModemActivityInfo(info, rat, freq);
8631 matched = true;
8632 }
8633 } else {
8634 updateLastModemActivityInfo(info, rat);
8635 matched = true;
8636 }
8637 }
8638 }
8639
8640 if (!matched) {
Kai Shi917fdc62022-11-28 14:01:02 -08008641 deltaSpecificInfo =
Gary Jian3aa9a762022-01-24 16:41:19 +08008642 new ActivityStatsTechSpecificInfo(
8643 rat,
8644 freq,
8645 info.getTransmitTimeMillis(rat, freq),
8646 (int) info.getReceiveTimeMillis(rat, freq));
Kai Shi917fdc62022-11-28 14:01:02 -08008647 merged.addAll(Arrays.asList(deltaSpecificInfo));
Gary Jian3aa9a762022-01-24 16:41:19 +08008648 }
8649 }
8650 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8651 mLastModemActivitySpecificInfo =
8652 new ActivityStatsTechSpecificInfo[merged.size()];
8653 merged.toArray(mLastModemActivitySpecificInfo);
8654
8655 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8656 mLastModemActivityInfo.setSleepTimeMillis(
8657 info.getSleepTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008658 + mLastModemActivityInfo.getSleepTimeMillis());
Gary Jian3aa9a762022-01-24 16:41:19 +08008659 mLastModemActivityInfo.setIdleTimeMillis(
8660 info.getIdleTimeMillis()
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008661 + mLastModemActivityInfo.getIdleTimeMillis());
Kai Shi917fdc62022-11-28 14:01:02 -08008662
8663 mLastModemActivityInfo =
Thomas Nguyen8ee49682023-02-01 11:46:09 -08008664 new ModemActivityInfo(
8665 mLastModemActivityInfo.getTimestampMillis(),
8666 mLastModemActivityInfo.getSleepTimeMillis(),
8667 mLastModemActivityInfo.getIdleTimeMillis(),
8668 mLastModemActivitySpecificInfo);
Kai Shi917fdc62022-11-28 14:01:02 -08008669 }
8670
8671 private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo(
8672 ActivityStatsTechSpecificInfo[] info) {
8673 int infoSize = info.length;
8674 ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize];
8675 for (int i = 0; i < infoSize; i++) {
8676 ret[i] = new ActivityStatsTechSpecificInfo(
8677 info[i].getRat(), info[i].getFrequencyRange(),
8678 info[i].getTransmitTimeMillis(),
8679 (int) info[i].getReceiveTimeMillis());
8680 }
8681 return ret;
Gary Jian3aa9a762022-01-24 16:41:19 +08008682 }
8683
Jack Yu85bd38a2015-11-09 11:34:32 -08008684 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008685 * Returns the service state information on specified subscription.
8686 */
8687 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008688 public ServiceState getServiceStateForSubscriber(int subId,
8689 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8690 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008691 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008692 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008693 return null;
8694 }
8695
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008696 boolean hasFinePermission = false;
8697 boolean hasCoarsePermission = false;
8698 if (!renounceFineLocationAccess) {
8699 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8700 LocationAccessPolicy.checkLocationPermission(mApp,
8701 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8702 .setCallingPackage(callingPackage)
8703 .setCallingFeatureId(callingFeatureId)
8704 .setCallingPid(Binder.getCallingPid())
8705 .setCallingUid(Binder.getCallingUid())
8706 .setMethod("getServiceStateForSubscriber")
8707 .setLogAsInfo(true)
8708 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8709 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8710 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8711 .build());
8712 hasFinePermission =
8713 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8714 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008715
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008716 if (!renounceCoarseLocationAccess) {
8717 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8718 LocationAccessPolicy.checkLocationPermission(mApp,
8719 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8720 .setCallingPackage(callingPackage)
8721 .setCallingFeatureId(callingFeatureId)
8722 .setCallingPid(Binder.getCallingPid())
8723 .setCallingUid(Binder.getCallingUid())
8724 .setMethod("getServiceStateForSubscriber")
8725 .setLogAsInfo(true)
8726 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8727 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8728 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8729 .build());
8730 hasCoarsePermission =
8731 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8732 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008733
Jack Yu479f40e2020-10-27 21:29:25 -07008734 final Phone phone = getPhone(subId);
8735 if (phone == null) {
8736 return null;
8737 }
8738
Jordan Liu0f2bc442020-11-18 16:47:37 -08008739 final long identity = Binder.clearCallingIdentity();
8740
Jack Yu479f40e2020-10-27 21:29:25 -07008741 boolean isCallingPackageDataService = phone.getDataServicePackages()
8742 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008743 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008744 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yu285100e2022-12-02 22:48:35 -08008745 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
Jack Yufa8ed012023-02-11 15:42:28 -08008746 SubscriptionInfoInternal subInfo = getSubscriptionManagerService()
Jack Yu285100e2022-12-02 22:48:35 -08008747 .getSubscriptionInfoInternal(subId);
8748 if (subInfo == null || !subInfo.isActive()) {
8749 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8750 + "subId=" + subId);
8751 return null;
8752 }
8753 } else {
8754 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
8755 callingFeatureId)) {
8756 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
8757 + "subId=" + subId);
8758 return null;
8759 }
Jordan Liuc437b192020-08-17 10:59:12 -07008760 }
8761
Hall Liuf19c44f2018-11-27 14:38:17 -08008762 ServiceState ss = phone.getServiceState();
8763
8764 // Scrub out the location info in ServiceState depending on what level of access
8765 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008766 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008767 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8768 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008769 } finally {
8770 Binder.restoreCallingIdentity(identity);
8771 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008772 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008773
8774 /**
8775 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8776 *
8777 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8778 * voicemail ringtone.
8779 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8780 * PhoneAccount.
8781 */
8782 @Override
8783 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008784 final long identity = Binder.clearCallingIdentity();
8785 try {
8786 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8787 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008788 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008789 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008790
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008791 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8792 } finally {
8793 Binder.restoreCallingIdentity(identity);
8794 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008795 }
8796
8797 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008798 * Sets the per-account voicemail ringtone.
8799 *
8800 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8801 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8802 *
8803 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8804 * voicemail ringtone.
8805 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8806 * PhoneAccount.
8807 */
8808 @Override
8809 public void setVoicemailRingtoneUri(String callingPackage,
8810 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008811 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008812 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008813 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8814 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8816 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8817 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008818 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008819
8820 final long identity = Binder.clearCallingIdentity();
8821 try {
8822 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8823 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008824 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008825 }
8826 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8827 } finally {
8828 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008829 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008830 }
8831
8832 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008833 * Returns whether vibration is set for voicemail notification in Phone settings.
8834 *
8835 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8836 * voicemail vibration setting.
8837 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8838 */
8839 @Override
8840 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008841 final long identity = Binder.clearCallingIdentity();
8842 try {
8843 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8844 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008845 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008846 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008847
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008848 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8849 } finally {
8850 Binder.restoreCallingIdentity(identity);
8851 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008852 }
8853
Youhan Wange64578a2016-05-02 15:32:42 -07008854 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008855 * Sets the per-account voicemail vibration.
8856 *
8857 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8858 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8859 *
8860 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8861 * voicemail vibration setting.
8862 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8863 * specific PhoneAccount.
8864 */
8865 @Override
8866 public void setVoicemailVibrationEnabled(String callingPackage,
8867 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008868 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008869 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008870 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8871 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8873 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8874 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008875 }
8876
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008877 final long identity = Binder.clearCallingIdentity();
8878 try {
8879 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8880 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008881 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008882 }
8883 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8884 } finally {
8885 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008886 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008887 }
8888
8889 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008890 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8891 *
8892 * @throws SecurityException if the caller does not have the required permission
8893 */
arunvoddud7401012022-12-15 16:08:12 +00008894 @VisibleForTesting
8895 public void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008896 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008897 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008898 }
8899
8900 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008901 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8902 * permission.
8903 *
8904 * @throws SecurityException if the caller does not have the required permission
8905 */
8906 private void enforceSendSmsPermission() {
8907 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8908 }
8909
8910 /**
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +00008911 * Make sure either called from same process as self (phone) or IPC caller has interact across
8912 * users permission.
8913 *
8914 * @throws SecurityException if the caller does not have the required permission
8915 */
8916 private void enforceInteractAcrossUsersPermission(String message) {
8917 mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message);
8918 }
8919
8920 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008921 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008922 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008923 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008924 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008925 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008926 final long identity = Binder.clearCallingIdentity();
8927 try {
8928 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008929 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008930 if (componentName == null) {
8931 throw new SecurityException(
8932 "Caller not current active visual voicemail package[null]");
8933 }
8934 String vvmPackage = componentName.getPackageName();
8935 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008936 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008937 }
8938 } finally {
8939 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008940 }
8941 }
8942
8943 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008944 * Return the application ID for the app type.
8945 *
8946 * @param subId the subscription ID that this request applies to.
8947 * @param appType the uicc app type.
8948 * @return Application ID for specificied app type, or null if no uicc.
8949 */
8950 @Override
8951 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008952 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008953 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008954
8955 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008956 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008957 if (phone == null) {
8958 return null;
8959 }
8960 String aid = null;
8961 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008962 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008963 .getApplicationByType(appType).getAid();
8964 } catch (Exception e) {
8965 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8966 }
8967 return aid;
8968 } finally {
8969 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008970 }
Youhan Wange64578a2016-05-02 15:32:42 -07008971 }
8972
Youhan Wang4001d252016-05-11 10:29:41 -07008973 /**
8974 * Return the Electronic Serial Number.
8975 *
8976 * @param subId the subscription ID that this request applies to.
8977 * @return ESN or null if error.
8978 */
8979 @Override
8980 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008981 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008982 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008983
8984 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008985 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008986 if (phone == null) {
8987 return null;
8988 }
8989 String esn = null;
8990 try {
8991 esn = phone.getEsn();
8992 } catch (Exception e) {
8993 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8994 }
8995 return esn;
8996 } finally {
8997 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008998 }
Youhan Wang4001d252016-05-11 10:29:41 -07008999 }
9000
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009001 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07009002 * Return the Preferred Roaming List Version.
9003 *
9004 * @param subId the subscription ID that this request applies to.
9005 * @return PRLVersion or null if error.
9006 */
9007 @Override
9008 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009009 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07009010 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009011
9012 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07009013 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009014 if (phone == null) {
9015 return null;
9016 }
9017 String cdmaPrlVersion = null;
9018 try {
9019 cdmaPrlVersion = phone.getCdmaPrlVersion();
9020 } catch (Exception e) {
9021 Log.e(LOG_TAG, "Not getting PRLVersion", e);
9022 }
9023 return cdmaPrlVersion;
9024 } finally {
9025 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07009026 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07009027 }
9028
9029 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009030 * Get snapshot of Telephony histograms
9031 * @return List of Telephony histograms
9032 * @hide
9033 */
9034 @Override
9035 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9037 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009038
9039 final long identity = Binder.clearCallingIdentity();
9040 try {
9041 return RIL.getTelephonyRILTimingHistograms();
9042 } finally {
9043 Binder.restoreCallingIdentity(identity);
9044 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07009045 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009046
9047 /**
9048 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009049 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
9050 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009051 * Require system privileges. In the future we may add this to carrier APIs.
9052 *
Michele Berionne482f8202018-11-27 18:57:59 -08009053 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009054 */
9055 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009056 @TelephonyManager.SetCarrierRestrictionResult
9057 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07009058 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07009059 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009060
Michele Berionne482f8202018-11-27 18:57:59 -08009061 if (carrierRestrictionRules == null) {
9062 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08009063 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009064
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009065 final long identity = Binder.clearCallingIdentity();
9066 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009067 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07009068 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009069 } finally {
9070 Binder.restoreCallingIdentity(identity);
9071 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009072 }
9073
9074 /**
9075 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08009076 * Get the allowed carrier list and the excluded carrier list, including the priority between
9077 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07009078 * Require system privileges. In the future we may add this to carrier APIs.
9079 *
Michele Berionne482f8202018-11-27 18:57:59 -08009080 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07009081 */
9082 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08009083 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009084 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07009085 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009086
9087 final long identity = Binder.clearCallingIdentity();
9088 try {
Michele Berionne482f8202018-11-27 18:57:59 -08009089 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
9090 if (response instanceof CarrierRestrictionRules) {
9091 return (CarrierRestrictionRules) response;
9092 }
9093 // Response is an Exception of some kind,
9094 // which is signalled to the user as a NULL retval
9095 return null;
9096 } catch (Exception e) {
9097 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
9098 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009099 } finally {
9100 Binder.restoreCallingIdentity(identity);
9101 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07009102 }
9103
fionaxu59545b42016-05-25 15:53:37 -07009104 /**
arunvoddud7401012022-12-15 16:08:12 +00009105 * Fetches the carrier restriction status of the device and sends the status to the caller
9106 * through the callback.
9107 *
9108 * @param callback The callback that will be used to send the result.
9109 * @throws SecurityException if the caller does not have the required permission/privileges or
9110 * the caller is not allowlisted.
9111 */
9112 @Override
9113 public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) {
9114 enforceReadPermission("getCarrierRestrictionStatus");
9115 int carrierId = validateCallerAndGetCarrierId(packageName);
9116 if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) {
9117 Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered");
9118 throw new SecurityException("Not an authorized caller");
9119 }
9120 final long identity = Binder.clearCallingIdentity();
9121 try {
9122 Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept);
9123 CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId);
9124 sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo);
9125 } finally {
9126 Binder.restoreCallingIdentity(identity);
9127 }
9128 }
9129
9130 @VisibleForTesting
9131 public int validateCallerAndGetCarrierId(String packageName) {
9132 CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp);
9133 return allowListInfo.validateCallerAndGetCarrierId(packageName);
9134 }
9135
9136 /**
fionaxu59545b42016-05-25 15:53:37 -07009137 * Action set from carrier signalling broadcast receivers to enable/disable radio
9138 * @param subId the subscription ID that this action applies to.
9139 * @param enabled control enable or disable radio.
9140 * {@hide}
9141 */
9142 @Override
9143 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
9144 enforceModifyPermission();
9145 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009146
9147 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07009148 if (phone == null) {
9149 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
9150 return;
9151 }
9152 try {
9153 phone.carrierActionSetRadioEnabled(enabled);
9154 } catch (Exception e) {
9155 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009156 } finally {
9157 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07009158 }
9159 }
9160
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009161 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009162 * Enable or disable Voice over NR (VoNR)
9163 * @param subId the subscription ID that this action applies to.
9164 * @param enabled enable or disable VoNR.
9165 * @return operation result.
9166 */
9167 @Override
9168 public int setVoNrEnabled(int subId, boolean enabled) {
9169 enforceModifyPermission();
9170 final Phone phone = getPhone(subId);
9171
9172 final long identity = Binder.clearCallingIdentity();
9173 if (phone == null) {
9174 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
9175 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
9176 }
9177
9178 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9179 try {
9180 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
9181 workSource);
9182 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08009183
9184 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
9185 if (DBG) {
9186 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
9187 }
9188 SubscriptionManager.setSubscriptionProperty(
9189 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
9190 (enabled ? "1" : "0"));
9191 }
9192
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07009193 return result;
9194 } finally {
9195 Binder.restoreCallingIdentity(identity);
9196 }
9197 }
9198
9199 /**
9200 * Is voice over NR enabled
9201 * @return true if VoNR is enabled else false
9202 */
9203 @Override
9204 public boolean isVoNrEnabled(int subId) {
9205 enforceReadPrivilegedPermission("isVoNrEnabled");
9206 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9207 final long identity = Binder.clearCallingIdentity();
9208 try {
9209 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
9210 null, subId, workSource);
9211 if (DBG) log("isVoNrEnabled: " + isEnabled);
9212 return isEnabled;
9213 } finally {
9214 Binder.restoreCallingIdentity(identity);
9215 }
9216 }
9217
9218 /**
fionaxu8da9cb12017-05-23 15:02:46 -07009219 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
9220 * network status based on which carrier apps could apply actions accordingly,
9221 * enable/disable default url handler for example.
9222 *
9223 * @param subId the subscription ID that this action applies to.
9224 * @param report control start/stop reporting the default network status.
9225 * {@hide}
9226 */
9227 @Override
9228 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
9229 enforceModifyPermission();
9230 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009231
9232 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07009233 if (phone == null) {
9234 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
9235 return;
9236 }
9237 try {
9238 phone.carrierActionReportDefaultNetworkStatus(report);
9239 } catch (Exception e) {
9240 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009241 } finally {
9242 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07009243 }
9244 }
9245
9246 /**
fionaxud9622282017-07-17 17:51:30 -07009247 * Action set from carrier signalling broadcast receivers to reset all carrier actions
9248 * @param subId the subscription ID that this action applies to.
9249 * {@hide}
9250 */
9251 @Override
9252 public void carrierActionResetAll(int subId) {
9253 enforceModifyPermission();
9254 final Phone phone = getPhone(subId);
9255 if (phone == null) {
9256 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
9257 return;
9258 }
9259 try {
9260 phone.carrierActionResetAll();
9261 } catch (Exception e) {
9262 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
9263 }
9264 }
9265
9266 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009267 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
9268 * bug report is being generated.
9269 */
9270 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07009271 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009272 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
9273 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07009274 writer.println("Permission Denial: can't dump Phone from pid="
9275 + Binder.getCallingPid()
9276 + ", uid=" + Binder.getCallingUid()
9277 + "without permission "
9278 + android.Manifest.permission.DUMP);
9279 return;
9280 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009281 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07009282 }
Jack Yueb89b242016-06-22 13:27:47 -07009283
Brad Ebingerdac2f002018-04-03 15:17:52 -07009284 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08009285 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
9286 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
9287 @NonNull String[] args) {
9288 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
9289 this, in.getFileDescriptor(), out.getFileDescriptor(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009290 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07009291 }
9292
Jack Yueb89b242016-06-22 13:27:47 -07009293 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009294 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00009295 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07009296 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009297 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07009298 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009299 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07009300 */
9301 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009302 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07009303 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009304 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
9305 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9306 try {
9307 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07009308 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009309 } catch (SecurityException se) {
9310 enforceModifyPermission();
9311 }
9312 } else {
9313 enforceModifyPermission();
9314 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009315
9316 final long identity = Binder.clearCallingIdentity();
9317 try {
9318 Phone phone = getPhone(subId);
9319 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009320 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
9321 phone.carrierActionSetMeteredApnsEnabled(enabled);
9322 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07009323 phone.getDataSettingsManager().setDataEnabled(
9324 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00009325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009326 }
9327 } finally {
9328 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07009329 }
9330 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009331
9332 /**
9333 * Get Client request stats
9334 * @return List of Client Request Stats
9335 * @hide
9336 */
9337 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009338 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
9339 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08009340 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009341 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009342 return null;
9343 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009344 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009345
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009346 final long identity = Binder.clearCallingIdentity();
9347 try {
9348 if (phone != null) {
9349 return phone.getClientRequestStats();
9350 }
9351
9352 return null;
9353 } finally {
9354 Binder.restoreCallingIdentity(identity);
9355 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009356 }
9357
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009358 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009359 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00009360 if (uid == Process.ROOT_UID && packageName == null) {
9361 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
9362 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
9363 // exception. ROOT_UID seems not to have a valid package name returned by
9364 // PackageManager, so just fake it here to avoid issues when running telephony shell
9365 // commands that plumb through the RIL as root, like so:
9366 // $ adb root
9367 // $ adb shell cmd phone ...
9368 packageName = "root";
9369 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00009370 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07009371 }
Jack Yueb4124c2017-02-16 15:32:43 -08009372
9373 /**
Grace Chen70990072017-03-24 17:21:30 -07009374 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08009375 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009376 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07009377 * @param state State of SIM (power down, power up, pass through)
9378 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9379 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9380 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08009381 *
9382 **/
9383 @Override
Grace Chen70990072017-03-24 17:21:30 -07009384 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08009385 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07009386 Phone phone = PhoneFactory.getPhone(slotIndex);
9387
vagdeviaf9a5b92018-08-15 16:01:53 -07009388 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9389
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009390 final long identity = Binder.clearCallingIdentity();
9391 try {
9392 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08009393 phone.setSimPowerState(state, null, workSource);
9394 }
9395 } finally {
9396 Binder.restoreCallingIdentity(identity);
9397 }
9398 }
9399
9400 /**
9401 * Set SIM card power state.
9402 *
9403 * @param slotIndex SIM slot id.
9404 * @param state State of SIM (power down, power up, pass through)
9405 * @param callback callback to trigger after success or failure
9406 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
9407 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
9408 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
9409 *
9410 **/
9411 @Override
9412 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
9413 IIntegerConsumer callback) {
9414 enforceModifyPermission();
9415 Phone phone = PhoneFactory.getPhone(slotIndex);
9416
9417 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9418
9419 final long identity = Binder.clearCallingIdentity();
9420 try {
9421 if (phone != null) {
9422 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
9423 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009424 }
9425 } finally {
9426 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08009427 }
9428 }
Shuo Qiandd210312017-04-12 22:11:33 +00009429
Tyler Gunn65d45c22017-06-05 11:22:26 -07009430 private boolean isUssdApiAllowed(int subId) {
9431 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009432 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07009433 if (configManager == null) {
9434 return false;
9435 }
9436 PersistableBundle pb = configManager.getConfigForSubId(subId);
9437 if (pb == null) {
9438 return false;
9439 }
9440 return pb.getBoolean(
9441 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
9442 }
9443
Shuo Qiandd210312017-04-12 22:11:33 +00009444 /**
9445 * Check if phone is in emergency callback mode
9446 * @return true if phone is in emergency callback mode
9447 * @param subId sub id
9448 */
goneil9c5f4872017-12-05 14:07:56 -08009449 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00009450 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009451 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00009452 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009453
9454 final long identity = Binder.clearCallingIdentity();
9455 try {
9456 if (phone != null) {
9457 return phone.isInEcm();
9458 } else {
9459 return false;
9460 }
9461 } finally {
9462 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00009463 }
9464 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009465
9466 /**
9467 * Get the current signal strength information for the given subscription.
9468 * Because this information is not updated when the device is in a low power state
9469 * it should not be relied-upon to be current.
9470 * @param subId Subscription index
9471 * @return the most recent cached signal strength info from the modem
9472 */
9473 @Override
9474 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009475 final long identity = Binder.clearCallingIdentity();
9476 try {
9477 Phone p = getPhone(subId);
9478 if (p == null) {
9479 return null;
9480 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009481
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009482 return p.getSignalStrength();
9483 } finally {
9484 Binder.restoreCallingIdentity(identity);
9485 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08009486 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009487
Pengquan Meng77b7f132018-08-22 14:49:57 -07009488 /**
Chen Xuf792fd62018-10-17 17:54:36 +00009489 * Get the current modem radio state for the given slot.
9490 * @param slotIndex slot index.
9491 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009492 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00009493 * @return the current radio power state from the modem
9494 */
9495 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009496 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00009497 Phone phone = PhoneFactory.getPhone(slotIndex);
9498 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009499 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
9500 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00009501 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9502 }
9503
9504 final long identity = Binder.clearCallingIdentity();
9505 try {
9506 return phone.getRadioPowerState();
9507 } finally {
9508 Binder.restoreCallingIdentity(identity);
9509 }
9510 }
9511 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
9512 }
9513
9514 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07009515 * Checks if data roaming is enabled on the subscription with id {@code subId}.
9516 *
9517 * <p>Requires one of the following permissions:
9518 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009519 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07009520 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
9521 * privileges.
9522 *
9523 * @param subId subscription id
9524 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
9525 * {@code false}.
9526 */
9527 @Override
9528 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009529 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07009530 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009531 try {
9532 mApp.enforceCallingOrSelfPermission(
9533 android.Manifest.permission.ACCESS_NETWORK_STATE,
9534 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009535 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009536 mApp.enforceCallingOrSelfPermission(
9537 permission.READ_BASIC_PHONE_STATE, functionName);
9538 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07009539 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07009540 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07009541 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07009542 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07009543
Pengquan Menga1bb6272018-09-06 09:59:22 -07009544 boolean isEnabled = false;
9545 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07009546 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009547 Phone phone = getPhone(subId);
9548 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07009549 } finally {
9550 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009551 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009552 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07009553 }
9554
9555
9556 /**
9557 * Enables/Disables the data roaming on the subscription with id {@code subId}.
9558 *
9559 * <p> Requires permission:
9560 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
9561 * privileges.
9562 *
9563 * @param subId subscription id
9564 * @param isEnabled {@code true} means enable, {@code false} means disable.
9565 */
9566 @Override
9567 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07009568 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9569 mApp, subId, "setDataRoamingEnabled");
9570
Pengquan Menga1bb6272018-09-06 09:59:22 -07009571 final long identity = Binder.clearCallingIdentity();
9572 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07009573 Phone phone = getPhone(subId);
9574 if (phone != null) {
9575 phone.setDataRoamingEnabled(isEnabled);
9576 }
9577 } finally {
9578 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07009579 }
9580 }
9581
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009582 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009583 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08009584 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009585 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009586 mApp, subId, "isManualNetworkSelectionAllowed");
Pengquan Meng44e66f12019-04-01 10:48:20 -07009587
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009588 boolean isAllowed = true;
9589 final long identity = Binder.clearCallingIdentity();
9590 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009591 Phone phone = getPhone(subId);
9592 if (phone != null) {
9593 isAllowed = phone.isCspPlmnEnabled();
9594 }
9595 } finally {
9596 Binder.restoreCallingIdentity(identity);
9597 }
9598 return isAllowed;
9599 }
9600
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009601 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
9602 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009603 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009604 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009605 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08009606 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
9607 if (phone == null) {
9608 return false;
9609 }
9610 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9611 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
9612 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009613 }
9614
Pengquan Meng6884a2c2018-10-03 12:19:13 -07009615 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08009616 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009617 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07009618 mApp.getSystemService(AppOpsManager.class)
9619 .checkPackage(Binder.getCallingUid(), callingPackage);
9620
Jordan Liu1e142fc2019-04-22 15:10:43 -07009621 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009622 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08009623 try {
9624 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07009625 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08009626 } catch (SecurityException e) {
9627 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
9628 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08009629 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Thomas Nguyen8ee49682023-02-01 11:46:09 -08009630 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07009631 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08009632 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08009633 }
sandeepjsb6c87872021-09-27 15:34:44 +00009634 // checking compatibility, if calling app's target SDK is T and beyond.
9635 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9636 Binder.getCallingUid())) {
9637 isIccIdAccessRestricted = true;
9638 }
Jordan Liu5aa07002018-12-18 15:44:48 -08009639 final long identity = Binder.clearCallingIdentity();
9640 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08009641 UiccController uiccController = UiccController.getInstance();
9642 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07009643 if (hasReadPermission) {
9644 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08009645 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07009646
9647 // Remove private info if the caller doesn't have access
9648 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
9649 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00009650 //setting the value after compatibility check
9651 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07009652 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
9653 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00009654 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009655 if (card == null) {
9656 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00009657 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009658 continue;
9659 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009660 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
9661 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00009662 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009663 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07009664 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009665 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
9666 for (UiccPortInfo portInfo : portInfos) {
9667 UiccPort port = uiccController.getUiccPortForSlot(
9668 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
9669 if (port == null) {
9670 // assume no access if port is null
9671 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9672 continue;
9673 }
9674 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9675 uiccPortInfos.add(portInfo);
9676 } else {
9677 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
9678 }
9679 }
9680 filteredInfos.add(new UiccCardInfo(
9681 cardInfo.isEuicc(),
9682 cardInfo.getCardId(),
9683 null,
9684 cardInfo.getPhysicalSlotIndex(),
9685 cardInfo.isRemovable(),
9686 cardInfo.isMultipleEnabledProfilesSupported(),
9687 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07009688 }
9689 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08009690 } finally {
9691 Binder.restoreCallingIdentity(identity);
9692 }
9693 }
9694
sandeepjsb6c87872021-09-27 15:34:44 +00009695 /**
9696 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
9697 * generally private and require carrier privileges to view.
9698 *
9699 * @hide
9700 */
9701 @NonNull
9702 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
9703 List<UiccPortInfo> portinfo = new ArrayList<>();
9704 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
9705 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9706 }
9707 return new UiccCardInfo(
9708 cardInfo.isEuicc(),
9709 cardInfo.getCardId(),
9710 null,
9711 cardInfo.getPhysicalSlotIndex(),
9712 cardInfo.isRemovable(),
9713 cardInfo.isMultipleEnabledProfilesSupported(),
9714 portinfo
9715 );
9716 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009717
sandeepjsb6c87872021-09-27 15:34:44 +00009718 /**
9719 * @hide
9720 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9721 * These values are generally private and require carrier privileges to view.
9722 */
9723 @NonNull
9724 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9725 return new UiccPortInfo(
9726 UiccPortInfo.ICCID_REDACTED,
9727 portInfo.getPortIndex(),
9728 portInfo.getLogicalSlotIndex(),
9729 portInfo.isActive()
9730 );
9731 }
9732 @Override
9733 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009734 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009735 mApp.getSystemService(AppOpsManager.class)
9736 .checkPackage(Binder.getCallingUid(), callingPackage);
9737
sandeepjsb6c87872021-09-27 15:34:44 +00009738 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009739
Aman Guptaf3c90b32022-03-17 04:54:16 +00009740 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9741 // we are reading iccId which is PII data.
9742 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009743
9744 // checking compatibility, if calling app's target SDK is T and beyond.
9745 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9746 Binder.getCallingUid())) {
9747 isLogicalSlotAccessRestricted = true;
9748 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009749 final long identity = Binder.clearCallingIdentity();
9750 try {
9751 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009752 if (slots == null || slots.length == 0) {
9753 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009754 return null;
9755 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009756 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9757 for (int i = 0; i < slots.length; i++) {
9758 UiccSlot slot = slots[i];
9759 if (slot == null) {
9760 continue;
9761 }
9762
Jordan Liu7be7e652019-05-06 18:55:02 +00009763 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009764 UiccCard card = slot.getUiccCard();
9765 if (card != null) {
9766 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009767 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009768 cardId = slot.getEid();
9769 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009770 // If cardId is null, use iccId of default port as cardId.
9771 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009772 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009773 }
9774
Jordan Liu857451f2019-05-09 16:35:35 -07009775 if (cardId != null) {
9776 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9777 // if cardId is an EID, it's all digits so this is fine
9778 cardId = IccUtils.stripTrailingFs(cardId);
9779 }
9780
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009781 int cardState = 0;
9782 switch (slot.getCardState()) {
9783 case CARDSTATE_ABSENT:
9784 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9785 break;
9786 case CARDSTATE_PRESENT:
9787 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9788 break;
9789 case CARDSTATE_ERROR:
9790 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9791 break;
9792 case CARDSTATE_RESTRICTED:
9793 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9794 break;
9795 default:
9796 break;
9797
9798 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009799 List<UiccPortInfo> portInfos = new ArrayList<>();
9800 int[] portIndexes = slot.getPortList();
9801 for (int portIdx : portIndexes) {
9802 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009803 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009804 portInfos.add(new UiccPortInfo(iccId, portIdx,
9805 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009806 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009807 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009808 slot.isEuicc(),
9809 cardId,
9810 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009811 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009812 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009813 //setting the value after compatibility check
9814 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009815 }
9816 return infos;
9817 } finally {
9818 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009819 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009820 }
9821
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009822 /* Returns null if doesn't have read permission or carrier privilege access. */
9823 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9824 boolean hasReadPermission) {
9825 String iccId = slot.getIccId(portIndex);
9826 if (hasReadPermission) { // if has read permission
9827 return iccId;
9828 } else {
9829 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9830 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9831 // if no read permission, checking carrier privilege access
9832 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9833 return iccId;
9834 }
9835 }
9836 }
9837 // No read permission or carrier privilege access.
9838 return UiccPortInfo.ICCID_REDACTED;
9839 }
9840
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009841 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009842 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009843 public boolean switchSlots(int[] physicalSlots) {
9844 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009845
9846 final long identity = Binder.clearCallingIdentity();
9847 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009848 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9849 for (int i = 0; i < physicalSlots.length; i++) {
9850 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9851 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9852 physicalSlots[i], i));
9853 }
9854 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009855 } finally {
9856 Binder.restoreCallingIdentity(identity);
9857 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009858 }
Jack Yu4c988042018-02-27 15:30:01 -08009859
9860 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009861 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9862 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9863 enforceModifyPermission();
9864
9865 final long identity = Binder.clearCallingIdentity();
9866 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009867 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009868 } finally {
9869 Binder.restoreCallingIdentity(identity);
9870 }
9871 }
9872
9873 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009874 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009875 final long identity = Binder.clearCallingIdentity();
9876 try {
9877 return UiccController.getInstance().getCardIdForDefaultEuicc();
9878 } finally {
9879 Binder.restoreCallingIdentity(identity);
9880 }
9881 }
9882
Pengquan Meng85728fb2018-03-12 16:31:21 -07009883 /**
goneil47ffb6e2018-04-06 15:40:58 -07009884 * A test API to reload the UICC profile.
9885 *
9886 * <p>Requires that the calling app has permission
9887 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9888 * @hide
9889 */
9890 @Override
9891 public void refreshUiccProfile(int subId) {
9892 enforceModifyPermission();
9893
9894 final long identity = Binder.clearCallingIdentity();
9895 try {
9896 Phone phone = getPhone(subId);
9897 if (phone == null) {
9898 return;
9899 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009900 UiccPort uiccPort = phone.getUiccPort();
9901 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009902 return;
9903 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009904 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009905 if (uiccProfile == null) {
9906 return;
9907 }
9908 uiccProfile.refresh();
9909 } finally {
9910 Binder.restoreCallingIdentity(identity);
9911 }
9912 }
9913
9914 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009915 * Returns false if the mobile data is disabled by default, otherwise return true.
9916 */
9917 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009918 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009919 }
9920
9921 /**
9922 * Returns true if the data roaming is enabled by default, i.e the system property
9923 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9924 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9925 */
9926 private boolean getDefaultDataRoamingEnabled(int subId) {
9927 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009928 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009929 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009930 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9931 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9932 return isDataRoamingEnabled;
9933 }
9934
9935 /**
9936 * Returns the default network type for the given {@code subId}, if the default network type is
9937 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9938 */
9939 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009940 List<Integer> list = TelephonyProperties.default_network();
Jack Yu285100e2022-12-02 22:48:35 -08009941 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009942 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9943 return list.get(phoneId);
9944 }
9945 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009946 }
fionaxua13278b2018-03-21 00:08:13 -07009947
9948 @Override
9949 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009950 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009951 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009952
9953 final long identity = Binder.clearCallingIdentity();
9954 try {
9955 final Phone phone = getPhone(subId);
9956 if (phone == null) {
9957 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9958 return;
9959 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009960 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9961 if (cpt != null) {
9962 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9963 }
9964 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009965 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9966 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009967 if (carrierPrivilegeRules == null) {
9968 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9969 } else {
9970 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9971 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009972 } finally {
9973 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009974 }
fionaxua13278b2018-03-21 00:08:13 -07009975 }
9976
9977 @Override
9978 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009979 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009980
9981 final long identity = Binder.clearCallingIdentity();
9982 try {
9983 final Phone phone = getPhone(subId);
9984 if (phone == null) {
9985 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9986 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9987 }
9988 return phone.getCarrierIdListVersion();
9989 } finally {
9990 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009991 }
fionaxua13278b2018-03-21 00:08:13 -07009992 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009993
9994 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009995 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9996 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009997 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009998 mApp, subId, callingPackage, callingFeatureId,
9999 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -070010000 return -1;
10001 }
10002
10003 final long identity = Binder.clearCallingIdentity();
10004 try {
10005 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
10006 } finally {
10007 Binder.restoreCallingIdentity(identity);
10008 }
10009 }
Pengquan Menga1bb6272018-09-06 09:59:22 -070010010
10011 @Override
10012 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +080010013 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010014 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010015 mApp, subId, "getCdmaRoamingMode");
Pengquan Menga1bb6272018-09-06 09:59:22 -070010016
10017 final long identity = Binder.clearCallingIdentity();
10018 try {
10019 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
10020 } finally {
10021 Binder.restoreCallingIdentity(identity);
10022 }
10023 }
10024
10025 @Override
10026 public boolean setCdmaRoamingMode(int subId, int mode) {
10027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10028 mApp, subId, "setCdmaRoamingMode");
10029
10030 final long identity = Binder.clearCallingIdentity();
10031 try {
10032 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
10033 } finally {
10034 Binder.restoreCallingIdentity(identity);
10035 }
10036 }
10037
10038 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -070010039 public int getCdmaSubscriptionMode(int subId) {
10040 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010041 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -070010042 mApp, subId, "getCdmaSubscriptionMode");
10043
10044 final long identity = Binder.clearCallingIdentity();
10045 try {
10046 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
10047 } finally {
10048 Binder.restoreCallingIdentity(identity);
10049 }
10050 }
10051
10052 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -070010053 public boolean setCdmaSubscriptionMode(int subId, int mode) {
10054 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10055 mApp, subId, "setCdmaSubscriptionMode");
10056
10057 final long identity = Binder.clearCallingIdentity();
10058 try {
10059 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
10060 } finally {
10061 Binder.restoreCallingIdentity(identity);
10062 }
10063 }
Makoto Onukida3bf792018-09-18 16:06:29 -070010064
sqianc5eccab2018-10-19 18:46:41 -070010065 @Override
sqian8c685422019-02-22 15:55:18 -080010066 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010067 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -080010068 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010069 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
10070 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -080010071 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10072 }
10073 final long identity = Binder.clearCallingIdentity();
10074 try {
sqian854d44b2018-12-12 16:48:18 -080010075 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
10076 for (Phone phone: PhoneFactory.getPhones()) {
10077 if (phone.getEmergencyNumberTracker() != null
10078 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
10079 emergencyNumberListInternal.put(
10080 phone.getSubId(),
10081 phone.getEmergencyNumberTracker().getEmergencyNumberList());
10082 }
sqian11b7a0e2018-12-05 18:48:28 -080010083 }
sqian854d44b2018-12-12 16:48:18 -080010084 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -080010085 } finally {
10086 Binder.restoreCallingIdentity(identity);
10087 }
sqianc5eccab2018-10-19 18:46:41 -070010088 }
10089
10090 @Override
sqian8c685422019-02-22 15:55:18 -080010091 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -080010092 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -080010093 if (!exactMatch) {
10094 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010095 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -080010096 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -080010097 }
10098 final long identity = Binder.clearCallingIdentity();
10099 try {
sqian854d44b2018-12-12 16:48:18 -080010100 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -070010101 //Note: we ignore passed in param exactMatch. We can remove it once
10102 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -080010103 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +090010104 && phone.getEmergencyNumberTracker()
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010105 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +090010106 return true;
sqian11b7a0e2018-12-05 18:48:28 -080010107 }
sqian11b7a0e2018-12-05 18:48:28 -080010108 }
10109 return false;
10110 } finally {
10111 Binder.restoreCallingIdentity(identity);
10112 }
10113 }
10114
sqianf4ca7ed2019-01-15 18:32:07 -080010115 /**
Shuo Qianccbaf742021-02-22 18:32:21 -080010116 * Start emergency callback mode for GsmCdmaPhone for testing.
10117 */
10118 @Override
10119 public void startEmergencyCallbackMode() {
10120 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10121 "startEmergencyCallbackMode");
10122 enforceModifyPermission();
10123 final long identity = Binder.clearCallingIdentity();
10124 try {
10125 for (Phone phone : PhoneFactory.getPhones()) {
10126 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
10127 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
10128 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
10129 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
10130 gsmCdmaPhone.obtainMessage(
10131 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
10132 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
10133 }
10134 }
10135 } finally {
10136 Binder.restoreCallingIdentity(identity);
10137 }
10138 }
10139
10140 /**
sqianf4ca7ed2019-01-15 18:32:07 -080010141 * Update emergency number list for test mode.
10142 */
10143 @Override
10144 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
10145 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10146 "updateEmergencyNumberListTestMode");
10147
10148 final long identity = Binder.clearCallingIdentity();
10149 try {
10150 for (Phone phone: PhoneFactory.getPhones()) {
10151 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10152 if (tracker != null) {
10153 tracker.executeEmergencyNumberTestModeCommand(action, num);
10154 }
10155 }
10156 } finally {
10157 Binder.restoreCallingIdentity(identity);
10158 }
10159 }
10160
10161 /**
10162 * Get the full emergency number list for test mode.
10163 */
10164 @Override
10165 public List<String> getEmergencyNumberListTestMode() {
10166 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10167 "getEmergencyNumberListTestMode");
10168
10169 final long identity = Binder.clearCallingIdentity();
10170 try {
10171 Set<String> emergencyNumbers = new HashSet<>();
10172 for (Phone phone: PhoneFactory.getPhones()) {
10173 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10174 if (tracker != null) {
10175 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
10176 emergencyNumbers.add(num.getNumber());
10177 }
10178 }
10179 }
10180 return new ArrayList<>(emergencyNumbers);
10181 } finally {
10182 Binder.restoreCallingIdentity(identity);
10183 }
10184 }
10185
chen xud6b45bd2018-10-30 22:27:10 -070010186 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -080010187 public int getEmergencyNumberDbVersion(int subId) {
10188 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
10189
10190 final long identity = Binder.clearCallingIdentity();
10191 try {
10192 final Phone phone = getPhone(subId);
10193 if (phone == null) {
10194 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
10195 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
10196 }
10197 return phone.getEmergencyNumberDbVersion();
10198 } finally {
10199 Binder.restoreCallingIdentity(identity);
10200 }
10201 }
10202
10203 @Override
10204 public void notifyOtaEmergencyNumberDbInstalled() {
10205 enforceModifyPermission();
10206
10207 final long identity = Binder.clearCallingIdentity();
10208 try {
10209 for (Phone phone: PhoneFactory.getPhones()) {
10210 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10211 if (tracker != null) {
10212 tracker.updateOtaEmergencyNumberDatabase();
10213 }
10214 }
10215 } finally {
10216 Binder.restoreCallingIdentity(identity);
10217 }
10218 }
10219
10220 @Override
Shuo Qianc373f112020-03-05 17:55:34 -080010221 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -080010222 enforceActiveEmergencySessionPermission();
10223
10224 final long identity = Binder.clearCallingIdentity();
10225 try {
10226 for (Phone phone: PhoneFactory.getPhones()) {
10227 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10228 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -080010229 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
10230 }
10231 }
10232 } finally {
10233 Binder.restoreCallingIdentity(identity);
10234 }
10235 }
10236
10237 @Override
10238 public void resetOtaEmergencyNumberDbFilePath() {
10239 enforceActiveEmergencySessionPermission();
10240
10241 final long identity = Binder.clearCallingIdentity();
10242 try {
10243 for (Phone phone: PhoneFactory.getPhones()) {
10244 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
10245 if (tracker != null) {
10246 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -080010247 }
10248 }
10249 } finally {
10250 Binder.restoreCallingIdentity(identity);
10251 }
10252 }
10253
10254 @Override
chen xud6b45bd2018-10-30 22:27:10 -070010255 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
10256 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
10257 Phone phone = getPhone(subId);
10258 if (phone == null) {
10259 return null;
10260 }
10261 final long identity = Binder.clearCallingIdentity();
10262 try {
10263 UiccProfile profile = UiccController.getInstance()
10264 .getUiccProfileForPhone(phone.getPhoneId());
10265 if (profile != null) {
10266 return profile.getCertsFromCarrierPrivilegeAccessRules();
10267 }
10268 } finally {
10269 Binder.restoreCallingIdentity(identity);
10270 }
10271 return null;
10272 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -080010273
10274 /**
10275 * Enable or disable a modem stack.
10276 */
10277 @Override
10278 public boolean enableModemForSlot(int slotIndex, boolean enable) {
10279 enforceModifyPermission();
10280
10281 final long identity = Binder.clearCallingIdentity();
10282 try {
10283 Phone phone = PhoneFactory.getPhone(slotIndex);
10284 if (phone == null) {
10285 return false;
10286 } else {
10287 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
10288 }
10289 } finally {
10290 Binder.restoreCallingIdentity(identity);
10291 }
10292 }
Michelecea4cf22018-12-21 15:00:11 -080010293
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010294 /**
10295 * Whether a modem stack is enabled or not.
10296 */
10297 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010298 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
10299 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010300 Phone phone = PhoneFactory.getPhone(slotIndex);
10301 if (phone == null) return false;
10302
10303 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010304 mApp, phone.getSubId(), callingPackage, callingFeatureId,
10305 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010306 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10307 }
10308
10309 final long identity = Binder.clearCallingIdentity();
10310 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -070010311 try {
10312 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
10313 } catch (NoSuchElementException ex) {
10314 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
10315 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -070010316 } finally {
10317 Binder.restoreCallingIdentity(identity);
10318 }
10319 }
10320
Michelecea4cf22018-12-21 15:00:11 -080010321 @Override
Michele0ea7d782019-03-19 14:58:42 -070010322 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -080010323 enforceModifyPermission();
10324
10325 final long identity = Binder.clearCallingIdentity();
10326 try {
10327 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -070010328 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -080010329 .commit();
10330 } finally {
10331 Binder.restoreCallingIdentity(identity);
10332 }
10333 }
10334
10335 @Override
Michele0ea7d782019-03-19 14:58:42 -070010336 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010337 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -080010338 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010339 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
10340 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -070010341 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -080010342 }
Michelecea4cf22018-12-21 15:00:11 -080010343
10344 final long identity = Binder.clearCallingIdentity();
10345 try {
Michele0ea7d782019-03-19 14:58:42 -070010346 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -080010347 } finally {
10348 Binder.restoreCallingIdentity(identity);
10349 }
10350 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010351
Michele0ea7d782019-03-19 14:58:42 -070010352 @TelephonyManager.IsMultiSimSupportedResult
10353 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -080010354 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
10355 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
10356 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010357 loge("isMultiSimSupportedInternal: requires at least 2 cards");
10358 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010359 }
10360 // Check if the hardware supports multisim functionality. If usage of multisim is not
10361 // supported by the modem, indicate that it is restricted.
10362 PhoneCapability staticCapability =
10363 mPhoneConfigurationManager.getStaticPhoneCapability();
10364 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -070010365 loge("isMultiSimSupportedInternal: no static configuration available");
10366 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010367 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010368 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -070010369 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
10370 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -080010371 }
10372 // Check if support of multiple SIMs is restricted by carrier
10373 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -070010374 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -080010375 }
10376
Michele0ea7d782019-03-19 14:58:42 -070010377 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -080010378 }
10379
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010380 /**
10381 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010382 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
10383 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
10384 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010385 * @param numOfSims number of active sims we want to switch to
10386 */
10387 @Override
10388 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -080010389 if (numOfSims == 1) {
10390 enforceModifyPermission();
10391 } else {
10392 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10393 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
10394 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010395 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -080010396
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010397 try {
Michele30b57b22019-03-01 12:01:14 -080010398 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -070010399 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -080010400 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
10401 return;
10402 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010403 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
10404 } finally {
10405 Binder.restoreCallingIdentity(identity);
10406 }
10407 }
10408
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010409 @Override
10410 public boolean isApplicationOnUicc(int subId, int appType) {
10411 enforceReadPrivilegedPermission("isApplicationOnUicc");
10412 Phone phone = getPhone(subId);
10413 if (phone == null) {
10414 return false;
10415 }
10416 final long identity = Binder.clearCallingIdentity();
10417 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010418 UiccPort uiccPort = phone.getUiccPort();
10419 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010420 return false;
10421 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +000010422 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +090010423 if (uiccProfile == null) {
10424 return false;
10425 }
10426 if (TelephonyManager.APPTYPE_SIM <= appType
10427 && appType <= TelephonyManager.APPTYPE_ISIM) {
10428 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
10429 }
10430 return false;
10431 } finally {
10432 Binder.restoreCallingIdentity(identity);
10433 }
10434 }
10435
Nazanin Bakhshi628473f2019-01-29 17:37:52 -080010436 /**
chen xub4baa772019-04-03 10:23:41 -070010437 * Get whether making changes to modem configurations will trigger reboot.
10438 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010439 */
10440 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010441 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
10442 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -070010443 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -070010444 mApp, subId, callingPackage, callingFeatureId,
10445 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -070010446 return false;
10447 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -080010448 final long identity = Binder.clearCallingIdentity();
10449 try {
10450 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
10451 } finally {
10452 Binder.restoreCallingIdentity(identity);
10453 }
10454 }
10455
Nathan Harold29f5f052019-02-15 13:41:57 -080010456 private void updateModemStateMetrics() {
10457 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
10458 // TODO: check the state for each modem if the api is ready.
10459 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
10460 }
10461
Pengquan Meng3889a572019-01-23 11:16:29 -080010462 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +000010463 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -080010464 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +000010465 // Verify that the callingPackage belongs to the calling UID
10466 mApp.getSystemService(AppOpsManager.class)
10467 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -080010468 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +000010469 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -080010470 try {
sandeepjsa208e3b2021-11-17 04:05:58 +000010471 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
10472 if (slotInfos != null) {
10473 for (int i = 0; i < slotInfos.length; i++) {
10474 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
10475 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
10476 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
10477 portInfo.getLogicalSlotIndex()));
10478 }
10479 }
Pengquan Meng3889a572019-01-23 11:16:29 -080010480 }
10481 }
sandeepjsa208e3b2021-11-17 04:05:58 +000010482 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -080010483 } finally {
10484 Binder.restoreCallingIdentity(identity);
10485 }
10486 }
Nathan Harold48d6fd52019-02-06 19:01:40 -080010487
10488 /**
10489 * Get the IRadio HAL Version
jimsunf9ec1622022-09-13 21:18:43 +080010490 * @deprecated use getHalVersion instead
Nathan Harold48d6fd52019-02-06 19:01:40 -080010491 */
jimsunf9ec1622022-09-13 21:18:43 +080010492 @Deprecated
Nathan Harold48d6fd52019-02-06 19:01:40 -080010493 @Override
10494 public int getRadioHalVersion() {
jimsunf9ec1622022-09-13 21:18:43 +080010495 return getHalVersion(HAL_SERVICE_RADIO);
10496 }
10497
10498 /**
10499 * Get the HAL Version of a specific service
10500 */
10501 @Override
10502 public int getHalVersion(int service) {
Nathan Harold48d6fd52019-02-06 19:01:40 -080010503 Phone phone = getDefaultPhone();
10504 if (phone == null) return -1;
jimsunf9ec1622022-09-13 21:18:43 +080010505 HalVersion hv = phone.getHalVersion(service);
Nathan Harold48d6fd52019-02-06 19:01:40 -080010506 if (hv.equals(HalVersion.UNKNOWN)) return -1;
10507 return hv.major * 100 + hv.minor;
10508 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010509
10510 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010511 * Get the current calling package name.
10512 * @return the current calling package name
10513 */
10514 @Override
10515 public String getCurrentPackageName() {
10516 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
10517 }
10518
10519 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -070010520 * Return whether data is enabled for certain APN type. This will tell if framework will accept
10521 * corresponding network requests on a subId.
10522 *
10523 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010524 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -070010525 * 2) APN is un-metered for this subscription, or
10526 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -070010527 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -070010528 *
10529 * @return whether data is allowed for a apn type.
10530 *
10531 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010532 */
10533 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -070010534 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -070010535 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
10536 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010537
10538 // Now that all security checks passes, perform the operation as ourselves.
10539 final long identity = Binder.clearCallingIdentity();
10540 try {
10541 Phone phone = getPhone(subId);
10542 if (phone == null) return false;
10543
Jack Yu27422a52022-03-21 10:38:05 -070010544 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -080010545 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -070010546 isMetered = phone.getDataNetworkController().getDataConfigManager()
10547 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
10548 phone.getServiceState().getDataRoaming());
10549 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -080010550 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -070010551 } finally {
10552 Binder.restoreCallingIdentity(identity);
10553 }
10554 }
10555
10556 @Override
Jack Yu41407ee2019-05-13 16:54:09 -070010557 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -070010558 enforceReadPrivilegedPermission("isApnMetered");
10559
10560 // Now that all security checks passes, perform the operation as ourselves.
10561 final long identity = Binder.clearCallingIdentity();
10562 try {
10563 Phone phone = getPhone(subId);
10564 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -070010565 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
10566 DataUtils.apnTypeToNetworkCapability(apnType),
10567 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -070010568 } finally {
10569 Binder.restoreCallingIdentity(identity);
10570 }
10571 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010572
10573 @Override
Hall Liu73f5d362020-01-20 13:42:00 -080010574 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
10575 int subscriptionId, IBooleanConsumer resultCallback) {
10576 enforceModifyPermission();
10577 long token = Binder.clearCallingIdentity();
10578 try {
10579 Phone phone = getPhone(subscriptionId);
10580 if (phone == null) {
10581 try {
10582 if (resultCallback != null) {
10583 resultCallback.accept(false);
10584 }
10585 } catch (RemoteException e) {
10586 // ignore
10587 }
10588 return;
10589 }
10590 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
10591 Pair.create(specifiers, (x) -> {
10592 try {
10593 if (resultCallback != null) {
10594 resultCallback.accept(x);
10595 }
10596 } catch (RemoteException e) {
10597 // ignore
10598 }
10599 });
10600 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
10601 } finally {
10602 Binder.restoreCallingIdentity(token);
10603 }
10604 }
10605
10606 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -080010607 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
10608 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -070010609 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -080010610 mApp, subId, "getSystemSelectionChannels");
10611 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10612 final long identity = Binder.clearCallingIdentity();
10613 try {
Sarah Chin428d1d62021-03-13 03:17:40 -080010614 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
10615 if (result instanceof IllegalStateException) {
10616 throw (IllegalStateException) result;
10617 }
10618 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -080010619 if (DBG) log("getSystemSelectionChannels: " + specifiers);
10620 return specifiers;
10621 } finally {
10622 Binder.restoreCallingIdentity(identity);
10623 }
10624 }
10625
10626 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -070010627 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +080010628 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -070010629 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +080010630 }
10631
10632 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010633 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
10634 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -080010635 if (callingPackage == null) {
10636 callingPackage = getCurrentPackageName();
10637 }
Brad Ebingera63db5f2019-04-23 16:31:13 -070010638 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
10639 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -070010640 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
10641 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -070010642 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
10643 }
10644 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
10645 Intent intent = new Intent();
10646 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
10647 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10648 // Bring up choose default SMS subscription dialog right now
10649 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
10650 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
10651 mApp.startActivity(intent);
10652 }
chen xud5ca2d52019-05-28 15:20:57 -070010653
10654 @Override
Ayush Sharma787854b2022-12-12 14:55:02 +000010655 public void showSwitchToManagedProfileDialog() {
10656 enforceModifyPermission();
10657
10658 Intent intent = new Intent();
10659 intent.setClass(mApp, ErrorDialogActivity.class);
10660 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
10661 mApp.startActivity(intent);
10662 }
10663
10664 @Override
chen xud5ca2d52019-05-28 15:20:57 -070010665 public String getMmsUAProfUrl(int subId) {
10666 //TODO investigate if this API should require proper permission check in R b/133791609
10667 final long identity = Binder.clearCallingIdentity();
10668 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010669 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
10670 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
10671 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
10672 return carrierUAProfUrl;
10673 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010674 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10675 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -070010676 } finally {
10677 Binder.restoreCallingIdentity(identity);
10678 }
10679 }
10680
10681 @Override
10682 public String getMmsUserAgent(int subId) {
10683 //TODO investigate if this API should require proper permission check in R b/133791609
10684 final long identity = Binder.clearCallingIdentity();
10685 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +080010686 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
10687 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
10688 if (!TextUtils.isEmpty(carrierUserAgent)) {
10689 return carrierUserAgent;
10690 }
Daniel Brightebb4eb72020-02-18 15:16:33 -080010691 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
10692 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -070010693 } finally {
10694 Binder.restoreCallingIdentity(identity);
10695 }
10696 }
Jack Yub07d4972019-05-28 16:12:25 -070010697
10698 @Override
Hall Liua62f5da2020-09-25 10:42:19 -070010699 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
10700 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -070010701
Jack Yub07d4972019-05-28 16:12:25 -070010702 final long identity = Binder.clearCallingIdentity();
10703 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010704 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -070010705 if (phone == null) return false;
10706
Ling Maf188d502022-09-16 15:22:36 -070010707 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -070010708 } finally {
10709 Binder.restoreCallingIdentity(identity);
10710 }
10711 }
10712
10713 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010714 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010715 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010716 enforceModifyPermission();
10717
changbettyd5c246e2019-12-24 15:40:37 +080010718 final long identity = Binder.clearCallingIdentity();
10719 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010720 Phone phone = getPhone(subscriptionId);
10721 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010722
Ling Maf188d502022-09-16 15:22:36 -070010723 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +080010724 } finally {
10725 Binder.restoreCallingIdentity(identity);
10726 }
10727 }
10728
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010729 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010730 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010731 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10732 * otherwise.
10733 */
10734 @Override
10735 public void setCepEnabled(boolean isCepEnabled) {
10736 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10737
10738 final long identity = Binder.clearCallingIdentity();
10739 try {
10740 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10741 for (Phone phone : PhoneFactory.getPhones()) {
10742 Phone defaultPhone = phone.getImsPhone();
10743 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10744 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10745 ImsPhoneCallTracker imsPhoneCallTracker =
10746 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10747 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10748 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10749 + imsPhone.getMsisdn());
10750 }
10751 }
10752 } finally {
10753 Binder.restoreCallingIdentity(identity);
10754 }
10755 }
allenwtsu46dcc572020-01-08 18:24:03 +080010756
10757 /**
10758 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10759 *
10760 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10761 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10762 * before being read.
10763 */
10764 @Override
10765 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10766 isCompressed) {
10767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10768 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010769 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10770 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10771 }
10772 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000010773 // ProvisioningManager can not handle ServiceSpecificException.
10774 // Throw the IllegalStateException and annotate ProvisioningManager.
10775 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000010776 }
10777
10778 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010779 try {
Hui Wang761a6682020-10-31 05:12:53 +000010780 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10781 } finally {
10782 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010783 }
10784 }
zoey chene02881a2019-12-30 16:11:23 +080010785
10786 @Override
10787 public boolean isIccLockEnabled(int subId) {
10788 enforceReadPrivilegedPermission("isIccLockEnabled");
10789
10790 // Now that all security checks passes, perform the operation as ourselves.
10791 final long identity = Binder.clearCallingIdentity();
10792 try {
10793 Phone phone = getPhone(subId);
10794 if (phone != null && phone.getIccCard() != null) {
10795 return phone.getIccCard().getIccLockEnabled();
10796 } else {
10797 return false;
10798 }
10799 } finally {
10800 Binder.restoreCallingIdentity(identity);
10801 }
10802 }
10803
10804 /**
10805 * Set the ICC pin lock enabled or disabled.
10806 *
10807 * @return an integer representing the status of IccLock enabled or disabled in the following
10808 * three cases:
10809 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10810 * successfully.
10811 * - Positive number and zero for remaining password attempts.
10812 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10813 *
10814 */
10815 @Override
10816 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10817 enforceModifyPermission();
10818
10819 Phone phone = getPhone(subId);
10820 if (phone == null) {
10821 return 0;
10822 }
10823 // Now that all security checks passes, perform the operation as ourselves.
10824 final long identity = Binder.clearCallingIdentity();
10825 try {
10826 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10827 new Pair<Boolean, String>(enabled, password), phone, null);
10828 return attemptsRemaining;
10829
10830 } catch (Exception e) {
10831 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10832 } finally {
10833 Binder.restoreCallingIdentity(identity);
10834 }
10835 return 0;
10836 }
10837
10838 /**
10839 * Change the ICC password used in ICC pin lock.
10840 *
10841 * @return an integer representing the status of IccLock changed in the following three cases:
10842 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10843 * - Positive number and zero for remaining password attempts.
10844 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10845 *
10846 */
10847 @Override
10848 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10849 enforceModifyPermission();
10850
10851 Phone phone = getPhone(subId);
10852 if (phone == null) {
10853 return 0;
10854 }
10855 // Now that all security checks passes, perform the operation as ourselves.
10856 final long identity = Binder.clearCallingIdentity();
10857 try {
10858 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10859 new Pair<String, String>(oldPassword, newPassword), phone, null);
10860 return attemptsRemaining;
10861
10862 } catch (Exception e) {
10863 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10864 } finally {
10865 Binder.restoreCallingIdentity(identity);
10866 }
10867 return 0;
10868 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010869
10870 /**
10871 * Request for receiving user activity notification
10872 */
10873 @Override
10874 public void requestUserActivityNotification() {
10875 if (!mNotifyUserActivity.get()
10876 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10877 mNotifyUserActivity.set(true);
10878 }
10879 }
10880
10881 /**
10882 * Called when userActivity is signalled in the power manager.
10883 * This is safe to call from any thread, with any window manager locks held or not.
10884 */
10885 @Override
10886 public void userActivity() {
10887 // ***************************************
10888 // * Inherited from PhoneWindowManager *
10889 // ***************************************
10890 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10891 // WITH ITS LOCKS HELD.
10892 //
10893 // This code must be VERY careful about the locks
10894 // it acquires.
10895 // In fact, the current code acquires way too many,
10896 // and probably has lurking deadlocks.
10897
10898 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10899 throw new SecurityException("Only the OS may call notifyUserActivity()");
10900 }
10901
10902 if (mNotifyUserActivity.getAndSet(false)) {
10903 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10904 USER_ACTIVITY_NOTIFICATION_DELAY);
10905 }
10906 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010907
10908 @Override
10909 public boolean canConnectTo5GInDsdsMode() {
10910 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10911 }
Jack Yud10cdd42020-09-28 20:28:01 -070010912
10913 @Override
10914 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10915 String callingFeatureId) {
10916 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10917 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10918 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10919 }
10920
10921 Phone phone = getPhone(subId);
10922 if (phone == null) {
10923 throw new RuntimeException("phone is not available");
10924 }
10925 // Now that all security checks passes, perform the operation as ourselves.
10926 final long identity = Binder.clearCallingIdentity();
10927 try {
10928 return phone.getEquivalentHomePlmns();
10929 } finally {
10930 Binder.restoreCallingIdentity(identity);
10931 }
10932 }
Daniel Bright59e67312020-11-13 11:49:37 -080010933
10934 @Override
10935 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010936 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10937 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010938 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010939 if (radioInterfaceCapabilities == null) {
10940 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010941 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010942 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010943 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010944
Hui Wang641e81c2020-10-12 12:14:23 -070010945 @Override
10946 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10947 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010948 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10949 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10950 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10951 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10952 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010953 if (DBG) {
10954 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10955 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10956 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10957 }
10958
10959 if (!SubscriptionManager.isValidSubscriptionId(subId)
10960 || appType < TelephonyManager.APPTYPE_UNKNOWN
10961 || appType > TelephonyManager.APPTYPE_ISIM
10962 || nafUrl == null || securityProtocol == null || callback == null) {
10963 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10964 if (callback != null) {
10965 try {
10966 callback.onAuthenticationFailure(
10967 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10968 } catch (RemoteException exception) {
10969 log("Fail to notify onAuthenticationFailure due to " + exception);
10970 }
10971 return;
10972 }
10973 }
10974
10975 final long token = Binder.clearCallingIdentity();
10976 try {
10977 getGbaManager(subId).bootstrapAuthenticationRequest(
10978 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
Thomas Nguyen8ee49682023-02-01 11:46:09 -080010979 forceBootStrapping, callback));
Hui Wang641e81c2020-10-12 12:14:23 -070010980 } finally {
10981 Binder.restoreCallingIdentity(token);
10982 }
10983 }
10984
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010985 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010986 * Attempts to set the radio power state for all phones for thermal reason.
10987 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010988 * requested radio power state will actually be set. See {@link
10989 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10990 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010991 * @param enable {@code true} if trying to turn radio on.
10992 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10993 * false}.
10994 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010995 private boolean setRadioPowerForThermal(boolean enable) {
10996 boolean isPhoneAvailable = false;
10997 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10998 Phone phone = PhoneFactory.getPhone(i);
10999 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000011000 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011001 isPhoneAvailable = true;
11002 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011003 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011004
11005 // return true if successfully informed the phone object about the thermal radio power
11006 // request.
11007 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011008 }
11009
11010 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070011011 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011012 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
11013 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
11014 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
11015 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
11016 throw new IllegalArgumentException("modem does not support data throttling");
11017 }
11018
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011019 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
11020 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011021 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011022 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11023 }
11024
Sarah Chinecc78c42022-03-31 21:16:48 -070011025 setDataEnabledForReason(
11026 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011027
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011028 if (isDataThrottlingSupported) {
11029 int thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011030 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011031 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
11032 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
11033 } else if (thermalMitigationResult
11034 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070011035 log("Modem likely does not support data throttling on secondary carrier. Data " +
11036 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
11037 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011038 }
11039 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011040 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080011041
11042 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011043 }
11044
Jack Nudelman644b91a2021-03-12 14:09:48 -080011045 private static List<String> getThermalMitigationAllowlist(Context context) {
11046 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
11047 for (String pckg : context.getResources()
11048 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
11049 sThermalMitigationAllowlistedPackages.add(pckg);
11050 }
11051 }
11052
11053 return sThermalMitigationAllowlistedPackages;
11054 }
11055
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011056 private boolean isAnyPhoneInEmergencyState() {
11057 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
11058 if (tm.isInEmergencyCall()) {
11059 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
11060 return true;
11061 }
11062 for (Phone phone : PhoneFactory.getPhones()) {
11063 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
11064 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011065 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
11066 + phone.isInEcm());
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011067 return true;
11068 }
11069 }
11070
11071 return false;
11072 }
11073
Jack Nudelman644b91a2021-03-12 14:09:48 -080011074 /**
11075 * Used by shell commands to add an authorized package name for thermal mitigation.
11076 * @param packageName name of package to be allowlisted
11077 * @param context
11078 */
11079 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
11080 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11081 sThermalMitigationAllowlistedPackages.add(packageName);
11082 }
11083
11084 /**
11085 * Used by shell commands to remove an authorized package name for thermal mitigation.
11086 * @param packageName name of package to remove from allowlist
11087 * @param context
11088 */
11089 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
11090 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
11091 sThermalMitigationAllowlistedPackages.remove(packageName);
11092 }
11093
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011094 /**
11095 * Thermal mitigation request to control functionalities at modem.
11096 *
11097 * @param subId the id of the subscription.
11098 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080011099 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011100 *
11101 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
11102 */
11103 @Override
11104 @ThermalMitigationResult
11105 public int sendThermalMitigationRequest(
11106 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080011107 ThermalMitigationRequest thermalMitigationRequest,
11108 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011109 enforceModifyPermission();
11110
Jack Nudelman644b91a2021-03-12 14:09:48 -080011111 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11112 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
11113 .contains(callingPackage)) {
11114 throw new SecurityException("Calling package must be configured in the device config. "
11115 + "calling package: " + callingPackage);
11116 }
11117
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011118 WorkSource workSource = getWorkSource(Binder.getCallingUid());
11119 final long identity = Binder.clearCallingIdentity();
11120
11121 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
11122 try {
11123 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
11124 switch (thermalMitigationAction) {
11125 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
11126 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011127 handleDataThrottlingRequest(subId,
11128 thermalMitigationRequest.getDataThrottlingRequest(),
11129 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011130 break;
11131 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
11132 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11133 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
11134 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
11135 }
11136
11137 // Ensure that radio is on. If not able to power on due to phone being
11138 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011139 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011140 thermalMitigationResult =
11141 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11142 break;
11143 }
11144
11145 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070011146 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011147 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
11148 break;
11149 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
11150 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
11151 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
11152 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
11153 }
11154
11155 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
11156 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011157 Phone phone = getPhone(subId);
11158 if (phone == null) {
11159 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011160 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011161 break;
11162 }
11163
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011164 TelephonyConnectionService service =
11165 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070011166 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070011167 Log.e(LOG_TAG, "An emergency call is pending");
11168 thermalMitigationResult =
11169 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
11170 break;
11171 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011172 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011173 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011174 break;
11175 }
11176 } else {
11177 thermalMitigationResult =
11178 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11179 break;
11180 }
11181
11182 // Turn radio off. If not able to power off due to phone being unavailable,
11183 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070011184 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011185 thermalMitigationResult =
11186 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
11187 break;
11188 }
11189 thermalMitigationResult =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080011190 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080011191 break;
11192 default:
11193 throw new IllegalArgumentException("the requested thermalMitigationAction does "
11194 + "not exist. Requested action: " + thermalMitigationAction);
11195 }
11196 } catch (IllegalArgumentException e) {
11197 throw e;
11198 } catch (Exception e) {
11199 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
11200 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
11201 } finally {
11202 Binder.restoreCallingIdentity(identity);
11203 }
11204
11205 if (DBG) {
11206 log("thermalMitigationRequest returning with thermalMitigationResult: "
11207 + thermalMitigationResult);
11208 }
11209
11210 return thermalMitigationResult;
11211 }
Hui Wang641e81c2020-10-12 12:14:23 -070011212
11213 /**
11214 * Set the GbaService Package Name that Telephony will bind to.
11215 *
11216 * @param subId The sim that the GbaService is associated with.
11217 * @param packageName The name of the package to be replaced with.
11218 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11219 */
11220 @Override
11221 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
11222 enforceModifyPermission();
11223
11224 final long identity = Binder.clearCallingIdentity();
11225 try {
11226 return getGbaManager(subId).overrideServicePackage(packageName);
11227 } finally {
11228 Binder.restoreCallingIdentity(identity);
11229 }
11230 }
11231
11232 /**
11233 * Return the package name of the currently bound GbaService.
11234 *
11235 * @param subId The sim that the GbaService is associated with.
11236 * @return the package name of the GbaService configuration, null if GBA is not supported.
11237 */
11238 @Override
11239 public String getBoundGbaService(int subId) {
11240 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
11241
11242 final long identity = Binder.clearCallingIdentity();
11243 try {
11244 return getGbaManager(subId).getServicePackage();
11245 } finally {
11246 Binder.restoreCallingIdentity(identity);
11247 }
11248 }
11249
11250 /**
11251 * Set the release time for telephony to unbind GbaService.
11252 *
11253 * @param subId The sim that the GbaService is associated with.
11254 * @param interval The release time to unbind GbaService by millisecond.
11255 * @return true if setting the GbaService to bind to succeeded, false if it did not.
11256 */
11257 @Override
11258 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
11259 enforceModifyPermission();
11260
11261 final long identity = Binder.clearCallingIdentity();
11262 try {
11263 return getGbaManager(subId).overrideReleaseTime(interval);
11264 } finally {
11265 Binder.restoreCallingIdentity(identity);
11266 }
11267 }
11268
11269 /**
11270 * Return the release time for telephony to unbind GbaService.
11271 *
11272 * @param subId The sim that the GbaService is associated with.
11273 * @return The release time to unbind GbaService by millisecond.
11274 */
11275 @Override
11276 public int getGbaReleaseTime(int subId) {
11277 enforceReadPrivilegedPermission("getGbaReleaseTime");
11278
11279 final long identity = Binder.clearCallingIdentity();
11280 try {
11281 return getGbaManager(subId).getReleaseTime();
11282 } finally {
11283 Binder.restoreCallingIdentity(identity);
11284 }
11285 }
11286
11287 private GbaManager getGbaManager(int subId) {
11288 GbaManager instance = GbaManager.getInstance(subId);
11289 if (instance == null) {
11290 String packageName = mApp.getResources().getString(R.string.config_gba_package);
11291 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
11292 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
11293 }
11294 return instance;
11295 }
Hui Wang761a6682020-10-31 05:12:53 +000011296
11297 /**
11298 * indicate whether the device and the carrier can support
11299 * RCS VoLTE single registration.
11300 */
11301 @Override
11302 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011303 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11304 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
11305 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11306 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011307
11308 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11309 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11310 }
11311
11312 final long identity = Binder.clearCallingIdentity();
11313 try {
11314 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
11315 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070011316 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
11317 if (isCapable != null) {
11318 return isCapable;
11319 }
Hui Wang761a6682020-10-31 05:12:53 +000011320 }
Hui Wang67af90e2021-06-04 16:57:15 -070011321 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11322 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011323 } finally {
11324 Binder.restoreCallingIdentity(identity);
11325 }
11326 }
11327
11328 /**
11329 * Register RCS provisioning callback.
11330 */
11331 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011332 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011333 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011334 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011335 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011336 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11337 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011338
11339 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11340 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11341 }
11342 if (!isImsAvailableOnDevice()) {
11343 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11344 "IMS not available on device.");
11345 }
11346
11347 final long identity = Binder.clearCallingIdentity();
11348 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011349 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011350 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070011351 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11352 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080011353 }
Hui Wang761a6682020-10-31 05:12:53 +000011354 } finally {
11355 Binder.restoreCallingIdentity(identity);
11356 }
11357 }
11358
11359 /**
11360 * Unregister RCS provisioning callback.
11361 */
11362 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080011363 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000011364 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011365 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080011366 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000011367 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
11368 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000011369
11370 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11371 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11372 }
11373 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011374 // operation failed silently
11375 Rlog.w(LOG_TAG, "IMS not available on device.");
11376 return;
Hui Wang761a6682020-10-31 05:12:53 +000011377 }
11378
11379 final long identity = Binder.clearCallingIdentity();
11380 try {
Hui Wang68cd3722021-01-11 20:04:53 -080011381 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080011382 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000011383 } finally {
11384 Binder.restoreCallingIdentity(identity);
11385 }
11386 }
11387
11388 /**
11389 * trigger RCS reconfiguration.
11390 */
11391 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011392 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11393 "triggerRcsReconfiguration",
11394 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011395
11396 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11397 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11398 }
11399 if (!isImsAvailableOnDevice()) {
joonhunshin46b49a32022-12-21 05:33:23 +000011400 // ProvisioningManager can not handle ServiceSpecificException.
11401 // Throw the IllegalStateException and annotate ProvisioningManager.
11402 throw new IllegalStateException("IMS not available on device.");
Hui Wang761a6682020-10-31 05:12:53 +000011403 }
11404
11405 final long identity = Binder.clearCallingIdentity();
11406 try {
11407 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
11408 } finally {
11409 Binder.restoreCallingIdentity(identity);
11410 }
11411 }
11412
11413 /**
11414 * Provide the client configuration parameters of the RCS application.
11415 */
11416 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000011417 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
11418 "setRcsClientConfiguration",
11419 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000011420
11421 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
11422 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
11423 }
11424 if (!isImsAvailableOnDevice()) {
11425 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11426 "IMS not available on device.");
11427 }
11428
11429 final long identity = Binder.clearCallingIdentity();
11430
11431 try {
11432 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
11433 if (configBinder == null) {
11434 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070011435 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
11436 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000011437 } else {
11438 configBinder.setRcsClientConfiguration(rcc);
11439 }
joonhunshin3e154242021-09-17 06:33:39 +000011440
11441 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
11442 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000011443 } catch (RemoteException e) {
11444 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070011445 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
11446 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000011447 } finally {
11448 Binder.restoreCallingIdentity(identity);
11449 }
11450 }
11451
11452 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080011453 * Enables or disables the test mode for RCS VoLTE single registration.
11454 */
11455 @Override
11456 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
11457 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11458 "setRcsSingleRegistrationTestModeEnabled");
11459
11460 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
11461 }
11462
11463 /**
11464 * Gets the test mode for RCS VoLTE single registration.
11465 */
11466 @Override
11467 public boolean getRcsSingleRegistrationTestModeEnabled() {
11468 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11469 "getRcsSingleRegistrationTestModeEnabled");
11470
11471 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
11472 }
11473
11474 /**
Hui Wang761a6682020-10-31 05:12:53 +000011475 * Overrides the config of RCS VoLTE single registration enabled for the device.
11476 */
11477 @Override
11478 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
11479 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11480 "setDeviceSingleRegistrationEnabledOverride");
11481 enforceModifyPermission();
11482
11483 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11484 : Boolean.parseBoolean(enabledStr);
11485 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000011486 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000011487 }
11488
11489 /**
Tyler Gunn92479152021-01-20 16:30:10 -080011490 * Sends a device to device communication message. Only usable via shell.
11491 * @param message message to send.
11492 * @param value message value.
11493 */
11494 @Override
11495 public void sendDeviceToDeviceMessage(int message, int value) {
11496 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080011497 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080011498 enforceModifyPermission();
11499
11500 final long identity = Binder.clearCallingIdentity();
11501 try {
11502 TelephonyConnectionService service =
11503 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11504 if (service == null) {
11505 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
11506 return;
11507 }
11508 service.sendTestDeviceToDeviceMessage(message, value);
11509 } finally {
11510 Binder.restoreCallingIdentity(identity);
11511 }
11512 }
11513
Tyler Gunnbabbda02021-02-10 11:05:02 -080011514 /**
11515 * Sets the specified device to device transport active.
11516 * @param transport The transport to set active.
11517 */
11518 @Override
11519 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
11520 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11521 "setActiveDeviceToDeviceTransport");
11522 enforceModifyPermission();
11523
11524 final long identity = Binder.clearCallingIdentity();
11525 try {
11526 TelephonyConnectionService service =
11527 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
11528 if (service == null) {
11529 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
11530 return;
11531 }
11532 service.setActiveDeviceToDeviceTransport(transport);
11533 } finally {
11534 Binder.restoreCallingIdentity(identity);
11535 }
11536 }
Tyler Gunn92479152021-01-20 16:30:10 -080011537
Tyler Gunnd4339262021-05-03 14:46:49 -070011538 @Override
11539 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
11540 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11541 "setDeviceToDeviceForceEnabled");
11542
11543 final long identity = Binder.clearCallingIdentity();
11544 try {
11545 Arrays.stream(PhoneFactory.getPhones()).forEach(
11546 p -> {
11547 Phone thePhone = p.getImsPhone();
11548 if (thePhone != null && thePhone instanceof ImsPhone) {
11549 ImsPhone imsPhone = (ImsPhone) thePhone;
11550 CallTracker tracker = imsPhone.getCallTracker();
11551 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
11552 ImsPhoneCallTracker imsPhoneCallTracker =
11553 (ImsPhoneCallTracker) tracker;
11554 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
11555 }
11556 }
11557 }
11558 );
11559 } finally {
11560 Binder.restoreCallingIdentity(identity);
11561 }
11562 }
11563
Tyler Gunn92479152021-01-20 16:30:10 -080011564 /**
Hui Wang761a6682020-10-31 05:12:53 +000011565 * Gets the config of RCS VoLTE single registration enabled for the device.
11566 */
11567 @Override
11568 public boolean getDeviceSingleRegistrationEnabled() {
11569 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
11570 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
11571 }
11572
11573 /**
11574 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
11575 */
11576 @Override
11577 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
11578 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11579 "setCarrierSingleRegistrationEnabledOverride");
11580 enforceModifyPermission();
11581
11582 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11583 : Boolean.parseBoolean(enabledStr);
11584 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
11585 subId, enabled);
11586 }
11587
11588 /**
11589 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
11590 */
11591 @Override
11592 public boolean getCarrierSingleRegistrationEnabled(int subId) {
11593 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
11594 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
11595 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080011596
11597 /**
Hui Wangb647abe2021-02-26 09:33:38 -080011598 * Overrides the ims feature validation result
11599 */
11600 @Override
11601 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
11602 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11603 "setImsFeatureValidationOverride");
11604
11605 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
11606 : Boolean.parseBoolean(enabledStr);
11607 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
11608 subId, enabled);
11609 }
11610
11611 /**
11612 * Gets the ims feature validation override value
11613 */
11614 @Override
11615 public boolean getImsFeatureValidationOverride(int subId) {
11616 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11617 "getImsFeatureValidationOverride");
11618 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
11619 }
11620
11621 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080011622 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
11623 * their mobile plan.
11624 */
11625 @Override
11626 public String getMobileProvisioningUrl() {
11627 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
11628 final long identity = Binder.clearCallingIdentity();
11629 try {
11630 return getDefaultPhone().getMobileProvisioningUrl();
11631 } finally {
11632 Binder.restoreCallingIdentity(identity);
11633 }
11634 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011635
James.cf Linbcdf8b32021-01-14 16:44:13 +080011636 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080011637 * Get the EAB contact from the EAB database.
11638 */
11639 @Override
11640 public String getContactFromEab(String contact) {
11641 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
11642 enforceModifyPermission();
11643 final long identity = Binder.clearCallingIdentity();
11644 try {
11645 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
11646 } finally {
11647 Binder.restoreCallingIdentity(identity);
11648 }
11649 }
11650
11651 /**
Calvin Pana1434322021-07-01 19:27:01 +080011652 * Get the EAB capability from the EAB database.
11653 */
11654 @Override
11655 public String getCapabilityFromEab(String contact) {
11656 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
11657 enforceModifyPermission();
11658 final long identity = Binder.clearCallingIdentity();
11659 try {
11660 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
11661 } finally {
11662 Binder.restoreCallingIdentity(identity);
11663 }
11664 }
11665
11666 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080011667 * Remove the EAB contacts from the EAB database.
11668 */
11669 @Override
11670 public int removeContactFromEab(int subId, String contacts) {
11671 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
11672 enforceModifyPermission();
11673 final long identity = Binder.clearCallingIdentity();
11674 try {
11675 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
11676 } finally {
11677 Binder.restoreCallingIdentity(identity);
11678 }
11679 }
11680
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011681 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080011682 public boolean getDeviceUceEnabled() {
11683 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
11684 final long identity = Binder.clearCallingIdentity();
11685 try {
11686 return mApp.getDeviceUceEnabled();
11687 } finally {
11688 Binder.restoreCallingIdentity(identity);
11689 }
11690 }
11691
11692 @Override
11693 public void setDeviceUceEnabled(boolean isEnabled) {
11694 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
11695 final long identity = Binder.clearCallingIdentity();
11696 try {
11697 mApp.setDeviceUceEnabled(isEnabled);
11698 } finally {
11699 Binder.restoreCallingIdentity(identity);
11700 }
11701 }
11702
Brad Ebinger14d467f2021-02-12 06:18:28 +000011703 /**
11704 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11705 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11706 */
11707 // Used for SHELL command only right now.
11708 @Override
11709 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11710 List<String> featureTags) {
11711 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11712 "addUceRegistrationOverrideShell");
11713 final long identity = Binder.clearCallingIdentity();
11714 try {
11715 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11716 new ArraySet<>(featureTags));
11717 } catch (ImsException e) {
11718 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11719 } finally {
11720 Binder.restoreCallingIdentity(identity);
11721 }
11722 }
11723
11724 /**
11725 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11726 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11727 */
11728 // Used for SHELL command only right now.
11729 @Override
11730 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11731 List<String> featureTags) {
11732 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11733 "removeUceRegistrationOverrideShell");
11734 final long identity = Binder.clearCallingIdentity();
11735 try {
11736 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11737 new ArraySet<>(featureTags));
11738 } catch (ImsException e) {
11739 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11740 } finally {
11741 Binder.restoreCallingIdentity(identity);
11742 }
11743 }
11744
11745 /**
11746 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11747 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11748 */
11749 // Used for SHELL command only right now.
11750 @Override
11751 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11752 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11753 "clearUceRegistrationOverrideShell");
11754 final long identity = Binder.clearCallingIdentity();
11755 try {
11756 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11757 } catch (ImsException e) {
11758 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11759 } finally {
11760 Binder.restoreCallingIdentity(identity);
11761 }
11762 }
11763
11764 /**
11765 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11766 */
11767 // Used for SHELL command only right now.
11768 @Override
11769 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11770 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11771 "getLatestRcsContactUceCapabilityShell");
11772 final long identity = Binder.clearCallingIdentity();
11773 try {
11774 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11775 } catch (ImsException e) {
11776 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11777 } finally {
11778 Binder.restoreCallingIdentity(identity);
11779 }
11780 }
11781
11782 /**
11783 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11784 * device does not have an active PUBLISH.
11785 */
11786 // Used for SHELL command only right now.
11787 @Override
11788 public String getLastUcePidfXmlShell(int subId) {
11789 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11790 final long identity = Binder.clearCallingIdentity();
11791 try {
11792 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11793 } catch (ImsException e) {
11794 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11795 } finally {
11796 Binder.restoreCallingIdentity(identity);
11797 }
11798 }
11799
James.cf Line8713a42021-04-29 16:04:26 +080011800 /**
11801 * Remove UCE requests cannot be sent to the network status.
11802 */
11803 // Used for SHELL command only right now.
11804 @Override
11805 public boolean removeUceRequestDisallowedStatus(int subId) {
11806 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11807 final long identity = Binder.clearCallingIdentity();
11808 try {
11809 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11810 } catch (ImsException e) {
11811 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11812 } finally {
11813 Binder.restoreCallingIdentity(identity);
11814 }
11815 }
11816
James.cf Lin18bb9002021-05-25 01:37:38 +080011817 /**
11818 * Remove UCE requests cannot be sent to the network status.
11819 */
11820 // Used for SHELL command only.
11821 @Override
11822 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11823 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11824 final long identity = Binder.clearCallingIdentity();
11825 try {
11826 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11827 } catch (ImsException e) {
11828 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11829 } finally {
11830 Binder.restoreCallingIdentity(identity);
11831 }
11832 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011833
James.cf Lin4b784aa2021-01-31 03:25:15 +080011834 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011835 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11836 String callingPackage) {
11837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11838 mApp, subId, "setSignalStrengthUpdateRequest");
11839
11840 final int callingUid = Binder.getCallingUid();
11841 // Verify that tha callingPackage belongs to the calling UID
11842 mApp.getSystemService(AppOpsManager.class)
11843 .checkPackage(callingUid, callingPackage);
11844
Rambo Wang3607f502021-02-01 21:51:40 -080011845 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011846
11847 final long identity = Binder.clearCallingIdentity();
11848 try {
11849 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11850 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11851
11852 if (result instanceof IllegalStateException) {
11853 throw (IllegalStateException) result;
11854 }
11855 } finally {
11856 Binder.restoreCallingIdentity(identity);
11857 }
11858 }
11859
11860 @Override
11861 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11862 String callingPackage) {
11863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11864 mApp, subId, "clearSignalStrengthUpdateRequest");
11865
11866 final int callingUid = Binder.getCallingUid();
11867 // Verify that tha callingPackage belongs to the calling UID
11868 mApp.getSystemService(AppOpsManager.class)
11869 .checkPackage(callingUid, callingPackage);
11870
11871 final long identity = Binder.clearCallingIdentity();
11872 try {
11873 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11874 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11875
11876 if (result instanceof IllegalStateException) {
11877 throw (IllegalStateException) result;
11878 }
11879 } finally {
11880 Binder.restoreCallingIdentity(identity);
11881 }
11882 }
11883
Rambo Wang3607f502021-02-01 21:51:40 -080011884 private static void validateSignalStrengthUpdateRequest(Context context,
11885 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011886 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11887 // phone/system process do not have further restriction on request
11888 return;
11889 }
11890
11891 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011892 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011893 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011894 context.enforceCallingOrSelfPermission(
11895 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11896 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011897 }
11898
11899 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
Nagendra Prasad Nagarle Basavarajufee544c2022-12-07 16:34:52 +000011900 // Only system caller can set mHysteresisMs/mIsEnabled.
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011901 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011902 || info.isEnabled()) {
11903 throw new IllegalArgumentException(
11904 "Only system can set hide fields in SignalThresholdInfo");
11905 }
11906
11907 // Thresholds length for each RAN need in range. This has been validated in
11908 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11909 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11910 final int[] thresholds = info.getThresholds();
11911 Objects.requireNonNull(thresholds);
11912 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11913 || thresholds.length
11914 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11915 throw new IllegalArgumentException(
11916 "thresholds length is out of range: " + thresholds.length);
11917 }
11918 }
11919 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011920
11921 /**
11922 * Gets the current phone capability.
11923 *
11924 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11925 * @return the PhoneCapability which describes the data connection capability of modem.
11926 * It's used to evaluate possible phone config change, for example from single
11927 * SIM device to multi-SIM device.
11928 */
11929 @Override
11930 public PhoneCapability getPhoneCapability() {
11931 enforceReadPrivilegedPermission("getPhoneCapability");
11932 final long identity = Binder.clearCallingIdentity();
11933 try {
11934 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11935 } finally {
11936 Binder.restoreCallingIdentity(identity);
11937 }
11938 }
Michele Berionne5e411512020-11-13 02:36:59 +000011939
11940 /**
11941 * Prepare TelephonyManager for an unattended reboot. The reboot is
11942 * required to be done shortly after the API is invoked.
11943 */
11944 @Override
11945 @TelephonyManager.PrepareUnattendedRebootResult
11946 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011947 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011948 enforceRebootPermission();
11949
11950 final long identity = Binder.clearCallingIdentity();
11951 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011952 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011953 } finally {
11954 Binder.restoreCallingIdentity(identity);
11955 }
11956 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011957
11958 /**
11959 * Request to get the current slicing configuration including URSP rules and
11960 * NSSAIs (configured, allowed and rejected).
11961 *
11962 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11963 */
11964 @Override
11965 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011966 TelephonyPermissions
11967 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11968 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011969
11970 final long identity = Binder.clearCallingIdentity();
11971 try {
11972 Phone phone = getDefaultPhone();
11973 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11974 } finally {
11975 Binder.restoreCallingIdentity(identity);
11976 }
11977 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011978
11979 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011980 * Check whether the given premium capability is available for purchase from the carrier.
11981 *
11982 * @param capability The premium capability to check.
11983 * @param subId The subId to check the premium capability for.
11984 *
11985 * @return Whether the given premium capability is available to purchase.
11986 */
11987 @Override
11988 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11989 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11990 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11991 log("Premium capability "
11992 + TelephonyManager.convertPremiumCapabilityToString(capability)
11993 + " is not available for purchase due to missing permissions.");
11994 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11995 + "permission READ_BASIC_PHONE_STATE.");
11996 }
11997
11998 Phone phone = getPhone(subId);
Thomas Nguyen7216ed62022-11-29 16:45:31 -080011999 if (phone == null) {
12000 loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId);
12001 return false;
12002 }
Sarah Chin2ec39f62022-08-31 17:03:26 -070012003 final long identity = Binder.clearCallingIdentity();
12004 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070012005 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070012006 .isPremiumCapabilityAvailableForPurchase(capability);
12007 } finally {
12008 Binder.restoreCallingIdentity(identity);
12009 }
12010 }
12011
12012 /**
12013 * Purchase the given premium capability from the carrier.
12014 *
12015 * @param capability The premium capability to purchase.
12016 * @param callback The result of the purchase request.
12017 * @param subId The subId to purchase the premium capability for.
12018 */
12019 @Override
12020 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
12021 log("purchasePremiumCapability: capability="
12022 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
12023 + getCurrentPackageName());
12024
12025 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
12026 mApp, "purchasePremiumCapability")) {
12027 log("purchasePremiumCapability "
12028 + TelephonyManager.convertPremiumCapabilityToString(capability)
12029 + " failed due to missing permissions.");
12030 throw new SecurityException("purchasePremiumCapability requires permission "
12031 + "READ_BASIC_PHONE_STATE.");
Sarah Chin532d6bb2022-12-28 22:50:43 -080012032 } else if (!TelephonyPermissions.checkInternetPermissionNoThrow(
12033 mApp, "purchasePremiumCapability")) {
12034 log("purchasePremiumCapability "
12035 + TelephonyManager.convertPremiumCapabilityToString(capability)
12036 + " failed due to missing permissions.");
12037 throw new SecurityException("purchasePremiumCapability requires permission INTERNET.");
Sarah Chin2ec39f62022-08-31 17:03:26 -070012038 }
12039
12040 Phone phone = getPhone(subId);
Sarah Chin19694112022-12-06 15:41:37 -080012041 if (phone == null) {
12042 try {
12043 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED;
12044 callback.accept(result);
12045 loge("purchasePremiumCapability: phone is null, subId=" + subId);
12046 } catch (RemoteException e) {
12047 String logStr = "Purchase premium capability "
12048 + TelephonyManager.convertPremiumCapabilityToString(capability)
12049 + " failed due to RemoteException handling null phone: " + e;
12050 if (DBG) log(logStr);
12051 AnomalyReporter.reportAnomaly(
12052 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12053 }
12054 return;
12055 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012056
12057 String callingProcess;
Sarah Chin71b3a852022-09-28 15:54:19 -070012058 try {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012059 callingProcess = mApp.getPackageManager().getApplicationInfo(
12060 getCurrentPackageName(), 0).processName;
Sarah Chin71b3a852022-09-28 15:54:19 -070012061 } catch (PackageManager.NameNotFoundException e) {
Sarah Chin532d6bb2022-12-28 22:50:43 -080012062 callingProcess = getCurrentPackageName();
Sarah Chin71b3a852022-09-28 15:54:19 -070012063 }
Sarah Chin532d6bb2022-12-28 22:50:43 -080012064
12065 boolean isVisible = false;
12066 ActivityManager am = mApp.getSystemService(ActivityManager.class);
12067 if (am != null) {
12068 List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
12069 if (processes != null) {
12070 for (ActivityManager.RunningAppProcessInfo process : processes) {
12071 log("purchasePremiumCapability: process " + process.processName
12072 + "has importance " + process.importance);
12073 if (process.processName.equals(callingProcess) && process.importance
12074 <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
12075 isVisible = true;
12076 break;
12077 }
12078 }
12079 }
12080 }
12081
12082 if (!isVisible) {
12083 try {
12084 int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND;
12085 callback.accept(result);
12086 loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground.");
12087 } catch (RemoteException e) {
12088 String logStr = "Purchase premium capability "
12089 + TelephonyManager.convertPremiumCapabilityToString(capability)
12090 + " failed due to RemoteException handling background application: " + e;
12091 if (DBG) log(logStr);
12092 AnomalyReporter.reportAnomaly(
12093 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
12094 }
12095 return;
12096 }
12097
Sarah Chin71b3a852022-09-28 15:54:19 -070012098 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
Sarah Chinb8218c22023-01-04 13:35:29 -080012099 new PurchasePremiumCapabilityArgument(capability, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070012100 }
12101
12102 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012103 * Register an IMS connection state callback
12104 */
12105 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012106 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
12107 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012108 if (feature == ImsFeature.FEATURE_MMTEL) {
12109 // ImsMmTelManager
12110 // The following also checks READ_PRIVILEGED_PHONE_STATE.
12111 TelephonyPermissions
12112 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
12113 mApp, subId, "registerImsStateCallback");
12114 } else if (feature == ImsFeature.FEATURE_RCS) {
12115 // ImsRcsManager or SipDelegateManager
12116 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
12117 Binder.getCallingUid(), "registerImsStateCallback",
12118 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12119 Manifest.permission.READ_PRECISE_PHONE_STATE,
12120 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
12121 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
12122 }
12123
12124 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
12125 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12126 "IMS not available on device.");
12127 }
12128
12129 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
12130 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
12131 }
12132
12133 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12134 if (controller == null) {
12135 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
12136 "IMS not available on device.");
12137 }
12138
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012139 if (callingPackage == null) {
12140 callingPackage = getCurrentPackageName();
12141 }
12142
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012143 final long token = Binder.clearCallingIdentity();
12144 try {
12145 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000012146 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000012147 } catch (ImsException e) {
12148 throw new ServiceSpecificException(e.getCode());
12149 } finally {
12150 Binder.restoreCallingIdentity(token);
12151 }
12152 }
12153
12154 /**
12155 * Unregister an IMS connection state callback
12156 */
12157 @Override
12158 public void unregisterImsStateCallback(IImsStateCallback cb) {
12159 final long token = Binder.clearCallingIdentity();
12160 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
12161 if (controller == null) {
12162 return;
12163 }
12164 try {
12165 controller.unregisterImsStateCallback(cb);
12166 } finally {
12167 Binder.restoreCallingIdentity(token);
12168 }
12169 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012170
12171 /**
12172 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
12173 *
12174 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
12175 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
12176 * SecurityException.
12177 * If there is current registered network this value will be same as the registered cell
12178 * identity. If the device goes out of service the previous cell identity is cached and
12179 * will be returned. If the cache age of the Cell identity is more than 24 hours
12180 * it will be cleared and null will be returned.
12181 *
12182 */
12183 @Override
12184 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
12185 String callingFeatureId) {
12186 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12187 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
12188 LocationAccessPolicy.checkLocationPermission(mApp,
12189 new LocationAccessPolicy.LocationPermissionQuery.Builder()
12190 .setCallingPackage(callingPackage)
12191 .setCallingFeatureId(callingFeatureId)
12192 .setCallingPid(Binder.getCallingPid())
12193 .setCallingUid(Binder.getCallingUid())
12194 .setMethod("getLastKnownCellIdentity")
12195 .setLogAsInfo(true)
12196 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
12197 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
12198 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
12199 .build());
12200
12201 boolean hasFinePermission =
12202 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
12203 if (!hasFinePermission
12204 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
12205 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070012206 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070012207 }
12208
12209 final long identity = Binder.clearCallingIdentity();
12210 try {
12211 Phone phone = getPhone(subId);
12212 if (phone == null) return null;
12213 ServiceStateTracker sst = phone.getServiceStateTracker();
12214 if (sst == null) return null;
12215 return sst.getLastKnownCellIdentity();
12216 } finally {
12217 Binder.restoreCallingIdentity(identity);
12218 }
12219 }
Jack Yu4c0a5502021-12-03 23:58:26 -080012220
jimsun3b9ccac2021-10-26 15:01:23 +080012221 /**
12222 * Sets the modem service class Name that Telephony will bind to.
12223 *
12224 * @param serviceName The class name of the modem service.
12225 * @return true if the operation is succeed, otherwise false.
12226 */
12227 public boolean setModemService(String serviceName) {
12228 Log.d(LOG_TAG, "setModemService - " + serviceName);
12229 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
12230 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012231 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12232 "setModemService");
jimsun3b9ccac2021-10-26 15:01:23 +080012233 return mPhoneConfigurationManager.setModemService(serviceName);
12234 }
12235
12236 /**
12237 * Return the class name of the currently bounded modem service.
12238 *
12239 * @return the class name of the modem service.
12240 */
12241 public String getModemService() {
12242 String result;
12243 Log.d(LOG_TAG, "getModemService");
12244 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
12245 TelephonyPermissions
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012246 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
jimsun3b9ccac2021-10-26 15:01:23 +080012247 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
12248 "getModemService");
12249 result = mPhoneConfigurationManager.getModemService();
12250 Log.d(LOG_TAG, "result = " + result);
12251 return result;
12252 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012253
12254 @Override
12255 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
12256 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
12257 mApp.enforceCallingOrSelfPermission(
12258 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
12259 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12260
12261 final long identity = Binder.clearCallingIdentity();
12262 try {
12263 Phone phone = getPhone(subId);
12264 if (phone == null) return;
Grant Menke63ade122023-01-20 14:31:54 -080012265 Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone
12266 + ", hasService=" + hasService + ", callingPackage=" + callingPackage);
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080012267 phone.setVoiceServiceStateOverride(hasService);
12268 } finally {
12269 Binder.restoreCallingIdentity(identity);
12270 }
12271 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012272
12273 /**
12274 * set removable eSIM as default eUICC.
12275 *
12276 * @hide
12277 */
12278 @Override
12279 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
12280 enforceModifyPermission();
12281 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12282
12283 final long identity = Binder.clearCallingIdentity();
12284 try {
12285 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
12286 } finally {
12287 Binder.restoreCallingIdentity(identity);
12288 }
12289 }
12290
12291 /**
12292 * Returns whether the removable eSIM is default eUICC or not.
12293 *
12294 * @hide
12295 */
12296 @Override
12297 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
12298 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
12299 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
12300
12301 final long identity = Binder.clearCallingIdentity();
12302 try {
12303 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
12304 } finally {
12305 Binder.restoreCallingIdentity(identity);
12306 }
12307 }
12308
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012309 /**
12310 * Get the component name of the default app to direct respond-via-message intent for the
12311 * user associated with this subscription, update the cache if there is no respond-via-message
12312 * application currently configured for this user.
12313 * @return component name of the app and class to direct Respond Via Message intent to, or
12314 * {@code null} if the functionality is not supported.
12315 * @hide
12316 */
12317 @Override
12318 public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId,
12319 boolean updateIfNeeded) {
12320 enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication");
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000012321
Aishwarya Mallampati5e581e12023-01-17 21:57:06 +000012322 Context context = getPhoneFromSubIdOrDefault(subId).getContext();
12323
Aishwarya Mallampatifbc70d32022-11-10 20:33:02 +000012324 UserHandle userHandle = null;
12325 final long identity = Binder.clearCallingIdentity();
12326 try {
12327 userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId);
12328 } finally {
12329 Binder.restoreCallingIdentity(identity);
12330 }
12331 return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context,
12332 updateIfNeeded, userHandle);
12333 }
Jack Yuf5badd92022-12-08 00:50:53 -080012334
12335 /**
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012336 * Set whether the device is able to connect with null ciphering or integrity
12337 * algorithms. This is a global setting and will apply to all active subscriptions
12338 * and all new subscriptions after this.
12339 *
12340 * @param enabled when true, null cipher and integrity algorithms are allowed.
12341 * @hide
12342 */
12343 @Override
12344 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
12345 public void setNullCipherAndIntegrityEnabled(boolean enabled) {
12346 enforceModifyPermission();
12347 checkForNullCipherAndIntegritySupport();
12348
12349 // Persist the state of our preference. Each GsmCdmaPhone instance is responsible
12350 // for listening to these preference changes and applying them immediately.
12351 SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
12352 editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled);
12353 editor.apply();
12354
12355 for (Phone phone: PhoneFactory.getPhones()) {
12356 phone.handleNullCipherEnabledChange();
12357 }
12358 }
12359
12360
12361 /**
12362 * Get whether the device is able to connect with null ciphering or integrity
12363 * algorithms. Note that this retrieves the phone-global preference and not
12364 * the state of the radio.
12365 *
12366 * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied
12367 * @throws UnsupportedOperationException if the device does not support the minimum HAL
12368 * version for this feature.
12369 * @hide
12370 */
12371 @Override
12372 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
12373 public boolean isNullCipherAndIntegrityPreferenceEnabled() {
12374 enforceReadPermission();
12375 checkForNullCipherAndIntegritySupport();
12376 return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference();
12377 }
12378
12379 private void checkForNullCipherAndIntegritySupport() {
12380 if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) {
12381 throw new UnsupportedOperationException(
12382 "Null cipher and integrity operations require HAL 2.1 or above");
12383 }
Gil Cukierman92cc7db2023-01-06 19:25:53 +000012384 if (!getDefaultPhone().isNullCipherAndIntegritySupported()) {
12385 throw new UnsupportedOperationException(
12386 "Null cipher and integrity operations unsupported by modem");
12387 }
Gil Cukierman1c0eb932022-12-06 22:28:24 +000012388 }
12389
12390 /**
Jack Yuf5badd92022-12-08 00:50:53 -080012391 * Get the SIM state for the slot index.
12392 * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN}
12393 *
12394 * @return SIM state as the ordinal of {@link IccCardConstants.State}
12395 */
12396 @Override
12397 @SimState
12398 public int getSimStateForSlotIndex(int slotIndex) {
12399 IccCardConstants.State simState;
12400 if (slotIndex < 0) {
12401 simState = IccCardConstants.State.UNKNOWN;
12402 } else {
12403 Phone phone = null;
12404 try {
12405 phone = PhoneFactory.getPhone(slotIndex);
12406 } catch (IllegalStateException e) {
12407 // ignore
12408 }
12409 if (phone == null) {
12410 simState = IccCardConstants.State.UNKNOWN;
12411 } else {
12412 IccCard icc = phone.getIccCard();
12413 if (icc == null) {
12414 simState = IccCardConstants.State.UNKNOWN;
12415 } else {
12416 simState = icc.getState();
12417 }
12418 }
12419 }
12420 return simState.ordinal();
12421 }
Hui Wang9b5793a2022-12-05 14:38:06 -060012422
12423 /**
12424 * Get current cell broadcast ranges.
12425 */
12426 @Override
12427 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12428 public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) {
12429 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12430 "getCellBroadcastIdRanges");
12431 final long identity = Binder.clearCallingIdentity();
12432 try {
12433 return getPhone(subId).getCellBroadcastIdRanges();
12434 } finally {
12435 Binder.restoreCallingIdentity(identity);
12436 }
12437 }
12438
12439 /**
12440 * Set reception of cell broadcast messages with the list of the given ranges
12441 *
12442 * @param ranges the list of {@link CellBroadcastIdRange} to be enabled
12443 */
12444 @Override
12445 @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS)
12446 public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges,
12447 @Nullable IIntegerConsumer callback) {
12448 mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS,
12449 "setCellBroadcastIdRanges");
12450 final long identity = Binder.clearCallingIdentity();
12451 try {
12452 Phone phone = getPhoneFromSubId(subId);
12453 if (DBG) {
12454 log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone);
12455 }
12456 phone.setCellBroadcastIdRanges(ranges, result -> {
12457 if (callback != null) {
12458 try {
12459 callback.accept(result);
12460 } catch (RemoteException e) {
12461 Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available.");
12462 }
12463 }
12464 });
12465 } finally {
12466 Binder.restoreCallingIdentity(identity);
12467 }
12468 }
Hunsuk Choi42cc62a2022-10-16 06:03:40 +000012469
12470 /**
12471 * Returns whether the device supports the domain selection service.
12472 *
12473 * @return {@code true} if the device supports the domain selection service.
12474 */
12475 @Override
12476 public boolean isDomainSelectionSupported() {
12477 mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
12478 "isDomainSelectionSupported");
12479
12480 final long identity = Binder.clearCallingIdentity();
12481 try {
12482 return DomainSelectionResolver.getInstance().isDomainSelectionSupported();
12483 } finally {
12484 Binder.restoreCallingIdentity(identity);
12485 }
12486 }
arunvoddud5c6ce02022-12-11 06:03:12 +000012487
12488 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012489 * Enable or disable the satellite modem. If the satellite modem is enabled, this will also
12490 * disable the cellular modem, and if the satellite modem is disabled, this will also re-enable
12491 * the cellular modem.
Sarah Chin503828c2023-02-01 23:54:20 -080012492 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012493 * @param subId The subId to set satellite enabled for.
12494 * @param enable {@code true} to enable the satellite modem and {@code false} to disable.
12495 * @param callback The callback to get the error code of the request.
Sarah Chin503828c2023-02-01 23:54:20 -080012496 *
12497 * @throws SecurityException if the caller doesn't have the required permission.
12498 */
12499 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012500 public void setSatelliteEnabled(int subId, boolean enable, @NonNull IIntegerConsumer callback) {
12501 enforceSatelliteCommunicationPermission("setSatelliteEnabled");
12502 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012503 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012504 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12505 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012506 }
Sarah Chin503828c2023-02-01 23:54:20 -080012507
12508 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012509 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012510 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
12511 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012512 }
12513
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012514 Phone phone = getPhoneOrDefault(validSubId, "setSatelliteEnabled");
Sarah Chin503828c2023-02-01 23:54:20 -080012515 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012516 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12517 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012518 }
12519
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012520 Pair<Boolean, Consumer<Integer>> arg = new Pair<>(enable, result);
12521 sendRequestAsync(CMD_SET_SATELLITE_ENABLED, arg, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012522 }
12523
12524 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012525 * Request to get whether the satellite modem is enabled.
Sarah Chin503828c2023-02-01 23:54:20 -080012526 *
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012527 * @param subId The subId to check whether satellite is enabled for.
12528 * @param result The result receiver that returns whether the satellite modem is enabled
12529 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012530 *
12531 * @throws SecurityException if the caller doesn't have the required permission.
12532 */
12533 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012534 public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) {
12535 enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012536 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012537 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12538 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012539 }
Sarah Chin503828c2023-02-01 23:54:20 -080012540
12541 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012542 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012543 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
12544 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012545 }
12546
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012547 Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteEnabled");
Sarah Chin503828c2023-02-01 23:54:20 -080012548 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012549 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12550 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012551 }
12552
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012553 sendRequest(CMD_IS_SATELLITE_ENABLED, result, subId);
Sarah Chin503828c2023-02-01 23:54:20 -080012554 }
12555
12556 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012557 * Request to get whether the satellite service is supported on the device.
Sarah Chin503828c2023-02-01 23:54:20 -080012558 *
12559 * @param subId The subId to check satellite service support for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012560 * @param result The result receiver that returns whether the satellite service is supported on
12561 * the device if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012562 */
12563 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012564 public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012565 synchronized (mIsSatelliteSupportedLock) {
12566 if (mIsSatelliteSupported != null) {
12567 /* We have already successfully queried the satellite modem. */
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012568 Bundle bundle = new Bundle();
12569 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, mIsSatelliteSupported);
12570 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, bundle);
12571 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012572 }
12573 }
Sarah Chin503828c2023-02-01 23:54:20 -080012574
12575 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012576 Phone phone = getPhoneOrDefault(validSubId, "requestIsSatelliteSupported");
Sarah Chin503828c2023-02-01 23:54:20 -080012577 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012578 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12579 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012580 }
12581
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012582 sendRequestAsync(CMD_IS_SATELLITE_SUPPORTED, result, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012583 }
12584
12585 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012586 * Request to get the {@link SatelliteCapabilities} of the satellite service.
Sarah Chin503828c2023-02-01 23:54:20 -080012587 *
12588 * @param subId The subId to get the satellite capabilities for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012589 * @param result The result receiver that returns the {@link SatelliteCapabilities}
12590 * if the request is successful or an error code if the request failed.
Sarah Chin503828c2023-02-01 23:54:20 -080012591 *
12592 * @throws SecurityException if the caller doesn't have required permission.
12593 */
12594 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012595 public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) {
12596 enforceSatelliteCommunicationPermission("requestSatelliteCapabilities");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012597 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012598 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12599 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012600 }
Sarah Chin503828c2023-02-01 23:54:20 -080012601
12602 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012603 Phone phone = getPhoneOrDefault(validSubId, "requestSatelliteCapabilities");
Sarah Chin503828c2023-02-01 23:54:20 -080012604 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012605 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12606 return;
Sarah Chin503828c2023-02-01 23:54:20 -080012607 }
12608
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012609 sendRequestAsync(CMD_GET_SATELLITE_CAPABILITIES, result, phone, null);
Sarah Chin503828c2023-02-01 23:54:20 -080012610 }
12611
12612 /**
Sarah Chineccfbd12023-01-20 19:00:35 -080012613 * Start receiving satellite position updates.
12614 * This can be called by the pointing UI when the user starts pointing to the satellite.
12615 * Modem should continue to report the pointing input as the device or satellite moves.
12616 *
12617 * @param subId The subId to start satellite position updates for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012618 * @param errorCallback The callback to get the error code of the request.
Sarah Chineccfbd12023-01-20 19:00:35 -080012619 * @param callback The callback to notify of changes in satellite position.
Sarah Chin503828c2023-02-01 23:54:20 -080012620 *
12621 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012622 */
12623 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012624 public void startSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012625 @NonNull ISatelliteStateListener callback) {
Sarah Chinf75afa72023-02-01 01:32:19 -080012626 enforceSatelliteCommunicationPermission("startSatellitePositionUpdates");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012627 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012628 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012629 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12630 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012631 }
Sarah Chinf75afa72023-02-01 01:32:19 -080012632
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012633 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012634 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012635 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
12636 return;
Sarah Chinf75afa72023-02-01 01:32:19 -080012637 }
12638
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012639 Phone phone = getPhoneOrDefault(validSubId, "startSatellitePositionUpdates");
Sarah Chineccfbd12023-01-20 19:00:35 -080012640 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012641 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12642 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012643 }
12644
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012645 if (mSatellitePositionUpdateHandlers.containsKey(callback.asBinder())) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012646 if (DBG) {
12647 log("startSatellitePositionUpdates: callback already registered: "
12648 + callback.asBinder());
12649 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012650 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
12651 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012652 }
12653
12654 SatellitePositionUpdateHandler handler =
12655 new SatellitePositionUpdateHandler(callback, Looper.getMainLooper());
12656 phone.registerForSatellitePointingInfoChanged(handler,
12657 SatellitePositionUpdateHandler.EVENT_POSITION_UPDATE, null);
12658 phone.registerForSatelliteMessagesTransferComplete(handler,
12659 SatellitePositionUpdateHandler.EVENT_MESSAGE_TRANSFER_STATE_UPDATE, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012660 mSatellitePositionUpdateHandlers.put(callback.asBinder(), handler);
Sarah Chineccfbd12023-01-20 19:00:35 -080012661
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012662 sendRequestAsync(CMD_START_SATELLITE_POSITION_UPDATES, result, phone, null);
Sarah Chineccfbd12023-01-20 19:00:35 -080012663 }
12664
12665 /**
12666 * Stop receiving satellite position updates.
12667 * This can be called by the pointing UI when the user stops pointing to the satellite.
12668 *
12669 * @param subId The subId to stop satellite position updates for.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012670 * @param errorCallback The callback to get the error code of the request.
12671 * @param callback The callback that was passed to {@link
12672 * #startSatellitePositionUpdates(int, IIntegerConsumer, ISatelliteStateListener)}
Sarah Chin503828c2023-02-01 23:54:20 -080012673 *
12674 * @throws SecurityException if the caller doesn't have the required permission.
Sarah Chineccfbd12023-01-20 19:00:35 -080012675 */
12676 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012677 public void stopSatellitePositionUpdates(int subId, @NonNull IIntegerConsumer errorCallback,
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012678 @NonNull ISatelliteStateListener callback) {
Sarah Chinf75afa72023-02-01 01:32:19 -080012679 enforceSatelliteCommunicationPermission("stopSatellitePositionUpdates");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012680 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012681 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012682 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12683 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012684 }
Sarah Chinf75afa72023-02-01 01:32:19 -080012685
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012686 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012687 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012688 result.accept(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED);
12689 return;
Sarah Chinf75afa72023-02-01 01:32:19 -080012690 }
12691
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012692 Phone phone = getPhoneOrDefault(validSubId, "stopSatellitePositionUpdates");
Sarah Chineccfbd12023-01-20 19:00:35 -080012693 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012694 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12695 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012696 }
12697
12698 SatellitePositionUpdateHandler handler =
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012699 mSatellitePositionUpdateHandlers.remove(callback.asBinder());
Sarah Chineccfbd12023-01-20 19:00:35 -080012700 if (handler == null) {
12701 loge("stopSatellitePositionUpdates: No SatellitePositionArgument");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012702 result.accept(SatelliteManager.SATELLITE_INVALID_ARGUMENTS);
12703 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012704 } else {
12705 phone.unregisterForSatellitePointingInfoChanged(handler);
12706 phone.unregisterForSatelliteMessagesTransferComplete(handler);
12707 }
12708
12709 if (!mSatellitePositionUpdateHandlers.isEmpty()) {
12710 log("stopSatellitePositionUpdates: other listeners still exist.");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012711 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
12712 return;
Sarah Chineccfbd12023-01-20 19:00:35 -080012713 }
12714
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012715 sendRequestAsync(CMD_STOP_SATELLITE_POSITION_UPDATES, result, phone, null);
Sarah Chineccfbd12023-01-20 19:00:35 -080012716 }
12717
12718 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012719 * Request to get the maximum number of characters per text message on satellite.
12720 *
12721 * @param subId The subId of the subscription.
12722 * @param result The result receiver that returns the maximum number of characters per text
12723 * message on satellite if the request is successful or an error code
12724 * if the request failed.
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012725 *
12726 * @throws SecurityException if the caller doesn't have the required permission.
12727 */
12728 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012729 public void requestMaxCharactersPerSatelliteTextMessage(int subId,
12730 @NonNull ResultReceiver result) {
12731 enforceSatelliteCommunicationPermission("requestMaxCharactersPerSatelliteTextMessage");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012732 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012733 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12734 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012735 }
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012736
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012737 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012738 if (!isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012739 result.send(SatelliteManager.SATELLITE_SERVICE_NOT_PROVISIONED, null);
12740 return;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012741 }
12742
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012743 Phone phone = getPhoneOrDefault(validSubId, "requestMaxCharactersPerSatelliteTextMessage");
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012744 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012745 result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, null);
12746 return;
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012747 }
12748
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012749 sendRequestAsync(CMD_GET_MAX_CHAR_PER_SATELLITE_TEXT_MSG, result, phone, null);
Aishwarya Mallampati60fe1132023-01-24 19:07:21 +000012750 }
12751
12752 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012753 * Register the subscription with a satellite provider.
12754 * This is needed to register the subscription if the provider allows dynamic registration.
12755 *
12756 * @param subId The subId of the subscription to be provisioned.
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012757 * @param token The token to be used as a unique identifier for provisioning with satellite
12758 * gateway.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012759 * @param callback The callback to get the error code of the request.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012760 * @return The signal transport used by the caller to cancel the provision request,
12761 * or {@code null} if the request failed.
12762 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012763 * @throws SecurityException if the caller doesn't have the required permission.
12764 */
12765 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012766 @Nullable public ICancellationSignal provisionSatelliteService(int subId,
12767 @NonNull String token, @NonNull IIntegerConsumer callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012768 enforceSatelliteCommunicationPermission("provisionSatelliteService");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012769 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012770 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012771 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012772 return null;
12773 }
12774
12775 final int validSubId = getValidSatelliteSubId(subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012776 Phone phone = getPhoneOrDefault(validSubId, "provisionSatelliteService");
12777 if (phone == null) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012778 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012779 return null;
12780 }
12781
12782 if (mSatelliteProvisionCallbacks.containsKey(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012783 result.accept(SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012784 return null;
12785 }
12786
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012787 if (isSatelliteProvisioned(validSubId)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012788 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012789 return null;
12790 }
12791
12792 sendRequestAsync(CMD_PROVISION_SATELLITE_SERVICE,
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012793 new ProvisionSatelliteServiceArgument(token, result, validSubId), phone, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012794
12795 ICancellationSignal cancelTransport = CancellationSignal.createTransport();
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012796 CancellationSignal.fromTransport(cancelTransport).setOnCancelListener(() -> {
12797 sendRequestAsync(CMD_DEPROVISION_SATELLITE_SERVICE,
12798 new ProvisionSatelliteServiceArgument(token, null, validSubId),
12799 phone, null);
12800 });
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012801 return cancelTransport;
12802 }
12803
12804 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012805 * Unregister the device/subscription with the satellite provider.
12806 * This is needed if the provider allows dynamic registration. Once deprovisioned,
12807 * {@link SatelliteCallback.SatelliteProvisionStateListener#onSatelliteProvisionStateChanged}
12808 * should report as deprovisioned.
12809 *
12810 * @param subId The subId of the subscription to be deprovisioned.
12811 * @param token The token of the device/subscription to be deprovisioned.
12812 * @param callback The callback to get the error code of the request.
12813 *
12814 * @throws SecurityException if the caller doesn't have the required permission.
12815 */
12816 @Override
12817 public void deprovisionSatelliteService(int subId,
12818 @NonNull String token, @NonNull IIntegerConsumer callback) {
12819 enforceSatelliteCommunicationPermission("deprovisionSatelliteService");
12820 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(callback::accept);
12821 if (!isSatelliteSupported()) {
12822 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12823 return;
12824 }
12825
12826 final int validSubId = getValidSatelliteSubId(subId);
12827 if (!isSatelliteProvisioned(validSubId)) {
12828 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
12829 return;
12830 }
12831
12832 Phone phone = getPhoneOrDefault(validSubId, "deprovisionSatelliteService");
12833 if (phone == null) {
12834 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12835 return;
12836 }
12837
12838 sendRequestAsync(CMD_DEPROVISION_SATELLITE_SERVICE,
12839 new ProvisionSatelliteServiceArgument(token, result, validSubId), phone, null);
12840 }
12841
12842 /**
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012843 * Register for the satellite provision state change.
12844 *
12845 * @param subId The subId of the subscription associated with the satellite service.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012846 * @param errorCallback The callback to get the error code of the request.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012847 * @param callback The callback to handle the satellite provision state changed event.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012848 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012849 * @throws SecurityException if the caller doesn't have the required permission.
12850 */
12851 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012852 public void registerForSatelliteProvisionStateChanged(int subId,
12853 @NonNull IIntegerConsumer errorCallback, @NonNull ISatelliteStateListener callback) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012854 enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged");
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012855 registerForSatelliteProvisionStateChangedInternal(subId, errorCallback, callback);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012856 }
12857
12858 /**
12859 * Unregister for the satellite provision state change.
12860 *
12861 * @param subId The subId of the subscription associated with the satellite service.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012862 * @param errorCallback The callback to get the error code of the request.
12863 * @param callback The callback that was passed to {@link
12864 * #registerForSatelliteProvisionStateChanged(int, IIntegerConsumer, ISatelliteStateListener)}.
12865 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012866 * @throws SecurityException if the caller doesn't have the required permission.
12867 */
12868 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012869 public void unregisterForSatelliteProvisionStateChanged(int subId,
12870 @NonNull IIntegerConsumer errorCallback, @NonNull ISatelliteStateListener callback) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012871 enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged");
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012872 Consumer<Integer> result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012873 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012874 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
12875 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012876 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012877
12878 final int validSubId = getValidSatelliteSubId(subId);
12879 SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler =
12880 mSatelliteProvisionStateChangedHandlers.get(validSubId);
12881 if (satelliteProvisionStateChangedHandler != null) {
12882 if (satelliteProvisionStateChangedHandler.removeListener(callback)) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012883 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
12884 return;
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012885 }
12886 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012887 result.accept(SatelliteManager.SATELLITE_INVALID_ARGUMENTS);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012888 }
12889
12890 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012891 * Request to get whether the device is provisioned with a satellite provider.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012892 *
12893 * @param subId The subId of the subscription associated with the satellite service.
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012894 * @param result The result receiver that returns whether the device is provisioned with a
12895 * satellite provider if the request is successful or an error code if the
12896 * request failed.
12897 *
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012898 * @throws SecurityException if the caller doesn't have the required permission.
12899 */
12900 @Override
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012901 public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) {
12902 enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned");
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012903 if (!isSatelliteSupported()) {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012904 result.send(SatelliteManager.SATELLITE_NOT_SUPPORTED, null);
12905 return;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012906 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012907
12908 final int validSubId = getValidSatelliteSubId(subId);
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012909 Bundle bundle = new Bundle();
12910 bundle.putBoolean(SatelliteManager.KEY_SATELLITE_PROVISIONED,
12911 isSatelliteProvisioned(validSubId));
12912 result.send(SatelliteManager.SATELLITE_ERROR_NONE, bundle);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012913 }
12914
12915 private void handleCmdProvisionSatelliteService(@NonNull ProvisionSatelliteServiceArgument arg,
12916 @NonNull Phone phone, Message onCompleted) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012917 if (!mSatelliteProvisionCallbacks.containsKey(arg.subId)) {
12918 mSatelliteProvisionCallbacks.put(arg.subId, arg.callback);
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012919 phone.provisionSatelliteService(onCompleted, arg.token);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012920 } else {
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012921 arg.callback.accept(SatelliteManager.SATELLITE_SERVICE_PROVISION_IN_PROGRESS);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012922 }
12923 }
12924
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012925 private void handleEventProvisionSatelliteServiceDone(
12926 @NonNull ProvisionSatelliteServiceArgument arg,
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012927 @SatelliteManager.SatelliteError int result) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012928 log("handleEventProvisionSatelliteServiceDone: result="
12929 + result + ", subId=" + arg.subId);
12930
12931 Consumer<Integer> callback = mSatelliteProvisionCallbacks.remove(arg.subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012932 if (callback == null) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012933 loge("handleEventProvisionSatelliteServiceDone: callback is null for subId="
12934 + arg.subId);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012935 return;
12936 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080012937 callback.accept(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012938
Thomas Nguyene77de6d2023-02-10 17:42:43 -080012939 if (result == SatelliteManager.SATELLITE_ERROR_NONE) {
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012940 setSatelliteProvisioned(arg.subId, true);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012941 }
12942
12943 /**
12944 * We need to update satellite provision status in SubscriptionController
12945 * or SatelliteController.
12946 * TODO (b/267826133) we need to do this for all subscriptions on the device.
12947 */
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012948 registerForSatelliteProvisionStateChangedInternal(arg.subId, null, null);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012949 }
12950
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012951 private void handleCmdDeprovisionSatelliteService(
12952 @NonNull ProvisionSatelliteServiceArgument arg,
12953 @NonNull Phone phone, Message onCompleted) {
12954 if (arg == null) {
12955 loge("handleCmdDeprovisionSatelliteService: arg is null");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012956 return;
12957 }
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012958 if (phone == null) {
12959 loge("handleCmdDeprovisionSatelliteService: phone is null");
12960 if (arg.callback != null) {
12961 arg.callback.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
12962 }
12963 return;
12964 }
12965 phone.deprovisionSatelliteService(onCompleted, arg.token);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012966 }
12967
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012968 private void handleEventDeprovisionSatelliteServiceDone(
12969 @NonNull ProvisionSatelliteServiceArgument arg,
12970 @SatelliteManager.SatelliteError int result) {
12971 if (arg == null) {
12972 loge("handleEventDeprovisionSatelliteServiceDone: arg is null");
12973 return;
12974 }
12975 log("handleEventDeprovisionSatelliteServiceDone: result="
12976 + result + ", subId=" + arg.subId);
12977
12978 if (arg.callback != null) {
12979 arg.callback.accept(result);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012980 }
12981
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080012982 if (result == SatelliteManager.SATELLITE_ERROR_NONE) {
12983 setSatelliteProvisioned(arg.subId, false);
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012984 }
Thomas Nguyen8ee49682023-02-01 11:46:09 -080012985 }
12986
12987 private Phone getPhoneOrDefault(int subId, String caller) {
12988 Phone phone = getPhone(subId);
12989 if (phone == null) {
12990 loge(caller + " called with invalid subId: " + subId
12991 + ". Retrying with default phone.");
12992 phone = getDefaultPhone();
12993 if (phone == null) {
12994 loge(caller + " failed with no phone object.");
12995 }
12996 }
12997 return phone;
12998 }
12999
13000 /**
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013001 * Check if satellite is provisioned for a subscription or the device.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013002 *
13003 * Note: this is the version without permission check for telephony internal use only. The
13004 * caller need to take care of the permission check.
13005 */
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013006 private boolean isSatelliteProvisioned(int subId) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013007 if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
13008 if (mSubscriptionController == null) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013009 loge("isSatelliteProvisioned mSubscriptionController is null");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013010 return false;
13011 }
13012
13013 String strResult = mSubscriptionController.getSubscriptionProperty(
13014 subId, SubscriptionManager.SATELLITE_ENABLED);
13015 if (strResult != null) {
13016 int intResult = Integer.parseInt(strResult);
13017 return (intResult == 1) ? true : false;
13018 }
13019 } else {
13020 //TODO (b/267826133): check via SatelliteController
13021 }
13022 return false;
13023 }
13024
13025 /**
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013026 * Set satellite provisioned for a subscription or the device.
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013027 *
13028 * The permission {@link android.Manifest.permission#MODIFY_PHONE_STATE} will be enforced by
13029 * {@link SubscriptionController} when setting satellite enabled for an active subscription.
13030 * Otherwise, {@link android.Manifest.permission#SATELLITE_COMMUNICATION} will be enforced.
13031 */
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013032 private synchronized void setSatelliteProvisioned(int subId, boolean isEnabled) {
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013033 if (subId != SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
13034 if (mSubscriptionController == null) {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013035 loge("setSatelliteProvisioned mSubscriptionController is null");
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013036 return;
13037 }
13038 mSubscriptionController.setSubscriptionProperty(
13039 subId, SubscriptionManager.SATELLITE_ENABLED, isEnabled ? "1" : "0");
13040 } else {
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013041 //TODO (b/267826133): set via SatelliteController
Thomas Nguyen8ee49682023-02-01 11:46:09 -080013042 }
13043 }
13044
13045 private int getValidSatelliteSubId(int subId) {
13046 if (mSubscriptionController == null) {
13047 loge("getValidSatelliteSubId mSubscriptionController is null. "
13048 + "Use DEFAULT_SUBSCRIPTION_ID for subId=" + subId);
13049 return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
13050 }
13051 final long identity = Binder.clearCallingIdentity();
13052 try {
13053 Context context = getDefaultPhone().getContext();
13054 if (mSubscriptionController.isActiveSubId(
13055 subId, context.getOpPackageName(), context.getAttributionTag())) {
13056 return subId;
13057 }
13058 } finally {
13059 Binder.restoreCallingIdentity(identity);
13060 }
13061 if (DBG) log("getValidSatelliteSubId: use DEFAULT_SUBSCRIPTION_ID for subId=" + subId);
13062 return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
13063 }
13064
13065 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013066 * If we have not successfully queried the satellite modem for its satellite service support,
13067 * we will retry the query one more time. Otherwise, we will return the queried result.
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013068 */
13069 private boolean isSatelliteSupported() {
13070 synchronized (mIsSatelliteSupportedLock) {
13071 if (mIsSatelliteSupported != null) {
13072 /* We have already successfully queried the satellite modem. */
13073 return mIsSatelliteSupported;
13074 }
13075 }
13076 /**
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013077 * We have not successfully checked whether the modem supports satellite service.
13078 * Thus, we need to retry it now.
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013079 */
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013080 requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
13081 mSatelliteSupportedReceiver);
13082 return false;
13083 }
13084
13085 /**
13086 * Get the {@link SatelliteManager.SatelliteError} from the provided result.
13087 * @param ar AsyncResult used to determine the error code.
13088 * @param caller The satellite request.
13089 * @param checkResult Whether to check if the result exists.
13090 * @return The {@link SatelliteManager.SatelliteError} error code from the request.
13091 */
13092 @SatelliteManager.SatelliteError private int getSatelliteError(@NonNull AsyncResult ar,
13093 @NonNull String caller, boolean checkResult) {
13094 int errorCode;
13095 if (ar.exception == null) {
13096 errorCode = SatelliteManager.SATELLITE_ERROR_NONE;
13097 if (checkResult && ar.result == null) {
13098 loge(caller + ": result is null");
13099 errorCode = SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
13100 }
13101 } else {
13102 errorCode = SatelliteManager.SATELLITE_ERROR;
13103 if (ar.exception instanceof CommandException) {
13104 CommandException.Error error =
13105 ((CommandException) (ar.exception)).getCommandError();
13106 errorCode = RILUtils.convertToSatelliteError(error);
13107 loge(caller + " CommandException: " + ar.exception);
13108 } else {
13109 loge(caller + " unknown exception: " + ar.exception);
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013110 }
13111 }
Sarah Chin4a9e8b82023-02-10 21:10:57 -080013112 log(caller + " error: " + errorCode);
13113 return errorCode;
Thomas Nguyene77de6d2023-02-10 17:42:43 -080013114 }
13115
13116 /**
Thomas Nguyen4a29b8e2023-02-13 09:26:15 -080013117 * Register for the satellite provision state change.
13118 *
13119 * @param subId The subId of the subscription associated with the satellite service.
13120 * @param errorCallback The callback to get the error code of the request.
13121 * @param callback The callback to handle the satellite provision state changed event.
13122 */
13123 private void registerForSatelliteProvisionStateChangedInternal(int subId,
13124 @Nullable IIntegerConsumer errorCallback, @Nullable ISatelliteStateListener callback) {
13125 Consumer<Integer> result = null;
13126 if (errorCallback != null) {
13127 result = FunctionalUtils.ignoreRemoteException(errorCallback::accept);
13128 }
13129 if (!isSatelliteSupported()) {
13130 if (result != null) {
13131 result.accept(SatelliteManager.SATELLITE_NOT_SUPPORTED);
13132 }
13133 return;
13134 }
13135
13136 final int validSubId = getValidSatelliteSubId(subId);
13137 Phone phone = getPhoneOrDefault(validSubId, "registerForSatelliteProvisionStateChanged");
13138 if (phone == null) {
13139 if (result != null) {
13140 result.accept(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE);
13141 }
13142 return;
13143 }
13144
13145 SatelliteProvisionStateChangedHandler satelliteProvisionStateChangedHandler =
13146 mSatelliteProvisionStateChangedHandlers.get(validSubId);
13147 if (satelliteProvisionStateChangedHandler == null) {
13148 satelliteProvisionStateChangedHandler = new SatelliteProvisionStateChangedHandler(
13149 Looper.getMainLooper(), validSubId);
13150 phone.registerForSatelliteProvisionStateChanged(satelliteProvisionStateChangedHandler,
13151 SatelliteProvisionStateChangedHandler.EVENT_PROVISION_STATE_CHANGED, null);
13152 }
13153
13154 if (callback != null) {
13155 satelliteProvisionStateChangedHandler.addListener(callback);
13156 }
13157 mSatelliteProvisionStateChangedHandlers.put(
13158 validSubId, satelliteProvisionStateChangedHandler);
13159 if (result != null) {
13160 result.accept(SatelliteManager.SATELLITE_ERROR_NONE);
13161 }
13162 }
13163
13164 /**
arunvoddud5c6ce02022-12-11 06:03:12 +000013165 * Check whether the caller (or self, if not processing an IPC) can read device identifiers.
13166 *
13167 * <p>This method behaves in one of the following ways:
13168 * <ul>
13169 * <li>return true : if the calling package has the appop permission {@link
13170 * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </>
13171 * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE
13172 * permission, the calling package passes a DevicePolicyManager Device Owner / Profile
13173 * Owner device identifier access check, or the calling package has carrier privileges</>
13174 * <li>throw SecurityException: if the caller does not meet any of the requirements.
13175 * </ul>
13176 */
13177 private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context,
13178 String callingPackage, @Nullable String callingFeatureId, String message) {
13179 for (Phone phone : PhoneFactory.getPhones()) {
13180 if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context,
13181 phone.getSubId(), callingPackage, callingFeatureId, message)) {
13182 return true;
13183 }
13184 }
13185 return false;
13186 }
arunvoddud7401012022-12-15 16:08:12 +000013187
13188 /**
Jack Yufa8ed012023-02-11 15:42:28 -080013189 * @return The subscription manager service instance.
13190 */
13191 public SubscriptionManagerService getSubscriptionManagerService() {
13192 return SubscriptionManagerService.getInstance();
13193 }
13194
13195 /**
arunvoddud7401012022-12-15 16:08:12 +000013196 * Class binds the consumer[callback] and carrierId.
13197 */
13198 private static class CallerCallbackInfo {
13199 private final Consumer<Integer> mConsumer;
13200 private final int mCarrierId;
13201
13202 public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) {
13203 mConsumer = consumer;
13204 mCarrierId = carrierId;
13205 }
13206
13207 public Consumer<Integer> getConsumer() {
13208 return mConsumer;
13209 }
13210
13211 public int getCarrierId() {
13212 return mCarrierId;
13213 }
13214 }
Jack Yufa8ed012023-02-11 15:42:28 -080013215}